mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
destructible units
This commit is contained in:
@@ -35,7 +35,7 @@ units = {
|
|||||||
health = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500},
|
health = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500},
|
||||||
cost = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500},
|
cost = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500},
|
||||||
range = {15, 15, 14, 14, 13, 13, 12, 12, 15, 25},
|
range = {15, 15, 14, 14, 13, 13, 12, 12, 15, 25},
|
||||||
rateOfFire = {100, 100, 100, 100, 100, 100, 100},
|
rateOfFire = {5000, 100, 100, 100, 100, 100, 100},
|
||||||
|
|
||||||
unitCornerPoints = {
|
unitCornerPoints = {
|
||||||
{
|
{
|
||||||
@@ -299,5 +299,23 @@ units = {
|
|||||||
PATH .. 'Sounds/Units/Carriers/selection.ogg',
|
PATH .. 'Sounds/Units/Carriers/selection.ogg',
|
||||||
PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
PATH .. 'Sounds/Units/Submarines/selection.ogg',
|
||||||
PATH .. 'Sounds/Units/Sample/selection.ogg',
|
PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||||
|
},
|
||||||
|
fireSfx = {
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
PATH .. 'Sounds/Units/WarMechs/fire.ogg',
|
||||||
|
},
|
||||||
|
deathSfx = {
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
|
PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
|
|||||||
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp)
|
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp)
|
||||||
set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
|
set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
|
||||||
set(PROJECTILES projectile.cpp)
|
set(PROJECTILES projectile.cpp)
|
||||||
set(FX explosion.cpp)
|
set(FX fx.cpp)
|
||||||
set(VEHICLES vehicle.cpp engineer.cpp)
|
set(VEHICLES vehicle.cpp engineer.cpp)
|
||||||
set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp ${VEHICLES})
|
set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp ${VEHICLES})
|
||||||
set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX})
|
set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX})
|
||||||
|
|||||||
+4
-16
@@ -9,7 +9,7 @@ using namespace std;
|
|||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
void detonate(Vector3 pos, Vector3 dir){
|
void detonate(string p){
|
||||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||||
sf::Sound *sfx = nullptr;
|
sf::Sound *sfx = nullptr;
|
||||||
string p = GameManager::getSingleton()->getPath() + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
|
string p = GameManager::getSingleton()->getPath() + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
|
||||||
@@ -19,11 +19,7 @@ namespace battleship{
|
|||||||
sfx->play();
|
sfx->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
Fx fx;
|
Game::getSingleton()->addFx(Fx(sfx, 2500));
|
||||||
fx.initTime = getTime();
|
|
||||||
fx.time = 2500;
|
|
||||||
fx.sfx = sfx;
|
|
||||||
Game::getSingleton()->addFx(fx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void detonateDepthCharge(){
|
void detonateDepthCharge(){
|
||||||
@@ -36,11 +32,7 @@ namespace battleship{
|
|||||||
sfx->play();
|
sfx->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
Fx fx;
|
Game::getSingleton()->addFx(Fx(sfx, 2000));
|
||||||
fx.initTime = getTime();
|
|
||||||
fx.time = 2000;
|
|
||||||
fx.sfx = sfx;
|
|
||||||
Game::getSingleton()->addFx(fx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void detonateTorpedo(){
|
void detonateTorpedo(){
|
||||||
@@ -53,10 +45,6 @@ namespace battleship{
|
|||||||
sfx->play();
|
sfx->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
Fx fx;
|
Game::getSingleton()->addFx(Fx(sfx, 250));
|
||||||
fx.initTime = getTime();
|
|
||||||
fx.time = 250;
|
|
||||||
fx.sfx = sfx;
|
|
||||||
Game::getSingleton()->addFx(fx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -1,12 +1,10 @@
|
|||||||
#ifndef EXPLOSION_H
|
#ifndef EXPLOSION_H
|
||||||
#define EXPLOSION_H
|
#define EXPLOSION_H
|
||||||
|
|
||||||
#include <vector.h>
|
#include <string>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
void detonate(vb01::Vector3, vb01::Vector3);
|
void detonate(std::string);
|
||||||
void detonateDepthCharge();
|
|
||||||
void detonateTorpedo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#include "fx.h"
|
||||||
|
|
||||||
|
#include <particleEmitter.h>
|
||||||
|
#include <node.h>
|
||||||
|
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
|
||||||
|
namespace battleship{
|
||||||
|
using namespace vb01;
|
||||||
|
|
||||||
|
void Fx::activate(){
|
||||||
|
if(sfx)
|
||||||
|
sfx->play();
|
||||||
|
|
||||||
|
if(peNode){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -7,10 +7,18 @@ namespace sf{
|
|||||||
class Sound;
|
class Sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace vb01{
|
||||||
|
class Node;
|
||||||
|
}
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
struct Fx {
|
struct Fx {
|
||||||
vb01::s64 initTime, time;
|
vb01::s64 initTime, time;
|
||||||
sf::Sound *sfx = nullptr;
|
sf::Sound *sfx = nullptr;
|
||||||
|
vb01::Node *peNode = nullptr;
|
||||||
|
|
||||||
|
Fx(vb01::s64 t, sf::Sound *s = nullptr, vb01::Node *n = nullptr) : time(t), sfx(s), peNode(n), initTime(vb01::getTime()){}
|
||||||
|
void activate();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,11 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "projectile.h"
|
#include "projectile.h"
|
||||||
|
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
|
using namespace vb01;
|
||||||
|
|
||||||
static Game *game = nullptr;
|
static Game *game = nullptr;
|
||||||
|
|
||||||
Game* Game::getSingleton(){
|
Game* Game::getSingleton(){
|
||||||
@@ -18,6 +22,24 @@ namespace battleship{
|
|||||||
|
|
||||||
for(Projectile *proj : projectiles)
|
for(Projectile *proj : projectiles)
|
||||||
proj->update();
|
proj->update();
|
||||||
|
|
||||||
|
for(int i = 0; i < fx.size(); i++)
|
||||||
|
if(getTime() - fx[i].initTime > fx[i].time)
|
||||||
|
removeFx(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::removeFx(int id){
|
||||||
|
const sf::SoundBuffer *buffer = fx[id].sfx->getBuffer();
|
||||||
|
fx[id].sfx->stop();
|
||||||
|
delete fx[id].sfx;
|
||||||
|
delete buffer;
|
||||||
|
|
||||||
|
if(fx[id].peNode){
|
||||||
|
Root::getSingleton()->getRootNode()->dettachChild(fx[id].peNode);
|
||||||
|
delete fx[id].peNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx.erase(fx.begin() + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::togglePause(){
|
void Game::togglePause(){
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace battleship{
|
|||||||
static Game* getSingleton();
|
static Game* getSingleton();
|
||||||
void update();
|
void update();
|
||||||
void togglePause();
|
void togglePause();
|
||||||
|
void removeFx(int);
|
||||||
inline void addFx(Fx f){fx.push_back(f);}
|
inline void addFx(Fx f){fx.push_back(f);}
|
||||||
inline void addPlayer(Player *pl){players.push_back(pl);}
|
inline void addPlayer(Player *pl){players.push_back(pl);}
|
||||||
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
||||||
|
|||||||
+22
-2
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <material.h>
|
#include <material.h>
|
||||||
|
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
@@ -64,9 +66,27 @@ namespace battleship{
|
|||||||
root->getRootNode()->attachChild(model);
|
root->getRootNode()->attachChild(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameObject::destroySound(){}
|
void GameObject::destroySound(){
|
||||||
|
}
|
||||||
|
|
||||||
void GameObject::initSound(){}
|
sf::Sound* GameObject::prepareSfx(sf::SoundBuffer *buffer, string key){
|
||||||
|
sol::table SOL_LUA_STATE = generateView()[GameObject::getGameObjTableName()];
|
||||||
|
string sfxPath = SOL_LUA_STATE[key][id + 1];
|
||||||
|
|
||||||
|
sf::Sound *sfx = nullptr;
|
||||||
|
|
||||||
|
if(buffer->loadFromFile(sfxPath.c_str())){
|
||||||
|
sfx = new sf::Sound(*buffer);
|
||||||
|
sfx->setBuffer(*buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sfx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameObject::initSound(){
|
||||||
|
deathSfxBuffer = new sf::SoundBuffer();
|
||||||
|
deathSfx = prepareSfx(deathSfxBuffer, "deathSfx");
|
||||||
|
}
|
||||||
|
|
||||||
string GameObject::getGameObjTableName(){
|
string GameObject::getGameObjTableName(){
|
||||||
switch(type){
|
switch(type){
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
#include <quaternion.h>
|
#include <quaternion.h>
|
||||||
#include <model.h>
|
#include <model.h>
|
||||||
|
|
||||||
|
namespace sf{
|
||||||
|
class SoundBuffer;
|
||||||
|
class Sound;
|
||||||
|
}
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
@@ -43,10 +48,13 @@ namespace battleship{
|
|||||||
virtual void initModel(bool = true);
|
virtual void initModel(bool = true);
|
||||||
virtual void destroySound();
|
virtual void destroySound();
|
||||||
virtual void initSound();
|
virtual void initSound();
|
||||||
|
sf::Sound* prepareSfx(sf::SoundBuffer*, std::string);
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
int id;
|
int id;
|
||||||
Player *player;
|
Player *player;
|
||||||
|
sf::SoundBuffer *deathSfxBuffer;
|
||||||
|
sf::Sound *deathSfx;
|
||||||
vb01::Model *model = nullptr;
|
vb01::Model *model = 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];
|
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];
|
||||||
vb01::Quaternion rot;
|
vb01::Quaternion rot;
|
||||||
|
|||||||
+16
@@ -62,4 +62,20 @@ namespace battleship{
|
|||||||
|
|
||||||
selectedUnits.clear();
|
selectedUnits.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::removeUnit(Unit *unit){
|
||||||
|
for(int i = 0; i < units.size(); i++)
|
||||||
|
if(unit == units[i]){
|
||||||
|
removeUnit(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::removeUnit(int id){
|
||||||
|
if(units[id]->isSelected())
|
||||||
|
deselectUnit(id);
|
||||||
|
|
||||||
|
delete units[id];
|
||||||
|
units.erase(units.begin() + id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace battleship{
|
|||||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||||
void deselectUnit(int);
|
void deselectUnit(int);
|
||||||
void deselectUnits();
|
void deselectUnits();
|
||||||
|
void removeUnit(Unit*);
|
||||||
|
void removeUnit(int);
|
||||||
bool isThisPlayersUnit(GameObject*);
|
bool isThisPlayersUnit(GameObject*);
|
||||||
const inline std::vector<Unit*>& getSelectedUnits(){return selectedUnits;}
|
const inline std::vector<Unit*>& getSelectedUnits(){return selectedUnits;}
|
||||||
inline Unit* getSelectedUnit(int i){return selectedUnits[i];}
|
inline Unit* getSelectedUnit(int i){return selectedUnits[i];}
|
||||||
|
|||||||
+2
-8
@@ -14,7 +14,7 @@
|
|||||||
#include "projectile.h"
|
#include "projectile.h"
|
||||||
#include "defConfigs.h"
|
#include "defConfigs.h"
|
||||||
#include "inGameAppState.h"
|
#include "inGameAppState.h"
|
||||||
#include "explosion.h"
|
#include "fx.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
@@ -111,13 +111,7 @@ namespace battleship{
|
|||||||
|
|
||||||
StateManager *sm = GameManager::getSingleton()->getStateManager();
|
StateManager *sm = GameManager::getSingleton()->getStateManager();
|
||||||
InGameAppState *inGameState = ((InGameAppState*)sm->getAppStateByType((int)AppStateType::IN_GAME_STATE));
|
InGameAppState *inGameState = ((InGameAppState*)sm->getAppStateByType((int)AppStateType::IN_GAME_STATE));
|
||||||
|
string path = GameManager::getSingleton()->getPath() + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
|
||||||
if(id == 8)
|
|
||||||
detonateTorpedo();
|
|
||||||
else if(weaponTypeId == 1 && (id == 2 || id == 3))
|
|
||||||
detonateDepthCharge();
|
|
||||||
else
|
|
||||||
detonate(pos, -dirVec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Projectile::debug(){
|
void Projectile::debug(){
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ namespace battleship{
|
|||||||
buildStatusForeground = createBar(Unit::lenHpBar, Vector4(0, 0, 1, 1));
|
buildStatusForeground = createBar(Unit::lenHpBar, Vector4(0, 0, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Structure::~Structure(){
|
||||||
|
removeBar(buildStatusForeground);
|
||||||
|
removeBar(buildStatusBackground);
|
||||||
|
Unit::~Unit();
|
||||||
|
}
|
||||||
|
|
||||||
void Structure::update(){
|
void Structure::update(){
|
||||||
Unit::update();
|
Unit::update();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace battleship{
|
|||||||
class Structure : public Unit{
|
class Structure : public Unit{
|
||||||
public:
|
public:
|
||||||
Structure(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
Structure(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||||
|
~Structure();
|
||||||
inline int getBuildStatus(){return buildStatus;}
|
inline int getBuildStatus(){return buildStatus;}
|
||||||
inline void incrementBuildStatus(){buildStatus++;}
|
inline void incrementBuildStatus(){buildStatus++;}
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <model.h>
|
#include <model.h>
|
||||||
#include <quad.h>
|
#include <quad.h>
|
||||||
#include <material.h>
|
#include <material.h>
|
||||||
|
#include <particleEmitter.h>
|
||||||
#include <texture.h>
|
#include <texture.h>
|
||||||
#include <ray.h>
|
#include <ray.h>
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
|
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "game.h"
|
||||||
#include "inGameAppState.h"
|
#include "inGameAppState.h"
|
||||||
#include "defConfigs.h"
|
#include "defConfigs.h"
|
||||||
#include "pathfinder.h"
|
#include "pathfinder.h"
|
||||||
@@ -32,8 +34,11 @@ namespace battleship{
|
|||||||
hpForegroundNode = createBar(lenHpBar, Vector4(0, 1, 0, 1));
|
hpForegroundNode = createBar(lenHpBar, Vector4(0, 1, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO complete implementation
|
|
||||||
Unit::~Unit() {
|
Unit::~Unit() {
|
||||||
|
removeBar(hpBackgroundNode);
|
||||||
|
removeBar(hpForegroundNode);
|
||||||
|
destroySound();
|
||||||
|
destroyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::init(){
|
void Unit::init(){
|
||||||
@@ -46,6 +51,7 @@ namespace battleship{
|
|||||||
|
|
||||||
void Unit::initProperties(){
|
void Unit::initProperties(){
|
||||||
sol::table SOL_LUA_STATE = generateView()[GameObject::getGameObjTableName()];
|
sol::table SOL_LUA_STATE = generateView()[GameObject::getGameObjTableName()];
|
||||||
|
string name = SOL_LUA_STATE["name"][id + 1];
|
||||||
health = SOL_LUA_STATE["health"][id + 1];
|
health = SOL_LUA_STATE["health"][id + 1];
|
||||||
maxHealth = health;
|
maxHealth = health;
|
||||||
|
|
||||||
@@ -71,16 +77,22 @@ namespace battleship{
|
|||||||
selectionSfx->stop();
|
selectionSfx->stop();
|
||||||
delete selectionSfx;
|
delete selectionSfx;
|
||||||
delete selectionSfxBuffer;
|
delete selectionSfxBuffer;
|
||||||
|
|
||||||
|
if(fireSfx){
|
||||||
|
fireSfx->stop();
|
||||||
|
delete fireSfx;
|
||||||
|
delete fireSfxBuffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::initSound(){
|
void Unit::initSound(){
|
||||||
sol::table SOL_LUA_STATE = generateView()[GameObject::getGameObjTableName()];
|
GameObject::initSound();
|
||||||
string name = SOL_LUA_STATE["name"][id + 1];
|
|
||||||
selectionSfxBuffer = new sf::SoundBuffer();
|
|
||||||
string sfxPath = SOL_LUA_STATE["selectionSfx"][id + 1];
|
|
||||||
|
|
||||||
if(selectionSfxBuffer->loadFromFile(sfxPath.c_str()))
|
selectionSfxBuffer = new sf::SoundBuffer();
|
||||||
selectionSfx = new sf::Sound(*selectionSfxBuffer);
|
selectionSfx = GameObject::prepareSfx(selectionSfxBuffer, "selectionSfx");
|
||||||
|
|
||||||
|
fireSfxBuffer = new sf::SoundBuffer();
|
||||||
|
fireSfx = prepareSfx(fireSfxBuffer, "fireSfx");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::reinit(){
|
void Unit::reinit(){
|
||||||
@@ -110,6 +122,11 @@ namespace battleship{
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::removeBar(Node *node){
|
||||||
|
Root::getSingleton()->getGuiNode()->dettachChild(node);
|
||||||
|
delete node;
|
||||||
|
}
|
||||||
|
|
||||||
void Unit::initUnitStats(){
|
void Unit::initUnitStats(){
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,11 +147,41 @@ namespace battleship{
|
|||||||
displayUnitStats(hpForegroundNode, hpBackgroundNode, health, maxHealth);
|
displayUnitStats(hpForegroundNode, hpBackgroundNode, health, maxHealth);
|
||||||
|
|
||||||
if (health <= 0)
|
if (health <= 0)
|
||||||
blowUp();
|
blowUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::blowUp(){
|
void Unit::blowUp(){
|
||||||
working = false;
|
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/explosion0" + to_string(7) + ".png";
|
||||||
|
|
||||||
|
Texture *tex = new Texture(numFrames, p, false);
|
||||||
|
|
||||||
|
Material *mat = new Material(root->getLibPath() + "particle");
|
||||||
|
mat->addVec4Uniform("startColor", Vector4(1, 1, 1, 1));
|
||||||
|
mat->addVec4Uniform("endColor", Vector4(1, 1, 0, 1));
|
||||||
|
mat->addTexUniform("tex", tex, false);
|
||||||
|
|
||||||
|
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(2500, deathSfx, node);
|
||||||
|
fx.activate();
|
||||||
|
Game::getSingleton()->addFx(fx);
|
||||||
|
|
||||||
|
player->removeUnit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::displayUnitStats(Node *foreground, Node *background, int currVal, int maxVal, Vector2 offset) {
|
void Unit::displayUnitStats(Node *foreground, Node *background, int currVal, int maxVal, Vector2 offset) {
|
||||||
|
|||||||
@@ -6,12 +6,15 @@
|
|||||||
#include <quaternion.h>
|
#include <quaternion.h>
|
||||||
#include <lineRenderer.h>
|
#include <lineRenderer.h>
|
||||||
|
|
||||||
#include <SFML/Audio.hpp>
|
|
||||||
|
|
||||||
#include "gameManager.h"
|
#include "gameManager.h"
|
||||||
#include "gameObject.h"
|
#include "gameObject.h"
|
||||||
#include "projectile.h"
|
#include "projectile.h"
|
||||||
|
|
||||||
|
namespace sf{
|
||||||
|
class SoundBuffer;
|
||||||
|
class Sound;
|
||||||
|
}
|
||||||
|
|
||||||
namespace vb01{
|
namespace vb01{
|
||||||
class Mesh;
|
class Mesh;
|
||||||
class Quad;
|
class Quad;
|
||||||
@@ -59,7 +62,6 @@ namespace battleship{
|
|||||||
virtual void addOrder(Order);
|
virtual void addOrder(Order);
|
||||||
virtual void reinit();
|
virtual void reinit();
|
||||||
inline vb01::Vector3 getCorner(int i){return corners[i];}
|
inline vb01::Vector3 getCorner(int i){return corners[i];}
|
||||||
inline bool isWorking(){return working;}
|
|
||||||
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
||||||
inline vb01::Vector3* getPosPtr() {return &pos;}
|
inline vb01::Vector3* getPosPtr() {return &pos;}
|
||||||
inline float getLineOfSight() {return lineOfSight;}
|
inline float getLineOfSight() {return lineOfSight;}
|
||||||
@@ -83,9 +85,10 @@ namespace battleship{
|
|||||||
vb01::Vector2 screenPos;
|
vb01::Vector2 screenPos;
|
||||||
std::vector<Order> orders;
|
std::vector<Order> orders;
|
||||||
vb01::Vector3 corners[8];
|
vb01::Vector3 corners[8];
|
||||||
|
sf::SoundBuffer *fireSfxBuffer;
|
||||||
|
sf::Sound *fireSfx = nullptr;
|
||||||
int health, maxHealth, cost, id, playerId, lenHpBar = 200, rateOfFire;
|
int health, maxHealth, cost, id, playerId, lenHpBar = 200, rateOfFire;
|
||||||
s64 orderLineDispTime = 0, lastFireTime = 0;
|
s64 orderLineDispTime = 0, lastFireTime = 0;
|
||||||
bool working = true;
|
|
||||||
float lineOfSight, range;
|
float lineOfSight, range;
|
||||||
|
|
||||||
void removeOrder(int);
|
void removeOrder(int);
|
||||||
@@ -101,6 +104,7 @@ namespace battleship{
|
|||||||
virtual void patrol(Order){}
|
virtual void patrol(Order){}
|
||||||
virtual void launch(Order){}
|
virtual void launch(Order){}
|
||||||
vb01::Node* createBar(float, vb01::Vector4);
|
vb01::Node* createBar(float, vb01::Vector4);
|
||||||
|
void removeBar(vb01::Node*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
@@ -26,6 +26,13 @@ namespace battleship{
|
|||||||
debugMat->addVec4Uniform("diffuseColor", Vector4::VEC_IJKL);
|
debugMat->addVec4Uniform("diffuseColor", Vector4::VEC_IJKL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vehicle::~Vehicle(){
|
||||||
|
removeAllPathpoints();
|
||||||
|
delete debugMat;
|
||||||
|
|
||||||
|
Unit::~Unit();
|
||||||
|
}
|
||||||
|
|
||||||
void Vehicle::halt(){
|
void Vehicle::halt(){
|
||||||
Unit::halt();
|
Unit::halt();
|
||||||
removeAllPathpoints();
|
removeAllPathpoints();
|
||||||
@@ -221,4 +228,13 @@ namespace battleship{
|
|||||||
fire();
|
fire();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Vehicle::fire(){
|
||||||
|
fireSfx->play();
|
||||||
|
|
||||||
|
Unit *targetUnit = orders[0].targets[0].unit;
|
||||||
|
|
||||||
|
if(targetUnit)
|
||||||
|
targetUnit->takeDamage(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace battleship{
|
|||||||
class Vehicle : public Unit{
|
class Vehicle : public Unit{
|
||||||
public:
|
public:
|
||||||
Vehicle(Player*, int, vb01::Vector3, vb01::Quaternion);
|
Vehicle(Player*, int, vb01::Vector3, vb01::Quaternion);
|
||||||
|
~Vehicle();
|
||||||
void move(Order);
|
void move(Order);
|
||||||
private:
|
private:
|
||||||
bool pursuingTarget = false;
|
bool pursuingTarget = false;
|
||||||
@@ -34,7 +35,7 @@ namespace battleship{
|
|||||||
void navigate(Order, float = 0.);
|
void navigate(Order, float = 0.);
|
||||||
void alignToSurface();
|
void alignToSurface();
|
||||||
void attack(Order);
|
void attack(Order);
|
||||||
void fire(){}
|
virtual void fire();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user