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

Commit

Permalink
Add Shooter:changeTo() function
Browse files Browse the repository at this point in the history
This function allows changing the Shooter appearances on the fly.
Not used in anything, but will be handy in the future.
  • Loading branch information
jakubg1 committed Jan 1, 2023
1 parent 73fe309 commit 7c00630
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Shooter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ local ShotSphere = require("src/ShotSphere")
---Constructs a new Shooter.
---@param data? table Data for the shooter.
function Shooter:new(data)
self.config = _Game.configManager:getShooter(data and data.name or "default")
self.movement = self.config.movement
if data and data.movement then
self.movement = data.movement
end
self.levelMovement = data and data.movement
self:changeTo(data and data.name or "default")

self.pos = self:getInitialPos()
self.angle = self:getInitialAngle()
Expand All @@ -43,15 +40,24 @@ function Shooter:new(data)
self.moveKeySpeed = 500
self.rotateKeySpeed = 4

self.sphereEntity = nil
end



---Changes this Shooter's configuration to the given one.
---@param name string The new shooter config to be obeyed.
function Shooter:changeTo(name)
self.config = _Game.configManager:getShooter(name)
self.movement = self.levelMovement or self.config.movement

self.sprite = self.config.sprite
self.shadowSprite = self.config.shadowSprite
self.speedShotSprite = self.config.speedShotBeam.sprite

self.reticleSprite = self.config.reticle.sprite
self.reticleNextSprite = self.config.reticle.nextBallSprite
self.radiusReticleSprite = self.config.reticle.radiusSprite

self.sphereEntity = nil
end


Expand Down

0 comments on commit 7c00630

Please sign in to comment.