move circle program to separate room
This commit is contained in:
parent
0195d7f9e9
commit
89f9bd1913
4 changed files with 61 additions and 34 deletions
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Lua.diagnostics.globals": [
|
||||
"love",
|
||||
"Circle"
|
||||
]
|
||||
}
|
||||
15
main.lua
15
main.lua
|
|
@ -12,6 +12,8 @@ Baton = require 'lib/baton/baton'
|
|||
---@type Timer
|
||||
Timer = require 'lib/hump/timer'
|
||||
|
||||
HC = require 'lib/hc'
|
||||
|
||||
Camera = require 'lib/cameramod/camera'
|
||||
require 'lib/cameramod/Shake'
|
||||
|
||||
|
|
@ -20,10 +22,6 @@ Room = require 'obj/Room'
|
|||
Area = require 'obj/Area'
|
||||
GameObject = require 'obj/GameObject'
|
||||
|
||||
-- game objects --
|
||||
Player = require 'obj/game/Player'
|
||||
Circle = require 'obj/game/Circle'
|
||||
|
||||
function love.load()
|
||||
-- screen setup
|
||||
love.graphics.setDefaultFilter("nearest")
|
||||
|
|
@ -33,6 +31,13 @@ function love.load()
|
|||
---@type Room|nil
|
||||
current_room = nil
|
||||
|
||||
-- load game objects
|
||||
local game_objects = {}
|
||||
print('loading game objects:')
|
||||
recursiveEnumerate('obj/game', game_objects)
|
||||
for _,v in ipairs(game_objects) do print('',v) end
|
||||
requireFiles(game_objects, true)
|
||||
|
||||
-- load rooms
|
||||
local room_files = {}
|
||||
print('loading rooms:')
|
||||
|
|
@ -60,7 +65,7 @@ end
|
|||
function love.update(dt)
|
||||
if current_room then current_room:update(dt) end
|
||||
input:update(dt)
|
||||
if input:pressed('f1') then gotoRoom('Stage') end
|
||||
if input:pressed('f1') then gotoRoom('CircleRoom') end
|
||||
if input:pressed('f3') then camera:shake(4, 60, 1) end
|
||||
|
||||
camera:update(dt)
|
||||
|
|
|
|||
45
rooms/CircleRoom.lua
Normal file
45
rooms/CircleRoom.lua
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
---@class CircleRoom:Room
|
||||
---@field timer Timer
|
||||
local CircleRoom = Room:extend()
|
||||
|
||||
function CircleRoom:new()
|
||||
CircleRoom.super.new(self)
|
||||
self.timer = Timer()
|
||||
|
||||
-- game objects
|
||||
self.timer:every(2, function()
|
||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh))
|
||||
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
|
||||
end)
|
||||
end
|
||||
|
||||
function CircleRoom:update(dt)
|
||||
CircleRoom.super.update(self, dt)
|
||||
|
||||
if input:pressed('action') then
|
||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh), {radius = 15})
|
||||
end
|
||||
|
||||
if input:pressed('right') then
|
||||
for _, game_object in ipairs(self.area.game_objects) do
|
||||
game_object:kill()
|
||||
end
|
||||
end
|
||||
|
||||
if input:pressed('left') then
|
||||
for _, game_object in ipairs(self.area.game_objects) do
|
||||
if game_object:is(Circle) then
|
||||
---@cast game_object Circle
|
||||
if game_object.mode == "fill" then game_object.mode = "line" else game_object.mode = "fill" end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.timer:update(dt)
|
||||
end
|
||||
|
||||
function CircleRoom:canvasDraw()
|
||||
CircleRoom.super.canvasDraw(self)
|
||||
end
|
||||
|
||||
return CircleRoom
|
||||
|
|
@ -1,43 +1,14 @@
|
|||
---@class Stage:Room
|
||||
---@field timer Timer
|
||||
local Stage = Room:extend()
|
||||
|
||||
function Stage:new()
|
||||
Stage.super.new(self)
|
||||
self.timer = Timer()
|
||||
|
||||
-- game objects
|
||||
self.timer:every(2, function()
|
||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh))
|
||||
latest_object.timer:after(love.math.random(2, 4), function() latest_object:kill() end)
|
||||
end)
|
||||
|
||||
self.area:addGameObject('Player', gw/2, gh/2)
|
||||
end
|
||||
|
||||
function Stage:update(dt)
|
||||
Stage.super.update(self, dt)
|
||||
|
||||
if input:pressed('action') then
|
||||
local latest_object = self.area:addGameObject('Circle', love.math.random(1, gw), love.math.random(1, gh), {radius = 15})
|
||||
end
|
||||
|
||||
if input:pressed('right') then
|
||||
for _, game_object in ipairs(self.area.game_objects) do
|
||||
game_object:kill()
|
||||
end
|
||||
end
|
||||
|
||||
if input:pressed('left') then
|
||||
for _, game_object in ipairs(self.area.game_objects) do
|
||||
if game_object:is(Circle) then
|
||||
---@cast game_object Circle
|
||||
if game_object.mode == "fill" then game_object.mode = "line" else game_object.mode = "fill" end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.timer:update(dt)
|
||||
end
|
||||
|
||||
function Stage:canvasDraw()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue