Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- love = require 'love'
- function love.load()
- anim8 = require 'libraries/anim8'
- love.graphics.setDefaultFilter('nearest', 'nearest')
- player = {}
- player.x = love.graphics.getWidth()/2 - 80/2
- player.y = love.graphics.getHeight()/2 - 80/2
- player.speed = 5
- player.spriteSheet = love.graphics.newImage("sprites/player-sheet.png")
- player.grid = anim8.newGrid(12, 18, player.spriteSheet:getWidth(), player.spriteSheet:getHeight())
- player.animations = {}
- player.animations.down = anim8.newAnimation(player.grid('1-4', 1), 0.2)
- player.animations.left = anim8.newAnimation(player.grid('1-4', 2), 0.2)
- player.animations.right = anim8.newAnimation(player.grid('1-4', 3), 0.2)
- player.animations.up = anim8.newAnimation(player.grid('1-4', 4), 0.2)
- player.anim = player.animations.left
- end
- function love.update(dt)
- local isMoving = false
- if love.keyboard.isDown("a", "left") then
- player.x = player.x - player.speed
- player.anim = player.animations.left
- isMoving = true
- end
- if love.keyboard.isDown("d", "right") then
- player.x = player.x + player.speed
- player.anim = player.animations.right
- isMoving = true
- end
- if love.keyboard.isDown("s", "down") then
- player.y = player.y + player.speed
- player.anim = player.animations.down
- isMoving = true
- end
- if love.keyboard.isDown("w", "up") then
- player.y = player.y - player.speed
- player.anim = player.animations.up
- isMoving = true
- end
- if isMoving == false then
- player.anim:gotoFrame(2)
- end
- player.anim:update(dt)
- end
- function love.draw()
- player.anim:draw(player.spriteSheet, player.x, player.y, nil, 6, nil, 6, 9)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement