Compare commits
4 Commits
background
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0aeb0139d3 | |||
| 391e2ab1b7 | |||
| 3af5bbe928 | |||
| e0ac6abaef |
7
main.lua
7
main.lua
@@ -37,6 +37,7 @@ if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
|||||||
function love.load()
|
function love.load()
|
||||||
love.window.setTitle('SpiderCut')
|
love.window.setTitle('SpiderCut')
|
||||||
love.graphics.setDefaultFilter('nearest', 'nearest')
|
love.graphics.setDefaultFilter('nearest', 'nearest')
|
||||||
|
love.graphics.setLineJoin( "bevel" )
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
|
|
||||||
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
|
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
|
||||||
@@ -59,7 +60,11 @@ function love.keypressed(key)
|
|||||||
if key == 'escape' then
|
if key == 'escape' then
|
||||||
love.event.quit()
|
love.event.quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if key == 'f' then
|
||||||
|
push:switchFullscreen()
|
||||||
|
end
|
||||||
|
|
||||||
love.keyboard.keysPressed[key] = true
|
love.keyboard.keysPressed[key] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
36
src/Clock.lua
Normal file
36
src/Clock.lua
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
Clock = Class {}
|
||||||
|
|
||||||
|
function Clock:init(timelimit, direction)
|
||||||
|
self.timeLimit = timelimit
|
||||||
|
self.direction = direction
|
||||||
|
self.color = {56 / 255, 56 / 255, 56 / 255, 1}
|
||||||
|
self.currentTime = "0"
|
||||||
|
self.timer = 0
|
||||||
|
self.startTime = self:getOsTime()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Clock:update(dt)
|
||||||
|
local passed = math.floor((self:getOsTime() - self.startTime) * 10 + 0.5)
|
||||||
|
if self.direction == 'down' then
|
||||||
|
self.currentTime = tostring(self.timeLimit - passed)
|
||||||
|
else
|
||||||
|
self.currentTime = tostring(passed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Clock:render()
|
||||||
|
if self.currentTime * 1 <= 10 then
|
||||||
|
local a = math.abs(math.cos(love.timer.getTime() * .85 % 2 * math.pi))
|
||||||
|
love.graphics.setColor(.8, .12, .12, a)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.color[1], self.color[2], self.color[3],
|
||||||
|
self.color[4])
|
||||||
|
end
|
||||||
|
love.graphics.setFont(gFonts['medium'])
|
||||||
|
love.graphics.printf('Time: ' .. self.currentTime, 0, 5, VIRTUAL_WIDTH,
|
||||||
|
'right')
|
||||||
|
love.graphics.setFont(gFonts['small'])
|
||||||
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Clock:getOsTime() return os.clock() end
|
||||||
@@ -10,6 +10,7 @@ Timer = require 'lib/knife.timer'
|
|||||||
require 'src/Animation'
|
require 'src/Animation'
|
||||||
require 'src/constants'
|
require 'src/constants'
|
||||||
require 'src/StateMachine'
|
require 'src/StateMachine'
|
||||||
|
require 'src/Clock'
|
||||||
require 'src/Util'
|
require 'src/Util'
|
||||||
|
|
||||||
require 'src/Level'
|
require 'src/Level'
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
-- require('mobdebug').start()
|
-- require('mobdebug').start()
|
||||||
Level = Class {}
|
Level = Class {}
|
||||||
|
|
||||||
function Level:init(stage)
|
function Level:init(def, stage)
|
||||||
self.stage = stage
|
self.stage = stage
|
||||||
self.points = {}
|
self.points = {}
|
||||||
self.player = {}
|
self.player = {}
|
||||||
self.segments = self:createLevel()
|
self.segments = self:createLevelFromDef(def, stage)
|
||||||
self.polygon = self:createPolygon()
|
self.polygon = self:createPolygon()
|
||||||
self.mesh = poly2mesh(self.points)
|
self.mesh = poly2mesh(self.points)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Level:update(dt)
|
function Level:update(dt)
|
||||||
-- print_r(self.points)
|
|
||||||
-- print(tostring(#self.points))
|
|
||||||
-- if self.mesh == nil and #self.points > 2 then
|
|
||||||
-- self.mesh = poly2mesh(self.points)
|
|
||||||
-- end
|
|
||||||
self.mesh = poly2mesh(self.points)
|
self.mesh = poly2mesh(self.points)
|
||||||
-- print_r(self.mesh:getVertices())
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Level:render()
|
function Level:render()
|
||||||
@@ -38,6 +31,14 @@ function Level:renderBackground()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Level:createLevelFromDef(def, stage)
|
||||||
|
local level = {}
|
||||||
|
for i, seg in pairs(def[1].segments) do
|
||||||
|
table.insert(level, Segment(seg.p1, seg.p2, seg.width, seg.face) )
|
||||||
|
end
|
||||||
|
return level
|
||||||
|
end
|
||||||
|
|
||||||
function Level:createLevel()
|
function Level:createLevel()
|
||||||
local level = {
|
local level = {
|
||||||
[1] = Segment({LEVEL_RENDER_OFFSET, LEVEL_RENDER_OFFSET_TOP}, {
|
[1] = Segment({LEVEL_RENDER_OFFSET, LEVEL_RENDER_OFFSET_TOP}, {
|
||||||
|
|||||||
@@ -39,13 +39,9 @@ function Player:init(def, level )
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Player:isMoveAllowed(point)
|
function Player:isMoveAllowed(point)
|
||||||
print("Player:isMoveAllowed " .. tostring(point[1]) .. "," .. tostring(point[2]))
|
|
||||||
point = {point[1] + self.width/2, point[2] + self.width/2}
|
point = {point[1] + self.width/2, point[2] + self.width/2}
|
||||||
print("Player:isMoveAllowed " .. tostring(point[1]) .. "," .. tostring(point[2]))
|
|
||||||
for i,segment in pairs (self.trailSegments) do
|
for i,segment in pairs (self.trailSegments) do
|
||||||
if segment:pointInSegment(point) then
|
if segment:pointInSegment(point) then
|
||||||
print("Player:isMoveAllowed = false")
|
|
||||||
print_r(segment)
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ function Segment:init(firstPoint, secondPoint, lineWidth, face, color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Segment:render()
|
function Segment:render()
|
||||||
love.graphics.setColor(self.color.r, self.color.g, self.color.b, 255)
|
love.graphics.setColor(self.color.r, self.color.g, self.color.b, 1)
|
||||||
love.graphics.setLineWidth(self.lineWidth)
|
love.graphics.setLineWidth(self.lineWidth)
|
||||||
love.graphics.line(self.firstPointX, self.firstPointY, self.secondPointX,
|
love.graphics.line(self.firstPointX, self.firstPointY, self.secondPointX,
|
||||||
self.secondPointY)
|
self.secondPointY)
|
||||||
|
|
||||||
love.graphics.setColor(255, 255, 255, 255)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
|
||||||
-- debug
|
-- debug
|
||||||
-- love.graphics.setFont(gFonts['small'])
|
-- love.graphics.setFont(gFonts['small'])
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ WINDOW_HEIGHT = 720
|
|||||||
LEVEL_RENDER_OFFSET_TOP = 30
|
LEVEL_RENDER_OFFSET_TOP = 30
|
||||||
LEVEL_RENDER_OFFSET = 10
|
LEVEL_RENDER_OFFSET = 10
|
||||||
|
|
||||||
TILE_SIZE = 16
|
TILE_SIZE = 16
|
||||||
|
|
||||||
|
LINE_WIDTH = .5
|
||||||
@@ -44,4 +44,36 @@ ENTITY_DEFS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LEVELS_DEF = {
|
||||||
|
[1] = {
|
||||||
|
segments =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
p1 = {LEVEL_RENDER_OFFSET, LEVEL_RENDER_OFFSET_TOP},
|
||||||
|
p2 = {VIRTUAL_WIDTH - LEVEL_RENDER_OFFSET, LEVEL_RENDER_OFFSET_TOP},
|
||||||
|
width = LINE_WIDTH,
|
||||||
|
face = 'down'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
p1 = {VIRTUAL_WIDTH - LEVEL_RENDER_OFFSET, LEVEL_RENDER_OFFSET_TOP},
|
||||||
|
p2 = {VIRTUAL_WIDTH - LEVEL_RENDER_OFFSET, VIRTUAL_HEIGHT - LEVEL_RENDER_OFFSET},
|
||||||
|
width = LINE_WIDTH,
|
||||||
|
face = 'left'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
p1 = {VIRTUAL_WIDTH - LEVEL_RENDER_OFFSET, VIRTUAL_HEIGHT - LEVEL_RENDER_OFFSET},
|
||||||
|
p2 = {LEVEL_RENDER_OFFSET, VIRTUAL_HEIGHT - LEVEL_RENDER_OFFSET},
|
||||||
|
width = LINE_WIDTH,
|
||||||
|
face = 'up'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
p1 = {LEVEL_RENDER_OFFSET, VIRTUAL_HEIGHT - LEVEL_RENDER_OFFSET},
|
||||||
|
p2 = {LEVEL_RENDER_OFFSET, LEVEL_RENDER_OFFSET_TOP},
|
||||||
|
width= LINE_WIDTH,
|
||||||
|
face = 'right'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -5,12 +5,13 @@ PlayState = Class{__includes = BaseState}
|
|||||||
function PlayState:init()
|
function PlayState:init()
|
||||||
self.name = 'PlayState'
|
self.name = 'PlayState'
|
||||||
self.stage = 1
|
self.stage = 1
|
||||||
self.level = Level(self.stage)
|
self.level = Level(LEVELS_DEF, self.stage)
|
||||||
self.player = Player ( ENTITY_DEFS['player'] , self.level)
|
self.player = Player ( ENTITY_DEFS['player'] , self.level)
|
||||||
self.level.player = self.player
|
self.level.player = self.player
|
||||||
self.balls = {}
|
self.balls = {}
|
||||||
self:createBalls()
|
self:createBalls()
|
||||||
self.level.balls = self.balls
|
self.level.balls = self.balls
|
||||||
|
self.clock = Clock(30,"down")
|
||||||
|
|
||||||
gSounds['music']:setLooping(true)
|
gSounds['music']:setLooping(true)
|
||||||
gSounds['music']:play()
|
gSounds['music']:play()
|
||||||
@@ -23,6 +24,7 @@ end
|
|||||||
function PlayState:update(dt)
|
function PlayState:update(dt)
|
||||||
self.level:update(dt)
|
self.level:update(dt)
|
||||||
self.player:update(dt)
|
self.player:update(dt)
|
||||||
|
self.clock:update(dt)
|
||||||
self:updateBalls(dt, self.level)
|
self:updateBalls(dt, self.level)
|
||||||
self:checkEndLevel(self.level)
|
self:checkEndLevel(self.level)
|
||||||
end
|
end
|
||||||
@@ -39,6 +41,7 @@ function PlayState:render()
|
|||||||
love.graphics.printf('Stage '..tostring(self.stage),
|
love.graphics.printf('Stage '..tostring(self.stage),
|
||||||
0, 5, VIRTUAL_WIDTH, 'center')
|
0, 5, VIRTUAL_WIDTH, 'center')
|
||||||
|
|
||||||
|
self.clock:render()
|
||||||
self.level:render()
|
self.level:render()
|
||||||
self.player:render()
|
self.player:render()
|
||||||
self:renderBalls(dt)
|
self:renderBalls(dt)
|
||||||
@@ -71,15 +74,6 @@ function PlayState:updateBalls(dt, level)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #self.balls <= 0 then
|
|
||||||
-- game over - reset level
|
|
||||||
self:gameOver()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check perimeter of level, if low enough, create new level move on to the next stage
|
|
||||||
if level:getPerimeter() < 500 then
|
|
||||||
self:nextStage()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlayState:checkEndLevel (level)
|
function PlayState:checkEndLevel (level)
|
||||||
@@ -92,6 +86,13 @@ function PlayState:checkEndLevel (level)
|
|||||||
if level:getPerimeter() < 500 then
|
if level:getPerimeter() < 500 then
|
||||||
self:nextStage()
|
self:nextStage()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if clock finished counting limit time
|
||||||
|
if self.clock.direction == 'up' and self.clock.currentTime * 1 > self.clock.timeLimit then
|
||||||
|
self:gameOver()
|
||||||
|
elseif self.clock.direction == 'down' and self.clock.currentTime * 1 <= 0 then
|
||||||
|
self:gameOver()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlayState:renderBalls(dt)
|
function PlayState:renderBalls(dt)
|
||||||
@@ -110,7 +111,8 @@ function PlayState:nextStage()
|
|||||||
gStateStack:push(FadeOutState({
|
gStateStack:push(FadeOutState({
|
||||||
r = 255/255, g = 255/255, b = 255/255}, 1,function()
|
r = 255/255, g = 255/255, b = 255/255}, 1,function()
|
||||||
self.stage = self.stage + 1
|
self.stage = self.stage + 1
|
||||||
self.level = Level(self.stage)
|
self.level = Level(LEVELS_DEF,self.stage)
|
||||||
|
self.clock = Clock(self.clock.timeLimit + 3 * #self.balls,"down")
|
||||||
self.player:reset()
|
self.player:reset()
|
||||||
self.player.score = self.player.score + self.player.multiplier * #self.balls
|
self.player.score = self.player.score + self.player.multiplier * #self.balls
|
||||||
self.player.multiplier = self.player.multiplier + #self.balls
|
self.player.multiplier = self.player.multiplier + #self.balls
|
||||||
|
|||||||
Reference in New Issue
Block a user