mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
factored out initFx method
refactored creation of explosion FX
This commit is contained in:
@@ -2,13 +2,32 @@ ProjectileId = {HE_SHELL = 0, EMP_SHELL = 1, CRUISE_MISSILE = 2, MISSILE = 3, TO
|
||||
ProjectileClass = {SHELL = 0, CRUISE_MISSILE = 1, MISSILE = 2, TORPEDO = 3}
|
||||
G = 9.8
|
||||
|
||||
explosionVfx = {
|
||||
vfx = true,
|
||||
duration = 50,
|
||||
offset = 0,
|
||||
mesh = {
|
||||
numParticles = 1,
|
||||
texture = PATH .. 'Textures/Explosion/explosion07.png',
|
||||
lowLife = 3,
|
||||
highLife = 3,
|
||||
size = {x = 10, y = 10},
|
||||
}
|
||||
}
|
||||
explosionSfx = {
|
||||
vfx = false,
|
||||
offset = 100,
|
||||
path = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg',
|
||||
duration = 2500
|
||||
}
|
||||
|
||||
projectiles = {
|
||||
{
|
||||
projectileClass = ProjectileClass.SHELL,
|
||||
size = {x = 1, y = 1, z = 1},
|
||||
speed = 5,
|
||||
rotAngle = .1,
|
||||
explosion = {damage = 100, radius = 20, sfx = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg'},
|
||||
explosion = {damage = 100, radius = 20, fx = {explosionVfx, explosionSfx}},
|
||||
directHitDamage = 200,
|
||||
rayLength = 1,
|
||||
name = "Shell",
|
||||
@@ -21,7 +40,7 @@ projectiles = {
|
||||
size = {x = 1, y = 1, z = 1},
|
||||
speed = 5,
|
||||
rotAngle = .1,
|
||||
explosion = {damage = 0, radius = 20, sfx = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg'},
|
||||
explosion = {damage = 0, radius = 20, fx = {explosionVfx, explosionSfx}},
|
||||
directHitDamage = 0,
|
||||
rayLength = 1,
|
||||
name = "Shell",
|
||||
@@ -34,7 +53,7 @@ projectiles = {
|
||||
size = {x = 6, y = 13.5, z = 2.54},
|
||||
speed = .5,
|
||||
rotAngle = .1,
|
||||
explosion = {damage = 100, radius = 20, sfx = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg'},
|
||||
explosion = {damage = 100, radius = 20, fx = {explosionVfx, explosionSfx}},
|
||||
directHitDamage = 450,
|
||||
rayLength = 6,
|
||||
name = "Cruise missile",
|
||||
@@ -47,7 +66,7 @@ projectiles = {
|
||||
size = {x = 3, y = 7., z = 1.27},
|
||||
speed = .5,
|
||||
rotAngle = .1,
|
||||
explosion = {damage = 70, radius = 12, sfx = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg'},
|
||||
explosion = {damage = 70, radius = 12, fx = {explosionVfx, explosionSfx}},
|
||||
directHitDamage = 250,
|
||||
rayLength = 3,
|
||||
name = "Missile",
|
||||
@@ -59,7 +78,7 @@ projectiles = {
|
||||
projectileClass = ProjectileClass.TORPEDO,
|
||||
size = {x = 1, y = 6, z = 1},
|
||||
speed = .06,
|
||||
explosion = {damage = 20, radius = 3, sfx = PATH .. 'Sounds/Units/Submarines/torpedo.ogg'},
|
||||
explosion = {damage = 20, radius = 3, fx = {explosionVfx, explosionSfx}},
|
||||
directHitDamage = 450,
|
||||
rayLength = 3.5,
|
||||
name = "Torpedo",
|
||||
|
||||
@@ -93,7 +93,6 @@ explosionSfx = {
|
||||
duration = 2500
|
||||
}
|
||||
|
||||
|
||||
units = {
|
||||
{
|
||||
weapons = {
|
||||
@@ -159,12 +158,12 @@ units = {
|
||||
albedoPath = 'mech.jpg',
|
||||
colorNodes = {'WarRobotTemplate.001'},
|
||||
selectionSfx = PATH .. 'Sounds/Units/WarMechs/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .3,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 1
|
||||
garrisonCategory = 1,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -214,12 +213,12 @@ units = {
|
||||
albedoPath = 'tank.jpg',
|
||||
colorNodes = {'Antenna_S', 'Antenna_L', 'Hatch'},
|
||||
selectionSfx = PATH .. 'Sounds/Units/Tanks/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 2
|
||||
garrisonCategory = 2,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -268,12 +267,12 @@ units = {
|
||||
albedoPath = 'artillery.jpg',
|
||||
colorNodes = {'turret'},
|
||||
selectionSfx = PATH .. 'Sounds/Units/Tanks/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 2
|
||||
garrisonCategory = 2,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -308,12 +307,12 @@ units = {
|
||||
colorNodes = {'Cube.008'},
|
||||
meshPath = 'engineer2.xml',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Engineers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {{orderType = OrderType.ATTACK, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 50, maxRange = 20}},
|
||||
@@ -333,12 +332,12 @@ units = {
|
||||
basePath = PATH .. vehiclePrefix .. 'Transports/',
|
||||
meshPath = 'scoutTransport.xml',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Transports/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {{orderType = OrderType.ATTACK, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/Tanks/attack.ogg', damage = 100, maxRange = 25}},
|
||||
@@ -359,12 +358,12 @@ units = {
|
||||
meshPath = 'hoverTransport.xml',
|
||||
albedoPath = 'transport.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Transports/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {},
|
||||
@@ -392,12 +391,12 @@ units = {
|
||||
meshPath = 'cargoship.xml',
|
||||
albedoPath = 'cargoship.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -443,12 +442,12 @@ units = {
|
||||
meshPath = 'tacticalCruiser.xml',
|
||||
albedoPath = 'cruiser.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Cruisers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -494,12 +493,12 @@ units = {
|
||||
meshPath = 'defensiveCruiser.xml',
|
||||
albedoPath = 'cruiser.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Cruisers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -544,12 +543,12 @@ units = {
|
||||
meshPath = 'cheapCruiser.xml',
|
||||
albedoPath = 'cruiser.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Cruisers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -595,12 +594,12 @@ units = {
|
||||
meshPath = 'transportCruiser.xml',
|
||||
albedoPath = 'cruiser.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Cruisers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -644,12 +643,12 @@ units = {
|
||||
meshPath = 'heavyCarrier.xml',
|
||||
albedoPath = 'carrier.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Carriers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -708,12 +707,12 @@ units = {
|
||||
meshPath = 'championCarrier.xml',
|
||||
albedoPath = 'carrier.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Carriers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -760,12 +759,12 @@ units = {
|
||||
albedoPath = 'submarine.jpg',
|
||||
colorNodes = {'missileSubmarine.001'},
|
||||
selectionSfx = PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -799,12 +798,12 @@ units = {
|
||||
meshPath = 'stealthSubmarine.xml',
|
||||
albedoPath = 'submarine.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.ICEBREAKER,
|
||||
@@ -822,12 +821,12 @@ units = {
|
||||
meshPath = 'icebreaker.xml',
|
||||
albedoPath = 'icebreaker.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -865,12 +864,12 @@ units = {
|
||||
meshPath = 'freezer.xml',
|
||||
albedoPath = 'freezer.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -905,12 +904,12 @@ units = {
|
||||
meshPath = 'empShip.xml',
|
||||
albedoPath = 'empShip.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
garrisonCategory = 3
|
||||
garrisonCategory = 3,
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
buildableUnits = {
|
||||
@@ -934,7 +933,7 @@ units = {
|
||||
basePath = PATH .. structurePrefix .. 'LandFactories/',
|
||||
meshPath = 'landFactory.xml',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.NAVAL_FACTORY,
|
||||
@@ -951,7 +950,7 @@ units = {
|
||||
meshPath = 'navalFactory.xml',
|
||||
albedoPath = 'factory.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.TRADE_CENTER,
|
||||
@@ -975,7 +974,7 @@ units = {
|
||||
meshPath = 'tradeCenter.xml',
|
||||
albedoPath = 'tradeCenter.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.LAB,
|
||||
@@ -997,7 +996,7 @@ units = {
|
||||
meshPath = 'lab2.xml',
|
||||
albedoPath = 'lab.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
@@ -1061,7 +1060,7 @@ units = {
|
||||
meshPath = 'pointDefense2.xml',
|
||||
albedoPath = 'pointDefense.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.EXTRACTOR,
|
||||
@@ -1081,7 +1080,7 @@ units = {
|
||||
meshPath = 'extractor.xml',
|
||||
albedoPath = 'extractor.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.REFINERY,
|
||||
@@ -1099,7 +1098,7 @@ units = {
|
||||
meshPath = 'refinery.xml',
|
||||
albedoPath = 'refinery.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
buildableUnits = {{id = UnitId.ENGINEER, buildable = true, trigger = 69}},
|
||||
@@ -1118,7 +1117,7 @@ units = {
|
||||
colorNodes = {'Cube.004'},
|
||||
albedoPath = 'fort.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
{
|
||||
unitClass = UnitClass.ICE_SHEET,
|
||||
@@ -1133,6 +1132,6 @@ units = {
|
||||
meshPath = 'iceSheet.xml',
|
||||
albedoPath = 'iceSheet.jpg',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Ice/break.ogg',
|
||||
deathFx = {explosionVfx, explosionSfx},
|
||||
},
|
||||
}
|
||||
|
||||
+118
-2
@@ -1,14 +1,18 @@
|
||||
#include "fxManager.h"
|
||||
#include "gameObject.h"
|
||||
|
||||
#include <root.h>
|
||||
#include <node.h>
|
||||
#include <model.h>
|
||||
#include <box.h>
|
||||
#include <material.h>
|
||||
#include <vector.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace sf;
|
||||
|
||||
FxManager::Fx::Component::Component(void *c, bool v, s64 dur, vb01::Vector3 p, s64 ot) : comp(c), vfx(v), duration(dur), pos(p), offsetTime(ot) {
|
||||
if(v) ((vb01::Node*)c)->setVisible(false);
|
||||
@@ -18,6 +22,118 @@ namespace battleship{
|
||||
toggleComponents(!re);
|
||||
}
|
||||
|
||||
FxManager::Fx* FxManager::initFx(sol::table fxTbl, Node *baseNode, bool attached, Vector3 cp){
|
||||
int numComponents = fxTbl.size();
|
||||
|
||||
if(numComponents == 0) return nullptr;
|
||||
|
||||
vector<FxManager::Fx::Component> fxComponents;
|
||||
|
||||
for(int i = 0; i < numComponents; i++){
|
||||
sol::table compTbl = fxTbl[i + 1];
|
||||
|
||||
bool vfx = compTbl["vfx"];
|
||||
s64 duration = compTbl["duration"], offset = compTbl["offset"].get_or(0);
|
||||
|
||||
if(vfx){
|
||||
sol::table meshTbl = compTbl["mesh"];
|
||||
|
||||
string meshPath = "";
|
||||
Material *mat = nullptr;
|
||||
Node *flashNode = nullptr;
|
||||
|
||||
sol::optional<sol::table> posOpt = compTbl["pos"], rotOpt = compTbl["rot"];
|
||||
Vector3 compPos = cp;
|
||||
Quaternion compRot = Quaternion::QUAT_W;
|
||||
float sc = compTbl["scale"].get_or(1);
|
||||
|
||||
if(posOpt != sol::nullopt){
|
||||
sol::table posTable = compTbl["pos"];
|
||||
compPos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
|
||||
}
|
||||
|
||||
if(rotOpt != sol::nullopt){
|
||||
sol::table rotTable = compTbl["rot"];
|
||||
compRot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
||||
}
|
||||
|
||||
sol::optional<string> pathOpt = meshTbl["path"];
|
||||
sol::optional<int> numPartOpt = meshTbl["numParticles"];
|
||||
|
||||
if(pathOpt != sol::nullopt){
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
|
||||
meshPath = meshTbl["path"];
|
||||
flashNode = new Model(meshPath);
|
||||
((Model*)flashNode)->setMaterial(mat);
|
||||
flashNode->setPosition(compPos);
|
||||
flashNode->setOrientation(compRot);
|
||||
flashNode->setScale(Vector3(sc, sc, sc));
|
||||
}
|
||||
else if(numPartOpt != sol::nullopt){
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "particle");
|
||||
|
||||
int numParticles = meshTbl["numParticles"];
|
||||
ParticleEmitter *pe = new ParticleEmitter(numParticles);
|
||||
pe->setMaterial(mat);
|
||||
pe->setLowLife(meshTbl["lowLife"]);
|
||||
pe->setHighLife(meshTbl["highLife"]);
|
||||
pe->setSpeed(0);
|
||||
|
||||
sol::table sizeTbl = meshTbl["size"];
|
||||
pe->setSize(Vector2(sizeTbl["x"], sizeTbl["y"]));
|
||||
|
||||
flashNode = new Node(compPos + Vector3(0, 2, 0), compRot, Vector3(sc, sc, sc));
|
||||
flashNode->attachParticleEmitter(pe);
|
||||
flashNode->lookAt(Vector3::VEC_J, Vector3::VEC_K);
|
||||
}
|
||||
else{
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
|
||||
sol::table sizeTbl = meshTbl["size"];
|
||||
Box *box = new Box(Vector3(sizeTbl["x"], sizeTbl["y"], 0));
|
||||
box->setMaterial(mat);
|
||||
|
||||
flashNode = new Node(compPos, compRot, Vector3(sc, sc, sc), "laser");
|
||||
flashNode->attachMesh(box);
|
||||
}
|
||||
|
||||
sol::optional<string> texOpt = meshTbl["texture"];
|
||||
|
||||
if(texOpt != sol::nullopt){
|
||||
string p[]{meshTbl["texture"]};
|
||||
Texture *tex = new Texture(p, 1, false);
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
mat->addTexUniform("diffuseMap[0]", tex, false);
|
||||
}
|
||||
else{
|
||||
sol::table colorTable = meshTbl["color"];
|
||||
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["a"]));
|
||||
mat->addBoolUniform("texturingEnabled", false);
|
||||
}
|
||||
|
||||
flashNode->setVisible(false);
|
||||
Node *parNode = (attached ? baseNode : Root::getSingleton()->getRootNode());
|
||||
sol::optional<string> parNameOpt = compTbl["parent"];
|
||||
|
||||
if(parNameOpt != sol::nullopt){
|
||||
string parName = compTbl["parent"];
|
||||
parNode = baseNode->findDescendant(parName, true);
|
||||
}
|
||||
|
||||
parNode->attachChild(flashNode);
|
||||
fxComponents.push_back(FxManager::Fx::Component((void*)flashNode, vfx, duration, compPos, offset));
|
||||
}
|
||||
else{
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = GameObject::prepareSfx(sfxBuffer, compTbl["path"]);
|
||||
fxComponents.push_back(FxManager::Fx::Component((void*)sfx, vfx, duration, Vector3::VEC_ZERO, offset));
|
||||
}
|
||||
}
|
||||
|
||||
return new FxManager::Fx(fxComponents, attached);
|
||||
}
|
||||
|
||||
void FxManager::Fx::toggleComponents(bool active){
|
||||
for(Component &component : components){
|
||||
component.active = active;
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
|
||||
#include <util.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class FxManager{
|
||||
public:
|
||||
@@ -24,6 +30,7 @@ namespace battleship{
|
||||
};
|
||||
|
||||
static FxManager* getSingleton();
|
||||
FxManager::Fx* initFx(sol::table, vb01::Node*, bool, vb01::Vector3 = vb01::Vector3::VEC_ZERO);
|
||||
void update();
|
||||
void removeFx(Fx*);
|
||||
inline void addFx(Fx *fx){fxs.push_back(fx);}
|
||||
|
||||
@@ -177,12 +177,6 @@ namespace battleship{
|
||||
return within;
|
||||
}
|
||||
|
||||
void GameObject::initSound(){
|
||||
deathSfxBuffer = new sf::SoundBuffer();
|
||||
string sfxPath = generateView()[getGameObjTableName()][id + 1]["deathSfx"];
|
||||
deathSfx = prepareSfx(deathSfxBuffer, sfxPath);
|
||||
}
|
||||
|
||||
string GameObject::getGameObjTableName(){
|
||||
switch(type){
|
||||
case GameObject::Type::UNIT:
|
||||
|
||||
+1
-3
@@ -56,13 +56,11 @@ namespace battleship{
|
||||
virtual void initHitbox();
|
||||
virtual void destroyHitbox();
|
||||
virtual void destroySound();
|
||||
virtual void initSound();
|
||||
virtual void initSound(){}
|
||||
|
||||
Type type;
|
||||
int id;
|
||||
Player *player;
|
||||
sf::SoundBuffer *deathSfxBuffer;
|
||||
sf::Sound *deathSfx;
|
||||
vb01::Model *model = nullptr;
|
||||
vb01::Node *hitbox = nullptr;
|
||||
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, 1), leftVec = vb01::Vector3(1, 0, 0), corners[8];
|
||||
|
||||
+8
-9
@@ -44,7 +44,6 @@ namespace battleship{
|
||||
initProperties();
|
||||
|
||||
initModel();
|
||||
initSound();
|
||||
|
||||
GameObject::reinit();
|
||||
}
|
||||
@@ -65,12 +64,6 @@ namespace battleship{
|
||||
rotAngle = projTable["rotAngle"].get_or(0.0);
|
||||
}
|
||||
|
||||
void Projectile::initSound(){
|
||||
explosionSfxBuffer = new sf::SoundBuffer();
|
||||
string sfxPath = generateView()[GameObject::getGameObjTableName()][id + 1]["explosion"]["sfx"];
|
||||
explosionSfx = GameObject::prepareSfx(explosionSfxBuffer, sfxPath);
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
GameObject::update();
|
||||
placeAt(pos + speed * dirVec);
|
||||
@@ -96,8 +89,11 @@ namespace battleship{
|
||||
if(!results.empty()){
|
||||
for(int i = 0; i < targetNodes.size(); i++)
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh){
|
||||
FxManager *fxManager = FxManager::getSingleton();
|
||||
FxManager::Fx *explosionFx = fxManager->initFx(generateView()[getGameObjTableName()][id + 1]["explosion"]["fx"], model, false, pos);
|
||||
explosionFx->toggleComponents(true);
|
||||
fxManager->addFx(explosionFx);
|
||||
targetUnits[i]->takeDamage(directHitDamage);
|
||||
Environment::explode(pos, explosionDamage, explosionRadius, explosionSfx);
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +104,10 @@ namespace battleship{
|
||||
int cellId = map->getCellId(pos, false);
|
||||
|
||||
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y){
|
||||
Environment::explode(pos, explosionDamage, explosionRadius, explosionSfx);
|
||||
FxManager *fxManager = FxManager::getSingleton();
|
||||
FxManager::Fx *explosionFx = fxManager->initFx(generateView()[getGameObjTableName()][id + 1]["explosion"]["fx"], model, false, pos);
|
||||
explosionFx->toggleComponents(true);
|
||||
fxManager->addFx(explosionFx);
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,20 +1,20 @@
|
||||
#ifndef PROJECTILE_H
|
||||
#define PROJECTILE_H
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship {
|
||||
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO};
|
||||
class Unit;
|
||||
|
||||
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO};
|
||||
|
||||
class Projectile : public GameObject{
|
||||
public:
|
||||
Projectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||
@@ -23,17 +23,17 @@ namespace battleship {
|
||||
virtual void debug();
|
||||
private:
|
||||
void initProperties();
|
||||
void initSound();
|
||||
protected:
|
||||
virtual void reinit();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision();
|
||||
void checkCollision();
|
||||
|
||||
float speed, rayLength, explosionRadius, rotAngle;
|
||||
int directHitDamage, explosionDamage;
|
||||
vb01::Vector3 initPos;
|
||||
Unit *unit = nullptr;
|
||||
FxManager::Fx *explosionFx = nullptr;
|
||||
float speed, rayLength, explosionRadius, rotAngle;
|
||||
int directHitDamage, explosionDamage;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx = nullptr, *explosionSfx = nullptr;
|
||||
};
|
||||
|
||||
@@ -325,7 +325,10 @@ namespace battleship{
|
||||
displayUnitStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, renderSelectables, slot.offset);
|
||||
|
||||
if (health <= DEATH_HP){
|
||||
Environment::explode(pos, 0, 0, deathSfx);
|
||||
FxManager *fxManager = FxManager::getSingleton();
|
||||
FxManager::Fx *deathFx = fxManager->initFx(generateView()[getGameObjTableName()][id + 1]["deathFx"], model, false, pos);
|
||||
deathFx->toggleComponents(true);
|
||||
fxManager->addFx(deathFx);
|
||||
remove = true;
|
||||
}
|
||||
|
||||
|
||||
+10
-127
@@ -14,8 +14,6 @@ namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
string Weapon::LASER_FLAG = "laser";
|
||||
|
||||
Weapon::Weapon(Unit *u, sol::table unitTable, int wid) :
|
||||
unit(u),
|
||||
id(wid),
|
||||
@@ -34,8 +32,9 @@ namespace battleship{
|
||||
if(horNodeTblOpt != sol::nullopt) horNode = initNode(weaponTable, true);
|
||||
if(vertNodeTblOpt != sol::nullopt) vertNode = initNode(weaponTable, false);
|
||||
|
||||
fireFx = initFx(weaponTable, "fireFx", true);
|
||||
if(fireFx) FxManager::getSingleton()->addFx(fireFx);
|
||||
FxManager *fxManager = FxManager::getSingleton();
|
||||
fireFx = fxManager->initFx(weaponTable["fireFx"], unit->getModel(), true);
|
||||
if(fireFx) fxManager->addFx(fireFx);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,123 +85,6 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
FxManager::Fx* Weapon::initFx(sol::table weaponTable, string fxKey, bool attached){
|
||||
sol::optional<sol::table> fxOpt = weaponTable[fxKey];
|
||||
|
||||
if(fxOpt == sol::nullopt) return nullptr;
|
||||
|
||||
sol::table fxTbl = weaponTable[fxKey];
|
||||
int numComponents = fxTbl.size();
|
||||
|
||||
if(numComponents == 0) return nullptr;
|
||||
|
||||
vector<FxManager::Fx::Component> fxComponents;
|
||||
|
||||
for(int i = 0; i < numComponents; i++){
|
||||
sol::table compTbl = fxTbl[i + 1];
|
||||
|
||||
bool vfx = compTbl["vfx"];
|
||||
s64 duration = compTbl["duration"], offset = compTbl["offset"].get_or(0);
|
||||
|
||||
if(vfx){
|
||||
sol::table meshTbl = compTbl["mesh"];
|
||||
|
||||
string meshPath = "";
|
||||
Material *mat = nullptr;
|
||||
Node *flashNode = nullptr;
|
||||
|
||||
sol::optional<sol::table> posOpt = compTbl["pos"], rotOpt = compTbl["rot"];
|
||||
Vector3 compPos = Vector3::VEC_ZERO;
|
||||
Quaternion compRot = Quaternion::QUAT_W;
|
||||
float sc = compTbl["scale"].get_or(1);
|
||||
|
||||
if(posOpt != sol::nullopt){
|
||||
sol::table posTable = compTbl["pos"];
|
||||
compPos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
|
||||
}
|
||||
|
||||
if(rotOpt != sol::nullopt){
|
||||
sol::table rotTable = compTbl["rot"];
|
||||
compRot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
||||
}
|
||||
|
||||
sol::optional<string> pathOpt = meshTbl["path"];
|
||||
sol::optional<int> numPartOpt = meshTbl["numParticles"];
|
||||
|
||||
if(pathOpt != sol::nullopt){
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
|
||||
meshPath = meshTbl["path"];
|
||||
flashNode = new Model(meshPath);
|
||||
((Model*)flashNode)->setMaterial(mat);
|
||||
flashNode->setPosition(compPos);
|
||||
flashNode->setOrientation(compRot);
|
||||
flashNode->setScale(Vector3(sc, sc, sc));
|
||||
}
|
||||
else if(numPartOpt != sol::nullopt){
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "particle");
|
||||
|
||||
int numParticles = meshTbl["numParticles"];
|
||||
ParticleEmitter *pe = new ParticleEmitter(numParticles);
|
||||
pe->setMaterial(mat);
|
||||
pe->setLowLife(meshTbl["lowLife"]);
|
||||
pe->setHighLife(meshTbl["highLife"]);
|
||||
pe->setSpeed(0);
|
||||
|
||||
sol::table sizeTbl = meshTbl["size"];
|
||||
pe->setSize(Vector2(sizeTbl["x"], sizeTbl["y"]));
|
||||
|
||||
flashNode = new Node(compPos, compRot, Vector3(sc, sc, sc));
|
||||
flashNode->attachParticleEmitter(pe);
|
||||
flashNode->lookAt(Vector3::VEC_J, Vector3::VEC_K);
|
||||
}
|
||||
else{
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
|
||||
sol::table sizeTbl = meshTbl["size"];
|
||||
Box *box = new Box(Vector3(sizeTbl["x"], sizeTbl["y"], 0));
|
||||
box->setMaterial(mat);
|
||||
|
||||
flashNode = new Node(compPos, compRot, Vector3(sc, sc, sc), LASER_FLAG);
|
||||
flashNode->attachMesh(box);
|
||||
}
|
||||
|
||||
sol::optional<string> texOpt = meshTbl["texture"];
|
||||
|
||||
if(texOpt != sol::nullopt){
|
||||
string p[]{meshTbl["texture"]};
|
||||
Texture *tex = new Texture(p, 1, false);
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
mat->addTexUniform("diffuseMap[0]", tex, false);
|
||||
}
|
||||
else{
|
||||
sol::table colorTable = meshTbl["color"];
|
||||
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["a"]));
|
||||
mat->addBoolUniform("texturingEnabled", false);
|
||||
}
|
||||
|
||||
flashNode->setVisible(false);
|
||||
Node *parNode = (attached ? unit->getModel() : Root::getSingleton()->getRootNode());
|
||||
sol::optional<string> parNameOpt = compTbl["parent"];
|
||||
|
||||
if(parNameOpt != sol::nullopt){
|
||||
string parName = compTbl["parent"];
|
||||
parNode = unit->getModel()->findDescendant(parName, true);
|
||||
}
|
||||
|
||||
parNode->attachChild(flashNode);
|
||||
fxComponents.push_back(FxManager::Fx::Component((void*)flashNode, vfx, duration, compPos, offset));
|
||||
}
|
||||
else{
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = GameObject::prepareSfx(sfxBuffer, compTbl["path"]);
|
||||
fxComponents.push_back(FxManager::Fx::Component((void*)sfx, vfx, duration, Vector3::VEC_ZERO, offset));
|
||||
}
|
||||
}
|
||||
|
||||
return new FxManager::Fx(fxComponents, attached);
|
||||
}
|
||||
|
||||
Weapon::~Weapon(){
|
||||
FxManager *fm = FxManager::getSingleton();
|
||||
|
||||
@@ -267,8 +149,9 @@ namespace battleship{
|
||||
for(int i = 0; i < fx->components.size(); i++){
|
||||
FxManager::Fx::Component &comp = fx->components[i];
|
||||
|
||||
if(comp.vfx){
|
||||
if(fire && ((Node*)comp.comp)->getName() == LASER_FLAG){
|
||||
if(!comp.vfx) continue;
|
||||
|
||||
if(fire && ((Node*)comp.comp)->getName() == "laser"){
|
||||
Vector3 initPos = unit->getPos(), laserDir = targPos - initPos;
|
||||
float targDist = laserDir.getLength();
|
||||
float angle = unit->getDirVec().getAngleBetween(laserDir);
|
||||
@@ -289,14 +172,13 @@ namespace battleship{
|
||||
((Node*)comp.comp)->setPosition(targPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Weapon::updateTargetUnit(Unit *targetUnit){
|
||||
targetUnit->takeDamage(damage);
|
||||
unit->updateGameStats(targetUnit);
|
||||
}
|
||||
|
||||
|
||||
//TODO replace the 'laser' flag literal
|
||||
void Weapon::fire(Order order){
|
||||
if(!canFire()) return;
|
||||
|
||||
@@ -307,16 +189,17 @@ namespace battleship{
|
||||
|
||||
if(projId == -1){
|
||||
sol::table weaponTbl = generateView()["units"][unit->getId() + 1]["weapons"][id + 1];
|
||||
FxManager *fxManager = FxManager::getSingleton();
|
||||
|
||||
if(targetUnit){
|
||||
updateTargetUnit(targetUnit);
|
||||
useFx(initFx(weaponTbl, "unitHitFx", false), targPos, false);
|
||||
useFx(fxManager->initFx(weaponTbl["unitHitFx"], unit->getModel(), false), targPos, false);
|
||||
}
|
||||
else{
|
||||
Map *map = Map::getSingleton();
|
||||
Map::Cell::Type cellType = map->getCells()[map->getCellId(targPos)].type;
|
||||
string fxKey = (cellType == Map::Cell::Type::LAND ? "landHitFx" : "waterHitFx");
|
||||
useFx(initFx(weaponTbl, fxKey, false), targPos, false);
|
||||
useFx(fxManager->initFx(weaponTbl[fxKey], unit->getModel(), false), targPos, false);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace battleship{
|
||||
void alignNode(vb01::Vector3, vb01::Node*, bool);
|
||||
void initProjectileData(sol::table);
|
||||
vb01::Node* initNode(sol::table, bool);
|
||||
FxManager::Fx* initFx(sol::table, std::string, bool);
|
||||
void useFx(FxManager::Fx*, vb01::Vector3, bool);
|
||||
inline bool canFire(){return vb01::getTime() - lastFireTime > rateOfFire;}
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user