aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bullets.lua16
-rw-r--r--enemies.lua0
-rw-r--r--objects.lua2
-rw-r--r--particles.lua26
-rw-r--r--players.lua40
5 files changed, 72 insertions, 12 deletions
diff --git a/bullets.lua b/bullets.lua
index dad5ba4..01e6dc7 100644
--- a/bullets.lua
+++ b/bullets.lua
@@ -4,6 +4,7 @@ function addbullet(x, y, velx, vely, evil)
local bullet = {}
bullet.type = "bullet"
+ bullet.evil = evil
bullet.x = x
bullet.y = y
bullet.velx = velx
@@ -13,9 +14,10 @@ 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)
+ function bullet.collide(object)
+ if bullet.x+4 >= object.x and bullet.x+4 <= object.x+object.w and bullet.y+4 >= object.y and bullet.y+4 <= object.y+object.h and object.inv < 0 then
+ object:shot()
+ del(obj, bullet)
end
end
@@ -26,7 +28,9 @@ function addbullet(x, y, velx, vely, evil)
--collision detection
if bullet.evil then
- foreach(players, bullet.collide(bullet))
+ foreach(players, bullet.collide)
+ elseif bullet.good then
+ --foreach(enemies, bullet.collide)
end
--delete bullet if off screen
@@ -37,4 +41,6 @@ function addbullet(x, y, velx, vely, evil)
add(obj, bullet)
add(bullet, #obj)
-end \ No newline at end of file
+end
+
+addbullet(120, 60, -1, 0, true) \ No newline at end of file
diff --git a/enemies.lua b/enemies.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/enemies.lua
diff --git a/objects.lua b/objects.lua
index 5284b03..69b2bd8 100644
--- a/objects.lua
+++ b/objects.lua
@@ -6,6 +6,6 @@ function updateobjs()
end
function drawobjs()
- foreach(players, function(obj) obj:draw() end)
foreach(obj, function(obj) obj:draw() end)
+ foreach(players, function(obj) obj:draw() end)
end \ No newline at end of file
diff --git a/particles.lua b/particles.lua
new file mode 100644
index 0000000..29a8140
--- /dev/null
+++ b/particles.lua
@@ -0,0 +1,26 @@
+function addcircle(x, y, velx, vely, r, time, color)
+ local circle = {}
+ circle.x = x
+ circle.y = y
+ circle.velx = velx
+ circle.vely = vely
+ circle.r = r
+ circle.time = time
+ circle.t = time
+ circle.col = color
+
+ function circle.draw(circle)
+ circfill(circle.x, circle.y, circle.r*sin(circle.time/circle.t), circle.col)
+ end
+
+ function circle.update(circle)
+ circle.x += circle.velx
+ circle.y += circle.vely
+ circle.time -= 1/60
+ if circle.time < 0 then
+ del(obj, circle)
+ end
+ end
+
+ add(obj, circle)
+end \ No newline at end of file
diff --git a/players.lua b/players.lua
index 60227fa..d5da525 100644
--- a/players.lua
+++ b/players.lua
@@ -10,17 +10,33 @@ function addplayer()
player.w = 8
player.h = 8
player.ymov = 0
+ player.inv = -1
player.id = playercount
player.shootcooldown = 0.0
+ player.particlecooldown = 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)
+ print(player.health)
+ if player.inv < 0 or ceil(player.inv*10%2) == 1 then
+ 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
+ end
+
+ function player.shot(player)
+ player.health -= 1
+ player.inv = 1
+ for i = 1, 4, 1 do
+ addcircle(player.x+rnd(8), player.y+rnd(8), -0.5, 0, rnd(8), rnd(1.5)+1, 5)
+ end
+ for i = 1, 4, 1 do
+ addcircle(player.x+rnd(8), player.y+rnd(8), -0.4, 0, rnd(8), rnd(1)+0.5, 9)
end
end
@@ -43,9 +59,21 @@ function addplayer()
player.x = mid(0, player.x, 120)
player.y = mid(0, player.y, 120)
+ --particles from rockets
+ player.particlecooldown -= 1/60
+ if player.particlecooldown < 0 then
+ addcircle(player.x-1, player.y, -0.5, 0, 1.5, 0.5, 9)
+ addcircle(player.x-1, player.y+7, -0.5, 0, 1.5, 0.5, 9)
+ player.particlecooldown = 0.1
+ end
+
--shooting
player.shootcooldown -= 1/60
+ player.inv -= 1/60
if btn(4, player.id) and player.shootcooldown < 0 then
+ --for i = 1, 4, 1 do
+ --addcircle(player.x+3, player.y+4, rnd(1)+0.5, rnd(1)-0.5, 1.5, rnd(0.4), 12)
+ --end
addbullet(player.x+3, player.y, 2, 0, false)
player.shootcooldown = 0.1
end