ball.lua - implement a random visiting ball
This commit is contained in:
23
ball.lua
Normal file
23
ball.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
local mkHopper = require "hopper"
|
||||
local dirs = {"se", "sw", "ne", "nw"}
|
||||
local height = 10;
|
||||
|
||||
return function(arena)
|
||||
local self
|
||||
local function update(dt, se, sw)
|
||||
if se+sw >= arena.getSize() then
|
||||
self.dead = true
|
||||
return
|
||||
end
|
||||
|
||||
local dir = dirs[math.random(2)]
|
||||
self.jump(dir)
|
||||
end
|
||||
local function draw(x, y )
|
||||
love.graphics.setColor(128,0,0);
|
||||
love.graphics.circle("fill", x, y, height)
|
||||
end
|
||||
|
||||
self = mkHopper(arena, draw, update)
|
||||
return self
|
||||
end
|
||||
7
main.lua
7
main.lua
@@ -1,6 +1,7 @@
|
||||
|
||||
local mkArena = require "arena"
|
||||
local mkQbert = require "qbert"
|
||||
local mkBall = require "ball"
|
||||
|
||||
local arena = mkArena(
|
||||
7,
|
||||
@@ -27,6 +28,12 @@ end
|
||||
|
||||
function love.update(dt)
|
||||
|
||||
time = time + dt
|
||||
if time > 10 then
|
||||
time = 0
|
||||
table.insert(mobs, mkBall(arena))
|
||||
end
|
||||
|
||||
if love.keyboard.isDown('i') then
|
||||
qbert.jump('ne')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user