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

Commit

Permalink
Implement Cannons functionality
Browse files Browse the repository at this point in the history
One new sphere shoot behavior has been added: `multishot`.
This takes an integer (`amount`) which is the amount of spheres shot at once.

A new sphere shoot behavior has also been added, `pierce`.
It destroys the spheres it passes through, similar to a Lightning powerup in Luxor.

Multishot code provided by Rex (https://modworkshop.net/user/3057).

This commit only adds code and schema definitions in order to prevent unwanted files from being merge in the event of jakubg1 cherry-picking commits that add features to this fork of OpenSMCE.

Co-Authored-By: RexTheWho <26837908+RexTheWho@users.noreply.github.com>
  • Loading branch information
ShamblesSM and RexTheWho committed Feb 6, 2023
1 parent 3491416 commit be22de0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
22 changes: 21 additions & 1 deletion schemas/config/sphere_hit_behavior.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"destroySphere",
"fireball",
"colorCloud",
"replaceColor"
"replaceColor",
"pierce"
]
}
},
Expand Down Expand Up @@ -147,6 +148,25 @@
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"type": {
"const": "pierce",
"description": "The sphere pierces through all spheres it can destroy, similar to Luxor's Lightning powerup."
}
},
"required": [
"type"
]
},
"then": {
"properties": {
"type": true
},
"additionalProperties": false
}
}
],
"required": [
Expand Down
30 changes: 29 additions & 1 deletion schemas/config/sphere_shoot_behavior.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": {
"enum": [
"normal",
"lightning"
"lightning",
"multishot"
]
}
},
Expand Down Expand Up @@ -62,6 +63,33 @@
],
"additionalProperties": false
}
},
{
"if": {
"properties": {
"type": {
"const": "multishot",
"description": "The sphere is launched alongside clones of itself that is evenly spread."
}
},
"required": [
"type"
]
},
"then": {
"properties": {
"type": true,
"amount": {
"type": "number",
"exclusiveMinimum": 0,
"description": "The total amount of spheres that will be shot from the shooter."
}
},
"required": [
"amount"
],
"additionalProperties": false
}
}
],
"required": [
Expand Down
15 changes: 14 additions & 1 deletion src/Shooter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,20 @@ function Shooter:shoot()
_Game:spawnParticle(sphereConfig.destroyParticle, self:getSpherePos())
_Game.session:destroyVerticalColor(self.pos.x, sphereConfig.shootBehavior.range, self.color)
else
_Game.session.level:spawnShotSphere(self, self:getSpherePos(), self.angle, self.color, self:getShootingSpeed())
if sphereConfig.shootBehavior.type == "multishot" then
local spread_max = 30.0
local orbs_per_shot = sphereConfig.shootBehavior.amount
local shot_angle_offset = -(spread_max / 2)
local shot_angle = spread_max / orbs_per_shot

for i = 1, orbs_per_shot do
local fire_angle = self.angle + math.rad(shot_angle_offset + (shot_angle * i))
_Game.session.level:spawnShotSphere(self, self:getSpherePos(), fire_angle, self.color, self:getShootingSpeed())
end
else
_Game.session.level:spawnShotSphere(self, self:getSpherePos(), self.angle, self.color, self:getShootingSpeed())
end

self.sphereEntity = nil
--self.active = false
-- knockback
Expand Down
7 changes: 6 additions & 1 deletion src/ShotSphere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function ShotSphere:moveStep()
_Game.session:replaceColor(hitColor, sphereConfig.hitBehavior.color, sphereConfig.hitBehavior.particle)
self:destroy()
_Game:spawnParticle(sphereConfig.destroyParticle, self.pos)
elseif sphereConfig.hitBehavior.type == "pierce" then
_Game.session:destroySingleSphere(nearestSphere.sphere)
self.hitSphere = nil
else
if self.hitSphere.half then
self.hitSphere.sphereID = self.hitSphere.sphereID + 1
Expand Down Expand Up @@ -171,8 +174,10 @@ function ShotSphere:moveStep()
if sphereConfig.hitBehavior.type == "fireball" then
_Game.session:destroyRadiusColor(self.pos, sphereConfig.hitBehavior.range, self.color)
_Game:playSound(sphereConfig.hitSound, 1, self.pos)
end
if not sphereConfig.hitBehavior.type == "pierce" then
self:destroy()
end
self:destroy()
_Game:spawnParticle(sphereConfig.destroyParticle, self.pos)
end
end
Expand Down

0 comments on commit be22de0

Please sign in to comment.