Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cam
- function love.load()
- anim8 = require 'libs/anim8'
- wf = require 'libs/windfield'
- world = wf.newWorld(0, 0)
- sti = require 'libs/sti'
- map = sti('map/test map.lua')
- gamera = require 'libs/gamera'
- local mapWidth = map.width * map.tilewidth
- local mapHeight = map.height * map.tileheight
- cam = gamera.new(0, 0, mapWidth, mapHeight)
- player = {}
- player.speed = 3
- player.x = 400
- player.y = 300
- player.sprite = love.graphics.newImage('sprites/$Lonely.png')
- player.Grid = anim8.newGrid(32, 32, player.sprite:getWidth(), player.sprite:getHeight())
- player.animations = {}
- player.animations.right = anim8.newAnimation(player.Grid('1-3', 3), 0.2)
- player.animations.up = anim8.newAnimation(player.Grid('1-3', 4), 0.2)
- player.animations.left = anim8.newAnimation(player.Grid('1-3', 2), 0.2)
- player.animations.down = anim8.newAnimation(player.Grid('1-3', 1), 0.2)
- player.anim = player.animations.right
- love.graphics.setDefaultFilter("nearest", "nearest")
- player.collider = world:newBSGRectangleCollider(player.x, player.y, 40, 80, 14)
- player.collider:setFixedRotation(true)
- end
- function love.update(dt)
- local isMoving = false
- if love.keyboard.isDown("w") then
- player.y = player.y - player.speed
- player.anim = player.animations.up
- isMoving = true
- end
- if love.keyboard.isDown("d") then
- player.x = player.x + player.speed
- isMoving = true
- player.anim = player.animations.right
- end
- if love.keyboard.isDown("a") then
- player.x = player.x - player.speed
- isMoving = true
- player.anim = player.animations.left
- end
- if love.keyboard.isDown("s") then
- player.y = player.y + player.speed
- player.anim = player.animations.down
- isMoving = true
- end
- player.anim:update(dt)
- if isMoving == false then
- player.anim:gotoFrame(2)
- end
- cam:setPosition(player.x, player.y)
- world:update(dt)
- player.x = player.collider:getX()
- player.y = player.collider:getY()
- end
- function love.draw()
- cam:draw(function(l, t, w, h)
- map:drawLayer(map.layers["ground"])
- map:drawLayer(map.layers["bushes"])
- map:drawLayer(map.layers["trees"])
- map:drawLayer(map.layers["buildings"])
- player.anim:draw(player.sprite, player.x, player.y, nil, 2)
- world:draw(dt)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement