From e75f2917c3378150e28019713a43dba8948ea7ca Mon Sep 17 00:00:00 2001 From: Nick Stokoe Date: Sat, 2 Jul 2022 23:00:27 +0100 Subject: [PATCH] ball.lua - implement a random visiting ball --- ball.lua | 23 +++++++++++++++++++++++ main.lua | 7 +++++++ 2 files changed, 30 insertions(+) create mode 100644 ball.lua diff --git a/ball.lua b/ball.lua new file mode 100644 index 0000000..f015f74 --- /dev/null +++ b/ball.lua @@ -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 diff --git a/main.lua b/main.lua index 480234f..605b7e3 100644 --- a/main.lua +++ b/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