A lightweight JavaScript game engine
git clone git://soophie.de/game-engine
28
return true;29
}30
return (dx - rect.shape.width / 2) ** 2 + (dy - rect.shape.height / 2) ** 2 < circle.radius ** 2;31
}31
\ No newline at end of file31
}33
export function collidePoint(object, point) {34
if(object.shape instanceof Shape.Rect) {35
const {x, y, shape: {width, height}} = object;36
return x < point.x && x + width > point.x && y < point.y && y + height > point.y;37
}38
if(object.shape instanceof Shape.Circle) {39
const {x, y, shape: {radius}} = object;40
return Math.sqrt((x - point.x) ** 2 + (y - point.y) ** 2) < radius;41
}42
}
36
render() {37
this.g.clearRect(0, 0, this.width, this.height);38
}39
resize(width, height) {40
this.width = width;41
this.height = height;42
scaleCanvas(this.canvas, this.width, this.height);43
}44
}46
export class Group {
102
add(item) {103
this.items.push(item);104
}100
get() {101
return this.items;105
[Symbol.iterator]() {106
return this.items.values();107
}108
}