Code: Select all
Gamestate.level1 = Gamestate.new( )
local state = Gamestate.level1
loader = require("AdvTiledLoader.Loader")
HC = require("HardonCollider")
function state:init( )
windowx = love.graphics.getWidth()
bg1 = {}
bg1.img = love.graphics.newImage("/images/Citybackgroundnight.png")
bg1.x = 0
bg1.width = bg1.img:getWidth()
bg2 = {}
bg2.img = love.graphics.newImage("/images/Citybackgroundnight.png")
bg2.x = windowx
bg2.width = bg2.img:getWidth()
tx = 0
ty = 0
loader.path = "maps/"
map = loader.load("level1.tmx")
map:setDrawRange (tx,ty, map.width * map.tileWidth, map.height * map.tileHeight)
player = {
x = 0,
y = 0,
y_velocity = 0,
ninja = love.graphics.newImage("/images/Character1.png")
}
speed = 200
gravity = 400
jump_height = 350
winW, winH = love.graphics.getWidth(), love.graphics.getHeight()
end
function state:update( dt )
if dt > 0.05 then
dt = 0.05
end
bg1.x = bg1.x - speed * dt
bg2.x = bg2.x - speed * dt
if bg1.x < -800 then
bg1.x = bg1.x + bg1.width
end
if bg2.x < 0 then
bg2.x = bg2.x + bg2.width
end
if player.y_velocity ~= 0 then
player.y = player.y + player.y_velocity * dt
player.y_velocity = player.y_velocity - gravity * dt
end
tx = tx - (speed * dt)
function love.keypressed(key)
if key == "right" then
speed = 400
elseif key == "left" then
speed = 50
elseif key == "up" then
if player.y_velocity == 0 then
player.y_velocity = jump_height
end
end
end
function love.keyreleased(key)
if key == "left" then
speed = 200
elseif key == "right" then
speed = 200
end
end
end
function state:draw( )
love.graphics.setColor(255,255,255,255)
love.graphics.draw(bg1.img, bg1.x, 0)
love.graphics.draw(bg2.img, bg2.x, 0)
love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 10, 10)
local ftx, fty = math.floor(tx), math.floor(ty)
love.graphics.push()
love.graphics.scale(scale)
love.graphics.translate(ftx, fty)
map:draw()
love.graphics.pop()
love.graphics.translate(30, 360)
love.graphics.draw(player.ninja, player.x, -player.y, 0, 1, 1, 1, 50)
end