mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
factored out explosion behaviour
This commit is contained in:
@@ -6,8 +6,9 @@ projectiles = {
|
||||
ProjectileClass.TORPEDO,
|
||||
},
|
||||
speed = {.5, .06},
|
||||
explosion = {{damage = 100, radius = 20}, {damage = 20, radius = 3}},
|
||||
rayLength = {1.25, .75},
|
||||
damage = {450, 300},
|
||||
directHitDamage = {450, 300},
|
||||
name = {
|
||||
"Cruise missile",
|
||||
"Torpedo"
|
||||
|
||||
+6
-2
@@ -2,6 +2,7 @@
|
||||
#include "player.h"
|
||||
#include "unit.h"
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
|
||||
#include <util.h>
|
||||
|
||||
@@ -50,8 +51,11 @@ namespace battleship{
|
||||
Map *map = Map::getSingleton();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
|
||||
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y)
|
||||
explode();
|
||||
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y){
|
||||
exploded = true;
|
||||
Game::getSingleton()->explode(pos, explosionDamage, explosionRadius, explosionSfx);
|
||||
player->removeProjectile(this);
|
||||
}
|
||||
}
|
||||
|
||||
void CruiseMissile::update(){
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "defConfigs.h"
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
@@ -143,4 +144,45 @@ namespace battleship{
|
||||
|
||||
paused = !paused;
|
||||
}
|
||||
|
||||
void Game::explode(Vector3 pos, int damage, float radius, sf::Sound *explosionSfx){
|
||||
if(!(damage == 0 || radius == 0))
|
||||
for(Player *pl : players){
|
||||
for(Unit *un : pl->getUnits()){
|
||||
float distance = un->getPos().getDistanceFrom(pos);
|
||||
|
||||
if(distance < radius)
|
||||
un->takeDamage(int(damage * (1.f - distance / radius)));
|
||||
}
|
||||
}
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
|
||||
const int numFrames = 1;
|
||||
string p[numFrames];
|
||||
|
||||
for(int i = 0; i < numFrames; i++)
|
||||
p[i] = GameManager::getSingleton()->getPath() + "Textures/Explosion/explosion07.png";
|
||||
|
||||
Texture *tex = new Texture(p, numFrames, false);
|
||||
|
||||
Material *mat = new Material(root->getLibPath() + "particle");
|
||||
mat->addTexUniform("tex", tex, true);
|
||||
|
||||
ParticleEmitter *pe = new ParticleEmitter(1);
|
||||
pe->setMaterial(mat);
|
||||
pe->setLowLife(3);
|
||||
pe->setHighLife(3);
|
||||
pe->setSize(10 * Vector2::VEC_IJ);
|
||||
pe->setSpeed(0);
|
||||
|
||||
Node *node = new Node(pos + Vector3(0, 2, 0));
|
||||
node->attachParticleEmitter(pe);
|
||||
node->lookAt(Vector3::VEC_J, Vector3::VEC_K);
|
||||
root->getRootNode()->attachChild(node);
|
||||
|
||||
Fx fx(50, 2500, explosionSfx, node);
|
||||
fx.activate();
|
||||
addFx(fx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace sf{
|
||||
class Sound;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Projectile;
|
||||
@@ -16,6 +20,7 @@ namespace battleship{
|
||||
void togglePause();
|
||||
void removeFx(int, bool);
|
||||
void removeAllElements();
|
||||
void explode(vb01::Vector3, int, float, sf::Sound*);
|
||||
inline void addFx(Fx f){fx.push_back(f);}
|
||||
inline void addPlayer(Player *pl){players.push_back(pl);}
|
||||
inline std::vector<Player*>& getPlayers(){return players;}
|
||||
|
||||
+16
-43
@@ -39,10 +39,13 @@ namespace battleship{
|
||||
void Projectile::initProperties(){
|
||||
GameObject::initProperties();
|
||||
|
||||
sol::table SOL_LUA_STATE = generateView()[GameObject::getGameObjTableName()];
|
||||
rayLength = SOL_LUA_STATE["rayLength"][id + 1];
|
||||
damage = SOL_LUA_STATE["damage"][id + 1];
|
||||
speed = SOL_LUA_STATE["speed"][id + 1];
|
||||
sol::table projTable = generateView()[GameObject::getGameObjTableName()];
|
||||
rayLength = projTable["rayLength"][id + 1];
|
||||
directHitDamage = projTable["directHitDamage"][id + 1];
|
||||
string explKey = "explosion";
|
||||
explosionDamage = projTable[explKey][id + 1]["damage"];
|
||||
explosionRadius = projTable[explKey][id + 1]["radius"];
|
||||
speed = projTable["speed"][id + 1];
|
||||
}
|
||||
|
||||
void Projectile::initSound(){
|
||||
@@ -84,8 +87,12 @@ namespace battleship{
|
||||
|
||||
if(!results.empty()){
|
||||
for(int i = 0; i < targetNodes.size(); i++)
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh)
|
||||
explode();
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh){
|
||||
exploded = true;
|
||||
targetUnits[i]->takeDamage(directHitDamage);
|
||||
Game::getSingleton()->explode(pos, explosionDamage, explosionRadius, explosionSfx);
|
||||
player->removeProjectile(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,46 +100,12 @@ namespace battleship{
|
||||
Map *map = Map::getSingleton();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
|
||||
if(map->getCells()[cellId].type == Map::Cell::LAND)
|
||||
if(map->getCells()[cellId].type == Map::Cell::LAND){
|
||||
exploded = true;
|
||||
player->removeProjectile(this);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO implement splash damage to units
|
||||
void Projectile::explode(){
|
||||
exploded = true;
|
||||
//target->takeDamage(damage);
|
||||
Root *root = Root::getSingleton();
|
||||
|
||||
const int numFrames = 1;
|
||||
string p[numFrames];
|
||||
|
||||
for(int i = 0; i < numFrames; i++)
|
||||
p[i] = GameManager::getSingleton()->getPath() + "Textures/Explosion/explosion07.png";
|
||||
|
||||
Texture *tex = new Texture(p, numFrames, false);
|
||||
|
||||
Material *mat = new Material(root->getLibPath() + "particle");
|
||||
mat->addTexUniform("tex", tex, true);
|
||||
|
||||
ParticleEmitter *pe = new ParticleEmitter(1);
|
||||
pe->setMaterial(mat);
|
||||
pe->setLowLife(3);
|
||||
pe->setHighLife(3);
|
||||
pe->setSize(10 * Vector2::VEC_IJ);
|
||||
pe->setSpeed(0);
|
||||
|
||||
Node *node = new Node(pos + Vector3(0, 2, 0));
|
||||
node->attachParticleEmitter(pe);
|
||||
node->lookAt(Vector3::VEC_J, Vector3::VEC_K);
|
||||
root->getRootNode()->attachChild(node);
|
||||
|
||||
Fx fx(50, 2500, explosionSfx, node);
|
||||
fx.activate();
|
||||
Game::getSingleton()->addFx(fx);
|
||||
|
||||
player->removeProjectile(this);
|
||||
}
|
||||
|
||||
void Projectile::debug(){
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -27,13 +27,12 @@ namespace battleship {
|
||||
void initSound();
|
||||
void checkCollision();
|
||||
protected:
|
||||
void explode();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision();
|
||||
|
||||
bool exploded = false;
|
||||
float speed, rayLength;
|
||||
int damage;
|
||||
float speed, rayLength, explosionRadius;
|
||||
int directHitDamage, explosionDamage;
|
||||
vb01::Vector3 initPos;
|
||||
Unit *unit = nullptr;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
|
||||
@@ -274,41 +274,10 @@ namespace battleship{
|
||||
for(GarrisonSlot &slot : garrisonSlots)
|
||||
displayUnitStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, renderSelectables, slot.offset);
|
||||
|
||||
if (health <= DEATH_HP)
|
||||
blowUp();
|
||||
}
|
||||
|
||||
void Unit::blowUp(){
|
||||
Root *root = Root::getSingleton();
|
||||
|
||||
const int numFrames = 1;
|
||||
string p[numFrames];
|
||||
|
||||
for(int i = 0; i < numFrames; i++)
|
||||
p[i] = GameManager::getSingleton()->getPath() + "Textures/Explosion/explosion07.png";
|
||||
|
||||
Texture *tex = new Texture(p, numFrames, false);
|
||||
|
||||
Material *mat = new Material(root->getLibPath() + "particle");
|
||||
mat->addTexUniform("tex", tex, true);
|
||||
|
||||
ParticleEmitter *pe = new ParticleEmitter(1);
|
||||
pe->setMaterial(mat);
|
||||
pe->setLowLife(3);
|
||||
pe->setHighLife(3);
|
||||
pe->setSize(10 * Vector2::VEC_IJ);
|
||||
pe->setSpeed(0);
|
||||
|
||||
Node *node = new Node(pos + Vector3(0, 2, 0));
|
||||
node->attachParticleEmitter(pe);
|
||||
node->lookAt(Vector3::VEC_J, Vector3::VEC_K);
|
||||
root->getRootNode()->attachChild(node);
|
||||
|
||||
Fx fx(50, 2500, deathSfx, node);
|
||||
fx.activate();
|
||||
Game::getSingleton()->addFx(fx);
|
||||
|
||||
player->removeUnit(this);
|
||||
if (health <= DEATH_HP){
|
||||
Game::getSingleton()->explode(pos, 0, 0, deathSfx);
|
||||
player->removeUnit(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::displayUnitStats(Node *foreground, Node *background, int currVal, int maxVal, bool render, Vector2 offset) {
|
||||
|
||||
Reference in New Issue
Block a user