asteroid sprites, spins and facing for all actors

This commit is contained in:
Donald Ball 2025-11-17 23:10:15 -05:00
parent 13bec1a0aa
commit eae3659768
12 changed files with 33 additions and 10 deletions

View file

@ -15,14 +15,14 @@ local function initGame()
time = 4,
sound = love.sound.newSoundData('resources/bullet.mp3'),
},
sprite = love.graphics.newImage('resources/ship.png'),
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
},
asteroids = {
stages = {
{ speed = 120, radius = 15 },
{ speed = 70, radius = 30 },
{ speed = 50, radius = 50 },
{ speed = 20, radius = 80 },
{ speed = 120, radius = 15, sprite = love.graphics.newImage('resources/meteorBrown_tiny1.png') },
{ speed = 70, radius = 30, sprite = love.graphics.newImage('resources/meteorBrown_small1.png') },
{ speed = 50, radius = 50, sprite = love.graphics.newImage('resources/meteorBrown_med1.png') },
{ speed = 20, radius = 80, sprite = love.graphics.newImage('resources/meteorBrown_big1.png') },
},
},
controls = {
@ -57,7 +57,10 @@ local function initState()
asteroid.stage = #game.asteroids.stages
local stage = game.asteroids.stages[asteroid.stage]
asteroid.speed = stage.speed
asteroid.facing = math.random() * phys.tau
asteroid.spin = 2 + math.random() * 5
asteroid.radius = stage.radius
asteroid.sprite = stage.sprite
end
local joystick = nil
if love.joystick.getJoystickCount() == 1 then
@ -68,8 +71,9 @@ local function initState()
x = game.width / 2,
y = game.height / 2,
angle = 0,
facing = phys.tau * 3 / 4,
speed = 0,
spin = 0,
facing = phys.tau * 3 / 4,
radius = game.ship.radius,
},
bullets = {},
@ -125,8 +129,10 @@ function love.update(dt)
if asteroid.stage > 1 then
local angle1 = love.math.random() * phys.tau
local angle2 = angle1 - phys.tau / 2
local radius = game.asteroids.stages[asteroid.stage - 1].radius
local speed = game.asteroids.stages[asteroid.stage - 1].speed
local stage = game.asteroids.stages[asteroid.stage - 1]
local radius = stage.radius
local speed = stage.speed
local sprite = stage.sprite
table.insert(state.asteroids, {
x = asteroid.x,
y = asteroid.y,
@ -134,6 +140,9 @@ function love.update(dt)
stage = asteroid.stage - 1,
radius = radius,
speed = speed,
facing = math.random() * phys.tau,
spin = 2 + math.random() * 5,
sprite = sprite,
})
table.insert(state.asteroids, {
x = asteroid.x,
@ -142,6 +151,9 @@ function love.update(dt)
stage = asteroid.stage - 1,
radius = radius,
speed = speed,
facing = math.random() * phys.tau,
spin = 2 + math.random() * 5,
sprite = sprite,
})
end
table.remove(state.asteroids, asteroidIndex)
@ -178,6 +190,8 @@ function love.gamepadpressed(joystick, button)
radius = game.ship.bullet.radius,
timeLeft = game.ship.bullet.time,
sound = love.audio.newSource(game.ship.bullet.sound),
facing = state.ship.facing,
spin = 0,
}
phys.apply(bullet, state.ship)
table.insert(state.bullets, bullet)
@ -212,8 +226,17 @@ function love.draw()
end
for _, asteroid in ipairs(state.asteroids) do
love.graphics.setColor(1, 1, 0)
love.graphics.circle('fill', asteroid.x, asteroid.y, game.asteroids.stages[asteroid.stage].radius)
love.graphics.setColor(1, 1, 1)
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

View file

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before After
Before After