From 63b296e19c7e9b68307ce531ed66ab43571327a4 Mon Sep 17 00:00:00 2001 From: Donald Ball Date: Mon, 17 Nov 2025 23:15:21 -0500 Subject: [PATCH] spinning asteroids --- asteroids/main.lua | 6 +++--- asteroids/phys.lua | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/asteroids/main.lua b/asteroids/main.lua index ccdaccd..27427fc 100644 --- a/asteroids/main.lua +++ b/asteroids/main.lua @@ -58,7 +58,7 @@ local function initState() local stage = game.asteroids.stages[asteroid.stage] asteroid.speed = stage.speed asteroid.facing = math.random() * phys.tau - asteroid.spin = 2 + math.random() * 5 + asteroid.spin = 0.1 + math.random() * 0.1 asteroid.radius = stage.radius asteroid.sprite = stage.sprite end @@ -141,7 +141,7 @@ function love.update(dt) radius = radius, speed = speed, facing = math.random() * phys.tau, - spin = 2 + math.random() * 5, + spin = 0.1 + math.random() * 0.1, sprite = sprite, }) table.insert(state.asteroids, { @@ -152,7 +152,7 @@ function love.update(dt) radius = radius, speed = speed, facing = math.random() * phys.tau, - spin = 2 + math.random() * 5, + spin = 0.1 + math.random() * 0.1, sprite = sprite, }) end diff --git a/asteroids/phys.lua b/asteroids/phys.lua index 3772423..5b1e003 100644 --- a/asteroids/phys.lua +++ b/asteroids/phys.lua @@ -10,12 +10,13 @@ function phys.intersects(actor1, actor2) end -- updates the actor's location by applying the passage of time --- TODO spin function phys.update(actor, dt) assert(actor.speed >= 0) local dv = actor.speed * dt actor.x = actor.x + math.cos(actor.angle) * dv actor.y = actor.y + math.sin(actor.angle) * dv + local dr = actor.spin * dt + actor.facing = (actor.facing + dr) % phys.tau end function phys.apply(actor, force)