Add news steps
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
BIN
steps/4_spaceship1/assets/sprites/spaceship.png
Normal file
After Width: | Height: | Size: 12 KiB |
@ -12,8 +12,8 @@ function love.load()
|
|||||||
-- Spaceship
|
-- Spaceship
|
||||||
spaceship = {}
|
spaceship = {}
|
||||||
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
||||||
spaceship.x = game.height / 8
|
spaceship.x = 200
|
||||||
spaceship.y = (game.height / 4) - (spaceship.img:getHeight() / 2)
|
spaceship.y = 200
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
BIN
steps/4_spaceship2/assets/sprites/background.jpg
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
steps/4_spaceship2/assets/sprites/spaceship.png
Normal file
After Width: | Height: | Size: 12 KiB |
49
steps/4_spaceship2/main.lua
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
function love.load()
|
||||||
|
game = {}
|
||||||
|
game.width = 800
|
||||||
|
game.height = 480
|
||||||
|
love.window.setMode(game.width, game.height)
|
||||||
|
score = { x = 500, y = 40 }
|
||||||
|
-- Background
|
||||||
|
background = {}
|
||||||
|
background.img = love.graphics.newImage('assets/sprites/background.jpg')
|
||||||
|
background.x = 0
|
||||||
|
background.y = 0
|
||||||
|
-- Spaceship
|
||||||
|
spaceship = {}
|
||||||
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
||||||
|
spaceship.x = 200
|
||||||
|
spaceship.y = 200
|
||||||
|
spaceship.num_frames = 4
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
spaceship.frame_height = spaceship.img:getHeight() / spaceship.num_frames
|
||||||
|
spaceship.pos = 2
|
||||||
|
spaceship.frames = {
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 0, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 1, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 2, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 3, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
-- Background
|
||||||
|
love.graphics.draw(background.img, background.x, background.y)
|
||||||
|
-- Spaceship
|
||||||
|
love.graphics.draw(spaceship.img, spaceship.frames[spaceship.pos_frame], spaceship.x, spaceship.y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
if spaceship.pos_frame ~= spaceship.num_frames then
|
||||||
|
spaceship.pos_frame = spaceship.pos_frame + 1
|
||||||
|
else
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controls
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if key == 'escape' then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
end
|
BIN
steps/5_move_spaceship/assets/sprites/background.jpg
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
steps/5_move_spaceship/assets/sprites/spaceship.png
Normal file
After Width: | Height: | Size: 12 KiB |
58
steps/5_move_spaceship/main.lua
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
function love.load()
|
||||||
|
game = {}
|
||||||
|
game.width = 800
|
||||||
|
game.height = 480
|
||||||
|
love.window.setMode(game.width, game.height)
|
||||||
|
score = { x = 500, y = 40 }
|
||||||
|
-- Background
|
||||||
|
background = {}
|
||||||
|
background.img = love.graphics.newImage('assets/sprites/background.jpg')
|
||||||
|
background.x = 0
|
||||||
|
background.y = 0
|
||||||
|
-- Spaceship
|
||||||
|
spaceship = {}
|
||||||
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
||||||
|
spaceship.x = game.height / 8
|
||||||
|
spaceship.num_frames = 4
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
spaceship.frame_height = spaceship.img:getHeight() / spaceship.num_frames
|
||||||
|
spaceship.y = {
|
||||||
|
(game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
2 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
3 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
}
|
||||||
|
spaceship.pos = 1
|
||||||
|
spaceship.frames = {
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 0, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 1, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 2, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 3, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
-- Background
|
||||||
|
love.graphics.draw(background.img, background.x, background.y)
|
||||||
|
-- Spaceship
|
||||||
|
love.graphics.draw(spaceship.img, spaceship.frames[spaceship.pos_frame], spaceship.x, spaceship.y[spaceship.pos])
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
if spaceship.pos_frame ~= spaceship.num_frames then
|
||||||
|
spaceship.pos_frame = spaceship.pos_frame + 1
|
||||||
|
else
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controls
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if key == 'escape' then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
if key == 'up' and spaceship.pos > 1 then
|
||||||
|
spaceship.pos = spaceship.pos - 1
|
||||||
|
elseif key == 'down' and spaceship.pos < 3 then
|
||||||
|
spaceship.pos = spaceship.pos + 1
|
||||||
|
end
|
||||||
|
end
|
BIN
steps/6_asteroids1/assets/sprites/asteroid_1.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_2.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_3.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_4.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_5.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_6.png
Executable file
After Width: | Height: | Size: 16 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_7.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_8.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids1/assets/sprites/asteroid_9.png
Executable file
After Width: | Height: | Size: 17 KiB |
BIN
steps/6_asteroids1/assets/sprites/background.jpg
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
steps/6_asteroids1/assets/sprites/spaceship.png
Normal file
After Width: | Height: | Size: 12 KiB |
73
steps/6_asteroids1/main.lua
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
function love.load()
|
||||||
|
math.randomseed(os.time())
|
||||||
|
game = {}
|
||||||
|
game.width = 800
|
||||||
|
game.height = 480
|
||||||
|
love.window.setMode(game.width, game.height)
|
||||||
|
score = { x = 500, y = 40 }
|
||||||
|
-- Background
|
||||||
|
background = {}
|
||||||
|
background.img = love.graphics.newImage('assets/sprites/background.jpg')
|
||||||
|
background.x = 0
|
||||||
|
background.y = 0
|
||||||
|
-- Spaceship
|
||||||
|
spaceship = {}
|
||||||
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
||||||
|
spaceship.x = game.height / 8
|
||||||
|
spaceship.num_frames = 4
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
spaceship.frame_height = spaceship.img:getHeight() / spaceship.num_frames
|
||||||
|
spaceship.y = {
|
||||||
|
(game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
2 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
3 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
}
|
||||||
|
spaceship.pos = 1
|
||||||
|
spaceship.frames = {
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 0, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 1, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 2, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 3, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Asteroid
|
||||||
|
asteroid = {}
|
||||||
|
asteroid.img = love.graphics.newImage('assets/sprites/asteroid_' .. tostring(math.random(1, 9)) .. '.png')
|
||||||
|
asteroid.x = 400
|
||||||
|
asteroid.y = {
|
||||||
|
(game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
2 * (game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
3 * (game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
}
|
||||||
|
asteroid.pos = 2
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
-- Background
|
||||||
|
love.graphics.draw(background.img, background.x, background.y)
|
||||||
|
-- Spaceship
|
||||||
|
love.graphics.draw(spaceship.img, spaceship.frames[spaceship.pos_frame], spaceship.x, spaceship.y[spaceship.pos])
|
||||||
|
-- Asteroid
|
||||||
|
love.graphics.draw(asteroid.img, asteroid.x, asteroid.y[asteroid.pos])
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
-- Spaceship
|
||||||
|
if spaceship.pos_frame ~= spaceship.num_frames then
|
||||||
|
spaceship.pos_frame = spaceship.pos_frame + 1
|
||||||
|
else
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controls
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if key == 'escape' then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
if key == 'up' and spaceship.pos > 1 then
|
||||||
|
spaceship.pos = spaceship.pos - 1
|
||||||
|
elseif key == 'down' and spaceship.pos < 3 then
|
||||||
|
spaceship.pos = spaceship.pos + 1
|
||||||
|
end
|
||||||
|
end
|
BIN
steps/6_asteroids2/assets/sprites/asteroid_1.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_2.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_3.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_4.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_5.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_6.png
Executable file
After Width: | Height: | Size: 16 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_7.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_8.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids2/assets/sprites/asteroid_9.png
Executable file
After Width: | Height: | Size: 17 KiB |
BIN
steps/6_asteroids2/assets/sprites/background.jpg
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
steps/6_asteroids2/assets/sprites/spaceship.png
Normal file
After Width: | Height: | Size: 12 KiB |
77
steps/6_asteroids2/main.lua
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
function love.load()
|
||||||
|
math.randomseed(os.time())
|
||||||
|
game = {}
|
||||||
|
game.width = 800
|
||||||
|
game.height = 480
|
||||||
|
love.window.setMode(game.width, game.height)
|
||||||
|
score = { x = 500, y = 40 }
|
||||||
|
-- Background
|
||||||
|
background = {}
|
||||||
|
background.img = love.graphics.newImage('assets/sprites/background.jpg')
|
||||||
|
background.x = 0
|
||||||
|
background.y = 0
|
||||||
|
-- Spaceship
|
||||||
|
spaceship = {}
|
||||||
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
||||||
|
spaceship.x = game.height / 8
|
||||||
|
spaceship.num_frames = 4
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
spaceship.frame_height = spaceship.img:getHeight() / spaceship.num_frames
|
||||||
|
spaceship.y = {
|
||||||
|
(game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
2 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
3 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
}
|
||||||
|
spaceship.pos = 1
|
||||||
|
spaceship.frames = {
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 0, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 1, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 2, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 3, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Asteroid
|
||||||
|
asteroid = {}
|
||||||
|
asteroid.img = love.graphics.newImage('assets/sprites/asteroid_' .. tostring(math.random(1, 9)) .. '.png')
|
||||||
|
asteroid.x = game.width
|
||||||
|
asteroid.y = {
|
||||||
|
(game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
2 * (game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
3 * (game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
}
|
||||||
|
asteroid.pos = 2
|
||||||
|
asteroid.speed = 600
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
-- Background
|
||||||
|
love.graphics.draw(background.img, background.x, background.y)
|
||||||
|
-- Spaceship
|
||||||
|
love.graphics.draw(spaceship.img, spaceship.frames[spaceship.pos_frame], spaceship.x, spaceship.y[spaceship.pos])
|
||||||
|
-- Asteroid
|
||||||
|
love.graphics.draw(asteroid.img, asteroid.x, asteroid.y[asteroid.pos])
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
-- Spaceship
|
||||||
|
if spaceship.pos_frame ~= spaceship.num_frames then
|
||||||
|
spaceship.pos_frame = spaceship.pos_frame + 1
|
||||||
|
else
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
end
|
||||||
|
-- Asteroid
|
||||||
|
asteroid.x = asteroid.x - (dt * asteroid.speed)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controls
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if key == 'escape' then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
if key == 'up' and spaceship.pos > 1 then
|
||||||
|
spaceship.pos = spaceship.pos - 1
|
||||||
|
elseif key == 'down' and spaceship.pos < 3 then
|
||||||
|
spaceship.pos = spaceship.pos + 1
|
||||||
|
end
|
||||||
|
end
|
BIN
steps/6_asteroids3/assets/sprites/asteroid_1.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_2.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_3.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_4.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_5.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_6.png
Executable file
After Width: | Height: | Size: 16 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_7.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_8.png
Executable file
After Width: | Height: | Size: 15 KiB |
BIN
steps/6_asteroids3/assets/sprites/asteroid_9.png
Executable file
After Width: | Height: | Size: 17 KiB |
BIN
steps/6_asteroids3/assets/sprites/background.jpg
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
steps/6_asteroids3/assets/sprites/spaceship.png
Normal file
After Width: | Height: | Size: 12 KiB |
89
steps/6_asteroids3/main.lua
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
function love.load()
|
||||||
|
math.randomseed(os.time())
|
||||||
|
game = {}
|
||||||
|
game.width = 800
|
||||||
|
game.height = 480
|
||||||
|
love.window.setMode(game.width, game.height)
|
||||||
|
score = { x = 500, y = 40 }
|
||||||
|
-- Background
|
||||||
|
background = {}
|
||||||
|
background.img = love.graphics.newImage('assets/sprites/background.jpg')
|
||||||
|
background.x = 0
|
||||||
|
background.y = 0
|
||||||
|
-- Spaceship
|
||||||
|
spaceship = {}
|
||||||
|
spaceship.img = love.graphics.newImage('assets/sprites/spaceship.png')
|
||||||
|
spaceship.x = game.height / 8
|
||||||
|
spaceship.num_frames = 4
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
spaceship.frame_height = spaceship.img:getHeight() / spaceship.num_frames
|
||||||
|
spaceship.y = {
|
||||||
|
(game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
2 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
3 * (game.height / 4) - (spaceship.img:getHeight() / 8),
|
||||||
|
}
|
||||||
|
spaceship.pos = 1
|
||||||
|
spaceship.frames = {
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 0, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 1, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 2, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight()),
|
||||||
|
love.graphics.newQuad(0, spaceship.frame_height * 3, spaceship.img:getWidth(), spaceship.frame_height, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Asteroids
|
||||||
|
num_asteroids = 3
|
||||||
|
asteroids = {}
|
||||||
|
for i = 1, num_asteroids do
|
||||||
|
asteroid = {}
|
||||||
|
asteroid.img = love.graphics.newImage('assets/sprites/asteroid_' .. tostring(math.random(1, 9)) .. '.png')
|
||||||
|
asteroid.x = game.width
|
||||||
|
asteroid.y = {
|
||||||
|
(game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
2 * (game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
3 * (game.height / 4) - (asteroid.img:getHeight() / 2),
|
||||||
|
}
|
||||||
|
asteroid.pos = 2
|
||||||
|
asteroid.speed = 600
|
||||||
|
asteroids[i] = asteroid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
|
-- Background
|
||||||
|
love.graphics.draw(background.img, background.x, background.y)
|
||||||
|
-- Spaceship
|
||||||
|
love.graphics.draw(spaceship.img, spaceship.frames[spaceship.pos_frame], spaceship.x, spaceship.y[spaceship.pos])
|
||||||
|
-- Asteroids
|
||||||
|
for key, asteroid in pairs(asteroids) do
|
||||||
|
love.graphics.draw(asteroid.img, asteroid.x, asteroid.y[asteroid.pos])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.update(dt)
|
||||||
|
-- Spaceship
|
||||||
|
if spaceship.pos_frame ~= spaceship.num_frames then
|
||||||
|
spaceship.pos_frame = spaceship.pos_frame + 1
|
||||||
|
else
|
||||||
|
spaceship.pos_frame = 1
|
||||||
|
end
|
||||||
|
-- Asteroids
|
||||||
|
for key, asteroid in pairs(asteroids) do
|
||||||
|
asteroid.x = asteroid.x - (dt * asteroid.speed)
|
||||||
|
if asteroid.x < -asteroid.img:getWidth() then
|
||||||
|
asteroid.x = game.width + math.random(0, game.width)
|
||||||
|
asteroid.pos = math.random(1, 3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controls
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if key == 'escape' then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
if key == 'up' and spaceship.pos > 1 then
|
||||||
|
spaceship.pos = spaceship.pos - 1
|
||||||
|
elseif key == 'down' and spaceship.pos < 3 then
|
||||||
|
spaceship.pos = spaceship.pos + 1
|
||||||
|
end
|
||||||
|
end
|