111 lines
2.9 KiB
Lua
111 lines
2.9 KiB
Lua
local Object = require("object")
|
|
local Entity = require("entity")
|
|
local Map = require("map")
|
|
local helpers = require("helpers")
|
|
|
|
local GameState = Object:extend()
|
|
|
|
function GameState:init()
|
|
GameState.__super.init(self)
|
|
self.input = {
|
|
start=false,
|
|
right=false,
|
|
left=false,
|
|
up=false,
|
|
down=false,
|
|
jump=false,
|
|
}
|
|
self.ended = false
|
|
self.next = nil
|
|
end
|
|
|
|
function GameState:updateInput(dt)
|
|
self.input.start = love.keyboard.isDown("return")
|
|
self.input.right = love.keyboard.isDown("d", "right")
|
|
self.input.left = love.keyboard.isDown("a", "left")
|
|
self.input.up = love.keyboard.isDown("w", "up")
|
|
self.input.down = love.keyboard.isDown("down", "s")
|
|
self.input.jump = love.keyboard.isDown("space")
|
|
end
|
|
|
|
function GameState:update(dt)
|
|
self:updateInput(dt)
|
|
end
|
|
|
|
function GameState:draw()
|
|
end
|
|
|
|
local Play = GameState:extend()
|
|
|
|
function Play:init()
|
|
Play.__super.init(self)
|
|
self.map = Map:new("assets/map.lua")
|
|
self.current_frame = 0
|
|
self.physics = {
|
|
gravity=self.map.tileheight*9.8, -- somewhat exagerated gravity (3x)
|
|
maxdx=self.map.tilewidth*8, -- max horizontal speed
|
|
maxdy=self.map.tileheight*24, -- max vertical speed
|
|
jump=self.map.tileheight*512, -- instant jump impulse
|
|
}
|
|
self.physics.horizontal_acc = self.physics.maxdx*2 -- horizontal acceleration
|
|
self.physics.friction = self.physics.maxdx*1.5 -- horizontal friction
|
|
self.player_entity = Entity:new(180, 100, 4, 8, self.physics.gravity, 2*8, self.physics.horizontal_acc, self.physics.friction, self.map)
|
|
end
|
|
|
|
function Play:updatePlayer(dt)
|
|
self.player_entity = self.player_entity:move(self.input, dt, self.current_frame)
|
|
end
|
|
|
|
function Play:updateCamera(dt)
|
|
end
|
|
function Play:updateItems(dt)
|
|
end
|
|
function Play:updateEnemies(dt)
|
|
end
|
|
function Play:updateChirps(dt)
|
|
end
|
|
|
|
function Play:update(dt)
|
|
Play.__super.update(self, dt)
|
|
self.current_frame = self.current_frame + 1
|
|
self:updatePlayer(dt)
|
|
self:updateCamera(dt)
|
|
self:updateItems(dt)
|
|
self:updateEnemies(dt)
|
|
self:updateChirps(dt)
|
|
end
|
|
|
|
function Play:draw()
|
|
love.graphics.setColor(0.2, 0.2, 0.2)
|
|
self.map:draw()
|
|
love.graphics.setColor(0, 0.8, 0.1)
|
|
self.player_entity:draw()
|
|
end
|
|
local Title = GameState:extend()
|
|
|
|
function Title:update(dt)
|
|
Title.__super.update(self, dt)
|
|
if self.input.start then
|
|
print("PRESSED START ENDING THIS STATE")
|
|
self.ended = true
|
|
self.next = Play:new()
|
|
end
|
|
end
|
|
|
|
function Title:draw()
|
|
Title.__super.draw(self)
|
|
local font = love.graphics.getFont()
|
|
local height = font:getHeight()
|
|
local width = font:getWidth("MICHI")
|
|
love.graphics.setColor(1, 1, 1)
|
|
love.graphics.print("MICHI", 320/2, 24, 0, 2, 2, width/2, height/2)
|
|
width = font:getWidth("DRAGON")
|
|
love.graphics.print("DRAGON", 320/2, 64, 0, 2, 2, width/2, height/2)
|
|
width = font:getWidth("START")
|
|
love.graphics.print("START", 320/2, 128, 0, 1, 1, width/2, height/2)
|
|
end
|
|
return {
|
|
Play=Play,
|
|
Title=Title,
|
|
}
|