Skip to content

Commit

Permalink
make a commit for once
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpobject committed Nov 18, 2013
1 parent bae6b5b commit a56df1b
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 46 deletions.
123 changes: 122 additions & 1 deletion enemies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ function border_of_wave_and_particle(self)
end
end

function mk_wander(x,y,w,h,accel,period)
x = x or 300
y = y or 40
w = w or 200
h = h or 170
accel = accel or 30
period = period or 120
return function(self)
while true do
self:wait(period)
-- Choose a random spot to wander to
local xx = random(w) + x
local yy = random(h) + y
local r, theta = get_polar(xx-self.x, yy-self.y)
self:change_speed(r/accel, accel)
self:change_direction(theta, 1)
self:wait(accel)
self:change_speed(0, accel)
self:wait(accel)
end
end
end

function mokou_wander(self)
local x, other_x, y, h, accel = {}, {475}, 0, 120, 30
for i=325,450,25 do other_x[#other_x+1] = i x[#x+1] = i+12.5 end
Expand Down Expand Up @@ -90,6 +113,61 @@ function grid(self)
Object({x=-25, y=-50, direction=facing_down, speed=50, kind="spawner"}, trace_a)
end

function archimedes(self)
local child = function(self, start_angle, b, c)
local r,theta = 0,0
c = c/60*tau
local c_x, c_y = self.x, self.y
local offset_x, offset_y
while true do
theta = theta+c
r = b*theta
offset_x,offset_y = get_cartesian(r, theta+start_angle)
self.x = c_x + offset_x
self.y = c_y + offset_y
self:wait(1)
end
end
local c, k, direction = 1/5, 1, 1
local n = 7
while true do
self:wait(max(400*c,7))
print(max(400*c,7))
c = 1/5/(1.3+.02*rank*k)
k = k+1
direction = -direction
self.child_color = colors.blue
for i=0,n-1 do
self:fire({edge_margin=400}, {child, i*tau/n + direction *k* tau/70, 100, c*direction})
end
end
end

function small_adds(self)
local child = function(self, wait_time)
self:wait(wait_time)
local direction = self:aim()
local gchild = function(self)
self:change_speed(0,1)
for i=1,3 do
self:wait(4)
self:fire({direction=direction, speed=8})
end
self:vanish()
end
self:fire({direction=direction-tau/4, speed=25}, gchild)
self:fire({direction=direction+tau/4, speed=25}, gchild)
self:vanish()
end
while true do
for i=0,3 do
self:wait(50)
self.child_color = colors.white
self:fire({edge_margin = 200,direction=random()*tau, speed=1/3}, {child, 490-50*i})
end
end
end

function add_laters(first, ...)
stuff = {...}
for idx,data in ipairs(stuff) do
Expand All @@ -98,11 +176,54 @@ function add_laters(first, ...)
return first, unpack(stuff)
end

function zander(self)
local mkguy = function(k)
return function(self)
self:change_speed(0,1)
self.child_color = colors.white
while true do
wait(30)
local direction = self:aim()
for j=1,3-abs(k) do
self:fire({direction=direction+4*degrees*k,speed=5+j})
end
end
end
end
local c_x = 400
local c_y = 400
local r = 350
for i=-2,2 do
--cos = x, -sin = y
local theta = facing_up + 25*degrees*i
local my_x,my_y = get_cartesian(r,theta)
my_x = my_x + c_x
my_y = my_y + c_y
local speed,direction = get_polar(my_x - self.x, my_y - self.y)
self:fire({direction=direction,speed=speed}, mkguy(i))
end
self:vanish()
--[[for i=-2,2 do
self:fire({direction=facing_left, speed=130*i}, mkguy(3-abs(i)))
end--]]
--[[while true do
wait(30)
local direction = self:aim()
for i=-2,2 do
for j=0,2-abs(i) do
self:fire({direction=direction+i*4*degrees,speed=6+j})
end
end
end--]]
end

function stage_one(junk, key)
local patterns = {
{{later, 30*60, Object.vanish, 0}, zander},
{{later, 22.5*60, Object.vanish, 60}, border_of_wave_and_particle},
{{later, 15*60, Object.vanish, 360}, mokou_197, mokou_wander},
--{{later, 5*60, Object.vanish, 0}, grid}
{{later, 5*60, Object.vanish, 0}, grid},
{{later, 23*60, Object.vanish, 0}, archimedes, mk_wander(), small_adds},
}
local boss = nil
for idx,data in ipairs(shuffle(patterns)) do
Expand Down
64 changes: 21 additions & 43 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,6 @@ require("enemies")

local N_FRAMES = 0

function love.run()
love.load(arg)

local dt = 0 -- time for current frame
local tau = 15 -- initial value for delay between frames

while true do
love.timer.step()
dt = math.min(0.1, love.timer.getDelta() )

love.graphics.clear()
love.graphics.setColor(unpack(colors.dgray))
love.graphics.rectangle("fill",-5,-5,900,900)
set_color(unpack(colors.white))
love.update(dt)
love.draw()
-- delay: ["..math.floor(tau).."ms] idle:["..math.floor(100 * (tau/1000)/dt).."%]", 10, 10)
if(N_FRAMES > 100) then
tau = tau + (love.timer.getFPS()-60)*0.2*dt
end

for e,a,b,c in love.event.poll() do
if e == "q" then
if love.audio then love.audio.stop() end
return
end
love.handlers[e](a,b,c)
end

-- love.timer.sleep(tau)
love.graphics.present()

N_FRAMES = N_FRAMES + 1
end
end

function love.load()
math.randomseed(os.time(os.date("*t")))
graphics_init() -- load images and set up stuff
Expand All @@ -54,21 +18,36 @@ function love.load()
mainloop = coroutine.create(fmainloop)
end

function love.update()
local status, err, ret = coroutine.resume(mainloop)
if not status then
error(err..'\n'..debug.traceback(mainloop))
local oneframe_time = 1/60
local leftover_time = 0

function love.update(dt)
leftover_time = leftover_time + dt
for qq=1,3 do
if leftover_time >= oneframe_time then
leftover_time = leftover_time - oneframe_time
gfx_q:clear()
set_color(unpack(colors.white))
local status, err, ret = coroutine.resume(mainloop)
if not status then
error(err..'\n'..debug.traceback(mainloop))
end
if ret then error(tostring(ret)) end
this_frame_keys = {}
end
if ret then error(tostring(ret)) end
this_frame_keys = {}
end
end

function love.draw()
--love.timer.step()
--print("update: "..tostring(love.timer.getDelta()*1000))
love.graphics.setColor(unpack(colors.dgray))
love.graphics.rectangle("fill",-5,-5,900,900)
love.graphics.setColor(unpack(colors.white))
set_color(unpack(colors.white))
gprint("FPS: ["..love.timer.getFPS().."]", 10, 10)
for i=gfx_q.first,gfx_q.last do
print("pring")
--[[local tab = {}
tab[love.graphics.print] = "print"
tab[love.graphics.rectangle] = "rectangle"
Expand All @@ -77,7 +56,6 @@ function love.draw()
print(tab[gfx_q[i][1] ], unpack(gfx_q[i][2]))--]]
gfx_q[i][1](unpack(gfx_q[i][2]))
end
gfx_q:clear()
--love.timer.step()
--print("draw: "..tostring(love.timer.getDelta()*1000))
end
Expand Down
5 changes: 3 additions & 2 deletions object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Object.update(o, a, ...)
o.rot_turns = o.rot_turns or 0
o.child_kind = a.child_kind or o.child_kind
o.top_half = a.top_half or o.top_half
o.edge_margin = a.edge_margin or o.edge_margin or 100
if not o.child_kind and o.kind == "spawner" then
o.child_kind = "enemy_bullet"
else
Expand Down Expand Up @@ -73,8 +74,8 @@ function Object.run(self)
self.x = self.x + dx
self.y = self.y + dy
-- TODO: don't hard code dimensions of space.
self.dead = self.dead or self.x < -100 or self.y < -100 or
self.x > 900 or self.y > 700
self.dead = self.dead or self.x < -self.edge_margin or self.y < -self.edge_margin or
self.x > 800+self.edge_margin or self.y > 600+self.edge_margin
self.age = self.age + 1
end

Expand Down

0 comments on commit a56df1b

Please sign in to comment.