diff --git a/asteroids/main.lua b/asteroids/main.lua index 0c80ed7..ccdaccd 100644 --- a/asteroids/main.lua +++ b/asteroids/main.lua @@ -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 diff --git a/asteroids/resources/meteorBrown_big1.png b/asteroids/resources/meteorBrown_big1.png new file mode 100644 index 0000000..31e06a4 Binary files /dev/null and b/asteroids/resources/meteorBrown_big1.png differ diff --git a/asteroids/resources/meteorBrown_big2.png b/asteroids/resources/meteorBrown_big2.png new file mode 100644 index 0000000..90413d7 Binary files /dev/null and b/asteroids/resources/meteorBrown_big2.png differ diff --git a/asteroids/resources/meteorBrown_big3.png b/asteroids/resources/meteorBrown_big3.png new file mode 100644 index 0000000..3fdcce3 Binary files /dev/null and b/asteroids/resources/meteorBrown_big3.png differ diff --git a/asteroids/resources/meteorBrown_big4.png b/asteroids/resources/meteorBrown_big4.png new file mode 100644 index 0000000..e643572 Binary files /dev/null and b/asteroids/resources/meteorBrown_big4.png differ diff --git a/asteroids/resources/meteorBrown_med1.png b/asteroids/resources/meteorBrown_med1.png new file mode 100644 index 0000000..14fa6f5 Binary files /dev/null and b/asteroids/resources/meteorBrown_med1.png differ diff --git a/asteroids/resources/meteorBrown_med3.png b/asteroids/resources/meteorBrown_med3.png new file mode 100644 index 0000000..5ec2d1e Binary files /dev/null and b/asteroids/resources/meteorBrown_med3.png differ diff --git a/asteroids/resources/meteorBrown_small1.png b/asteroids/resources/meteorBrown_small1.png new file mode 100644 index 0000000..60cf04a Binary files /dev/null and b/asteroids/resources/meteorBrown_small1.png differ diff --git a/asteroids/resources/meteorBrown_small2.png b/asteroids/resources/meteorBrown_small2.png new file mode 100644 index 0000000..48cbc23 Binary files /dev/null and b/asteroids/resources/meteorBrown_small2.png differ diff --git a/asteroids/resources/meteorBrown_tiny1.png b/asteroids/resources/meteorBrown_tiny1.png new file mode 100644 index 0000000..69ef3a3 Binary files /dev/null and b/asteroids/resources/meteorBrown_tiny1.png differ diff --git a/asteroids/resources/meteorBrown_tiny2.png b/asteroids/resources/meteorBrown_tiny2.png new file mode 100644 index 0000000..8a561b5 Binary files /dev/null and b/asteroids/resources/meteorBrown_tiny2.png differ diff --git a/asteroids/resources/ship.png b/asteroids/resources/playerShip1_blue.png similarity index 100% rename from asteroids/resources/ship.png rename to asteroids/resources/playerShip1_blue.png