asteroid sprites, spins and facing for all actors
|
|
@ -15,14 +15,14 @@ local function initGame()
|
||||||
time = 4,
|
time = 4,
|
||||||
sound = love.sound.newSoundData('resources/bullet.mp3'),
|
sound = love.sound.newSoundData('resources/bullet.mp3'),
|
||||||
},
|
},
|
||||||
sprite = love.graphics.newImage('resources/ship.png'),
|
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
|
||||||
},
|
},
|
||||||
asteroids = {
|
asteroids = {
|
||||||
stages = {
|
stages = {
|
||||||
{ speed = 120, radius = 15 },
|
{ speed = 120, radius = 15, sprite = love.graphics.newImage('resources/meteorBrown_tiny1.png') },
|
||||||
{ speed = 70, radius = 30 },
|
{ speed = 70, radius = 30, sprite = love.graphics.newImage('resources/meteorBrown_small1.png') },
|
||||||
{ speed = 50, radius = 50 },
|
{ speed = 50, radius = 50, sprite = love.graphics.newImage('resources/meteorBrown_med1.png') },
|
||||||
{ speed = 20, radius = 80 },
|
{ speed = 20, radius = 80, sprite = love.graphics.newImage('resources/meteorBrown_big1.png') },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
controls = {
|
controls = {
|
||||||
|
|
@ -57,7 +57,10 @@ local function initState()
|
||||||
asteroid.stage = #game.asteroids.stages
|
asteroid.stage = #game.asteroids.stages
|
||||||
local stage = game.asteroids.stages[asteroid.stage]
|
local stage = game.asteroids.stages[asteroid.stage]
|
||||||
asteroid.speed = stage.speed
|
asteroid.speed = stage.speed
|
||||||
|
asteroid.facing = math.random() * phys.tau
|
||||||
|
asteroid.spin = 2 + math.random() * 5
|
||||||
asteroid.radius = stage.radius
|
asteroid.radius = stage.radius
|
||||||
|
asteroid.sprite = stage.sprite
|
||||||
end
|
end
|
||||||
local joystick = nil
|
local joystick = nil
|
||||||
if love.joystick.getJoystickCount() == 1 then
|
if love.joystick.getJoystickCount() == 1 then
|
||||||
|
|
@ -68,8 +71,9 @@ local function initState()
|
||||||
x = game.width / 2,
|
x = game.width / 2,
|
||||||
y = game.height / 2,
|
y = game.height / 2,
|
||||||
angle = 0,
|
angle = 0,
|
||||||
facing = phys.tau * 3 / 4,
|
|
||||||
speed = 0,
|
speed = 0,
|
||||||
|
spin = 0,
|
||||||
|
facing = phys.tau * 3 / 4,
|
||||||
radius = game.ship.radius,
|
radius = game.ship.radius,
|
||||||
},
|
},
|
||||||
bullets = {},
|
bullets = {},
|
||||||
|
|
@ -125,8 +129,10 @@ function love.update(dt)
|
||||||
if asteroid.stage > 1 then
|
if asteroid.stage > 1 then
|
||||||
local angle1 = love.math.random() * phys.tau
|
local angle1 = love.math.random() * phys.tau
|
||||||
local angle2 = angle1 - phys.tau / 2
|
local angle2 = angle1 - phys.tau / 2
|
||||||
local radius = game.asteroids.stages[asteroid.stage - 1].radius
|
local stage = game.asteroids.stages[asteroid.stage - 1]
|
||||||
local speed = game.asteroids.stages[asteroid.stage - 1].speed
|
local radius = stage.radius
|
||||||
|
local speed = stage.speed
|
||||||
|
local sprite = stage.sprite
|
||||||
table.insert(state.asteroids, {
|
table.insert(state.asteroids, {
|
||||||
x = asteroid.x,
|
x = asteroid.x,
|
||||||
y = asteroid.y,
|
y = asteroid.y,
|
||||||
|
|
@ -134,6 +140,9 @@ function love.update(dt)
|
||||||
stage = asteroid.stage - 1,
|
stage = asteroid.stage - 1,
|
||||||
radius = radius,
|
radius = radius,
|
||||||
speed = speed,
|
speed = speed,
|
||||||
|
facing = math.random() * phys.tau,
|
||||||
|
spin = 2 + math.random() * 5,
|
||||||
|
sprite = sprite,
|
||||||
})
|
})
|
||||||
table.insert(state.asteroids, {
|
table.insert(state.asteroids, {
|
||||||
x = asteroid.x,
|
x = asteroid.x,
|
||||||
|
|
@ -142,6 +151,9 @@ function love.update(dt)
|
||||||
stage = asteroid.stage - 1,
|
stage = asteroid.stage - 1,
|
||||||
radius = radius,
|
radius = radius,
|
||||||
speed = speed,
|
speed = speed,
|
||||||
|
facing = math.random() * phys.tau,
|
||||||
|
spin = 2 + math.random() * 5,
|
||||||
|
sprite = sprite,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
table.remove(state.asteroids, asteroidIndex)
|
table.remove(state.asteroids, asteroidIndex)
|
||||||
|
|
@ -178,6 +190,8 @@ function love.gamepadpressed(joystick, button)
|
||||||
radius = game.ship.bullet.radius,
|
radius = game.ship.bullet.radius,
|
||||||
timeLeft = game.ship.bullet.time,
|
timeLeft = game.ship.bullet.time,
|
||||||
sound = love.audio.newSource(game.ship.bullet.sound),
|
sound = love.audio.newSource(game.ship.bullet.sound),
|
||||||
|
facing = state.ship.facing,
|
||||||
|
spin = 0,
|
||||||
}
|
}
|
||||||
phys.apply(bullet, state.ship)
|
phys.apply(bullet, state.ship)
|
||||||
table.insert(state.bullets, bullet)
|
table.insert(state.bullets, bullet)
|
||||||
|
|
@ -212,8 +226,17 @@ function love.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, asteroid in ipairs(state.asteroids) do
|
for _, asteroid in ipairs(state.asteroids) do
|
||||||
love.graphics.setColor(1, 1, 0)
|
love.graphics.setColor(1, 1, 1)
|
||||||
love.graphics.circle('fill', asteroid.x, asteroid.y, game.asteroids.stages[asteroid.stage].radius)
|
scale = 2 * asteroid.radius / math.max(asteroid.sprite:getWidth(), asteroid.sprite:getHeight())
|
||||||
|
love.graphics.draw(asteroid.sprite,
|
||||||
|
asteroid.x,
|
||||||
|
asteroid.y,
|
||||||
|
asteroid.facing,
|
||||||
|
scale,
|
||||||
|
scale,
|
||||||
|
asteroid.sprite:getWidth() / 2,
|
||||||
|
asteroid.sprite:getHeight() / 2
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
BIN
asteroids/resources/meteorBrown_big1.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
asteroids/resources/meteorBrown_big2.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
asteroids/resources/meteorBrown_big3.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
asteroids/resources/meteorBrown_big4.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
asteroids/resources/meteorBrown_med1.png
Normal file
|
After Width: | Height: | Size: 982 B |
BIN
asteroids/resources/meteorBrown_med3.png
Normal file
|
After Width: | Height: | Size: 881 B |
BIN
asteroids/resources/meteorBrown_small1.png
Normal file
|
After Width: | Height: | Size: 692 B |
BIN
asteroids/resources/meteorBrown_small2.png
Normal file
|
After Width: | Height: | Size: 667 B |
BIN
asteroids/resources/meteorBrown_tiny1.png
Normal file
|
After Width: | Height: | Size: 461 B |
BIN
asteroids/resources/meteorBrown_tiny2.png
Normal file
|
After Width: | Height: | Size: 371 B |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |