diff options
| author | Ribbon <ambiguousmachine@gmail.com> | 2022-02-02 15:38:28 -0800 |
|---|---|---|
| committer | Ribbon <ambiguousmachine@gmail.com> | 2022-02-02 15:38:28 -0800 |
| commit | 0dc11e3e4315cbbfcaec75950a7c106f3b7d73eb (patch) | |
| tree | e9535a7500555ee753f6dbaf324855df55034b70 | |
| parent | 21df32741f726c0fb0dfe75ad71bac778db913f2 (diff) | |
| parent | ab78a5fc2b109c4d028d1abd197fc1575d9d37ab (diff) | |
Merge branch 'main' of https://github.com/1029chris/pico-bhell
| -rw-r--r-- | bullets.lua | 14 | ||||
| -rw-r--r-- | objects.lua | 2 | ||||
| -rw-r--r-- | players.lua | 18 |
3 files changed, 26 insertions, 8 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 diff --git a/objects.lua b/objects.lua index 2dba154..5284b03 100644 --- a/objects.lua +++ b/objects.lua @@ -1,9 +1,11 @@ obj = {} function updateobjs() + foreach(players, function(obj) obj:update() end) foreach(obj, function(obj) obj:update() end) end function drawobjs() + foreach(players, function(obj) obj:draw() end) foreach(obj, function(obj) obj:draw() end) end
\ No newline at end of file diff --git a/players.lua b/players.lua index 92c3646..60227fa 100644 --- a/players.lua +++ b/players.lua @@ -4,8 +4,11 @@ players = {} function addplayer() playercount += 1 local player = {} + player.health = 3 player.x = 18 player.y = 60 + player.w = 8 + player.h = 8 player.ymov = 0 player.id = playercount player.shootcooldown = 0.0 @@ -24,15 +27,15 @@ function addplayer() function player.update(player) --movement if btn(0, player.id) then - player.x -= 2 + player.x -= 1 elseif btn(1, player.id) then - player.x += 2 + player.x += 1 end if btn(2, player.id) then - player.y -= 2 + player.y -= 1 player.ymov = 1 elseif btn(3, player.id) then - player.y += 2 + player.y += 1 player.ymov = -1 else player.ymov = 0 @@ -41,15 +44,14 @@ function addplayer() player.y = mid(0, player.y, 120) --shooting - player.shootcooldown -= 1/30 + player.shootcooldown -= 1/60 if btn(4, player.id) and player.shootcooldown < 0 then - addbullet(player.x+3, player.y, 4, 0, false) + addbullet(player.x+3, player.y, 2, 0, false) player.shootcooldown = 0.1 end end - add(obj, player) - add(players, #obj) + add(players, player) end addplayer()
\ No newline at end of file |
