forked from A-deLuna/Concurso_IDGD_2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerup.lua
70 lines (62 loc) · 1.74 KB
/
powerup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
powerup={}
powerup.pUpTime = 50
function powerup.load()
powerup.oneupicon = love.graphics.newImage("img/1up.png")
powerup.rpgicon = love.graphics.newImage("img/rpg.png")
powerup.revicon = love.graphics.newImage("img/revolver.png")
powerup.murricaicon = love.graphics.newImage("img/murrica.png")
end
function powerup.draw()
love.graphics.setColor(255,255,255)
for i, v in ipairs(powerup) do
if (v.time>40 and math.floor(v.time) % 2 ==0) or v.time<40 then
if v.type == 1 then
love.graphics.draw(powerup.rpgicon,v.x, v.y,v.rot,1,1)
elseif v.type == 2 then
love.graphics.draw(powerup.murricaicon,v.x, v.y,v.rot,1,1)
elseif v.type == 3 then
love.graphics.draw(powerup.revicon,v.x, v.y,v.rot,1,1)
elseif v.type == 4 then
love.graphics.draw(powerup.oneupicon,v.x, v.y,v.rot,1,1)
end
end
end
end
function powerup.spawn(x,y)
local testnum = love.math.random(30)
if testnum==3 then
table.insert(powerup,{x=x, y=y, type=math.random(4), time=0, rot=love.math.random(100)})
end
end
function powerup.pickup()
for i, v in ipairs(powerup) do
if math.sqrt(math.pow(player.x+player.width/2-v.x+15/2,2)+math.pow(player.y+player.width/2-v.y+15/2,2)) < player.width/2 + 16 then
if v.type ~= 4 then
player.bullettype= v.type
end
if v.type == 1 then
player.ammo=3
elseif v.type == 2 then
player.ammo = 10
elseif v.type == 3 then
player.ammo = 2
elseif v.type == 4 and player.hp<5 then
player.hp = player.hp+1
end
table.remove(powerup,i)
end
end
end
function powerup.removal(dt)
for i, v in ipairs(powerup) do
if v.time > powerup.pUpTime then
table.remove(powerup, i)
else
v.time= v.time +5*dt
end
end
end
function POWERUP_UPDATE(dt)
powerup.pickup()
powerup.removal(dt)
end