Skip to content

Commit d61309f

Browse files
committed
collide superballs with cursor
1 parent 6a12b07 commit d61309f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/demo/ents/superball.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ export class SuperballHook implements V.Hook {
1010
ent.sprite.y += ent.superball.vy * v.tick.s
1111

1212
const left = v.cam.x
13-
const right = v.cam.x + v.cam.w - ent.sprite.w
13+
const right = v.cam.x + v.cam.w - ent.sprite.hitbox!.w
1414
const top = v.cam.y
15-
const bottom = v.cam.y + v.cam.h - ent.sprite.h
15+
const bottom = v.cam.y + v.cam.h - ent.sprite.hitbox!.h
16+
17+
if (v.loader.cursor?.sprite.hitsZ(ent.sprite, v.cam)) {
18+
ent.superball.vx = -ent.superball.vx
19+
ent.superball.vy = -ent.superball.vy
20+
ent.sprite.x += ent.superball.vx * 2 * v.tick.s
21+
ent.sprite.y += ent.superball.vy * 2 * v.tick.s
22+
}
1623

1724
if (ent.sprite.x < left) {
1825
ent.sprite.x = left

0 commit comments

Comments
 (0)