From ab78a5fc2b109c4d028d1abd197fc1575d9d37ab Mon Sep 17 00:00:00 2001 From: 1029chris <1029chris@gmail.com> Date: Wed, 2 Feb 2022 15:12:58 -0800 Subject: Bullet collision stuff --- bullets.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'bullets.lua') 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 -- cgit