forked from A-deLuna/Concurso_IDGD_2014
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.lua
132 lines (120 loc) · 4.33 KB
/
bullet.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
bullet = {}
bullet.speed = 600
bullet.radius = 5
bullet.timer = 0
bullet.type = {{fireRate = 0.25}}
function bullet.load()
bullet.rocket = love.graphics.newImage("img/rocket.png")
end
function bullet.spawn(x, y, angle,type)
if type==2 then
table.insert(bullet, {x = x, y = y, dx = bullet.speed * math.cos(angle - math.pi/16), dy = bullet.speed * math.sin(angle - math.pi/16), type=10, angle=angle-math.pi/16, radius = bullet.radius} )
table.insert(bullet, {x = x, y = y, dx = bullet.speed * math.cos(angle), dy = bullet.speed * math.sin(angle), type=11, angle=angle, radius = bullet.radius} )
table.insert(bullet, {x = x, y = y, dx = bullet.speed * math.cos(angle + math.pi/16), dy = bullet.speed * math.sin(angle + math.pi/16), type=12, angle=angle+math.pi/16, radius = bullet.radius} )
elseif type==3 then
table.insert(bullet, {x = x, y = y, dx = bullet.speed * math.cos(angle), dy = bullet.speed * math.sin(angle), type=type, angle=angle, radius = bullet.radius+5})
elseif type==0 or player.ammo>0 then
table.insert(bullet, {x = x, y = y, dx = bullet.speed * math.cos(angle), dy = bullet.speed * math.sin(angle), type=type, angle=angle, radius = bullet.radius} )
end
if type~=0 then
player.ammo=player.ammo-1
end
end
function bullet.draw()
for i,v in ipairs(bullet) do
love.graphics.setColor(255,255,255)
if v.type==1 then
love.graphics.draw(bullet.rocket,v.x, v.y,v.angle,1,1)
elseif v.type==3 then
love.graphics.setColor(175,100,255)
love.graphics.circle("fill", v.x , v.y , v.radius, 10)
elseif v.type==10 then
love.graphics.setColor(0,0,255)
love.graphics.circle("fill", v.x , v.y , v.radius, 10)
elseif v.type==11 then
love.graphics.setColor(255,255,255)
love.graphics.circle("fill", v.x , v.y , v.radius, 10)
elseif v.type==12 then
love.graphics.setColor(255,0,0)
love.graphics.circle("fill", v.x , v.y , v.radius, 10)
else
love.graphics.setColor(225,225,225)
love.graphics.circle("fill", v.x , v.y , v.radius, 10)
end
end
end
function bullet.update(dt)
for i, v in ipairs(bullet) do
v.x = v.x + v.dx * dt
v.y = v.y + v.dy * dt
end
end
function bullet.collition()
for i, v in ipairs(enemy) do
for n, q in ipairs (bullet ) do
if ((v.x < q.x-bullet.radius and q.x-bullet.radius<v.x+enemy.width) and (v.y < q.y-bullet.radius and q.y-bullet.radius<v.y+enemy.height)) or
((v.x < q.x+bullet.radius and q.x+bullet.radius <v.x+enemy.width) and (v.y < q.y+bullet.radius and q.y+bullet.radius+player.height<v.y+enemy.height)) or
((v.x < q.x+bullet.radius and q.x+bullet.radius<v.x+enemy.width) and (v.y < q.y-bullet.radius and q.y-bullet.radius<v.y+enemy.height)) or
((v.x < q.x-bullet.radius and q.x-bullet.radius<v.x+enemy.width) and (v.y < q.y+bullet.radius and q.y+bullet.radius<v.y+enemy.height)) then
v.hp = v.hp - 1
if ( v.hp < 1) then
powerup.spawn(v.x,v.y)
table.remove(enemy, i)
player.scoreValue=player.scoreValue+100
end
-- AQUI ESTAN LOS TIPOS DE BALAS QUE SE VAN A LLAMAR
if q.type==1 then
explosion.spawn(q.x, q.y)
end
if q.type~=3 then
table.remove(bullet, n)
end
elseif q.x < 0 or q.x > love.window.getWidth() or q.y<0 or q.y>love.window.getHeight() then
table.remove(bullet, n)
if q.type==1 then
explosion.spawn(q.x, q.y)
end
end
end
end
end
function BULLET_UPDATE(dt)
bullet.update(dt)
bullet.collition()
bullet.shoot(dt)
end
function BULLET_DRAW()
bullet.draw()
end
function bullet.shoot(dt)
if bullet.timer > bullet.type[1].fireRate then
if love.mouse.isDown("l") or love.mouse.isDown("r") then
local x = love.mouse.getX()
local y = love.mouse.getY()
local angle = math.atan2(y - player.y, x - player.x)
if love.mouse.isDown("l") then
type = 0
else
type = player.bullettype
end
bullet.spawn(player.x + player.width /2 ,player.y + player.height /2 ,angle,type)
bullet.timer = 0
piu:play()
elseif gamepad.isDown[7] or gamepad.isDown[8] then
if (gamepad.rx ~= 0 and gamepad.ry ~= 0) then
gpadangle = math.atan2(gamepad.ry, gamepad.rx)
else
gpadangle = player.angle
end
if gamepad.isDown[8] then
type = 0
else
type = player.bullettype
end
bullet.spawn(player.x + player.width /2 ,player.y + player.height /2 ,gpadangle,type)
bullet.timer=0
piu:play()
end
end
bullet.timer = bullet.timer + dt
end