diff options
| author | 1029chris <1029chris@gmail.com> | 2022-02-02 15:12:58 -0800 |
|---|---|---|
| committer | 1029chris <1029chris@gmail.com> | 2022-02-02 15:12:58 -0800 |
| commit | ab78a5fc2b109c4d028d1abd197fc1575d9d37ab (patch) | |
| tree | 9223c0ed805a991cda6a93ce62788989ebe602a4 /bullets.lua | |
| parent | 2c30b81ec818341251929d11c59e77cfefc5c3e3 (diff) | |
Bullet collision stuff
Diffstat (limited to 'bullets.lua')
| -rw-r--r-- | bullets.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/bullets.lua b/bullets.lua index b7b113d..dad5ba4 100644 --- a/bullets.lua +++ b/bullets.lua @@ -13,9 +13,23 @@ function addbullet(x, y, velx, vely, evil) spr(6, bullet.x, bullet.y) end + function bullet.collide(object, bullet) + if bullet.x >= object.x and bullet.x <= object.x+object.w and bullet.y >= object.y and bullet.y <= object.y+object.h then + cls(4) + end + end + function bullet.update(bullet) + --applying velocity bullet.x += bullet.velx bullet.y += bullet.vely + + --collision detection + if bullet.evil then + foreach(players, bullet.collide(bullet)) + end + + --delete bullet if off screen if bullet.y > 128 or bullet.y < -8 or bullet.x > 128 or bullet.x < -8 then del(obj, bullet) end |
