Skip to content

Commit a56df1b

Browse files
committed
make a commit for once
1 parent bae6b5b commit a56df1b

File tree

3 files changed

+146
-46
lines changed

3 files changed

+146
-46
lines changed

enemies.lua

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ function border_of_wave_and_particle(self)
2424
end
2525
end
2626

27+
function mk_wander(x,y,w,h,accel,period)
28+
x = x or 300
29+
y = y or 40
30+
w = w or 200
31+
h = h or 170
32+
accel = accel or 30
33+
period = period or 120
34+
return function(self)
35+
while true do
36+
self:wait(period)
37+
-- Choose a random spot to wander to
38+
local xx = random(w) + x
39+
local yy = random(h) + y
40+
local r, theta = get_polar(xx-self.x, yy-self.y)
41+
self:change_speed(r/accel, accel)
42+
self:change_direction(theta, 1)
43+
self:wait(accel)
44+
self:change_speed(0, accel)
45+
self:wait(accel)
46+
end
47+
end
48+
end
49+
2750
function mokou_wander(self)
2851
local x, other_x, y, h, accel = {}, {475}, 0, 120, 30
2952
for i=325,450,25 do other_x[#other_x+1] = i x[#x+1] = i+12.5 end
@@ -90,6 +113,61 @@ function grid(self)
90113
Object({x=-25, y=-50, direction=facing_down, speed=50, kind="spawner"}, trace_a)
91114
end
92115

116+
function archimedes(self)
117+
local child = function(self, start_angle, b, c)
118+
local r,theta = 0,0
119+
c = c/60*tau
120+
local c_x, c_y = self.x, self.y
121+
local offset_x, offset_y
122+
while true do
123+
theta = theta+c
124+
r = b*theta
125+
offset_x,offset_y = get_cartesian(r, theta+start_angle)
126+
self.x = c_x + offset_x
127+
self.y = c_y + offset_y
128+
self:wait(1)
129+
end
130+
end
131+
local c, k, direction = 1/5, 1, 1
132+
local n = 7
133+
while true do
134+
self:wait(max(400*c,7))
135+
print(max(400*c,7))
136+
c = 1/5/(1.3+.02*rank*k)
137+
k = k+1
138+
direction = -direction
139+
self.child_color = colors.blue
140+
for i=0,n-1 do
141+
self:fire({edge_margin=400}, {child, i*tau/n + direction *k* tau/70, 100, c*direction})
142+
end
143+
end
144+
end
145+
146+
function small_adds(self)
147+
local child = function(self, wait_time)
148+
self:wait(wait_time)
149+
local direction = self:aim()
150+
local gchild = function(self)
151+
self:change_speed(0,1)
152+
for i=1,3 do
153+
self:wait(4)
154+
self:fire({direction=direction, speed=8})
155+
end
156+
self:vanish()
157+
end
158+
self:fire({direction=direction-tau/4, speed=25}, gchild)
159+
self:fire({direction=direction+tau/4, speed=25}, gchild)
160+
self:vanish()
161+
end
162+
while true do
163+
for i=0,3 do
164+
self:wait(50)
165+
self.child_color = colors.white
166+
self:fire({edge_margin = 200,direction=random()*tau, speed=1/3}, {child, 490-50*i})
167+
end
168+
end
169+
end
170+
93171
function add_laters(first, ...)
94172
stuff = {...}
95173
for idx,data in ipairs(stuff) do
@@ -98,11 +176,54 @@ function add_laters(first, ...)
98176
return first, unpack(stuff)
99177
end
100178

179+
function zander(self)
180+
local mkguy = function(k)
181+
return function(self)
182+
self:change_speed(0,1)
183+
self.child_color = colors.white
184+
while true do
185+
wait(30)
186+
local direction = self:aim()
187+
for j=1,3-abs(k) do
188+
self:fire({direction=direction+4*degrees*k,speed=5+j})
189+
end
190+
end
191+
end
192+
end
193+
local c_x = 400
194+
local c_y = 400
195+
local r = 350
196+
for i=-2,2 do
197+
--cos = x, -sin = y
198+
local theta = facing_up + 25*degrees*i
199+
local my_x,my_y = get_cartesian(r,theta)
200+
my_x = my_x + c_x
201+
my_y = my_y + c_y
202+
local speed,direction = get_polar(my_x - self.x, my_y - self.y)
203+
self:fire({direction=direction,speed=speed}, mkguy(i))
204+
end
205+
self:vanish()
206+
--[[for i=-2,2 do
207+
self:fire({direction=facing_left, speed=130*i}, mkguy(3-abs(i)))
208+
end--]]
209+
--[[while true do
210+
wait(30)
211+
local direction = self:aim()
212+
for i=-2,2 do
213+
for j=0,2-abs(i) do
214+
self:fire({direction=direction+i*4*degrees,speed=6+j})
215+
end
216+
end
217+
end--]]
218+
end
219+
101220
function stage_one(junk, key)
102221
local patterns = {
222+
{{later, 30*60, Object.vanish, 0}, zander},
103223
{{later, 22.5*60, Object.vanish, 60}, border_of_wave_and_particle},
104224
{{later, 15*60, Object.vanish, 360}, mokou_197, mokou_wander},
105-
--{{later, 5*60, Object.vanish, 0}, grid}
225+
{{later, 5*60, Object.vanish, 0}, grid},
226+
{{later, 23*60, Object.vanish, 0}, archimedes, mk_wander(), small_adds},
106227
}
107228
local boss = nil
108229
for idx,data in ipairs(shuffle(patterns)) do

main.lua

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,6 @@ require("enemies")
99

1010
local N_FRAMES = 0
1111

12-
function love.run()
13-
love.load(arg)
14-
15-
local dt = 0 -- time for current frame
16-
local tau = 15 -- initial value for delay between frames
17-
18-
while true do
19-
love.timer.step()
20-
dt = math.min(0.1, love.timer.getDelta() )
21-
22-
love.graphics.clear()
23-
love.graphics.setColor(unpack(colors.dgray))
24-
love.graphics.rectangle("fill",-5,-5,900,900)
25-
set_color(unpack(colors.white))
26-
love.update(dt)
27-
love.draw()
28-
-- delay: ["..math.floor(tau).."ms] idle:["..math.floor(100 * (tau/1000)/dt).."%]", 10, 10)
29-
if(N_FRAMES > 100) then
30-
tau = tau + (love.timer.getFPS()-60)*0.2*dt
31-
end
32-
33-
for e,a,b,c in love.event.poll() do
34-
if e == "q" then
35-
if love.audio then love.audio.stop() end
36-
return
37-
end
38-
love.handlers[e](a,b,c)
39-
end
40-
41-
-- love.timer.sleep(tau)
42-
love.graphics.present()
43-
44-
N_FRAMES = N_FRAMES + 1
45-
end
46-
end
47-
4812
function love.load()
4913
math.randomseed(os.time(os.date("*t")))
5014
graphics_init() -- load images and set up stuff
@@ -54,21 +18,36 @@ function love.load()
5418
mainloop = coroutine.create(fmainloop)
5519
end
5620

57-
function love.update()
58-
local status, err, ret = coroutine.resume(mainloop)
59-
if not status then
60-
error(err..'\n'..debug.traceback(mainloop))
21+
local oneframe_time = 1/60
22+
local leftover_time = 0
23+
24+
function love.update(dt)
25+
leftover_time = leftover_time + dt
26+
for qq=1,3 do
27+
if leftover_time >= oneframe_time then
28+
leftover_time = leftover_time - oneframe_time
29+
gfx_q:clear()
30+
set_color(unpack(colors.white))
31+
local status, err, ret = coroutine.resume(mainloop)
32+
if not status then
33+
error(err..'\n'..debug.traceback(mainloop))
34+
end
35+
if ret then error(tostring(ret)) end
36+
this_frame_keys = {}
6137
end
62-
if ret then error(tostring(ret)) end
63-
this_frame_keys = {}
38+
end
6439
end
6540

6641
function love.draw()
6742
--love.timer.step()
6843
--print("update: "..tostring(love.timer.getDelta()*1000))
44+
love.graphics.setColor(unpack(colors.dgray))
45+
love.graphics.rectangle("fill",-5,-5,900,900)
46+
love.graphics.setColor(unpack(colors.white))
6947
set_color(unpack(colors.white))
7048
gprint("FPS: ["..love.timer.getFPS().."]", 10, 10)
7149
for i=gfx_q.first,gfx_q.last do
50+
print("pring")
7251
--[[local tab = {}
7352
tab[love.graphics.print] = "print"
7453
tab[love.graphics.rectangle] = "rectangle"
@@ -77,7 +56,6 @@ function love.draw()
7756
print(tab[gfx_q[i][1] ], unpack(gfx_q[i][2]))--]]
7857
gfx_q[i][1](unpack(gfx_q[i][2]))
7958
end
80-
gfx_q:clear()
8159
--love.timer.step()
8260
--print("draw: "..tostring(love.timer.getDelta()*1000))
8361
end

object.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Object.update(o, a, ...)
2525
o.rot_turns = o.rot_turns or 0
2626
o.child_kind = a.child_kind or o.child_kind
2727
o.top_half = a.top_half or o.top_half
28+
o.edge_margin = a.edge_margin or o.edge_margin or 100
2829
if not o.child_kind and o.kind == "spawner" then
2930
o.child_kind = "enemy_bullet"
3031
else
@@ -73,8 +74,8 @@ function Object.run(self)
7374
self.x = self.x + dx
7475
self.y = self.y + dy
7576
-- TODO: don't hard code dimensions of space.
76-
self.dead = self.dead or self.x < -100 or self.y < -100 or
77-
self.x > 900 or self.y > 700
77+
self.dead = self.dead or self.x < -self.edge_margin or self.y < -self.edge_margin or
78+
self.x > 800+self.edge_margin or self.y > 600+self.edge_margin
7879
self.age = self.age + 1
7980
end
8081

0 commit comments

Comments
 (0)