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
150
151
152
|
function addbullet(x, y, velx, vely, evil, sprite)
local bullet = {
sprite = sprite or 2,
evil = evil,
x = x,
y = y,
velx = velx,
vely = vely,
}
function bullet.draw(bullet)
spr(bullet.sprite, bullet.x, bullet.y)
end
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
function bullet.accurate_collide(object)
if bullet.x+4 >= object.x-2 and bullet.x+4 <= object.x+2+object.w and bullet.y+4 >= object.y-2 and bullet.y+4 <= object.y+object.h+2 then
object:shot()
del(obj, bullet)
end
end
function bullet.update(bullet)
--applying velocity
bullet.x += bullet.velx
bullet.y += bullet.vely
--collision detection
if bullet.evil then
foreach(players, bullet.collide)
elseif bullet.evil == false then
foreach(enemies, bullet.accurate_collide)
end
--delete bullet if off screen
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)
end
--ERROR Sticks around after boss dies
function addlaser(x, y, r)
local laser = {
--lasers!!!!!!!!!!!!!!!
x = x,
y = y,
r = r,
timer = 0,
playingsound = false
}
function laser.draw(laser)
if laser.timer > 1.5 then
local radius = (min(laser.timer*laser.r*0.7,laser.r)+sin(t()*6))-mid(0, laser.timer-3, laser.r)*laser.r
for i = -10, laser.x, 1 do
line(i, laser.y+radius*sin(t()*3+i/(10+laser.timer^3.5))*1.6, i, laser.y-radius*sin(t()*3+i/(10+laser.timer^3.5))*1.6, 14)
pset(i, laser.y+(cos(t()*1.5+i/50)+sin(i/4.32535+t())*2)*radius/1.8, 14)
end
circfill(laser.x, laser.y, radius, 14)
rectfill(-10, laser.y-radius, laser.x, laser.y+radius, 14)
circfill(laser.x, laser.y, radius*0.7, 11)
rectfill(-10, laser.y-radius*0.7, laser.x, laser.y+radius*0.7, 11)
circfill(laser.x, laser.y, radius*0.3, 7)
rectfill(-10, laser.y-radius*0.3, laser.x, laser.y+radius*0.3, 7)
else
circfill(laser.x, laser.y, laser.timer*4+sin(t()*8), 11)
circfill(laser.x, laser.y, laser.timer*2+sin(t()*8), 7)
for i = mid(-5, laser.x-laser.timer*laser.x,laser.x), laser.x, 1 do
pset(i, laser.y+sin(i/(3/(laser.timer/2))-t())*laser.timer*laser.r/2, 11)
pset(i, laser.y+cos(t()*laser.timer+i/30)*laser.timer*3+sin(i/8.32535+t()), 14)
end
end
end
function laser.collide(object)
if object.x < laser.x and laser.y+laser.r*2 > object.y+object.h and laser.y-laser.r*2 < object.y and object.inv < 0 then
object:shot()
end
end
function laser.update(laser)
laser.timer += 1/60
--collision detection after the warm up
if laser.timer > 1.5 and laser.timer < 3.6 then
if not laser.playingsound then
sfx(24,3)
laser.playingsound = true
end
shake = rnd(8)/laser.timer
foreach(players, laser.collide)
foreach(enemies, laser.collide)
end
--delete laser once its done
if laser.timer > 4 then
del(obj, laser)
sfx(25, 3)
for i = 1, 16, 1 do
addcircle(rnd(laser.x), laser.y-laser.r/2+rnd(laser.r), -0.5, -0.5, rnd(3), rnd(2), rnd({11,14,3}), 0)
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(enemy)
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[enemy.target].y - enemy.y)/30
addcircle(enemy.x+12, enemy.y+rnd(8), 0, rnd()/8, 2.1, 0.6, rnd({9,5}), 0)
enemymisc(enemy)
if enemy.health <= 0 then -- die!!!!!
enemydie(enemy,17,2)
end
end
sfx(14,3) --missle launch/thruster loop
add(enemies, enemy, 1)
end
|