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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
despawnallbullets = false
function addbullet(x, y, velx, vely, good, sprite)
local bullet = {
}
sprite = sprite or 2
--good = good or false
function bullet.draw()
spr(sprite, x, y)
end
function bullet.collide(object)
if x+4 >= object.x and x+4 <= object.x+object.w and y+4 >= object.y and y+4 <= object.y+object.h and object.inv < 0 then
object:shot()
del(obj, bullet)
end
end
function bullet.accurate_collide(object)
if x+4 >= object.x-2 and x+4 <= object.x+2+object.w and y+4 >= object.y-2 and y+4 <= object.y+object.h+2 then
object:shot()
explosion(x,y)
del(obj, bullet)
end
end
function bullet.update()
--applying velocity
x += velx
y += vely
--collision detection
if good then
foreach(enemies, bullet.accurate_collide)
else
foreach(players, bullet.collide)
end
--delete bullet if off screen
if y > 128 or y < -8 or x > 128 or x < -8 or (despawnallbullets and not good) then
del(obj, bullet)
end
end
add(obj, bullet)
end
function addlaser(x, y, r, enemy)
local laser = {
--lasers!!!!!!!!!!!!!!!
}
timer = 0
playingsound = false
function laser:draw()
if timer > 1.5 then
local radius = (min(timer*r*0.7,r)+sin(t()*6))-mid(0, timer-3, r)*r
for i = -10, x, 1 do
local offset = radius*sin(t()*3+i/(10+timer^3.5))*1.6
line(i, y+offset, i, y-offset, 14)
pset(i, y+(cos(t()+i/50)+sin(i/4.32535+t())*2)*radius/1.8, 14)
end
--circfill(x, y, radius, 14)
--rectfill(-10, y-radius, x, y+radius, 14)
circfill(x, y, radius*0.7, 11)
rectfill(-10, y-radius*0.7, x, y+radius*0.7, 11)
circfill(x, y, radius*0.3, 7)
rectfill(-10, y-radius*0.3, x, y+radius*0.3, 7)
else
circfill(x, y, timer*4+sin(t()*8), 11)
circfill(x, y, timer*2+sin(t()*8), 7)
for i = mid(-5, x-timer*x,x), x, 1 do
pset(i, y+sin(i/(3/(timer/2))-t())*timer*r/2, 11)
pset(i, y+cos(t()*timer+i/30)*timer*3+sin(i/8.32535+t()), 14)
end
end
end
function laser.collide(object)
--local _ENV = laser
if object.x < x and y+r*2 > object.y+object.h and y-r*2 < object.y and object.inv < 0 and not object.stay then
object:shot()
end
end
function laser.update()
timer += ft
--collision detection after the warm up
if timer > 1.5 and timer < 3.6 then
if not playingsound then
sfx(24,3)
playingsound = true
end
shake = rnd(8)/timer
foreach(players, laser.collide)
foreach(enemies, laser.collide)
end
--delete laser once its done
if timer > 4 or enemy.health <= 0 then
del(obj, laser)
sfx(25, 3)
for i = 1, 16, 1 do
addcircle(rnd(x), y-5+rnd(r), -0.5, -0.5, rnd(3), rnd(2), rnd({11,14,3}))
end
end
end
add(obj, laser)
sfx(23,3)
end
function addmissile(x, y, target) --basic small weak enemy
local enemy = {
--target = target,
x = x,
y = y,
w = 16,
h = 8,
inv = -1,
health = 3,
speed = 0.3,
shootcooldown = 0,
shot = enemyshot,
collide = enemycollide
}
function enemy.draw()
if enemy.inv < 0 or ceil(enemy.inv*10%2) == 1 then
spr(42, enemy.x, enemy.y, 2, 1)
end
end
function enemy.update()
enemy.x -= enemy.speed
enemy.speed += 0.015
enemy.y += (players[target].y - enemy.y)/30
addcircle(enemy.x+12, enemy.y+rnd(8), 0, rnd()/8, 2.1, 0.6, rnd({9,5}))
enemymisc(enemy)
if enemy.health <= 0 then -- die!!!!!
enemydie(enemy,17,2,17)
end
end
sfx(14,3) --missle launch/thruster loop
add(enemies, enemy, 1)
end
|