Add animation fire spaceship and light
This commit is contained in:
@ -1,29 +1,53 @@
|
||||
local anim8 = require 'assets/scripts/vendor/anim8'
|
||||
|
||||
local spaceship = {}
|
||||
local press_button = false
|
||||
|
||||
function spaceship.load(game)
|
||||
-- power origin 1000
|
||||
spaceship = { x = game.canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
|
||||
spaceship.width = 156
|
||||
spaceship.height = 143
|
||||
spaceship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
|
||||
spaceship.body = love.physics.newBody(game.world, (game.canvas.width / 2) - (spaceship.img:getWidth() / 2) , spaceship.y, 'dynamic')
|
||||
spaceship.shape = love.physics.newCircleShape(20)
|
||||
spaceship.fixture = love.physics.newFixture(spaceship.body, spaceship.shape, 1)
|
||||
spaceship.fixture:setRestitution(0.9)
|
||||
local g = anim8.newGrid(110, 103, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||
spaceship.animation = anim8.newAnimation(g('1-1', 1), 0.1)
|
||||
local g = anim8.newGrid(spaceship.width, spaceship.height, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||
spaceship.animation_stop = anim8.newAnimation(g('1-1', 1), 0.1)
|
||||
spaceship.animation_fire = anim8.newAnimation(g('2-5', 1), 0.01)
|
||||
-- Light
|
||||
light = {
|
||||
img = love.graphics.newImage('assets/sprites/spaceship/light.png'),
|
||||
y = spaceship.y
|
||||
}
|
||||
light.x = spaceship.x + (spaceship.img:getWidth() / 2) + (light.img:getWidth() / 2)
|
||||
light.num_frames = 9
|
||||
light.width = 16
|
||||
light.height = 16
|
||||
g = anim8.newGrid(light.width, light.height, light.img:getWidth(), light.img:getHeight())
|
||||
light.animation = anim8.newAnimation(g('1-' .. light.num_frames, 1), 0.1)
|
||||
end
|
||||
|
||||
function spaceship.update(dt)
|
||||
spaceship.animation:update(dt)
|
||||
-- Spaceship
|
||||
spaceship.animation_fire:update(dt)
|
||||
press_button = false
|
||||
-- Light
|
||||
light.animation:update(dt)
|
||||
light.x = spaceship.body:getX() + (spaceship.width / 2) + (light.width / 2)
|
||||
light.y = spaceship.body:getY()
|
||||
-- Controls
|
||||
if control_up then
|
||||
spaceship.body:applyForce(0, -spaceship.power)
|
||||
press_button = true
|
||||
end
|
||||
if control_right then
|
||||
spaceship.body:applyForce(spaceship.power, 0)
|
||||
press_button = true
|
||||
elseif control_left then
|
||||
spaceship.body:applyForce(-spaceship.power, 0)
|
||||
press_button = true
|
||||
end
|
||||
if control_quit then
|
||||
love.event.push('quit')
|
||||
@ -31,7 +55,12 @@ function spaceship.update(dt)
|
||||
end
|
||||
|
||||
function spaceship.draw()
|
||||
spaceship.animation:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
|
||||
light.animation:draw(light.img, light.x, light.y)
|
||||
if press_button then
|
||||
spaceship.animation_fire:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
|
||||
else
|
||||
spaceship.animation_stop:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
|
||||
end
|
||||
end
|
||||
|
||||
return spaceship
|
BIN
assets/sprites/spaceship/light.png
Executable file
BIN
assets/sprites/spaceship/light.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user