diff options
| author | 1029chris <1029chris@gmail.com> | 2022-02-02 14:34:05 -0800 |
|---|---|---|
| committer | 1029chris <1029chris@gmail.com> | 2022-02-02 14:34:05 -0800 |
| commit | 2c30b81ec818341251929d11c59e77cfefc5c3e3 (patch) | |
| tree | 83c4159edd3072e904572c432a305818fdfcc559 | |
| parent | 29d9e7517dd77038df6f29f17e139b7ef68837ff (diff) | |
Added player controller and real basic bullets
| -rw-r--r-- | bullets.lua | 26 | ||||
| -rw-r--r-- | draw.lua | 3 | ||||
| -rw-r--r-- | objects.lua | 9 | ||||
| -rw-r--r-- | players.lua | 55 | ||||
| -rw-r--r-- | update.lua | 1 |
5 files changed, 94 insertions, 0 deletions
diff --git a/bullets.lua b/bullets.lua new file mode 100644 index 0000000..b7b113d --- /dev/null +++ b/bullets.lua @@ -0,0 +1,26 @@ +bullets = {} + +function addbullet(x, y, velx, vely, evil) + local bullet = {} + + bullet.type = "bullet" + bullet.x = x + bullet.y = y + bullet.velx = velx + bullet.vely = vely + + function bullet.draw(bullet) + spr(6, bullet.x, bullet.y) + end + + function bullet.update(bullet) + bullet.x += bullet.velx + bullet.y += bullet.vely + if bullet.y > 128 or bullet.y < -8 or bullet.x > 128 or bullet.x < -8 then + del(obj, bullet) + end + end + + add(obj, bullet) + add(bullet, #obj) +end
\ No newline at end of file diff --git a/draw.lua b/draw.lua new file mode 100644 index 0000000..01598a3 --- /dev/null +++ b/draw.lua @@ -0,0 +1,3 @@ +cls(0) +drawobjs() +print(#obj)
\ No newline at end of file diff --git a/objects.lua b/objects.lua new file mode 100644 index 0000000..2dba154 --- /dev/null +++ b/objects.lua @@ -0,0 +1,9 @@ +obj = {} + +function updateobjs() + foreach(obj, function(obj) obj:update() end) +end + +function drawobjs() + foreach(obj, function(obj) obj:draw() end) +end
\ No newline at end of file diff --git a/players.lua b/players.lua new file mode 100644 index 0000000..92c3646 --- /dev/null +++ b/players.lua @@ -0,0 +1,55 @@ +playercount = -1 +players = {} + +function addplayer() + playercount += 1 + local player = {} + player.x = 18 + player.y = 60 + player.ymov = 0 + player.id = playercount + player.shootcooldown = 0.0 + player.type = "player" + + function player.draw(player) + if (player.ymov == 0) then + spr(2, player.x, player.y) + elseif (player.ymov == 1) then + spr(3, player.x, player.y) + elseif (player.ymov == -1) then + spr(3, player.x, player.y, 1, 1, false, true) + end + end + + function player.update(player) + --movement + if btn(0, player.id) then + player.x -= 2 + elseif btn(1, player.id) then + player.x += 2 + end + if btn(2, player.id) then + player.y -= 2 + player.ymov = 1 + elseif btn(3, player.id) then + player.y += 2 + player.ymov = -1 + else + player.ymov = 0 + end + player.x = mid(0, player.x, 120) + player.y = mid(0, player.y, 120) + + --shooting + player.shootcooldown -= 1/30 + if btn(4, player.id) and player.shootcooldown < 0 then + addbullet(player.x+3, player.y, 4, 0, false) + player.shootcooldown = 0.1 + end + end + + add(obj, player) + add(players, #obj) +end + +addplayer()
\ No newline at end of file diff --git a/update.lua b/update.lua new file mode 100644 index 0000000..dd67050 --- /dev/null +++ b/update.lua @@ -0,0 +1 @@ +updateobjs()
\ No newline at end of file |
