Code: Select all
loader = require("AdvTiledLoader.Loader")
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()
ninja1 = love.graphics.newImage("/images/Character1.png")
ninja2 = love.graphics.newImage("/images/Character2.png")
ninja3 = love.graphics.newImage("/images/Character3.png")
tx = 0
ty = 0
loader.path = "maps/"
map = loader.load("level1.tmx")
map:setDrawRange (tx,ty, map.width * map.tileWidth, map.height * map.tileHeight)
world = {
speed = 200,
gravity = -400,
}
player = {
x = 50,
y = 300,
y_vel = 0,
speed = 200,
jump_vel = -500,
jumpheight = 300,
grounded = false,
}
end
Code: Select all
function state:update( dt )
if dt > 0.05 then
dt = 0.05
end
bg1.x = bg1.x - world.speed * dt
bg2.x = bg2.x - world.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 love.keyboard.isDown("right") then
world.speed = 400
elseif love.keyboard.isDown("left") then
world.speed = 50
elseif love.keyboard.isDown("up") then
player:jump()
end
tx = tx - (world.speed * dt)
end
Code: Select all
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.draw(ninja1, player.x, player.y,0,1,1,64,103 )
end