Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
(BUGGY) Base for powerup system
Browse files Browse the repository at this point in the history
Requires latest commit of asset branch.

Attempts to implement a powerup system.
Transition effects (normal->powerup and vice versa) TBA.
Powerups expiring works, but they still instantly turn back in the next tick.
  • Loading branch information
ShamblesSM committed Jan 3, 2023
1 parent 2f84d80 commit fab065b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/Sphere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ function Sphere:new(sphereGroup, deserializationTable, color, shootOrigin, shoot
self.boostCombo = false
self.shootOrigin = nil
self.shootTime = nil
self.currentPowerup = nil
self.powerupTime = nil
self.effects = {}
self.gaps = gaps or {}
self.ghostTime = nil
self.ghostTime = nil
self.powerupTime = nil
-- this should be per-level in the future
self.powerupCooldown = 3
end

self.entity = sphereEntity or SphereEntity(self:getPos(), self.color)
Expand Down Expand Up @@ -89,6 +94,28 @@ function Sphere:update(dt)
end
end

-- Base for powerup system
-- TODO: De-hardcode stuff in this block of code
self.powerupCooldown = self.powerupCooldown - dt
if math.random() >= 0.75 then
if not self.currentPowerup and self.powerupCooldown >= 0 then
self.currentPowerup = "time"
self.entity:setSprite(self.currentPowerup)
-- also dehardcode this in the future
self.powerupTime = 3 - dt
--_Debug.console:print("Powerup added")
else
self.powerupCooldown = 15
self.powerupTime = self.powerupTime - dt
if self.powerupTime <= 0 then
self.currentPowerup = nil
self.entity:setSprite()
self.powerupTime = nil
--_Debug.console:print("Powerup removed")
end
end
end

-- Update the effects.
for i, effect in ipairs(self.effects) do
-- If it has to infect...
Expand Down Expand Up @@ -633,6 +660,9 @@ function Sphere:deserialize(t)
self.shootOrigin = t.shootOrigin and Vec2(t.shootOrigin.x, t.shootOrigin.y) or nil
self.shootTime = t.shootTime
self.ghostTime = t.ghostTime
self.currentPowerup = t.currentPowerup
self.powerupTime = t.powerupTime
self.powerupCooldown = t.powerupCooldown

self.effects = {}
if t.effects then
Expand Down
36 changes: 35 additions & 1 deletion src/SphereEntity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ function SphereEntity:new(pos, color)
if _Game.runtimeManager.options:getColorblindMode() and self.config.colorblindSprite then
self.sprite = _Game.resourceManager:getSprite(self.config.colorblindSprite)
end
self.shouldRotate = true
self.particle = self.config.idleParticle and _Game:spawnParticle(self.config.idleParticle, pos)
end



---Gets the current sprite which is dependant on Colorblind Mode.
---Gets the current sprite which is dependent on Colorblind Mode.
---@return Sprite
function SphereEntity:getSprite()
if _Game.runtimeManager.options:getColorblindMode() and self.config.colorblindSprite then
Expand All @@ -42,6 +43,39 @@ function SphereEntity:getSprite()
end


---Sets the current sprite to whatever powerup is specified.
---@param powerup? string Defaults to `nil`, which resets the sphere.
---@param shouldRotate? boolean Defaults to `true`. If `powerup` is nil, this will always be true.
function SphereEntity:setSprite(powerup, shouldRotate)
if not powerup then
powerup = nil
end
if not shouldRotate then
shouldRotate = true
end

if shouldRotate then
self.shouldRotate = shouldRotate
end
if powerup then
if _Game.runtimeManager.options:getColorblindMode() and self.config.colorblindPowerupSprites[powerup] then
self.sprite = _Game.resourceManager:getSprite(self.config.colorblindPowerupSprites[powerup])
else
self.sprite = _Game.resourceManager:getSprite(self.config.powerupSprites[powerup])
end
else
-- fallback to defaults
-- should rotate regardless of shouldRotate setting
self.shouldRotate = true
if _Game.runtimeManager.options:getColorblindMode() and self.config.colorblindSprite then
self.sprite = _Game.resourceManager:getSprite(self.config.colorblindSprite)
else
self.sprite = _Game.resourceManager:getSprite(self.config.sprite)
end
end
end



---Moves the sphere entity to a given location.
---@param pos Vector2 The new position of this Sphere Entity.
Expand Down

0 comments on commit fab065b

Please sign in to comment.