mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
changed namespace
This commit is contained in:
+50
-51
@@ -7,76 +7,75 @@
|
||||
#include "abstractAppState.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
void AbstractAppState::onAttachment() {
|
||||
const int stateId=(int)type,numBinds=core::numBinds[stateId];
|
||||
int firstLine=0,lastLine;
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
for(int i=0;i<stateId;i++)
|
||||
firstLine+=core::numConfBinds[i];
|
||||
void AbstractAppState::onAttachment() {
|
||||
const int stateId = (int)type, numBinds = configData::numBinds[stateId];
|
||||
int firstLine=0,lastLine;
|
||||
|
||||
// firstLine++;
|
||||
lastLine=firstLine+core::numConfBinds[stateId];
|
||||
std::vector<string> lines;
|
||||
readFile(PATH_STR + "../options.cfg", lines, firstLine,lastLine);
|
||||
for(int i=0;i<stateId;i++)
|
||||
firstLine += configData::numConfBinds[i];
|
||||
|
||||
for(int i=0;i<numBinds;i++){
|
||||
int trigger=core::triggers[stateId][i];
|
||||
//firstLine++;
|
||||
lastLine=firstLine + configData::numConfBinds[stateId];
|
||||
std::vector<string> lines;
|
||||
readFile(PATH + "../options.cfg", lines, firstLine,lastLine);
|
||||
|
||||
if(i<core::numConfBinds[stateId]&&stateId!=(int)AppStateTypes::GUI_STATE){
|
||||
int xId=-1;
|
||||
for(int i=0;i<numBinds;i++){
|
||||
int trigger=triggers[stateId][i];
|
||||
|
||||
for(int i2=0;i2<lines[i].size()&&xId==-1;i2++)
|
||||
if(lines[i].c_str()[i2]=='x')
|
||||
xId=i2;
|
||||
if(i<configData::numConfBinds[stateId]&&stateId!=(int)AppStateTypes::GUI_STATE){
|
||||
int xId=-1;
|
||||
|
||||
char ch[2];
|
||||
for(int i2=0;i2<lines[i].size()&&xId==-1;i2++)
|
||||
if(lines[i].c_str()[i2]=='x')
|
||||
xId=i2;
|
||||
|
||||
for(int i2=0;i2<2;i2++)
|
||||
ch[i2]=(char)lines[i].substr(xId+1,2).c_str()[i2];
|
||||
char ch[2];
|
||||
|
||||
stringstream ss;
|
||||
ss<<ch;
|
||||
ss>>std::hex>>trigger;
|
||||
}
|
||||
for(int i2=0;i2<2;i2++)
|
||||
ch[i2]=(char)lines[i].substr(xId+1,2).c_str()[i2];
|
||||
|
||||
Mapping::Bind bind=binds[stateId][i];
|
||||
Mapping::BindType type = (stateId > 0 ? Mapping::KEYBOARD : Mapping::MOUSE_KEY);
|
||||
bool isAnalog = core::isAnalog[stateId][i];
|
||||
|
||||
Mapping *m = new Mapping;
|
||||
m->bind = bind;
|
||||
m->trigger = trigger;
|
||||
m->type = type;
|
||||
m->action = !isAnalog;
|
||||
attachedKeys.push_back(m);
|
||||
stringstream ss;
|
||||
ss<<ch;
|
||||
ss>>std::hex>>trigger;
|
||||
}
|
||||
|
||||
attached = true;
|
||||
Mapping::Bind bind=binds[stateId][i];
|
||||
Mapping::BindType type = (stateId > 0 ? Mapping::KEYBOARD : Mapping::MOUSE_KEY);
|
||||
bool isAnalog = configData::isAnalog[stateId][i];
|
||||
|
||||
Mapping *m = new Mapping;
|
||||
m->bind = bind;
|
||||
m->trigger = trigger;
|
||||
m->type = type;
|
||||
m->action = !isAnalog;
|
||||
attachedKeys.push_back(m);
|
||||
}
|
||||
|
||||
void AbstractAppState::onDetachment() {
|
||||
attached = false;
|
||||
}
|
||||
attached = true;
|
||||
}
|
||||
|
||||
void AbstractAppState::detachKey(Mapping *key) {
|
||||
for (int i = 0; i < attachedKeys.size(); i++)
|
||||
if (key == attachedKeys[i]) {
|
||||
delete key;
|
||||
attachedKeys.erase(attachedKeys.begin() + i);
|
||||
}
|
||||
}
|
||||
void AbstractAppState::onDetachment() {
|
||||
attached = false;
|
||||
}
|
||||
|
||||
void AbstractAppState::detachAllKeys() {
|
||||
while (attachedKeys.size() > 0) {
|
||||
delete attachedKeys[attachedKeys.size() - 1];
|
||||
attachedKeys.pop_back();
|
||||
void AbstractAppState::detachKey(Mapping *key) {
|
||||
for (int i = 0; i < attachedKeys.size(); i++)
|
||||
if (key == attachedKeys[i]) {
|
||||
delete key;
|
||||
attachedKeys.erase(attachedKeys.begin() + i);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractAppState::detachAllKeys() {
|
||||
while (attachedKeys.size() > 0) {
|
||||
delete attachedKeys[attachedKeys.size() - 1];
|
||||
attachedKeys.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-32
@@ -5,38 +5,36 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
enum class AppStateTypes {GUI_STATE,IN_GAME_STATE,ACTIVE_STATE};
|
||||
class AbstractAppState {
|
||||
public:
|
||||
AbstractAppState(){}
|
||||
~AbstractAppState(){}
|
||||
void setKey(int, Mapping*);
|
||||
AppStateTypes getType() {return type;}
|
||||
inline bool isAttached(){return attached;}
|
||||
inline int getKeysNumber(){return attachedKeys.size();}
|
||||
inline Mapping* getKey(int i){return attachedKeys[i];}
|
||||
inline std::vector<Mapping*>& getKeys(){return attachedKeys;}
|
||||
virtual void onAttachment();
|
||||
virtual void onDetachment();
|
||||
virtual void update(){}
|
||||
virtual void onAction(Mapping::Bind, bool){}
|
||||
virtual void onAnalog(Mapping::Bind, double){}
|
||||
/*
|
||||
virtual void onRawKeyPress(irr::SEvent::SKeyInput){}
|
||||
virtual void onRawMousePress(irr::SEvent::SMouseInput){}
|
||||
*/
|
||||
private:
|
||||
bool attached = false;
|
||||
std::vector<Mapping*> attachedKeys;
|
||||
protected:
|
||||
AppStateTypes type;
|
||||
inline void attachKey(Mapping *k){attachedKeys.push_back(k);}
|
||||
void detachKey(Mapping*);
|
||||
void detachAllKeys();
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
enum class AppStateTypes {GUI_STATE,IN_GAME_STATE,ACTIVE_STATE};
|
||||
class AbstractAppState {
|
||||
public:
|
||||
AbstractAppState(){}
|
||||
~AbstractAppState(){}
|
||||
void setKey(int, Mapping*);
|
||||
AppStateTypes getType() {return type;}
|
||||
inline bool isAttached(){return attached;}
|
||||
inline int getKeysNumber(){return attachedKeys.size();}
|
||||
inline Mapping* getKey(int i){return attachedKeys[i];}
|
||||
inline std::vector<Mapping*>& getKeys(){return attachedKeys;}
|
||||
virtual void onAttachment();
|
||||
virtual void onDetachment();
|
||||
virtual void update(){}
|
||||
virtual void onAction(Mapping::Bind, bool){}
|
||||
virtual void onAnalog(Mapping::Bind, double){}
|
||||
/*
|
||||
virtual void onRawKeyPress(irr::SEvent::SKeyInput){}
|
||||
virtual void onRawMousePress(irr::SEvent::SMouseInput){}
|
||||
*/
|
||||
private:
|
||||
bool attached = false;
|
||||
std::vector<Mapping*> attachedKeys;
|
||||
protected:
|
||||
AppStateTypes type;
|
||||
inline void attachKey(Mapping *k){attachedKeys.push_back(k);}
|
||||
void detachKey(Mapping*);
|
||||
void detachAllKeys();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+566
-568
File diff suppressed because it is too large
Load Diff
+61
-63
@@ -10,72 +10,70 @@ namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
class ActiveGameState : public AbstractAppState {
|
||||
namespace battleship{
|
||||
class ActiveGameState : public AbstractAppState {
|
||||
public:
|
||||
ActiveGameState(GuiAppState*, Map*, std::vector<Player*> players, int);
|
||||
~ActiveGameState();
|
||||
void onAttachment();
|
||||
void onDetachment();
|
||||
void update();
|
||||
void onAction(Mapping::Bind, bool);
|
||||
void onAnalog(Mapping::Bind, double);
|
||||
inline void setSelectingLaunchPoint(bool s){this->selectingGuidedMissileTarget=s;}
|
||||
inline Player* getPlayer(){return mainPlayer;}
|
||||
inline std::vector<Unit*>& getSelectedUnits(){return selectedUnits;}
|
||||
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
|
||||
private:
|
||||
class UnitButton : public vb01Gui::Button{
|
||||
public:
|
||||
ActiveGameState(GuiAppState*, content::Map*, std::vector<content::Player*> players, int);
|
||||
~ActiveGameState();
|
||||
void onAttachment();
|
||||
void onDetachment();
|
||||
void update();
|
||||
void onAction(Mapping::Bind, bool);
|
||||
void onAnalog(Mapping::Bind, double);
|
||||
inline void setSelectingLaunchPoint(bool s){this->selectingGuidedMissileTarget=s;}
|
||||
inline content::Player* getPlayer(){return mainPlayer;}
|
||||
inline std::vector<content::Unit*>& getSelectedUnits(){return selectedUnits;}
|
||||
inline std::vector<content::Unit*>& getUnitGroup(int i){return unitGroups[i];}
|
||||
UnitButton(ActiveGameState*, vb01::Vector2, vb01::Vector2, std::string, int, int);
|
||||
~UnitButton(){}
|
||||
virtual void onClick();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseAway();
|
||||
private:
|
||||
class UnitButton : public vb01Gui::Button{
|
||||
public:
|
||||
UnitButton(ActiveGameState*, vb01::Vector2, vb01::Vector2, std::string, int, int);
|
||||
~UnitButton(){}
|
||||
virtual void onClick();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseAway();
|
||||
private:
|
||||
ActiveGameState *activeState;
|
||||
int faction, unitId;
|
||||
};
|
||||
|
||||
class UnitActionButton : public vb01Gui::Button{
|
||||
public:
|
||||
UnitActionButton(content::unitData::UNIT_TYPE, vb01::Vector2, vb01::Vector2, std::string, std::string);
|
||||
~UnitActionButton(){}
|
||||
virtual void onClick();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseAway();
|
||||
protected:
|
||||
content::unitData::UNIT_TYPE type;
|
||||
std::vector<content::Unit*> units;
|
||||
ActiveGameState *activeState;
|
||||
};
|
||||
|
||||
void renderGUIBorders();
|
||||
void renderActionButtons();
|
||||
void renderUnits(std::vector<content::Unit*>);
|
||||
void updateVectors();
|
||||
void updateSelectionBox();
|
||||
void addPos();
|
||||
void issueOrder(content::Order::TYPE, std::vector<vb01::Vector3*>, bool);
|
||||
void lookAround(bool);
|
||||
GuiAppState *guiState;
|
||||
content::Map *map;
|
||||
std::vector<content::Player*> players;
|
||||
content::Player *mainPlayer;
|
||||
vb01::Camera *cam;
|
||||
vb01::Vector3 camDir = vb01::Vector3(0, 0, 1), camLeft = vb01::Vector3(1, 0, 0), camUp = vb01::Vector3(0, 1, 0);
|
||||
vb01::Vector2 clickPoint, selectionBoxOrigin, selectionBoxEnd;
|
||||
std::vector<vb01::Vector2> unitScreenPosVec;
|
||||
std::vector<vb01::Vector3*> orderPos;
|
||||
std::vector<vb01::Node*> unitLightNodes;
|
||||
std::vector<content::Unit*> unitGroups[9], selectedUnits;
|
||||
UnitActionButton *actionButtons[4]{nullptr,nullptr,nullptr,nullptr};
|
||||
bool isSelectionBox = false, shiftPressed=false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false,lookingAround=false;
|
||||
bool isInLineOfSight(vb01::Vector3, float, content::Unit*);
|
||||
int playerId, zooms = 0;
|
||||
ActiveGameState *activeState;
|
||||
int faction, unitId;
|
||||
};
|
||||
}
|
||||
|
||||
class UnitActionButton : public vb01Gui::Button{
|
||||
public:
|
||||
UnitActionButton(unitData::UNIT_TYPE, vb01::Vector2, vb01::Vector2, std::string, std::string);
|
||||
~UnitActionButton(){}
|
||||
virtual void onClick();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseAway();
|
||||
protected:
|
||||
unitData::UNIT_TYPE type;
|
||||
std::vector<Unit*> units;
|
||||
ActiveGameState *activeState;
|
||||
};
|
||||
|
||||
void renderGUIBorders();
|
||||
void renderActionButtons();
|
||||
void renderUnits(std::vector<Unit*>);
|
||||
void updateVectors();
|
||||
void updateSelectionBox();
|
||||
void addPos();
|
||||
void issueOrder(Order::TYPE, std::vector<vb01::Vector3*>, bool);
|
||||
void lookAround(bool);
|
||||
GuiAppState *guiState;
|
||||
Map *map;
|
||||
std::vector<Player*> players;
|
||||
Player *mainPlayer;
|
||||
vb01::Camera *cam;
|
||||
vb01::Vector3 camDir = vb01::Vector3(0, 0, 1), camLeft = vb01::Vector3(1, 0, 0), camUp = vb01::Vector3(0, 1, 0);
|
||||
vb01::Vector2 clickPoint, selectionBoxOrigin, selectionBoxEnd;
|
||||
std::vector<vb01::Vector2> unitScreenPosVec;
|
||||
std::vector<vb01::Vector3*> orderPos;
|
||||
std::vector<vb01::Node*> unitLightNodes;
|
||||
std::vector<Unit*> unitGroups[9], selectedUnits;
|
||||
UnitActionButton *actionButtons[4]{nullptr,nullptr,nullptr,nullptr};
|
||||
bool isSelectionBox = false, shiftPressed=false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false,lookingAround=false;
|
||||
bool isInLineOfSight(vb01::Vector3, float, Unit*);
|
||||
int playerId, zooms = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+43
-46
@@ -3,66 +3,63 @@
|
||||
#include "missileJet.h"
|
||||
#include "demoJet.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
AircraftCarrier::AircraftCarrier(Player *player, Vector3 pos, int unitId) : Vessel(player,pos, unitId) {
|
||||
maxNumJets = unitData::numJets[unitId];
|
||||
jets = new Jet*[maxNumJets];
|
||||
namespace battleship{
|
||||
AircraftCarrier::AircraftCarrier(Player *player, Vector3 pos, int unitId) : Vessel(player,pos, unitId) {
|
||||
maxNumJets = unitData::numJets[unitId];
|
||||
jets = new Jet*[maxNumJets];
|
||||
|
||||
for(int i=0;i<maxNumJets;i++)
|
||||
jets[i]=nullptr;
|
||||
for(int i=0;i<maxNumJets;i++)
|
||||
jets[i]=nullptr;
|
||||
|
||||
runwayLength=unitData::runwayLenght[unitId];
|
||||
runwayLength=unitData::runwayLenght[unitId];
|
||||
|
||||
for (int i = 0; i < unitData::numJets[unitId]; i++)
|
||||
makeJet();
|
||||
}
|
||||
for (int i = 0; i < unitData::numJets[unitId]; i++)
|
||||
makeJet();
|
||||
}
|
||||
|
||||
AircraftCarrier::~AircraftCarrier(){
|
||||
delete[] jets;
|
||||
}
|
||||
|
||||
void AircraftCarrier::makeJet(){
|
||||
int slot=-1;
|
||||
AircraftCarrier::~AircraftCarrier(){
|
||||
delete[] jets;
|
||||
}
|
||||
|
||||
void AircraftCarrier::makeJet(){
|
||||
int slot=-1;
|
||||
|
||||
for(int i=0; i<unitData::numJets[id]&&slot==-1; i++)
|
||||
if(!jets[i])
|
||||
slot=i;
|
||||
for(int i=0; i<unitData::numJets[id]&&slot==-1; i++)
|
||||
if(!jets[i])
|
||||
slot=i;
|
||||
|
||||
if(slot!=-1){
|
||||
int id = 0;
|
||||
Jet *j = nullptr;
|
||||
if(slot!=-1){
|
||||
int id = 0;
|
||||
Jet *j = nullptr;
|
||||
|
||||
if (this->id == 6) {
|
||||
id = 9;
|
||||
j = (MissileJet*)new MissileJet(player,getJetPos(slot), id);
|
||||
} else {
|
||||
id = 10;
|
||||
j = (DemoJet*)new DemoJet(player,getJetPos(slot), id);
|
||||
}
|
||||
|
||||
j->setJetId(slot);
|
||||
jets[slot]=j;
|
||||
j->setAircraftCarrier(this);
|
||||
player->addUnit(j);
|
||||
if (this->id == 6) {
|
||||
id = 9;
|
||||
j = (MissileJet*)new MissileJet(player,getJetPos(slot), id);
|
||||
} else {
|
||||
id = 10;
|
||||
j = (DemoJet*)new DemoJet(player,getJetPos(slot), id);
|
||||
}
|
||||
|
||||
j->setJetId(slot);
|
||||
jets[slot]=j;
|
||||
j->setAircraftCarrier(this);
|
||||
player->addUnit(j);
|
||||
}
|
||||
|
||||
void AircraftCarrier::move(Order order, float offset) {
|
||||
Unit::move(order, offset);
|
||||
}
|
||||
|
||||
void AircraftCarrier::move(Order order, float offset) {
|
||||
Unit::move(order, offset);
|
||||
|
||||
for (int i=0;i<maxNumJets;i++) {
|
||||
Jet *j=jets[i];
|
||||
for (int i=0;i<maxNumJets;i++) {
|
||||
Jet *j=jets[i];
|
||||
|
||||
if (j && j->isOnBoard()) {
|
||||
Vector3 oP = j->getOffsetPos();
|
||||
j->orientUnit(dirVec);
|
||||
j->placeUnit(pos + leftVec * oP.x + upVec * oP.y - dirVec * oP.z);
|
||||
}
|
||||
if (j && j->isOnBoard()) {
|
||||
Vector3 oP = j->getOffsetPos();
|
||||
j->orientUnit(dirVec);
|
||||
j->placeUnit(pos + leftVec * oP.x + upVec * oP.y - dirVec * oP.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-20
@@ -6,26 +6,24 @@
|
||||
#include "jet.h"
|
||||
#include "aircraftCarrierData.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class AircraftCarrier : public Vessel {
|
||||
public:
|
||||
AircraftCarrier(Player*, vb01::Vector3, int);
|
||||
~AircraftCarrier();
|
||||
void makeJet();
|
||||
inline void setJet(int i, Jet *j){this->jets[i]=j;}
|
||||
inline int getMaxNumJets(){return maxNumJets;}
|
||||
inline Jet* getJet(int i){return jets[i];}
|
||||
inline Jet** getJets(){return jets;}
|
||||
inline vb01::Vector3 getJetPos(int i){return pos + leftVec * unitData::jetPos[id][i].x - dirVec * unitData::jetPos[id][i].z + upVec * unitData::jetPos[id][i].y;}
|
||||
inline float getRunwayLength(){return runwayLength;}
|
||||
private:
|
||||
Jet** jets;
|
||||
int maxNumJets;
|
||||
float runwayLength;
|
||||
void move(Order, float = 0.);
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class AircraftCarrier : public Vessel {
|
||||
public:
|
||||
AircraftCarrier(Player*, vb01::Vector3, int);
|
||||
~AircraftCarrier();
|
||||
void makeJet();
|
||||
inline void setJet(int i, Jet *j){this->jets[i]=j;}
|
||||
inline int getMaxNumJets(){return maxNumJets;}
|
||||
inline Jet* getJet(int i){return jets[i];}
|
||||
inline Jet** getJets(){return jets;}
|
||||
inline vb01::Vector3 getJetPos(int i){return pos + leftVec * unitData::jetPos[id][i].x - dirVec * unitData::jetPos[id][i].z + upVec * unitData::jetPos[id][i].y;}
|
||||
inline float getRunwayLength(){return runwayLength;}
|
||||
private:
|
||||
Jet** jets;
|
||||
int maxNumJets;
|
||||
float runwayLength;
|
||||
void move(Order, float = 0.);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+28
-30
@@ -13,36 +13,34 @@
|
||||
5: 戦闘機
|
||||
*/
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
namespace unitData {
|
||||
const int numJets[numberOfUnits]{0, 0, 0, 0, 0, 0, 6, 6};
|
||||
const vb01::Vector3 jetPos[numberOfUnits][20]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
vb01::Vector3(0.13674, 1.60034, 7.78832),
|
||||
vb01::Vector3(1.5889, 1.60034, 7.78832),
|
||||
vb01::Vector3(0.13674, 1.60034, 5.47672),
|
||||
vb01::Vector3(1.5889, 1.60034, 5.47672),
|
||||
vb01::Vector3(0.13674, 1.60034, 3.37257),
|
||||
vb01::Vector3(1.5889, 1.60034, 3.37257)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(-0.61651, 2.78469, 7.88753),
|
||||
vb01::Vector3(0.40384, 2.78469, 7.88753),
|
||||
vb01::Vector3(-0.61651, 2.78469, 5.82783),
|
||||
vb01::Vector3(0.40384, 2.78469, 5.82783),
|
||||
vb01::Vector3(-0.61651, 2.78469, 3.87186),
|
||||
vb01::Vector3(0.40384, 2.78469, 3.87186)
|
||||
}
|
||||
};
|
||||
const float runwayLenght[numberOfUnits]{0, 0, 0, 0, 0, 0, 10, 10};
|
||||
}
|
||||
namespace battleship {
|
||||
namespace unitData {
|
||||
const int numJets[numberOfUnits]{0, 0, 0, 0, 0, 0, 6, 6};
|
||||
const vb01::Vector3 jetPos[numberOfUnits][20]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
vb01::Vector3(0.13674, 1.60034, 7.78832),
|
||||
vb01::Vector3(1.5889, 1.60034, 7.78832),
|
||||
vb01::Vector3(0.13674, 1.60034, 5.47672),
|
||||
vb01::Vector3(1.5889, 1.60034, 5.47672),
|
||||
vb01::Vector3(0.13674, 1.60034, 3.37257),
|
||||
vb01::Vector3(1.5889, 1.60034, 3.37257)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(-0.61651, 2.78469, 7.88753),
|
||||
vb01::Vector3(0.40384, 2.78469, 7.88753),
|
||||
vb01::Vector3(-0.61651, 2.78469, 5.82783),
|
||||
vb01::Vector3(0.40384, 2.78469, 5.82783),
|
||||
vb01::Vector3(-0.61651, 2.78469, 3.87186),
|
||||
vb01::Vector3(0.40384, 2.78469, 3.87186)
|
||||
}
|
||||
};
|
||||
const float runwayLenght[numberOfUnits]{0, 0, 0, 0, 0, 0, 10, 10};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+98
-100
@@ -12,119 +12,117 @@
|
||||
#include "demoJet.h"
|
||||
#include "missileJet.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::content;
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, string name, vector<string> args) {
|
||||
listbox = l;
|
||||
this->players = players;
|
||||
this->name = name;
|
||||
arguments = args;
|
||||
execute();
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, string name, vector<string> args) {
|
||||
listbox = l;
|
||||
this->players = players;
|
||||
this->name = name;
|
||||
arguments = args;
|
||||
execute();
|
||||
}
|
||||
|
||||
ConsoleCommand::~ConsoleCommand() {
|
||||
}
|
||||
|
||||
void ConsoleCommand::execute() {
|
||||
if (name == commandList[0])
|
||||
addUnit();
|
||||
else if (name == commandList[1])
|
||||
debugUnits();
|
||||
else
|
||||
printConsoleMessage("No such command");
|
||||
}
|
||||
|
||||
void ConsoleCommand::addUnit() {
|
||||
int unitId = 0, playerId = 0;
|
||||
Vector3 pos(0, 0, 0);
|
||||
float angle = 0;
|
||||
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
arguments[i].erase(0);
|
||||
for (int i2 = 0; i2 < arguments[i].size(); i2++) {
|
||||
if (i == 0)
|
||||
playerId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
else
|
||||
unitId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleCommand::~ConsoleCommand() {
|
||||
}
|
||||
if ((playerId == 0 || playerId == 1) && (unitId >= 0 && unitId <= numberOfUnits)) {
|
||||
Unit *u = nullptr;
|
||||
|
||||
void ConsoleCommand::execute() {
|
||||
if (name == commandList[0])
|
||||
addUnit();
|
||||
else if (name == commandList[1])
|
||||
debugUnits();
|
||||
else
|
||||
printConsoleMessage("No such command");
|
||||
}
|
||||
|
||||
void ConsoleCommand::addUnit() {
|
||||
int unitId = 0, playerId = 0;
|
||||
Vector3 pos(0, 0, 0);
|
||||
float angle = 0;
|
||||
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
arguments[i].erase(0);
|
||||
for (int i2 = 0; i2 < arguments[i].size(); i2++) {
|
||||
if (i == 0)
|
||||
playerId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
else
|
||||
unitId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
switch (unitType[unitId]) {
|
||||
case UNIT_TYPE::VESSEL:
|
||||
u = new Vessel(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::DESTROYER:
|
||||
u = new Destroyer(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::CRUISER:
|
||||
u = new Cruiser(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::SUBMARINE:
|
||||
u = new Submarine(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::AIRCRAFT_CARRIER:
|
||||
{
|
||||
u = new AircraftCarrier(players[playerId],pos, unitId);
|
||||
break;
|
||||
}
|
||||
case UNIT_TYPE::MISSILE_JET:
|
||||
u = new MissileJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
case UNIT_TYPE::DEMO_JET:
|
||||
u = new DemoJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ((playerId == 0 || playerId == 1) && (unitId >= 0 && unitId <= numberOfUnits)) {
|
||||
Unit *u = nullptr;
|
||||
players[playerId]->addUnit(u);
|
||||
} else if (playerId != 0 && playerId != 1)
|
||||
printConsoleMessage("Invalid player id");
|
||||
else if (unitId < 0 || unitId > numberOfUnits)
|
||||
printConsoleMessage("Invalid unit id");
|
||||
}
|
||||
|
||||
switch (unitType[unitId]) {
|
||||
case UNIT_TYPE::VESSEL:
|
||||
u = new Vessel(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::DESTROYER:
|
||||
u = new Destroyer(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::CRUISER:
|
||||
u = new Cruiser(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::SUBMARINE:
|
||||
u = new Submarine(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::AIRCRAFT_CARRIER:
|
||||
{
|
||||
u = new AircraftCarrier(players[playerId],pos, unitId);
|
||||
break;
|
||||
}
|
||||
case UNIT_TYPE::MISSILE_JET:
|
||||
u = new MissileJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
case UNIT_TYPE::DEMO_JET:
|
||||
u = new DemoJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
void ConsoleCommand::debugUnits() {
|
||||
if (arguments.size() == 0)
|
||||
for (Player *pl : players){
|
||||
vector<Unit*> &units=pl->getUnits();
|
||||
|
||||
for (Unit *u : units){
|
||||
u->toggleDebugging(true);
|
||||
vector<Projectile*> projectiles=u->getProjectiles();
|
||||
|
||||
for(Projectile *pr : projectiles)
|
||||
pr->debug();
|
||||
}
|
||||
}
|
||||
else
|
||||
printConsoleMessage("Too many arguments");
|
||||
}
|
||||
|
||||
players[playerId]->addUnit(u);
|
||||
} else if (playerId != 0 && playerId != 1)
|
||||
printConsoleMessage("Invalid player id");
|
||||
else if (unitId < 0 || unitId > numberOfUnits)
|
||||
printConsoleMessage("Invalid unit id");
|
||||
}
|
||||
void ConsoleCommand::printConsoleMessage(string message) {
|
||||
int messageId = 0;
|
||||
bool foundEmptySlot = false;
|
||||
|
||||
void ConsoleCommand::debugUnits() {
|
||||
if (arguments.size() == 0)
|
||||
for (Player *pl : players){
|
||||
vector<Unit*> &units=pl->getUnits();
|
||||
|
||||
for (Unit *u : units){
|
||||
u->toggleDebugging(true);
|
||||
vector<Projectile*> projectiles=u->getProjectiles();
|
||||
|
||||
for(Projectile *pr : projectiles)
|
||||
pr->debug();
|
||||
}
|
||||
}
|
||||
else
|
||||
printConsoleMessage("Too many arguments");
|
||||
}
|
||||
|
||||
void ConsoleCommand::printConsoleMessage(string message) {
|
||||
int messageId = 0;
|
||||
bool foundEmptySlot = false;
|
||||
|
||||
for (int i = 0; i < listbox->getContents().size() && !foundEmptySlot; i++)
|
||||
if (listbox->getContents()[i] == L"") {
|
||||
messageId = i;
|
||||
foundEmptySlot = true;
|
||||
}
|
||||
/*
|
||||
if (foundEmptySlot)
|
||||
listbox->changeLine(messageId, message);
|
||||
else
|
||||
listbox->addLine(message);
|
||||
*/
|
||||
}
|
||||
for (int i = 0; i < listbox->getContents().size() && !foundEmptySlot; i++)
|
||||
if (listbox->getContents()[i] == L"") {
|
||||
messageId = i;
|
||||
foundEmptySlot = true;
|
||||
}
|
||||
/*
|
||||
if (foundEmptySlot)
|
||||
listbox->changeLine(messageId, message);
|
||||
else
|
||||
listbox->addLine(message);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
+19
-21
@@ -8,26 +8,24 @@
|
||||
#include "listbox.h"
|
||||
#include "player.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace gui{
|
||||
class ConsoleCommand{
|
||||
public:
|
||||
ConsoleCommand(vb01Gui::Listbox*, std::vector<content::Player*>, std::string, std::vector<std::string>);
|
||||
~ConsoleCommand();
|
||||
void execute();
|
||||
private:
|
||||
vb01Gui::Listbox *listbox;
|
||||
void printConsoleMessage(std::string);
|
||||
std::vector<content::Player*> players;
|
||||
std::string name;
|
||||
std::vector<std::string> arguments;
|
||||
std::string commandList[2] = {"addUnit","debugUnits"};
|
||||
// #0
|
||||
void addUnit();
|
||||
// #1
|
||||
void debugUnits();
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class ConsoleCommand{
|
||||
public:
|
||||
ConsoleCommand(vb01Gui::Listbox*, std::vector<Player*>, std::string, std::vector<std::string>);
|
||||
~ConsoleCommand();
|
||||
void execute();
|
||||
private:
|
||||
vb01Gui::Listbox *listbox;
|
||||
void printConsoleMessage(std::string);
|
||||
std::vector<Player*> players;
|
||||
std::string name;
|
||||
std::vector<std::string> arguments;
|
||||
std::string commandList[2] = {"addUnit","debugUnits"};
|
||||
// #0
|
||||
void addUnit();
|
||||
// #1
|
||||
void debugUnits();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+12
-16
@@ -6,25 +6,21 @@
|
||||
#include "util.h"
|
||||
#include "projectileData.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Cruiser::Cruiser(Player *player, Vector3 pos, int id) : Vessel(player, pos, id) {
|
||||
guidedMissiles = unitData::maxGuidedMissiles[id];
|
||||
}
|
||||
namespace battleship{
|
||||
Cruiser::Cruiser(Player *player, Vector3 pos, int id) : Vessel(player, pos, id) {
|
||||
guidedMissiles = unitData::maxGuidedMissiles[id];
|
||||
}
|
||||
|
||||
void Cruiser::launch(Order order) {
|
||||
if (guidedMissiles > 0) {
|
||||
float angle = order.targetPos[0]->getAngleBetween(dirVec);
|
||||
Quaternion rotQuat = Quaternion(dirVec.x < 0 ? angle : -angle, Vector3(0, 1, 0));
|
||||
Vector3 basePos = leftVec * projectileData::pos[getId()][1][guidedMissiles - 1].x + upVec * projectileData::pos[getId()][1][guidedMissiles - 1].y - dirVec * projectileData::pos[getId()][1][guidedMissiles - 1].z;
|
||||
addProjectile(new GuidedMissile(this, pos + basePos, *order.targetPos[0], rotQuat * Vector3(0, 1, 0), rotQuat * Vector3(1, 0, 0), rotQuat * Vector3(0, 0, -1), getId(), 1, 0));
|
||||
removeOrder(0);
|
||||
// guidedMissiles--;
|
||||
}
|
||||
void Cruiser::launch(Order order) {
|
||||
if (guidedMissiles > 0) {
|
||||
float angle = order.targetPos[0]->getAngleBetween(dirVec);
|
||||
Quaternion rotQuat = Quaternion(dirVec.x < 0 ? angle : -angle, Vector3(0, 1, 0));
|
||||
Vector3 basePos = leftVec * projectileData::pos[getId()][1][guidedMissiles - 1].x + upVec * projectileData::pos[getId()][1][guidedMissiles - 1].y - dirVec * projectileData::pos[getId()][1][guidedMissiles - 1].z;
|
||||
addProjectile(new GuidedMissile(this, pos + basePos, *order.targetPos[0], rotQuat * Vector3(0, 1, 0), rotQuat * Vector3(1, 0, 0), rotQuat * Vector3(0, 0, -1), getId(), 1, 0));
|
||||
removeOrder(0);
|
||||
guidedMissiles--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,16 @@
|
||||
#include "vessel.h"
|
||||
#include "player.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace content {
|
||||
class Cruiser : public Vessel {
|
||||
public:
|
||||
Cruiser(Player*, vb01::Vector3, int);
|
||||
void launch(Order);
|
||||
private:
|
||||
bool canFire();
|
||||
int guidedMissiles, reloadTime = 5000;
|
||||
s64 lastUpdateTime;
|
||||
};
|
||||
}
|
||||
namespace battleship {
|
||||
class Cruiser : public Vessel {
|
||||
public:
|
||||
Cruiser(Player*, vb01::Vector3, int);
|
||||
void launch(Order);
|
||||
private:
|
||||
bool canFire();
|
||||
int guidedMissiles, reloadTime = 5000;
|
||||
s64 lastUpdateTime;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+3
-6
@@ -4,12 +4,9 @@
|
||||
|
||||
#include "vesselData.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace content{
|
||||
namespace unitData {
|
||||
const int maxGuidedMissiles[numberOfUnits]{0, 0, 0, 0, 6, 2};
|
||||
}
|
||||
namespace battleship{
|
||||
namespace unitData {
|
||||
const int maxGuidedMissiles[numberOfUnits]{0, 0, 0, 0, 6, 2};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+163
-162
@@ -6,169 +6,170 @@
|
||||
|
||||
#include "key.h"
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
const std::string PATH = "/home/dominykas/c++/Battleship/Assets/";
|
||||
const std::string PATH_STR = "/home/dominykas/c++/Battleship/Assets/";
|
||||
const std::string DEFAULT_TEXTURE = PATH + "Textures/defaultTexture.jpg";
|
||||
const double camPanSpeed = .1;
|
||||
namespace battleship{
|
||||
namespace configData{
|
||||
const std::string PATH = "/home/dominykas/c++/Battleship/Assets/";
|
||||
const std::string DEFAULT_TEXTURE = PATH + "Textures/defaultTexture.jpg";
|
||||
const double camPanSpeed = .1;
|
||||
|
||||
const static int numAppStates = 3, numMaxBinds = 23;
|
||||
static const int numBinds[numAppStates]{12, 1, 23};
|
||||
static const int numConfBinds[numAppStates]{0, 1, 13};
|
||||
const static Mapping::Bind binds[numAppStates][numMaxBinds]{
|
||||
{
|
||||
Mapping::LEFT_CLICK,
|
||||
Mapping::SCROLLING_UP,
|
||||
Mapping::SCROLLING_DOWN,
|
||||
Mapping::LEFT,
|
||||
Mapping::RIGHT,
|
||||
Mapping::DELETE_CHAR,
|
||||
Mapping::CAPS_LOCK,
|
||||
Mapping::SHIFT_CAPS,
|
||||
Mapping::SPACE,
|
||||
Mapping::PLUS,
|
||||
Mapping::MINUS,
|
||||
Mapping::DEVSTERISK
|
||||
},
|
||||
{
|
||||
Mapping::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Mapping::HALT,
|
||||
Mapping::ZOOM_IN,
|
||||
Mapping::ZOOM_OUT,
|
||||
Mapping::LOOK_AROUND,
|
||||
Mapping::DRAG_BOX,
|
||||
Mapping::DESELECT,
|
||||
Mapping::LEFT_CONTROL,
|
||||
Mapping::LEFT_SHIFT,
|
||||
Mapping::SELECT_PATROL_POINTS,
|
||||
Mapping::LAUNCH,
|
||||
Mapping::TOGGLE_SUB,
|
||||
Mapping::INSTALL_AAM,
|
||||
Mapping::INSTALL_AWM,
|
||||
Mapping::GROUP_0,
|
||||
Mapping::GROUP_1,
|
||||
Mapping::GROUP_2,
|
||||
Mapping::GROUP_3,
|
||||
Mapping::GROUP_4,
|
||||
Mapping::GROUP_5,
|
||||
Mapping::GROUP_6,
|
||||
Mapping::GROUP_7,
|
||||
Mapping::GROUP_8,
|
||||
Mapping::GROUP_9
|
||||
}
|
||||
};
|
||||
const static int triggers[numAppStates][numMaxBinds]{
|
||||
{
|
||||
0,
|
||||
3,
|
||||
4,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE,
|
||||
GLFW_KEY_CAPS_LOCK,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_SPACE,
|
||||
GLFW_KEY_KP_ADD,
|
||||
GLFW_KEY_MINUS,
|
||||
GLFW_KEY_3
|
||||
},
|
||||
{
|
||||
GLFW_KEY_ESCAPE
|
||||
|
||||
},
|
||||
{
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
GLFW_KEY_LEFT_CONTROL,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_P,
|
||||
GLFW_KEY_C,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_A,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_0,
|
||||
GLFW_KEY_1,
|
||||
GLFW_KEY_2,
|
||||
GLFW_KEY_3,
|
||||
GLFW_KEY_4,
|
||||
GLFW_KEY_5,
|
||||
GLFW_KEY_6,
|
||||
GLFW_KEY_7,
|
||||
GLFW_KEY_8,
|
||||
GLFW_KEY_9
|
||||
}
|
||||
};
|
||||
const static bool isKey[numAppStates][numMaxBinds]{
|
||||
{0,0,0,1,1,1,1,1,1,1,1,1},
|
||||
{1},
|
||||
{1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,1,1,1,1,1,1,1,1,1,1,1}
|
||||
};
|
||||
const static bool isAnalog[numAppStates][numMaxBinds]{
|
||||
{0,0,0,0,0,0,0,0,0,0,0,0},
|
||||
{0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0}
|
||||
};
|
||||
// const int guiBindsNumber = 3;
|
||||
// const std::string guiAppStateBinds[guiBindsNumber]{"leftClick", "upScroll", "downScroll"};
|
||||
// const int guiAppStateTriggers[guiBindsNumber]{0, 1, 1};
|
||||
// const bool guiAppStateIsKey[guiBindsNumber]{0, 0, 0};
|
||||
// const bool guiAppStateIsAnalog[guiBindsNumber]{0, 0, 0};
|
||||
// const std::string guiAppStateKeys[guiBindsNumber]{"LeftMouse", "UpScroll", "DownScroll"};
|
||||
//
|
||||
// const int inGameAppStateBindsNumber = 1;
|
||||
// const std::string inGameAppStateBinds[inGameAppStateBindsNumber]{"toggleMainMenu"};
|
||||
// const int inGameAppStateTriggers[inGameAppStateBindsNumber]{irr::KEY_ESCAPE};
|
||||
// const bool inGameAppStateIsKey[inGameAppStateBindsNumber]{1};
|
||||
// const bool inGameAppStateIsAnalog[inGameAppStateBindsNumber]{0};
|
||||
// const std::string inGameAppStateKeys[inGameAppStateBindsNumber]{"Esc"};
|
||||
//
|
||||
// const int activeGameStateBindsNumber = 10;
|
||||
// const std::string activeGameStateBinds[activeGameStateBindsNumber]{
|
||||
// "halt",
|
||||
// "zoomIn",
|
||||
// "zoomOut",
|
||||
// "lookAround",
|
||||
// "dragBox",
|
||||
// "deselect",
|
||||
// "leftControl",
|
||||
// "selectingPatrolPoints",
|
||||
// "launch",
|
||||
// "toggleSub"
|
||||
// };
|
||||
// const int activeGameStateTriggers[activeGameStateBindsNumber]{
|
||||
// irr::KEY_KEY_H,
|
||||
// 3,
|
||||
// 4,
|
||||
// 1,
|
||||
// 0,
|
||||
// 2,
|
||||
// irr::KEY_LCONTROL,
|
||||
// irr::KEY_KEY_P,
|
||||
// irr::KEY_KEY_C,
|
||||
// irr::KEY_KEY_S
|
||||
// };
|
||||
// const bool activeGameStateIsKey[activeGameStateBindsNumber]{1, 0, 0, 0, 0, 0, 1, 1, 1, 1};
|
||||
// const bool activeGameStateIsAnalog[activeGameStateBindsNumber]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
// const std::string activeGameStateKeys[activeGameStateBindsNumber]{
|
||||
// "H",
|
||||
// "UpScroll",
|
||||
// "DownScroll",
|
||||
// "MiddleMouse",
|
||||
// "LeftMouse",
|
||||
// "RightMouse",
|
||||
// "leftControl",
|
||||
// "P",
|
||||
// "C",
|
||||
// "S"
|
||||
// };
|
||||
}
|
||||
const static int numAppStates = 3, numMaxBinds = 23;
|
||||
static const int numBinds[numAppStates]{12, 1, 23};
|
||||
static const int numConfBinds[numAppStates]{0, 1, 13};
|
||||
const static Mapping::Bind binds[numAppStates][numMaxBinds]{
|
||||
{
|
||||
Mapping::LEFT_CLICK,
|
||||
Mapping::SCROLLING_UP,
|
||||
Mapping::SCROLLING_DOWN,
|
||||
Mapping::LEFT,
|
||||
Mapping::RIGHT,
|
||||
Mapping::DELETE_CHAR,
|
||||
Mapping::CAPS_LOCK,
|
||||
Mapping::SHIFT_CAPS,
|
||||
Mapping::SPACE,
|
||||
Mapping::PLUS,
|
||||
Mapping::MINUS,
|
||||
Mapping::DEVSTERISK
|
||||
},
|
||||
{
|
||||
Mapping::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Mapping::HALT,
|
||||
Mapping::ZOOM_IN,
|
||||
Mapping::ZOOM_OUT,
|
||||
Mapping::LOOK_AROUND,
|
||||
Mapping::DRAG_BOX,
|
||||
Mapping::DESELECT,
|
||||
Mapping::LEFT_CONTROL,
|
||||
Mapping::LEFT_SHIFT,
|
||||
Mapping::SELECT_PATROL_POINTS,
|
||||
Mapping::LAUNCH,
|
||||
Mapping::TOGGLE_SUB,
|
||||
Mapping::INSTALL_AAM,
|
||||
Mapping::INSTALL_AWM,
|
||||
Mapping::GROUP_0,
|
||||
Mapping::GROUP_1,
|
||||
Mapping::GROUP_2,
|
||||
Mapping::GROUP_3,
|
||||
Mapping::GROUP_4,
|
||||
Mapping::GROUP_5,
|
||||
Mapping::GROUP_6,
|
||||
Mapping::GROUP_7,
|
||||
Mapping::GROUP_8,
|
||||
Mapping::GROUP_9
|
||||
}
|
||||
};
|
||||
const static int triggers[numAppStates][numMaxBinds]{
|
||||
{
|
||||
0,
|
||||
3,
|
||||
4,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE,
|
||||
GLFW_KEY_CAPS_LOCK,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_SPACE,
|
||||
GLFW_KEY_KP_ADD,
|
||||
GLFW_KEY_MINUS,
|
||||
GLFW_KEY_3
|
||||
},
|
||||
{
|
||||
GLFW_KEY_ESCAPE
|
||||
|
||||
},
|
||||
{
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
GLFW_KEY_LEFT_CONTROL,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_P,
|
||||
GLFW_KEY_C,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_A,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_0,
|
||||
GLFW_KEY_1,
|
||||
GLFW_KEY_2,
|
||||
GLFW_KEY_3,
|
||||
GLFW_KEY_4,
|
||||
GLFW_KEY_5,
|
||||
GLFW_KEY_6,
|
||||
GLFW_KEY_7,
|
||||
GLFW_KEY_8,
|
||||
GLFW_KEY_9
|
||||
}
|
||||
};
|
||||
const static bool isKey[numAppStates][numMaxBinds]{
|
||||
{0,0,0,1,1,1,1,1,1,1,1,1},
|
||||
{1},
|
||||
{1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,1,1,1,1,1,1,1,1,1,1,1}
|
||||
};
|
||||
const static bool isAnalog[numAppStates][numMaxBinds]{
|
||||
{0,0,0,0,0,0,0,0,0,0,0,0},
|
||||
{0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0}
|
||||
};
|
||||
/*
|
||||
const int guiBindsNumber = 3;
|
||||
const std::string guiAppStateBinds[guiBindsNumber]{"leftClick", "upScroll", "downScroll"};
|
||||
const int guiAppStateTriggers[guiBindsNumber]{0, 1, 1};
|
||||
const bool guiAppStateIsKey[guiBindsNumber]{0, 0, 0};
|
||||
const bool guiAppStateIsAnalog[guiBindsNumber]{0, 0, 0};
|
||||
const std::string guiAppStateKeys[guiBindsNumber]{"LeftMouse", "UpScroll", "DownScroll"};
|
||||
|
||||
const int inGameAppStateBindsNumber = 1;
|
||||
const std::string inGameAppStateBinds[inGameAppStateBindsNumber]{"toggleMainMenu"};
|
||||
const int inGameAppStateTriggers[inGameAppStateBindsNumber]{irr::KEY_ESCAPE};
|
||||
const bool inGameAppStateIsKey[inGameAppStateBindsNumber]{1};
|
||||
const bool inGameAppStateIsAnalog[inGameAppStateBindsNumber]{0};
|
||||
const std::string inGameAppStateKeys[inGameAppStateBindsNumber]{"Esc"};
|
||||
|
||||
const int activeGameStateBindsNumber = 10;
|
||||
const std::string activeGameStateBinds[activeGameStateBindsNumber]{
|
||||
"halt",
|
||||
"zoomIn",
|
||||
"zoomOut",
|
||||
"lookAround",
|
||||
"dragBox",
|
||||
"deselect",
|
||||
"leftControl",
|
||||
"selectingPatrolPoints",
|
||||
"launch",
|
||||
"toggleSub"
|
||||
};
|
||||
const int activeGameStateTriggers[activeGameStateBindsNumber]{
|
||||
irr::KEY_KEY_H,
|
||||
3,
|
||||
4,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
irr::KEY_LCONTROL,
|
||||
irr::KEY_KEY_P,
|
||||
irr::KEY_KEY_C,
|
||||
irr::KEY_KEY_S
|
||||
};
|
||||
const bool activeGameStateIsKey[activeGameStateBindsNumber]{1, 0, 0, 0, 0, 0, 1, 1, 1, 1};
|
||||
const bool activeGameStateIsAnalog[activeGameStateBindsNumber]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
const std::string activeGameStateKeys[activeGameStateBindsNumber]{
|
||||
"H",
|
||||
"UpScroll",
|
||||
"DownScroll",
|
||||
"MiddleMouse",
|
||||
"LeftMouse",
|
||||
"RightMouse",
|
||||
"leftControl",
|
||||
"P",
|
||||
"C",
|
||||
"S"
|
||||
};
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+33
-37
@@ -5,52 +5,48 @@
|
||||
#include "stateManager.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
DemoJet::DemoJet(Player *player, Vector3 pos, int id, bool onBoard) : Jet(player, pos, id,onBoard) {}
|
||||
|
||||
void DemoJet::attack(Order order){
|
||||
if(!onBoard){
|
||||
Unit::attack(order);
|
||||
Vector3 target = *order.targetPos[0];
|
||||
float angle = dirVec.getAngleBetween(target - pos);
|
||||
Vector3 axis = dirVec.cross(target - pos);
|
||||
namespace battleship{
|
||||
DemoJet::DemoJet(Player *player, Vector3 pos, int id, bool onBoard) : Jet(player, pos, id,onBoard) {}
|
||||
|
||||
void DemoJet::attack(Order order){
|
||||
if(!onBoard){
|
||||
Unit::attack(order);
|
||||
Vector3 target = *order.targetPos[0];
|
||||
float angle = dirVec.getAngleBetween(target - pos);
|
||||
Vector3 axis = dirVec.cross(target - pos);
|
||||
|
||||
if(maxTurnAngle < angle / PI * 180){
|
||||
Quaternion rotQuat = Quaternion(maxTurnAngle / 180 * PI, axis);
|
||||
orientUnit(rotQuat*dirVec);
|
||||
}
|
||||
if(maxTurnAngle < angle / PI * 180){
|
||||
Quaternion rotQuat = Quaternion(maxTurnAngle / 180 * PI, axis);
|
||||
orientUnit(rotQuat*dirVec);
|
||||
}
|
||||
else
|
||||
takeOff();
|
||||
}
|
||||
|
||||
void DemoJet::update(){
|
||||
Jet::update();
|
||||
if(!onBoard&&!orders.empty()&&orders[0].type==Order::TYPE::ATTACK){
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
ISceneManager *smgr = gm->getDevice()->getSceneManager();
|
||||
ISceneNode *collNode = castRay(smgr,pos,pos+dirVec*length);
|
||||
else
|
||||
takeOff();
|
||||
}
|
||||
|
||||
void DemoJet::update(){
|
||||
Jet::update();
|
||||
if(!onBoard&&!orders.empty()&&orders[0].type==Order::TYPE::ATTACK){
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
ISceneManager *smgr = gm->getDevice()->getSceneManager();
|
||||
ISceneNode *collNode = castRay(smgr,pos,pos+dirVec*length);
|
||||
|
||||
if(collNode && collNode != node){
|
||||
InGameAppState *inGameState = ((InGameAppState*)gm->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
if(collNode && collNode != node){
|
||||
InGameAppState *inGameState = ((InGameAppState*)gm->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits())
|
||||
if(u->getNode() == collNode)
|
||||
u->takeDamage(damage);
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits())
|
||||
if(u->getNode() == collNode)
|
||||
u->takeDamage(damage);
|
||||
|
||||
blowUp();
|
||||
}
|
||||
else if(pos.y<0)
|
||||
blowUp();
|
||||
*/
|
||||
blowUp();
|
||||
}
|
||||
else if(pos.y<0)
|
||||
blowUp();
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,16 @@
|
||||
#include "jet.h"
|
||||
#include "player.h"
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
class DemoJet : public Jet {
|
||||
public:
|
||||
DemoJet(Player*, vb01::Vector3, int, bool = 1);
|
||||
void attack(Order);
|
||||
void update();
|
||||
private:
|
||||
float length = 1;
|
||||
int damage = 250;
|
||||
};
|
||||
}
|
||||
namespace battleship {
|
||||
class DemoJet : public Jet {
|
||||
public:
|
||||
DemoJet(Player*, vb01::Vector3, int, bool = 1);
|
||||
void attack(Order);
|
||||
void update();
|
||||
private:
|
||||
float length = 1;
|
||||
int damage = 250;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+39
-43
@@ -5,56 +5,52 @@
|
||||
#include "inGameAppState.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
DepthCharge::DepthCharge(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
|
||||
speed = 0;
|
||||
initTime = getTime();
|
||||
}
|
||||
void DepthCharge::update(){
|
||||
//x=x0+vX+a*t*t/2
|
||||
//y=y0+vY-g*t*t/2
|
||||
float t = float(getTime() - initTime) / 1000;
|
||||
pos = initPos + dirVec * speed + Vector3(0, speed * t - .5 * g * t * t, 0);
|
||||
node->setPosition(pos);
|
||||
checkForCollision();
|
||||
}
|
||||
void DepthCharge::checkForCollision() {
|
||||
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
Node *collNode = nullptr;
|
||||
bool detonated = false;
|
||||
namespace battleship{
|
||||
DepthCharge::DepthCharge(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
|
||||
speed = 0;
|
||||
initTime = getTime();
|
||||
}
|
||||
void DepthCharge::update(){
|
||||
//x=x0+vX+a*t*t/2
|
||||
//y=y0+vY-g*t*t/2
|
||||
float t = float(getTime() - initTime) / 1000;
|
||||
pos = initPos + dirVec * speed + Vector3(0, speed * t - .5 * g * t * t, 0);
|
||||
node->setPosition(pos);
|
||||
checkForCollision();
|
||||
}
|
||||
void DepthCharge::checkForCollision() {
|
||||
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
Node *collNode = nullptr;
|
||||
bool detonated = false;
|
||||
|
||||
if(pos.y < -10)
|
||||
detonated = true;
|
||||
if(pos.y < -10)
|
||||
detonated = true;
|
||||
|
||||
if(!detonated)
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits()){
|
||||
if(u == unit) continue;
|
||||
if(!detonated)
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits()){
|
||||
if(u == unit) continue;
|
||||
|
||||
Vector3 p0 = u->getCorner(0);
|
||||
Vector3 p1 = u->getCorner(1);
|
||||
Vector3 p3 = u->getCorner(3);
|
||||
Vector3 p4 = u->getCorner(4);
|
||||
Vector3 p0 = u->getCorner(0);
|
||||
Vector3 p1 = u->getCorner(1);
|
||||
Vector3 p3 = u->getCorner(3);
|
||||
Vector3 p4 = u->getCorner(4);
|
||||
|
||||
/*
|
||||
if(isWithinCuboid(p0,p1,p3,p4,pos)){
|
||||
detonated=true;
|
||||
collNode=u->getNode();
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if(isWithinCuboid(p0,p1,p3,p4,pos)){
|
||||
detonated=true;
|
||||
collNode=u->getNode();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if(detonated)
|
||||
explode(collNode);
|
||||
}
|
||||
void DepthCharge::explode(Node *collNode) {
|
||||
Projectile::explode(collNode);
|
||||
}
|
||||
if(detonated)
|
||||
explode(collNode);
|
||||
}
|
||||
void DepthCharge::explode(Node *collNode) {
|
||||
Projectile::explode(collNode);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-12
@@ -4,18 +4,16 @@
|
||||
|
||||
#include "projectile.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class DepthCharge : public Projectile {
|
||||
public:
|
||||
DepthCharge(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
void update();
|
||||
private:
|
||||
s64 initTime;
|
||||
void explode(vb01::Node*);
|
||||
void checkForCollision();
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class DepthCharge : public Projectile {
|
||||
public:
|
||||
DepthCharge(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
void update();
|
||||
private:
|
||||
s64 initTime;
|
||||
void explode(vb01::Node*);
|
||||
void checkForCollision();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+48
-51
@@ -11,65 +11,62 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace game::content::unitData;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Destroyer::Destroyer(Player *player, vb01::Vector3 pos,int id) : Vessel(player, pos, id) {
|
||||
this->maxDepthCharges = unitData::maxDepthCharges[id];
|
||||
depthCharges = maxDepthCharges;
|
||||
this->rateOfDrops = unitData::rateOfDrops[id];
|
||||
this->reloadRate = unitData::reloadRate[id];
|
||||
this->maxDepthChargeDropRange = unitData::maxDepthChargeDropRange[id];
|
||||
}
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
void Destroyer::update(){
|
||||
Vessel::update();
|
||||
reload();
|
||||
}
|
||||
Destroyer::Destroyer(Player *player, vb01::Vector3 pos,int id) : Vessel(player, pos, id) {
|
||||
this->maxDepthCharges = unitData::maxDepthCharges[id];
|
||||
depthCharges = maxDepthCharges;
|
||||
this->rateOfDrops = unitData::rateOfDrops[id];
|
||||
this->reloadRate = unitData::reloadRate[id];
|
||||
this->maxDepthChargeDropRange = unitData::maxDepthChargeDropRange[id];
|
||||
}
|
||||
|
||||
void Destroyer::attack(Order order){
|
||||
Vector3 t = *order.targetPos[0];
|
||||
bool sub=false;
|
||||
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
void Destroyer::update(){
|
||||
Vessel::update();
|
||||
reload();
|
||||
}
|
||||
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits())
|
||||
if(u->getType() == UNIT_TYPE::SUBMARINE&&order.targetPos[0] == u->getPosPtr())
|
||||
sub = true;
|
||||
void Destroyer::attack(Order order){
|
||||
Vector3 t = *order.targetPos[0];
|
||||
bool sub=false;
|
||||
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
if(sub)
|
||||
dropDepthCharge();
|
||||
else
|
||||
Vessel::attack(order);
|
||||
}
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits())
|
||||
if(u->getType() == UNIT_TYPE::SUBMARINE&&order.targetPos[0] == u->getPosPtr())
|
||||
sub = true;
|
||||
|
||||
void Destroyer::dropDepthCharge() {
|
||||
if(canDropDepthCharge()){
|
||||
float angle = rand() % 360;
|
||||
float radius = 1;
|
||||
Vector3 offsetVec = Vector3(cos(angle), 0, sin(angle)) * radius;
|
||||
addProjectile(new DepthCharge(this, pos + projectileData::pos[id][1][1] + offsetVec, dirVec, leftVec, upVec, id, 1, 0));
|
||||
lastDropTime = getTime();
|
||||
if(sub)
|
||||
dropDepthCharge();
|
||||
else
|
||||
Vessel::attack(order);
|
||||
}
|
||||
|
||||
if(depthCharges == maxDepthCharges)
|
||||
reloadStartTime = getTime();
|
||||
|
||||
}
|
||||
}
|
||||
void Destroyer::reload(){
|
||||
if(depthCharges < maxDepthCharges){
|
||||
reloading = true;
|
||||
void Destroyer::dropDepthCharge() {
|
||||
if(canDropDepthCharge()){
|
||||
float angle = rand() % 360;
|
||||
float radius = 1;
|
||||
Vector3 offsetVec = Vector3(cos(angle), 0, sin(angle)) * radius;
|
||||
addProjectile(new DepthCharge(this, pos + projectileData::pos[id][1][1] + offsetVec, dirVec, leftVec, upVec, id, 1, 0));
|
||||
lastDropTime = getTime();
|
||||
|
||||
if(getTime() - reloadStartTime > reloadRate) {
|
||||
reloadStartTime += reloadRate;
|
||||
depthCharges++;
|
||||
}
|
||||
}
|
||||
else
|
||||
reloading = false;
|
||||
if(depthCharges == maxDepthCharges)
|
||||
reloadStartTime = getTime();
|
||||
|
||||
}
|
||||
}
|
||||
void Destroyer::reload(){
|
||||
if(depthCharges < maxDepthCharges){
|
||||
reloading = true;
|
||||
|
||||
if(getTime() - reloadStartTime > reloadRate) {
|
||||
reloadStartTime += reloadRate;
|
||||
depthCharges++;
|
||||
}
|
||||
}
|
||||
else
|
||||
reloading = false;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-18
@@ -7,24 +7,21 @@
|
||||
#include "player.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace content {
|
||||
class Destroyer : public Vessel {
|
||||
public:
|
||||
Destroyer(Player*, vb01::Vector3, int);
|
||||
void dropDepthCharge();
|
||||
void attack(Order);
|
||||
void update();
|
||||
private:
|
||||
void reload();
|
||||
inline bool canDropDepthCharge(){return vb01::getTime() - lastDropTime > rateOfDrops;}
|
||||
bool reloading = false;
|
||||
float maxDepthChargeDropRange;
|
||||
int depthCharges, maxDepthCharges, rateOfDrops, reloadRate;
|
||||
s64 lastShotTime = 0, reloadStartTime = 0, lastDropTime = 0;
|
||||
};
|
||||
}
|
||||
namespace battleship {
|
||||
class Destroyer : public Vessel {
|
||||
public:
|
||||
Destroyer(Player*, vb01::Vector3, int);
|
||||
void dropDepthCharge();
|
||||
void attack(Order);
|
||||
void update();
|
||||
private:
|
||||
void reload();
|
||||
inline bool canDropDepthCharge(){return vb01::getTime() - lastDropTime > rateOfDrops;}
|
||||
bool reloading = false;
|
||||
float maxDepthChargeDropRange;
|
||||
int depthCharges, maxDepthCharges, rateOfDrops, reloadRate;
|
||||
s64 lastShotTime = 0, reloadStartTime = 0, lastDropTime = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+6
-9
@@ -4,15 +4,12 @@
|
||||
|
||||
#include "vesselData.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace content{
|
||||
namespace unitData {
|
||||
const int rateOfDrops[numberOfUnits]{0, 0, 500, 500};
|
||||
const int reloadRate[numberOfUnits]{0, 0, 2000, 2000};
|
||||
const int maxDepthCharges[numberOfUnits]{0, 0, 15, 15};
|
||||
const float maxDepthChargeDropRange[numberOfUnits]{0, 0, 3, 3};
|
||||
}
|
||||
namespace battleship{
|
||||
namespace unitData {
|
||||
const int rateOfDrops[numberOfUnits]{0, 0, 500, 500};
|
||||
const int reloadRate[numberOfUnits]{0, 0, 2000, 2000};
|
||||
const int maxDepthCharges[numberOfUnits]{0, 0, 15, 15};
|
||||
const float maxDepthChargeDropRange[numberOfUnits]{0, 0, 3, 3};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -5,8 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
namespace battleship{
|
||||
double *posX,*posY,strX,strY;
|
||||
int width,height;
|
||||
|
||||
@@ -122,5 +121,4 @@ namespace game{
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-16
@@ -5,23 +5,21 @@
|
||||
|
||||
class GLFWwindow;
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
class StateManager;
|
||||
namespace battleship{
|
||||
class StateManager;
|
||||
|
||||
class InputManager {
|
||||
public:
|
||||
InputManager(GLFWwindow*);
|
||||
~InputManager();
|
||||
//virtual bool OnEvent(const irr::SEvent&);
|
||||
void update();
|
||||
private:
|
||||
//irr::SEvent* event;
|
||||
GLFWwindow *window = nullptr;
|
||||
StateManager *stateManager = nullptr;
|
||||
bool keyEvent = false, mouseEvent = false;
|
||||
};
|
||||
}
|
||||
class InputManager {
|
||||
public:
|
||||
InputManager(GLFWwindow*);
|
||||
~InputManager();
|
||||
//virtual bool OnEvent(const irr::SEvent&);
|
||||
void update();
|
||||
private:
|
||||
//irr::SEvent* event;
|
||||
GLFWwindow *window = nullptr;
|
||||
StateManager *stateManager = nullptr;
|
||||
bool keyEvent = false, mouseEvent = false;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+5
-8
@@ -4,14 +4,11 @@
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace gui{
|
||||
ExitButton::ExitButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
}
|
||||
namespace battleship{
|
||||
ExitButton::ExitButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void ExitButton::onClick() {
|
||||
//Root::getSingleton()->set
|
||||
}
|
||||
void ExitButton::onClick() {
|
||||
//Root::getSingleton()->set
|
||||
}
|
||||
}
|
||||
|
||||
+6
-9
@@ -5,15 +5,12 @@
|
||||
#include <button.h>
|
||||
#include <vector.h>
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace gui {
|
||||
class ExitButton : public vb01Gui::Button {
|
||||
public:
|
||||
ExitButton(vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
}
|
||||
namespace battleship {
|
||||
class ExitButton : public vb01Gui::Button {
|
||||
public:
|
||||
ExitButton(vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+45
-46
@@ -4,61 +4,60 @@
|
||||
#include "util.h"
|
||||
#include "inGameAppState.h"
|
||||
|
||||
using namespace game::util;
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
void detonate(InGameAppState *inGameState, Vector3 pos, Vector3 dir){
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = nullptr;
|
||||
string p = PATH + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
if(sfxBuffer->loadFromFile(p.c_str())){
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
sfx->play();
|
||||
}
|
||||
void detonate(InGameAppState *inGameState, Vector3 pos, Vector3 dir){
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = nullptr;
|
||||
string p = PATH + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
|
||||
|
||||
Fx fx;
|
||||
fx.initTime = getTime();
|
||||
fx.time = 2500;
|
||||
fx.sfx = sfx;
|
||||
inGameState->addFx(fx);
|
||||
if(sfxBuffer->loadFromFile(p.c_str())){
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
sfx->play();
|
||||
}
|
||||
|
||||
void detonateDepthCharge(core::InGameAppState *inGameState, Vector3){
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = nullptr;
|
||||
string p = PATH + "Sounds/Destroyers/depthCharge.ogg";
|
||||
Fx fx;
|
||||
fx.initTime = getTime();
|
||||
fx.time = 2500;
|
||||
fx.sfx = sfx;
|
||||
inGameState->addFx(fx);
|
||||
}
|
||||
|
||||
if(sfxBuffer->loadFromFile(p.c_str())){
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
sfx->play();
|
||||
}
|
||||
|
||||
Fx fx;
|
||||
fx.initTime = getTime();
|
||||
fx.time = 2000;
|
||||
fx.sfx = sfx;
|
||||
inGameState->addFx(fx);
|
||||
void detonateDepthCharge(InGameAppState *inGameState, Vector3){
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = nullptr;
|
||||
string p = PATH + "Sounds/Destroyers/depthCharge.ogg";
|
||||
|
||||
if(sfxBuffer->loadFromFile(p.c_str())){
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
sfx->play();
|
||||
}
|
||||
|
||||
Fx fx;
|
||||
fx.initTime = getTime();
|
||||
fx.time = 2000;
|
||||
fx.sfx = sfx;
|
||||
inGameState->addFx(fx);
|
||||
}
|
||||
|
||||
void detonateTorpedo(InGameAppState *inGameState, Vector3){
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = nullptr;
|
||||
string p = PATH + "Sounds/Submarines/torpedo.ogg";
|
||||
|
||||
if(sfxBuffer->loadFromFile(p.c_str())){
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
sfx->play();
|
||||
}
|
||||
|
||||
void detonateTorpedo(core::InGameAppState *inGameState, Vector3){
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = nullptr;
|
||||
string p = PATH + "Sounds/Submarines/torpedo.ogg";
|
||||
|
||||
if(sfxBuffer->loadFromFile(p.c_str())){
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
sfx->play();
|
||||
}
|
||||
|
||||
Fx fx;
|
||||
fx.initTime = getTime();
|
||||
fx.time = 250;
|
||||
fx.sfx = sfx;
|
||||
inGameState->addFx(fx);
|
||||
}
|
||||
Fx fx;
|
||||
fx.initTime = getTime();
|
||||
fx.time = 250;
|
||||
fx.sfx = sfx;
|
||||
inGameState->addFx(fx);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-9
@@ -4,15 +4,12 @@
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
class InGameAppState;
|
||||
}
|
||||
namespace content{
|
||||
void detonate(core::InGameAppState*, vb01::Vector3, vb01::Vector3);
|
||||
void detonateDepthCharge(core::InGameAppState*, vb01::Vector3);
|
||||
void detonateTorpedo(core::InGameAppState*, vb01::Vector3);
|
||||
}
|
||||
namespace battleship{
|
||||
class InGameAppState;
|
||||
|
||||
void detonate(InGameAppState*, vb01::Vector3, vb01::Vector3);
|
||||
void detonateDepthCharge(InGameAppState*, vb01::Vector3);
|
||||
void detonateTorpedo(InGameAppState*, vb01::Vector3);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+20
-31
@@ -7,45 +7,34 @@
|
||||
#include "eventListener.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace game::gui;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
static GameManager *gameManager = nullptr;
|
||||
namespace battleship{
|
||||
static GameManager *gameManager = nullptr;
|
||||
|
||||
GameManager* GameManager::getSingleton(){
|
||||
if(!gameManager)
|
||||
gameManager = new GameManager();
|
||||
GameManager* GameManager::getSingleton(){
|
||||
if(!gameManager)
|
||||
gameManager = new GameManager();
|
||||
|
||||
return gameManager;
|
||||
}
|
||||
return gameManager;
|
||||
}
|
||||
|
||||
GameManager::GameManager() {
|
||||
}
|
||||
GameManager::GameManager() {
|
||||
}
|
||||
|
||||
GameManager::~GameManager() {}
|
||||
GameManager::~GameManager() {}
|
||||
|
||||
void GameManager::start() {
|
||||
Root *root = Root::getSingleton();
|
||||
root->start(800, 600, "../../vb01", "Battleship");
|
||||
void GameManager::start() {
|
||||
Root *root = Root::getSingleton();
|
||||
root->start(800, 600, "../../vb01/", "Battleship");
|
||||
|
||||
stateManager = new StateManager();
|
||||
listener = new InputManager(root->getWindow());
|
||||
}
|
||||
stateManager = new StateManager();
|
||||
listener = new InputManager(root->getWindow());
|
||||
}
|
||||
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
listener->update();
|
||||
stateManager->update();
|
||||
|
||||
/*
|
||||
for (BitmapText *b : bitmapTexts)
|
||||
b->update();
|
||||
|
||||
for (Image *i : images)
|
||||
i->update();
|
||||
*/
|
||||
}
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
listener->update();
|
||||
stateManager->update();
|
||||
}
|
||||
}
|
||||
|
||||
+24
-36
@@ -9,43 +9,31 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
class AbstractBitmapText;
|
||||
class AbstractImage;
|
||||
}
|
||||
namespace battleship{
|
||||
class InputManager;
|
||||
class StateManager;
|
||||
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
void start();
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline InputManager* getListener(){return listener;}
|
||||
inline bool isServerSide(){return serverSide;}
|
||||
inline StateManager* getStateManager(){return stateManager;}
|
||||
private:
|
||||
GameManager();
|
||||
~GameManager();
|
||||
|
||||
typedef gui::AbstractBitmapText BitmapText;
|
||||
typedef gui::AbstractImage Image;
|
||||
|
||||
namespace core{
|
||||
class InputManager;
|
||||
class StateManager;
|
||||
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
void start();
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline InputManager* getListener(){return listener;}
|
||||
inline bool isServerSide(){return serverSide;}
|
||||
inline StateManager* getStateManager(){return stateManager;}
|
||||
private:
|
||||
GameManager();
|
||||
~GameManager();
|
||||
|
||||
StateManager *stateManager = nullptr;
|
||||
std::vector<AbstractAppState*> appStates;
|
||||
int width, height;
|
||||
std::vector<gui::AbstractBitmapText*> bitmapTexts;
|
||||
std::vector<gui::AbstractImage*> images;
|
||||
InputManager *listener = nullptr;
|
||||
bool serverSide;
|
||||
};
|
||||
|
||||
}
|
||||
StateManager *stateManager = nullptr;
|
||||
std::vector<AbstractAppState*> appStates;
|
||||
int width, height;
|
||||
InputManager *listener = nullptr;
|
||||
bool serverSide;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+387
-390
@@ -4,416 +4,413 @@
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
|
||||
using namespace game::gui;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
Vector2 mousePos;
|
||||
namespace battleship{
|
||||
Vector2 mousePos;
|
||||
|
||||
GuiAppState::GuiAppState() {
|
||||
type = AppStateTypes::GUI_STATE;
|
||||
}
|
||||
GuiAppState::GuiAppState() {
|
||||
type = AppStateTypes::GUI_STATE;
|
||||
}
|
||||
|
||||
GuiAppState::~GuiAppState() {}
|
||||
GuiAppState::~GuiAppState() {}
|
||||
|
||||
void GuiAppState::update() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
mousePos[0] = gm->getDevice()->getCursorControl()->getPosition().X;
|
||||
mousePos[1] = gm->getDevice()->getCursorControl()->getPosition().Y;
|
||||
*/
|
||||
|
||||
for (Button *b : buttons) {
|
||||
if (b->isSeparate())
|
||||
b->update();
|
||||
|
||||
bool withinX=mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
|
||||
bool withinY=mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
|
||||
|
||||
/*
|
||||
if(withinX&&withinY)
|
||||
b->onMouseOver();
|
||||
else
|
||||
b->onMouseAway();
|
||||
|
||||
b->setMouseOverDone(withinX&&withinY);
|
||||
b->setMouseAwayDone(!(withinX&&withinY));
|
||||
*/
|
||||
}
|
||||
|
||||
for (Listbox *l : listboxes)
|
||||
l->update();
|
||||
|
||||
for (Checkbox *c : checkboxes)
|
||||
c->update();
|
||||
|
||||
for (Slider *s : sliders)
|
||||
s->update();
|
||||
|
||||
for (Textbox *t : textboxes)
|
||||
t->update();
|
||||
|
||||
for (Tooltip *t : tooltips)
|
||||
t->update();
|
||||
}
|
||||
|
||||
void GuiAppState::onAttachment() {
|
||||
AbstractAppState::onAttachment();
|
||||
//GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(true);
|
||||
attachKeyboardKeys();
|
||||
}
|
||||
|
||||
void GuiAppState::onDetachment() {
|
||||
AbstractAppState::onDetachment();
|
||||
AbstractAppState::detachAllKeys();
|
||||
//GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(false);
|
||||
}
|
||||
|
||||
void GuiAppState::attachKeyboardKeys() {
|
||||
/*
|
||||
int firstId = Bind::LAST_BIND + 1, lastId = firstId + numKeys;
|
||||
|
||||
for (int i = firstId; i <= lastId; i++){
|
||||
int offset=i-firstId;
|
||||
int trigger = offset < 10 ? int(irr::KEY_KEY_0)+offset:int(irr::KEY_KEY_A)+offset-10;
|
||||
AbstractAppState::attachKey(new Key((Bind)i, trigger, true, false));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void GuiAppState::onAction(Mapping::Bind bind, bool isPressed) {
|
||||
switch(bind){
|
||||
case Mapping::LEFT_CLICK:
|
||||
if(isPressed)
|
||||
for (int i=0;i<buttons.size();i++) {
|
||||
Button *b=buttons[i];
|
||||
bool withinX=mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
|
||||
bool withinY=mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
|
||||
|
||||
if (withinX&&withinY)
|
||||
b->onClick();
|
||||
}
|
||||
break;
|
||||
case Mapping::SCROLLING_UP:
|
||||
for (Listbox *l : listboxes)
|
||||
if (l->isOpen())
|
||||
l->scrollUp();
|
||||
break;
|
||||
case Mapping::SCROLLING_DOWN:
|
||||
for (Listbox *l : listboxes)
|
||||
if (l->isOpen())
|
||||
l->scrollDown();
|
||||
break;
|
||||
}
|
||||
Textbox *t = getOpenTextbox();
|
||||
if (t)
|
||||
switch(bind){
|
||||
case Mapping::SHIFT_CAPS:
|
||||
shiftPressed = !shiftPressed;
|
||||
//t->setIsCapitalLeters(isPressed);
|
||||
break;
|
||||
case Mapping::LEFT:
|
||||
//if(isPressed)t->moveCursor(true);
|
||||
break;
|
||||
case Mapping::RIGHT:
|
||||
//if(isPressed)t->moveCursor(false);
|
||||
break;
|
||||
case Mapping::CAPS_LOCK:
|
||||
//if(isPressed)t->setIsCapitalLeters(!t->isCapitalLeters());
|
||||
break;
|
||||
case Mapping::SPACE:
|
||||
if(isPressed)t->type(' ');
|
||||
break;
|
||||
case Mapping::DELETE_CHAR:
|
||||
if(isPressed)t->deleteCharacter();
|
||||
break;
|
||||
case Mapping::PLUS:
|
||||
if(isPressed) t->type(shiftPressed?'+':'=');
|
||||
break;
|
||||
case Mapping::MINUS:
|
||||
if(isPressed) t->type(shiftPressed?'_':'-');
|
||||
break;
|
||||
case Mapping::DEVSTERISK:
|
||||
if(isPressed) t->type(shiftPressed?'~':'`');
|
||||
break;
|
||||
default:
|
||||
if(bind>Mapping::LAST_BIND)checkKeyboard(t, bind, isPressed);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::checkKeyboard(Textbox *t, Mapping::Bind bind, bool isPressed) {
|
||||
int firstId = Mapping::Bind::LAST_BIND+1,lastId=firstId+numKeys;
|
||||
|
||||
for (int i = firstId; i <= lastId; i++) {
|
||||
int offset=i-firstId;
|
||||
char c = keyChars[offset];
|
||||
|
||||
if (bind==i&&isPressed) {
|
||||
if (shiftPressed) {
|
||||
switch(offset){
|
||||
case 1:
|
||||
c = '!';
|
||||
break;
|
||||
case 2:
|
||||
c = '@';
|
||||
break;
|
||||
case 3:
|
||||
c = '#';
|
||||
break;
|
||||
case 4:
|
||||
c = '$';
|
||||
break;
|
||||
case 5:
|
||||
c = '%';
|
||||
break;
|
||||
case 6:
|
||||
c = '^';
|
||||
break;
|
||||
case 7:
|
||||
c = '&';
|
||||
break;
|
||||
case 8:
|
||||
c = '*';
|
||||
break;
|
||||
case 9:
|
||||
c = '(';
|
||||
break;
|
||||
case 0:
|
||||
c = ')';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
t->type(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::updateControlsListbox(int trigger){
|
||||
Listbox *controlsListbox=nullptr;
|
||||
|
||||
for(Listbox *l : listboxes)
|
||||
if(l->isOpen() /*&& l->isControlsListbox()*/)
|
||||
controlsListbox=l;
|
||||
|
||||
if(controlsListbox){
|
||||
int selectedOption=controlsListbox->getSelectedOption(),colonId=-1;
|
||||
wstring line = controlsListbox->getContents()[selectedOption];
|
||||
|
||||
for(int i=0;i<line.size()&&colonId==-1;i++)
|
||||
if(line.c_str()[i]==':')
|
||||
colonId=i;
|
||||
|
||||
stringstream ss;
|
||||
ss<<hex<<trigger;
|
||||
line=line.substr(0,colonId+1)+L"0x"/*+ss.str().c_str()*/;
|
||||
controlsListbox->changeLine(selectedOption,line);
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::update() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
void GuiAppState::onRawKeyPress(SEvent::SKeyInput event){
|
||||
updateControlsListbox(event.Key);
|
||||
}
|
||||
|
||||
void GuiAppState::onRawMousePress(SEvent::SMouseInput event){
|
||||
int trigger=0;
|
||||
if(event.isMiddlePressed())
|
||||
trigger=1;
|
||||
else if(event.isRightPressed())
|
||||
trigger=2;
|
||||
updateControlsListbox(trigger);
|
||||
}
|
||||
mousePos[0] = gm->getDevice()->getCursorControl()->getPosition().X;
|
||||
mousePos[1] = gm->getDevice()->getCursorControl()->getPosition().Y;
|
||||
*/
|
||||
|
||||
Textbox* GuiAppState::getOpenTextbox() {
|
||||
Textbox* t = nullptr;
|
||||
for (int i = 0; i < textboxes.size(); i++)
|
||||
if (textboxes[i]->isEnabled())
|
||||
t = textboxes[i];
|
||||
if (t)
|
||||
return t;
|
||||
|
||||
for (Button *b : buttons) {
|
||||
if (b->isSeparate())
|
||||
b->update();
|
||||
|
||||
bool withinX=mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
|
||||
bool withinY=mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
|
||||
|
||||
/*
|
||||
if(withinX&&withinY)
|
||||
b->onMouseOver();
|
||||
else
|
||||
return nullptr;
|
||||
b->onMouseAway();
|
||||
|
||||
b->setMouseOverDone(withinX&&withinY);
|
||||
b->setMouseAwayDone(!(withinX&&withinY));
|
||||
*/
|
||||
}
|
||||
|
||||
Listbox* GuiAppState::getOpenListbox() {
|
||||
Listbox *l = nullptr;
|
||||
for (int i = 0; i < listboxes.size(); i++)
|
||||
if (listboxes[i]->isOpen())
|
||||
l = listboxes[i];
|
||||
if (l)
|
||||
return l;
|
||||
else
|
||||
return nullptr;
|
||||
for (Listbox *l : listboxes)
|
||||
l->update();
|
||||
|
||||
for (Checkbox *c : checkboxes)
|
||||
c->update();
|
||||
|
||||
for (Slider *s : sliders)
|
||||
s->update();
|
||||
|
||||
for (Textbox *t : textboxes)
|
||||
t->update();
|
||||
|
||||
for (Tooltip *t : tooltips)
|
||||
t->update();
|
||||
}
|
||||
|
||||
void GuiAppState::onAttachment() {
|
||||
AbstractAppState::onAttachment();
|
||||
//GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(true);
|
||||
attachKeyboardKeys();
|
||||
}
|
||||
|
||||
void GuiAppState::onDetachment() {
|
||||
AbstractAppState::onDetachment();
|
||||
AbstractAppState::detachAllKeys();
|
||||
//GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(false);
|
||||
}
|
||||
|
||||
void GuiAppState::attachKeyboardKeys() {
|
||||
/*
|
||||
int firstId = Bind::LAST_BIND + 1, lastId = firstId + numKeys;
|
||||
|
||||
for (int i = firstId; i <= lastId; i++){
|
||||
int offset=i-firstId;
|
||||
int trigger = offset < 10 ? int(irr::KEY_KEY_0)+offset:int(irr::KEY_KEY_A)+offset-10;
|
||||
AbstractAppState::attachKey(new Key((Bind)i, trigger, true, false));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void GuiAppState::onAction(Mapping::Bind bind, bool isPressed) {
|
||||
switch(bind){
|
||||
case Mapping::LEFT_CLICK:
|
||||
if(isPressed)
|
||||
for (int i=0;i<buttons.size();i++) {
|
||||
Button *b=buttons[i];
|
||||
bool withinX=mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
|
||||
bool withinY=mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
|
||||
|
||||
if (withinX&&withinY)
|
||||
b->onClick();
|
||||
}
|
||||
break;
|
||||
case Mapping::SCROLLING_UP:
|
||||
for (Listbox *l : listboxes)
|
||||
if (l->isOpen())
|
||||
l->scrollUp();
|
||||
break;
|
||||
case Mapping::SCROLLING_DOWN:
|
||||
for (Listbox *l : listboxes)
|
||||
if (l->isOpen())
|
||||
l->scrollDown();
|
||||
break;
|
||||
}
|
||||
|
||||
void GuiAppState::onAnalog(Mapping::Bind bind, double strength) {}
|
||||
|
||||
void GuiAppState::addButton(Button* b) {
|
||||
buttons.push_back(b);
|
||||
}
|
||||
|
||||
void GuiAppState::addListbox(Listbox* l) {
|
||||
listboxes.push_back(l);
|
||||
buttons.push_back(l->getListboxButton());
|
||||
}
|
||||
|
||||
void GuiAppState::addCheckbox(Checkbox* c) {
|
||||
buttons.push_back(c->getCheckboxButton());
|
||||
checkboxes.push_back(c);
|
||||
}
|
||||
|
||||
void GuiAppState::addSlider(Slider* s) {
|
||||
buttons.push_back(s->getMovableSliderButton());
|
||||
buttons.push_back(s->getStaticSliderButton());
|
||||
sliders.push_back(s);
|
||||
}
|
||||
|
||||
void GuiAppState::addTextbox(Textbox* t) {
|
||||
buttons.push_back(t->getTextboxButton());
|
||||
textboxes.push_back(t);
|
||||
}
|
||||
|
||||
void GuiAppState::addTooltip(Tooltip* t) {
|
||||
tooltips.push_back(t);
|
||||
}
|
||||
|
||||
void GuiAppState::removeButton(Button *b) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (b == buttons[i]) {
|
||||
/*
|
||||
if (b->isImageButton())
|
||||
GameManager::getSingleton()->detachImage(b->getImage());
|
||||
*/
|
||||
delete b;
|
||||
buttons.erase(buttons.begin() + i);
|
||||
Textbox *t = getOpenTextbox();
|
||||
if (t)
|
||||
switch(bind){
|
||||
case Mapping::SHIFT_CAPS:
|
||||
shiftPressed = !shiftPressed;
|
||||
//t->setIsCapitalLeters(isPressed);
|
||||
break;
|
||||
case Mapping::LEFT:
|
||||
//if(isPressed)t->moveCursor(true);
|
||||
break;
|
||||
case Mapping::RIGHT:
|
||||
//if(isPressed)t->moveCursor(false);
|
||||
break;
|
||||
case Mapping::CAPS_LOCK:
|
||||
//if(isPressed)t->setIsCapitalLeters(!t->isCapitalLeters());
|
||||
break;
|
||||
case Mapping::SPACE:
|
||||
if(isPressed)t->type(' ');
|
||||
break;
|
||||
case Mapping::DELETE_CHAR:
|
||||
if(isPressed)t->deleteCharacter();
|
||||
break;
|
||||
case Mapping::PLUS:
|
||||
if(isPressed) t->type(shiftPressed?'+':'=');
|
||||
break;
|
||||
case Mapping::MINUS:
|
||||
if(isPressed) t->type(shiftPressed?'_':'-');
|
||||
break;
|
||||
case Mapping::DEVSTERISK:
|
||||
if(isPressed) t->type(shiftPressed?'~':'`');
|
||||
break;
|
||||
default:
|
||||
if(bind>Mapping::LAST_BIND)checkKeyboard(t, bind, isPressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeButton(string name) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (name == buttons[i]->getName() && buttons[i]->isSeparate()) {
|
||||
/*
|
||||
if (buttons[i]->isImageButton())
|
||||
GameManager::getSingleton()->detachImage(buttons[i]->getImage());
|
||||
*/
|
||||
void GuiAppState::checkKeyboard(Textbox *t, Mapping::Bind bind, bool isPressed) {
|
||||
int firstId = Mapping::Bind::LAST_BIND+1,lastId=firstId+numKeys;
|
||||
|
||||
delete buttons[i];
|
||||
for (int i = firstId; i <= lastId; i++) {
|
||||
int offset=i-firstId;
|
||||
char c = keyChars[offset];
|
||||
|
||||
buttons.erase(buttons.begin() + i);
|
||||
if (bind==i&&isPressed) {
|
||||
if (shiftPressed) {
|
||||
switch(offset){
|
||||
case 1:
|
||||
c = '!';
|
||||
break;
|
||||
case 2:
|
||||
c = '@';
|
||||
break;
|
||||
case 3:
|
||||
c = '#';
|
||||
break;
|
||||
case 4:
|
||||
c = '$';
|
||||
break;
|
||||
case 5:
|
||||
c = '%';
|
||||
break;
|
||||
case 6:
|
||||
c = '^';
|
||||
break;
|
||||
case 7:
|
||||
c = '&';
|
||||
break;
|
||||
case 8:
|
||||
c = '*';
|
||||
break;
|
||||
case 9:
|
||||
c = '(';
|
||||
break;
|
||||
case 0:
|
||||
c = ')';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeSeparateButton(Button *b) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (b == buttons[i]) {
|
||||
delete b;
|
||||
buttons.erase(buttons.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeListbox(Listbox *l) {
|
||||
for (int i = 0; i < listboxes.size(); i++) {
|
||||
if (l == listboxes[i]) {
|
||||
removeSeparateButton(l->getListboxButton());
|
||||
delete l;
|
||||
listboxes.erase(listboxes.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeCheckbox(Checkbox *c) {
|
||||
for (int i = 0; i < checkboxes.size(); i++) {
|
||||
if (c == checkboxes[i]) {
|
||||
removeSeparateButton(c->getCheckboxButton());
|
||||
delete c;
|
||||
checkboxes.erase(checkboxes.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeSlider(Slider *s) {
|
||||
for (int i = 0; i < sliders.size(); i++) {
|
||||
if (s == sliders[i]) {
|
||||
removeSeparateButton(s->getMovableSliderButton());
|
||||
removeSeparateButton(s->getStaticSliderButton());
|
||||
delete s;
|
||||
sliders.erase(sliders.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeTextbox(Textbox* t) {
|
||||
for (int i = 0; i < textboxes.size(); i++) {
|
||||
if (t == textboxes[i]) {
|
||||
removeSeparateButton(t->getTextboxButton());
|
||||
delete t;
|
||||
textboxes.erase(textboxes.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeTooltip(Tooltip *t) {
|
||||
for (int i = 0; i < tooltips.size(); i++) {
|
||||
if (t == tooltips[i]) {
|
||||
delete t;
|
||||
tooltips.erase(tooltips.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllButtons() {
|
||||
while (buttons.size() > 0) {
|
||||
delete buttons[buttons.size() - 1];
|
||||
buttons.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllListboxes() {
|
||||
while (listboxes.size() > 0) {
|
||||
removeSeparateButton(listboxes[listboxes.size() - 1]->getListboxButton());
|
||||
delete listboxes[listboxes.size() - 1];
|
||||
listboxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllCheckboxes() {
|
||||
while (checkboxes.size() > 0) {
|
||||
removeSeparateButton(checkboxes[checkboxes.size() - 1]->getCheckboxButton());
|
||||
delete checkboxes[checkboxes.size() - 1];
|
||||
checkboxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllSliders() {
|
||||
while (sliders.size() > 0) {
|
||||
removeSeparateButton(sliders[sliders.size() - 1]->getMovableSliderButton());
|
||||
removeSeparateButton(sliders[sliders.size() - 1]->getStaticSliderButton());
|
||||
delete sliders[sliders.size() - 1];
|
||||
sliders.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllTextboxes() {
|
||||
while (textboxes.size() > 0) {
|
||||
removeSeparateButton(textboxes[textboxes.size() - 1]->getTextboxButton());
|
||||
delete textboxes[textboxes.size() - 1];
|
||||
textboxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllTooltips(){
|
||||
while(!tooltips.empty()){
|
||||
delete tooltips[tooltips.size()-1];
|
||||
tooltips.pop_back();
|
||||
t->type(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::updateControlsListbox(int trigger){
|
||||
Listbox *controlsListbox=nullptr;
|
||||
|
||||
for(Listbox *l : listboxes)
|
||||
if(l->isOpen() /*&& l->isControlsListbox()*/)
|
||||
controlsListbox=l;
|
||||
|
||||
if(controlsListbox){
|
||||
int selectedOption=controlsListbox->getSelectedOption(),colonId=-1;
|
||||
wstring line = controlsListbox->getContents()[selectedOption];
|
||||
|
||||
for(int i=0;i<line.size()&&colonId==-1;i++)
|
||||
if(line.c_str()[i]==':')
|
||||
colonId=i;
|
||||
|
||||
stringstream ss;
|
||||
ss<<hex<<trigger;
|
||||
line=line.substr(0,colonId+1)+L"0x"/*+ss.str().c_str()*/;
|
||||
controlsListbox->changeLine(selectedOption,line);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void GuiAppState::onRawKeyPress(SEvent::SKeyInput event){
|
||||
updateControlsListbox(event.Key);
|
||||
}
|
||||
|
||||
void GuiAppState::onRawMousePress(SEvent::SMouseInput event){
|
||||
int trigger=0;
|
||||
if(event.isMiddlePressed())
|
||||
trigger=1;
|
||||
else if(event.isRightPressed())
|
||||
trigger=2;
|
||||
updateControlsListbox(trigger);
|
||||
}
|
||||
*/
|
||||
|
||||
Textbox* GuiAppState::getOpenTextbox() {
|
||||
Textbox* t = nullptr;
|
||||
for (int i = 0; i < textboxes.size(); i++)
|
||||
if (textboxes[i]->isEnabled())
|
||||
t = textboxes[i];
|
||||
if (t)
|
||||
return t;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Listbox* GuiAppState::getOpenListbox() {
|
||||
Listbox *l = nullptr;
|
||||
for (int i = 0; i < listboxes.size(); i++)
|
||||
if (listboxes[i]->isOpen())
|
||||
l = listboxes[i];
|
||||
if (l)
|
||||
return l;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GuiAppState::onAnalog(Mapping::Bind bind, double strength) {}
|
||||
|
||||
void GuiAppState::addButton(Button* b) {
|
||||
buttons.push_back(b);
|
||||
}
|
||||
|
||||
void GuiAppState::addListbox(Listbox* l) {
|
||||
listboxes.push_back(l);
|
||||
buttons.push_back(l->getListboxButton());
|
||||
}
|
||||
|
||||
void GuiAppState::addCheckbox(Checkbox* c) {
|
||||
buttons.push_back(c->getCheckboxButton());
|
||||
checkboxes.push_back(c);
|
||||
}
|
||||
|
||||
void GuiAppState::addSlider(Slider* s) {
|
||||
buttons.push_back(s->getMovableSliderButton());
|
||||
buttons.push_back(s->getStaticSliderButton());
|
||||
sliders.push_back(s);
|
||||
}
|
||||
|
||||
void GuiAppState::addTextbox(Textbox* t) {
|
||||
buttons.push_back(t->getTextboxButton());
|
||||
textboxes.push_back(t);
|
||||
}
|
||||
|
||||
void GuiAppState::addTooltip(Tooltip* t) {
|
||||
tooltips.push_back(t);
|
||||
}
|
||||
|
||||
void GuiAppState::removeButton(Button *b) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (b == buttons[i]) {
|
||||
/*
|
||||
if (b->isImageButton())
|
||||
GameManager::getSingleton()->detachImage(b->getImage());
|
||||
*/
|
||||
delete b;
|
||||
buttons.erase(buttons.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeButton(string name) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (name == buttons[i]->getName() && buttons[i]->isSeparate()) {
|
||||
/*
|
||||
if (buttons[i]->isImageButton())
|
||||
GameManager::getSingleton()->detachImage(buttons[i]->getImage());
|
||||
*/
|
||||
|
||||
delete buttons[i];
|
||||
|
||||
buttons.erase(buttons.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeSeparateButton(Button *b) {
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
if (b == buttons[i]) {
|
||||
delete b;
|
||||
buttons.erase(buttons.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeListbox(Listbox *l) {
|
||||
for (int i = 0; i < listboxes.size(); i++) {
|
||||
if (l == listboxes[i]) {
|
||||
removeSeparateButton(l->getListboxButton());
|
||||
delete l;
|
||||
listboxes.erase(listboxes.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeCheckbox(Checkbox *c) {
|
||||
for (int i = 0; i < checkboxes.size(); i++) {
|
||||
if (c == checkboxes[i]) {
|
||||
removeSeparateButton(c->getCheckboxButton());
|
||||
delete c;
|
||||
checkboxes.erase(checkboxes.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeSlider(Slider *s) {
|
||||
for (int i = 0; i < sliders.size(); i++) {
|
||||
if (s == sliders[i]) {
|
||||
removeSeparateButton(s->getMovableSliderButton());
|
||||
removeSeparateButton(s->getStaticSliderButton());
|
||||
delete s;
|
||||
sliders.erase(sliders.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeTextbox(Textbox* t) {
|
||||
for (int i = 0; i < textboxes.size(); i++) {
|
||||
if (t == textboxes[i]) {
|
||||
removeSeparateButton(t->getTextboxButton());
|
||||
delete t;
|
||||
textboxes.erase(textboxes.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeTooltip(Tooltip *t) {
|
||||
for (int i = 0; i < tooltips.size(); i++) {
|
||||
if (t == tooltips[i]) {
|
||||
delete t;
|
||||
tooltips.erase(tooltips.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllButtons() {
|
||||
while (buttons.size() > 0) {
|
||||
delete buttons[buttons.size() - 1];
|
||||
buttons.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllListboxes() {
|
||||
while (listboxes.size() > 0) {
|
||||
removeSeparateButton(listboxes[listboxes.size() - 1]->getListboxButton());
|
||||
delete listboxes[listboxes.size() - 1];
|
||||
listboxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllCheckboxes() {
|
||||
while (checkboxes.size() > 0) {
|
||||
removeSeparateButton(checkboxes[checkboxes.size() - 1]->getCheckboxButton());
|
||||
delete checkboxes[checkboxes.size() - 1];
|
||||
checkboxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllSliders() {
|
||||
while (sliders.size() > 0) {
|
||||
removeSeparateButton(sliders[sliders.size() - 1]->getMovableSliderButton());
|
||||
removeSeparateButton(sliders[sliders.size() - 1]->getStaticSliderButton());
|
||||
delete sliders[sliders.size() - 1];
|
||||
sliders.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllTextboxes() {
|
||||
while (textboxes.size() > 0) {
|
||||
removeSeparateButton(textboxes[textboxes.size() - 1]->getTextboxButton());
|
||||
delete textboxes[textboxes.size() - 1];
|
||||
textboxes.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::removeAllTooltips(){
|
||||
while(!tooltips.empty()){
|
||||
delete tooltips[tooltips.size()-1];
|
||||
tooltips.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+90
-92
@@ -13,99 +13,97 @@
|
||||
#include "tooltip.h"
|
||||
#include "key.h"
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
class GuiAppState : public AbstractAppState {
|
||||
public:
|
||||
GuiAppState();
|
||||
~GuiAppState();
|
||||
void onAttachment();
|
||||
void onDetachment();
|
||||
void update();
|
||||
void addButton(vb01Gui::Button*);
|
||||
void removeButton(vb01Gui::Button*);
|
||||
void removeSeparateButton(vb01Gui::Button*);
|
||||
void removeButton(std::string);
|
||||
void addListbox(vb01Gui::Listbox*);
|
||||
void removeListbox(vb01Gui::Listbox*);
|
||||
void addCheckbox(vb01Gui::Checkbox*);
|
||||
void removeCheckbox(vb01Gui::Checkbox*);
|
||||
void addTextbox(vb01Gui::Textbox*);
|
||||
void removeTextbox(vb01Gui::Textbox*);
|
||||
void addSlider(vb01Gui::Slider*);
|
||||
void addTooltip(gui::Tooltip*);
|
||||
void removeTooltip(gui::Tooltip*);
|
||||
void removeSlider(vb01Gui::Slider*);
|
||||
void removeAllButtons();
|
||||
void removeAllListboxes();
|
||||
void removeAllCheckboxes();
|
||||
void removeAllSliders();
|
||||
void removeAllTextboxes();
|
||||
void removeAllTooltips();
|
||||
inline bool isLeftMousePressed(){return leftMousePressed;}
|
||||
private:
|
||||
virtual void onAction(Mapping::Bind, bool);
|
||||
virtual void onAnalog(Mapping::Bind, double);
|
||||
/*
|
||||
virtual void onRawKeyPress(irr::SEvent::SKeyInput);
|
||||
virtual void onRawMousePress(irr::SEvent::SMouseInput);
|
||||
*/
|
||||
vb01Gui::Textbox* getOpenTextbox();
|
||||
vb01Gui::Listbox* getOpenListbox();
|
||||
void attachBindKeys();
|
||||
void attachKeyboardKeys();
|
||||
void checkKeyboard(vb01Gui::Textbox*, Mapping::Bind, bool);
|
||||
void updateControlsListbox(int);
|
||||
|
||||
std::vector<vb01Gui::Button*> buttons;
|
||||
std::vector<vb01Gui::Listbox*> listboxes;
|
||||
std::vector<vb01Gui::Checkbox*> checkboxes;
|
||||
std::vector<vb01Gui::Textbox*> textboxes;
|
||||
std::vector<vb01Gui::Slider*> sliders;
|
||||
std::vector<gui::Tooltip*> tooltips;
|
||||
bool leftMousePressed = false, shiftPressed = false;
|
||||
const static int numKeys=36;
|
||||
const char keyChars[numKeys]{
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm',
|
||||
'n',
|
||||
'o',
|
||||
'p',
|
||||
'q',
|
||||
'r',
|
||||
's',
|
||||
't',
|
||||
'u',
|
||||
'v',
|
||||
'w',
|
||||
'x',
|
||||
'y',
|
||||
'z'
|
||||
};
|
||||
protected:
|
||||
namespace battleship{
|
||||
class GuiAppState : public AbstractAppState {
|
||||
public:
|
||||
GuiAppState();
|
||||
~GuiAppState();
|
||||
void onAttachment();
|
||||
void onDetachment();
|
||||
void update();
|
||||
void addButton(vb01Gui::Button*);
|
||||
void removeButton(vb01Gui::Button*);
|
||||
void removeSeparateButton(vb01Gui::Button*);
|
||||
void removeButton(std::string);
|
||||
void addListbox(vb01Gui::Listbox*);
|
||||
void removeListbox(vb01Gui::Listbox*);
|
||||
void addCheckbox(vb01Gui::Checkbox*);
|
||||
void removeCheckbox(vb01Gui::Checkbox*);
|
||||
void addTextbox(vb01Gui::Textbox*);
|
||||
void removeTextbox(vb01Gui::Textbox*);
|
||||
void addSlider(vb01Gui::Slider*);
|
||||
void addTooltip(Tooltip*);
|
||||
void removeTooltip(Tooltip*);
|
||||
void removeSlider(vb01Gui::Slider*);
|
||||
void removeAllButtons();
|
||||
void removeAllListboxes();
|
||||
void removeAllCheckboxes();
|
||||
void removeAllSliders();
|
||||
void removeAllTextboxes();
|
||||
void removeAllTooltips();
|
||||
inline bool isLeftMousePressed(){return leftMousePressed;}
|
||||
private:
|
||||
virtual void onAction(Mapping::Bind, bool);
|
||||
virtual void onAnalog(Mapping::Bind, double);
|
||||
/*
|
||||
virtual void onRawKeyPress(irr::SEvent::SKeyInput);
|
||||
virtual void onRawMousePress(irr::SEvent::SMouseInput);
|
||||
*/
|
||||
vb01Gui::Textbox* getOpenTextbox();
|
||||
vb01Gui::Listbox* getOpenListbox();
|
||||
void attachBindKeys();
|
||||
void attachKeyboardKeys();
|
||||
void checkKeyboard(vb01Gui::Textbox*, Mapping::Bind, bool);
|
||||
void updateControlsListbox(int);
|
||||
|
||||
std::vector<vb01Gui::Button*> buttons;
|
||||
std::vector<vb01Gui::Listbox*> listboxes;
|
||||
std::vector<vb01Gui::Checkbox*> checkboxes;
|
||||
std::vector<vb01Gui::Textbox*> textboxes;
|
||||
std::vector<vb01Gui::Slider*> sliders;
|
||||
std::vector<Tooltip*> tooltips;
|
||||
bool leftMousePressed = false, shiftPressed = false;
|
||||
const static int numKeys=36;
|
||||
const char keyChars[numKeys]{
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm',
|
||||
'n',
|
||||
'o',
|
||||
'p',
|
||||
'q',
|
||||
'r',
|
||||
's',
|
||||
't',
|
||||
'u',
|
||||
'v',
|
||||
'w',
|
||||
'x',
|
||||
'y',
|
||||
'z'
|
||||
};
|
||||
}
|
||||
protected:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+35
-40
@@ -5,52 +5,47 @@
|
||||
#include "guidedMissileData.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace game::content;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
GuidedMissile::GuidedMissile(Unit *unit, Vector3 pos, Vector3 target, Vector3 dirVec, Vector3 leftVec, Vector3 upVec, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, nullptr, pos, dirVec, leftVec, upVec, id, weaponTypeId, weaponId) {
|
||||
speed = .05;
|
||||
namespace battleship{
|
||||
GuidedMissile::GuidedMissile(Unit *unit, Vector3 pos, Vector3 target, Vector3 dirVec, Vector3 leftVec, Vector3 upVec, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, nullptr, pos, dirVec, leftVec, upVec, id, weaponTypeId, weaponId) {
|
||||
speed = .05;
|
||||
|
||||
for (int i = 0; i < 180; i++)
|
||||
arcLength += speed * cos(turnAngle * i);
|
||||
for (int i = 0; i < 180; i++)
|
||||
arcLength += speed * cos(turnAngle * i);
|
||||
|
||||
this->target = target;
|
||||
this->target = target;
|
||||
Vector3 targVec = Vector3(target.x - initPos.x, 0, target.z - initPos.z);
|
||||
b = targVec.getLength() / 2;
|
||||
x = -b;
|
||||
dirVec = Vector3(0,1,0);
|
||||
upVec = -targVec.norm();
|
||||
leftVec = Quaternion(PI / 2, dirVec) * dirVec;
|
||||
rayLength = 3;
|
||||
damage = 100;
|
||||
}
|
||||
|
||||
void GuidedMissile::update() {
|
||||
Projectile::update();
|
||||
updateVecs();
|
||||
node->setPosition(pos);
|
||||
checkForCollision();
|
||||
}
|
||||
|
||||
void GuidedMissile::updateVecs() {
|
||||
if(x < b){
|
||||
Vector3 targVec = Vector3(target.x - initPos.x, 0, target.z - initPos.z);
|
||||
b = targVec.getLength() / 2;
|
||||
x = -b;
|
||||
dirVec = Vector3(0,1,0);
|
||||
upVec = -targVec.norm();
|
||||
leftVec = Quaternion(PI / 2, dirVec) * dirVec;
|
||||
rayLength = 3;
|
||||
damage = 100;
|
||||
}
|
||||
|
||||
void GuidedMissile::update() {
|
||||
Projectile::update();
|
||||
updateVecs();
|
||||
node->setPosition(pos);
|
||||
checkForCollision();
|
||||
}
|
||||
|
||||
void GuidedMissile::updateVecs() {
|
||||
if(x < b){
|
||||
Vector3 targVec = Vector3(target.x - initPos.x, 0, target.z - initPos.z);
|
||||
pos = pos + targVec.norm() * speed;
|
||||
x += speed;
|
||||
pos.y = sqrt(1. - x * x / (b * b)) * a;
|
||||
float tanAngle = atan(-a*x/(b*b*sqrt(1.-x*x/(b*b))));
|
||||
Quaternion rotQuat = Quaternion(tanAngle, leftVec);
|
||||
Vector3 dirProj = (dirVec == Vector3::VEC_J ? upVec : Vector3(dirVec.x, 0, dirVec.z).norm());
|
||||
orientProjectile(rotQuat * targVec);
|
||||
}
|
||||
else
|
||||
pos.y -= speed;
|
||||
pos = pos + targVec.norm() * speed;
|
||||
x += speed;
|
||||
pos.y = sqrt(1. - x * x / (b * b)) * a;
|
||||
float tanAngle = atan(-a*x/(b*b*sqrt(1.-x*x/(b*b))));
|
||||
Quaternion rotQuat = Quaternion(tanAngle, leftVec);
|
||||
Vector3 dirProj = (dirVec == Vector3::VEC_J ? upVec : Vector3(dirVec.x, 0, dirVec.z).norm());
|
||||
orientProjectile(rotQuat * targVec);
|
||||
}
|
||||
else
|
||||
pos.y -= speed;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-14
@@ -4,20 +4,18 @@
|
||||
|
||||
#include "projectile.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class GuidedMissile : public Projectile {
|
||||
public:
|
||||
GuidedMissile(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~GuidedMissile(){}
|
||||
void update();
|
||||
private:
|
||||
void updateVecs();
|
||||
bool firstPhase = true;
|
||||
float a = 4,b,x,turnAngle = 1,arcLength = 0.,maxHeight = 5;
|
||||
vb01::Vector3 target;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class GuidedMissile : public Projectile {
|
||||
public:
|
||||
GuidedMissile(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~GuidedMissile(){}
|
||||
void update();
|
||||
private:
|
||||
void updateVecs();
|
||||
bool firstPhase = true;
|
||||
float a = 4,b,x,turnAngle = 1,arcLength = 0.,maxHeight = 5;
|
||||
vb01::Vector3 target;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+17
-20
@@ -4,26 +4,23 @@
|
||||
|
||||
#include "projectileData.h"
|
||||
|
||||
namespace game
|
||||
{
|
||||
namespace content{
|
||||
namespace projectileData {
|
||||
const vb01::Vector3 guidedMissilePos[unitData::numberOfUnits][6]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
vb01::Vector3(0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.88017),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.88017)
|
||||
},
|
||||
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
namespace projectileData {
|
||||
const vb01::Vector3 guidedMissilePos[unitData::numberOfUnits][6]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
vb01::Vector3(0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.88017),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.88017)
|
||||
},
|
||||
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+389
-392
@@ -7,433 +7,430 @@
|
||||
#include "aircraftCarrier.h"
|
||||
#include "vessel.h"
|
||||
|
||||
using namespace game::gui;
|
||||
using namespace game::util;
|
||||
using namespace game::content;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
void InGameAppState::ResumeButton::onClick() {
|
||||
inGameState->toggleMainMenu();
|
||||
}
|
||||
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
GuiAppState* InGameAppState::ResumeButton::getGuiState() {
|
||||
return guiState;
|
||||
}
|
||||
void InGameAppState::ResumeButton::onClick() {
|
||||
inGameState->toggleMainMenu();
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
GuiAppState* InGameAppState::ResumeButton::getGuiState() {
|
||||
return guiState;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
class ConsoleCommandEntryButton : public Button {
|
||||
public:
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
|
||||
ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->inGameState = inGameState;
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
class ConsoleCommandEntryButton : public Button {
|
||||
public:
|
||||
|
||||
ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->inGameState = inGameState;
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
wstring name;
|
||||
vector<string> args;
|
||||
vector<int> spaceIds;
|
||||
|
||||
for (int i = 0; i < textbox->getText().size(); i++) {
|
||||
if (textbox->getText()[i] == ' ') {
|
||||
spaceIds.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
wstring name;
|
||||
vector<string> args;
|
||||
vector<int> spaceIds;
|
||||
if (spaceIds.size() > 0) {
|
||||
for (int i = 0; i < spaceIds[0]; i++)
|
||||
name += textbox->getText()[i];
|
||||
|
||||
for (int i = 0; i < textbox->getText().size(); i++) {
|
||||
if (textbox->getText()[i] == ' ') {
|
||||
spaceIds.push_back(i);
|
||||
}
|
||||
for (int i = 0; i < spaceIds.size() - 1; i++) {
|
||||
string w;
|
||||
for (int i2 = spaceIds[i]; i2 < spaceIds[i + 1]; i2++)
|
||||
w += textbox->getText()[i2];
|
||||
args.push_back(w);
|
||||
}
|
||||
|
||||
if (spaceIds.size() > 0) {
|
||||
for (int i = 0; i < spaceIds[0]; i++)
|
||||
name += textbox->getText()[i];
|
||||
args.push_back("");
|
||||
|
||||
for (int i = 0; i < spaceIds.size() - 1; i++) {
|
||||
string w;
|
||||
for (int i2 = spaceIds[i]; i2 < spaceIds[i + 1]; i2++)
|
||||
w += textbox->getText()[i2];
|
||||
args.push_back(w);
|
||||
for (int i = spaceIds[spaceIds.size() - 1]; i < textbox->getText().size(); i++) {
|
||||
args[args.size() - 1] += textbox->getText()[i];
|
||||
}
|
||||
} else
|
||||
name = textbox->getText();
|
||||
|
||||
//ConsoleCommand c(listbox, inGameState->getPlayerList(), name, args);
|
||||
}
|
||||
private:
|
||||
InGameAppState *inGameState;
|
||||
Textbox *textbox;
|
||||
Listbox *listbox;
|
||||
};
|
||||
|
||||
vector<string> list;
|
||||
int emptyEntries = 20;
|
||||
|
||||
for (int i = 0; i < emptyEntries; i++)
|
||||
list.push_back("");
|
||||
|
||||
Vector2 pos = Vector2(300, 100);
|
||||
Listbox *consoleListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(420, 20), list, 20, PATH + "Fonts/batang.ttf");
|
||||
consoleListbox->openUp();
|
||||
guiState->addListbox(consoleListbox);
|
||||
Textbox *consoleTextbox = new Textbox(Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)), Vector2(300, 20), PATH + "Fonts/batang.ttf");
|
||||
guiState->addTextbox(consoleTextbox);
|
||||
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, Vector2(pos.x + 320, pos.y + 20 * (emptyEntries + 1)), Vector2(100, 20), "Enter", true);
|
||||
guiState->addButton(entryButton);
|
||||
}
|
||||
|
||||
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
void InGameAppState::InGameOptionsButton::ReturnButton::onClick() {
|
||||
guiState->removeAllCheckboxes();
|
||||
guiState->removeAllListboxes();
|
||||
guiState->removeAllSliders();
|
||||
guiState->removeAllTextboxes();
|
||||
guiState->removeButton("Controls");
|
||||
guiState->removeButton("Mouse");
|
||||
guiState->removeButton("Video");
|
||||
guiState->removeButton("Audio");
|
||||
guiState->removeButton("Multiplayer");
|
||||
Vector2 pos = Vector2(100, 100);
|
||||
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
|
||||
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
|
||||
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
|
||||
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
|
||||
inGameState->setResumeButton(resumeButton);
|
||||
inGameState->setConsoleButton(consoleButton);
|
||||
inGameState->setOptionsButton(optionsButton);
|
||||
inGameState->setMainMenuButton(mainMenuButton);
|
||||
inGameState->setExitButton(exitButton);
|
||||
guiState->addButton(resumeButton);
|
||||
guiState->addButton(consoleButton);
|
||||
guiState->addButton(optionsButton);
|
||||
guiState->addButton(mainMenuButton);
|
||||
guiState->addButton(exitButton);
|
||||
guiState->removeButton("Back");
|
||||
}
|
||||
|
||||
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
void InGameAppState::InGameOptionsButton::onClick() {
|
||||
returnButton = new ReturnButton(guiState, inGameState, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
|
||||
guiState->addButton(returnButton);
|
||||
guiState->removeButton("Resume");
|
||||
guiState->removeButton("Console");
|
||||
guiState->removeButton("Main menu");
|
||||
guiState->removeButton("Exit");
|
||||
OptionsButton::onClick();
|
||||
}
|
||||
|
||||
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
void InGameAppState::MainMenuButton::onClick() {
|
||||
|
||||
}
|
||||
|
||||
InGameAppState::UnitCreationButton::UnitCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
//setImageButton(new Image(icon, pos, size));
|
||||
}
|
||||
|
||||
void InGameAppState::UnitCreationButton::onClick() {
|
||||
}
|
||||
|
||||
void InGameAppState::UnitCreationButton::update() {
|
||||
Button::update();
|
||||
}
|
||||
|
||||
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::BattleshipCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::DestroyerCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::CruiserCreationButton::CruiserCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::CruiserCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::CarrierCreationButton::CarrierCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::CarrierCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::SubmarineCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(vector<string> difficultyLevels, vector<string> factions) {
|
||||
type = AppStateTypes::IN_GAME_STATE;
|
||||
this->playerId = 0;
|
||||
this->difficultyLevels = difficultyLevels;
|
||||
this->factions = factions;
|
||||
}
|
||||
|
||||
InGameAppState::~InGameAppState() {
|
||||
}
|
||||
|
||||
void InGameAppState::onAttachment() {
|
||||
AbstractAppState::onAttachment();
|
||||
map = new Map();
|
||||
map->load();
|
||||
|
||||
for (int i = 0; i < factions.size(); i++) {
|
||||
int faction;
|
||||
int difficulty;
|
||||
|
||||
if (i == 0)
|
||||
difficulty = -1;
|
||||
else {
|
||||
if (difficultyLevels[i - 1] == "Easy")
|
||||
difficulty = 0;
|
||||
else if (difficultyLevels[i - 1] == "Medium")
|
||||
difficulty = 1;
|
||||
else
|
||||
difficulty = 2;
|
||||
}
|
||||
|
||||
faction = factions[i][0] - 48;
|
||||
Player *p = new Player(difficulty, faction);
|
||||
players.push_back(p);
|
||||
p->setId(players.size() - 1);
|
||||
}
|
||||
|
||||
mainPlayer = players[playerId];
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
guiState = ((GuiAppState*)stateManager->getAppState(AppStateTypes::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, map, players, playerId);
|
||||
stateManager->attachState(activeState);
|
||||
}
|
||||
|
||||
void InGameAppState::onDetachment() {
|
||||
|
||||
}
|
||||
|
||||
void InGameAppState::update() {
|
||||
if (map)
|
||||
map->update();
|
||||
|
||||
if (isMainMenuActive) {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
|
||||
driver->draw2DRectangle(SColor(100, 0, 0, 0), rect<s32>(0, 0, gm->getWidth(), gm->getHeight()));
|
||||
*/
|
||||
}
|
||||
|
||||
for (Player *p : players)
|
||||
if (p) {
|
||||
p->update();
|
||||
|
||||
for (int i=0;i<p->getNumberOfUnits();i++){
|
||||
Unit *u=p->getUnit(i);
|
||||
|
||||
if(u->isWorking())
|
||||
u->update();
|
||||
else{
|
||||
int selectedId=-1;
|
||||
std::vector<Unit*> &units=p->getUnits(),&selectedUnits=activeState->getSelectedUnits();
|
||||
units.erase(units.begin()+i);
|
||||
|
||||
if(u->getType()==unitData::UNIT_TYPE::MISSILE_JET||u->getType()==unitData::UNIT_TYPE::DEMO_JET){
|
||||
AircraftCarrier *carrier=nullptr;
|
||||
|
||||
for(int i2=0;i2<p->getUnits().size()&&!carrier;i2++){
|
||||
AircraftCarrier *a=((Jet*)u)->getAircraftCarrier();
|
||||
|
||||
if(a)
|
||||
carrier=a;
|
||||
}
|
||||
|
||||
if(carrier){
|
||||
Jet** jets=carrier->getJets();
|
||||
jets[((Jet*)u)->getJetId()]=nullptr;
|
||||
}
|
||||
}
|
||||
else if(u->getType()==unitData::UNIT_TYPE::AIRCRAFT_CARRIER){
|
||||
AircraftCarrier *carrier=(AircraftCarrier*)u;
|
||||
|
||||
for(int i2=0;i2<carrier->getMaxNumJets();i2++){
|
||||
Jet *j=carrier->getJet(i2);
|
||||
|
||||
if(j&&j->isOnBoard())
|
||||
j->blowUp();
|
||||
}
|
||||
}
|
||||
|
||||
for(int i2=0;i2<10;i2++){
|
||||
int id=-1;
|
||||
std::vector<Unit*> &group=activeState->getUnitGroup(i2);
|
||||
|
||||
for(int i3=0;i3<group.size()&&id==-1;i3++)
|
||||
if(group[i3]==u)
|
||||
id=i3;
|
||||
|
||||
if(id!=-1)
|
||||
group.erase(group.begin()+id);
|
||||
}
|
||||
|
||||
args.push_back("");
|
||||
for(int i2=0;i2<selectedUnits.size()&&selectedId==-1;i2++)
|
||||
if(selectedUnits[i2]==u)
|
||||
selectedId=i2;
|
||||
|
||||
for (int i = spaceIds[spaceIds.size() - 1]; i < textbox->getText().size(); i++) {
|
||||
args[args.size() - 1] += textbox->getText()[i];
|
||||
}
|
||||
} else
|
||||
name = textbox->getText();
|
||||
if(selectedId!=-1)
|
||||
selectedUnits.erase(selectedUnits.begin()+selectedId);
|
||||
|
||||
//ConsoleCommand c(listbox, inGameState->getPlayerList(), name, args);
|
||||
delete u;
|
||||
}
|
||||
}
|
||||
private:
|
||||
InGameAppState *inGameState;
|
||||
Textbox *textbox;
|
||||
Listbox *listbox;
|
||||
};
|
||||
}
|
||||
|
||||
vector<string> list;
|
||||
int emptyEntries = 20;
|
||||
for(int i=0;i<projectiles.size();i++){
|
||||
Projectile *p=projectiles[i];
|
||||
|
||||
for (int i = 0; i < emptyEntries; i++)
|
||||
list.push_back("");
|
||||
|
||||
Vector2 pos = Vector2(300, 100);
|
||||
Listbox *consoleListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(420, 20), list, 20, PATH + "Fonts/batang.ttf");
|
||||
consoleListbox->openUp();
|
||||
guiState->addListbox(consoleListbox);
|
||||
Textbox *consoleTextbox = new Textbox(Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)), Vector2(300, 20), PATH + "Fonts/batang.ttf");
|
||||
guiState->addTextbox(consoleTextbox);
|
||||
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, Vector2(pos.x + 320, pos.y + 20 * (emptyEntries + 1)), Vector2(100, 20), "Enter", true);
|
||||
guiState->addButton(entryButton);
|
||||
if(!p->isExploded()){
|
||||
p->update();
|
||||
}
|
||||
else{
|
||||
delete p;
|
||||
projectiles.erase(projectiles.begin()+i);
|
||||
}
|
||||
}
|
||||
|
||||
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
for(int i=0;i<fx.size();i++){
|
||||
if(getTime()-fx[i].initTime>fx[i].time){
|
||||
/*
|
||||
IParticleSystemSceneNode *node=fx[i].node;
|
||||
|
||||
void InGameAppState::InGameOptionsButton::ReturnButton::onClick() {
|
||||
guiState->removeAllCheckboxes();
|
||||
guiState->removeAllListboxes();
|
||||
guiState->removeAllSliders();
|
||||
guiState->removeAllTextboxes();
|
||||
guiState->removeButton("Controls");
|
||||
guiState->removeButton("Mouse");
|
||||
guiState->removeButton("Video");
|
||||
guiState->removeButton("Audio");
|
||||
guiState->removeButton("Multiplayer");
|
||||
if(node){
|
||||
node->removeAllAffectors();
|
||||
node->setVisible(false);
|
||||
}
|
||||
|
||||
if(fx[i].sfx){
|
||||
delete fx[i].sfx->getBuffer();
|
||||
delete fx[i].sfx;
|
||||
}
|
||||
|
||||
fx.erase(fx.begin()+i);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::attachGui() {
|
||||
int idOffset = 0;
|
||||
|
||||
if (mainPlayer->getFaction() == 1)
|
||||
idOffset += 7;
|
||||
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
bcb = new BattleshipCreationButton(gameManager, driver->getTexture(iconPath[idOffset]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 540), vector2d<s32>(100, 100), "battleships", true);
|
||||
dcb = new DestroyerCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 1]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 430), vector2d<s32>(100, 100), "destroyers", true);
|
||||
crcb = new CruiserCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 2]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 320), vector2d<s32>(100, 100), "cruisers", true);
|
||||
ccb = new CarrierCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 3]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 210), vector2d<s32>(100, 100), "carriers", true);
|
||||
scb = new SubmarineCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 4]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 100), vector2d<s32>(100, 100), "submarines", true);
|
||||
*/
|
||||
guiState->addButton(bcb);
|
||||
guiState->addButton(dcb);
|
||||
guiState->addButton(crcb);
|
||||
guiState->addButton(ccb);
|
||||
guiState->addButton(scb);
|
||||
}
|
||||
|
||||
void InGameAppState::detachGui() {
|
||||
guiState->removeButton(bcb);
|
||||
guiState->removeButton(dcb);
|
||||
guiState->removeButton(crcb);
|
||||
guiState->removeButton(ccb);
|
||||
guiState->removeButton(scb);
|
||||
}
|
||||
|
||||
void InGameAppState::toggleMainMenu() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
|
||||
if (!isMainMenuActive) {
|
||||
isMainMenuActive = true;
|
||||
gm->getStateManager()->dettachState(activeState);
|
||||
Vector2 pos = Vector2(100, 100);
|
||||
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
|
||||
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
|
||||
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
|
||||
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
|
||||
inGameState->setResumeButton(resumeButton);
|
||||
inGameState->setConsoleButton(consoleButton);
|
||||
inGameState->setOptionsButton(optionsButton);
|
||||
inGameState->setMainMenuButton(mainMenuButton);
|
||||
inGameState->setExitButton(exitButton);
|
||||
//detachGui();
|
||||
resumeButton = new ResumeButton(guiState, this, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
|
||||
consoleButton = new ConsoleButton(guiState, this, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
|
||||
optionsButton = new InGameOptionsButton(guiState, this, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
|
||||
mainMenuButton = new MainMenuButton(guiState, this, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
|
||||
exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
|
||||
guiState->addButton(resumeButton);
|
||||
guiState->addButton(consoleButton);
|
||||
guiState->addButton(optionsButton);
|
||||
guiState->addButton(mainMenuButton);
|
||||
guiState->addButton(exitButton);
|
||||
guiState->removeButton("Back");
|
||||
}
|
||||
|
||||
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
void InGameAppState::InGameOptionsButton::onClick() {
|
||||
returnButton = new ReturnButton(guiState, inGameState, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
|
||||
guiState->addButton(returnButton);
|
||||
guiState->removeButton("Resume");
|
||||
//gameManager->getDevice()->getSceneManager()->getActiveCamera()->setVisible(false);
|
||||
}
|
||||
else {
|
||||
isMainMenuActive = false;
|
||||
gm->getStateManager()->attachState(activeState);
|
||||
//attachGui();
|
||||
guiState->removeAllCheckboxes();
|
||||
guiState->removeAllListboxes();
|
||||
guiState->removeAllSliders();
|
||||
guiState->removeAllTextboxes();
|
||||
guiState->removeButton("Enter");
|
||||
guiState->removeButton("Console");
|
||||
guiState->removeButton("Main menu");
|
||||
guiState->removeButton("Options");
|
||||
guiState->removeButton("Exit");
|
||||
OptionsButton::onClick();
|
||||
guiState->removeButton("Resume");
|
||||
//gameManager->getDevice()->getSceneManager()->getActiveCamera()->setVisible(true);
|
||||
}
|
||||
|
||||
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->guiState = guiState;
|
||||
this->inGameState = inGameState;
|
||||
}
|
||||
|
||||
void InGameAppState::MainMenuButton::onClick() {
|
||||
|
||||
}
|
||||
|
||||
InGameAppState::UnitCreationButton::UnitCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
//setImageButton(new Image(icon, pos, size));
|
||||
}
|
||||
|
||||
void InGameAppState::UnitCreationButton::onClick() {
|
||||
}
|
||||
|
||||
void InGameAppState::UnitCreationButton::update() {
|
||||
Button::update();
|
||||
}
|
||||
|
||||
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::BattleshipCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::DestroyerCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::CruiserCreationButton::CruiserCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::CruiserCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::CarrierCreationButton::CarrierCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::CarrierCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
|
||||
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
|
||||
}
|
||||
|
||||
void InGameAppState::SubmarineCreationButton::onClick() {
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(vector<string> difficultyLevels, vector<string> factions) {
|
||||
type = AppStateTypes::IN_GAME_STATE;
|
||||
this->playerId = 0;
|
||||
this->difficultyLevels = difficultyLevels;
|
||||
this->factions = factions;
|
||||
}
|
||||
|
||||
InGameAppState::~InGameAppState() {
|
||||
}
|
||||
|
||||
void InGameAppState::onAttachment() {
|
||||
AbstractAppState::onAttachment();
|
||||
map = new Map();
|
||||
map->load();
|
||||
|
||||
for (int i = 0; i < factions.size(); i++) {
|
||||
int faction;
|
||||
int difficulty;
|
||||
|
||||
if (i == 0)
|
||||
difficulty = -1;
|
||||
else {
|
||||
if (difficultyLevels[i - 1] == "Easy")
|
||||
difficulty = 0;
|
||||
else if (difficultyLevels[i - 1] == "Medium")
|
||||
difficulty = 1;
|
||||
else
|
||||
difficulty = 2;
|
||||
}
|
||||
|
||||
faction = factions[i][0] - 48;
|
||||
Player *p = new Player(difficulty, faction);
|
||||
players.push_back(p);
|
||||
p->setId(players.size() - 1);
|
||||
}
|
||||
|
||||
mainPlayer = players[playerId];
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
guiState = ((GuiAppState*)stateManager->getAppState(AppStateTypes::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, map, players, playerId);
|
||||
stateManager->attachState(activeState);
|
||||
}
|
||||
|
||||
void InGameAppState::onDetachment() {
|
||||
|
||||
}
|
||||
|
||||
void InGameAppState::update() {
|
||||
if (map)
|
||||
map->update();
|
||||
|
||||
if (isMainMenuActive) {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
|
||||
driver->draw2DRectangle(SColor(100, 0, 0, 0), rect<s32>(0, 0, gm->getWidth(), gm->getHeight()));
|
||||
*/
|
||||
}
|
||||
|
||||
for (Player *p : players)
|
||||
if (p) {
|
||||
p->update();
|
||||
|
||||
for (int i=0;i<p->getNumberOfUnits();i++){
|
||||
Unit *u=p->getUnit(i);
|
||||
|
||||
if(u->isWorking())
|
||||
u->update();
|
||||
else{
|
||||
int selectedId=-1;
|
||||
std::vector<Unit*> &units=p->getUnits(),&selectedUnits=activeState->getSelectedUnits();
|
||||
units.erase(units.begin()+i);
|
||||
|
||||
if(u->getType()==unitData::UNIT_TYPE::MISSILE_JET||u->getType()==unitData::UNIT_TYPE::DEMO_JET){
|
||||
AircraftCarrier *carrier=nullptr;
|
||||
|
||||
for(int i2=0;i2<p->getUnits().size()&&!carrier;i2++){
|
||||
AircraftCarrier *a=((Jet*)u)->getAircraftCarrier();
|
||||
|
||||
if(a)
|
||||
carrier=a;
|
||||
}
|
||||
|
||||
if(carrier){
|
||||
Jet** jets=carrier->getJets();
|
||||
jets[((Jet*)u)->getJetId()]=nullptr;
|
||||
}
|
||||
}
|
||||
else if(u->getType()==unitData::UNIT_TYPE::AIRCRAFT_CARRIER){
|
||||
AircraftCarrier *carrier=(AircraftCarrier*)u;
|
||||
|
||||
for(int i2=0;i2<carrier->getMaxNumJets();i2++){
|
||||
Jet *j=carrier->getJet(i2);
|
||||
|
||||
if(j&&j->isOnBoard())
|
||||
j->blowUp();
|
||||
}
|
||||
}
|
||||
|
||||
for(int i2=0;i2<10;i2++){
|
||||
int id=-1;
|
||||
std::vector<Unit*> &group=activeState->getUnitGroup(i2);
|
||||
|
||||
for(int i3=0;i3<group.size()&&id==-1;i3++)
|
||||
if(group[i3]==u)
|
||||
id=i3;
|
||||
|
||||
if(id!=-1)
|
||||
group.erase(group.begin()+id);
|
||||
}
|
||||
|
||||
for(int i2=0;i2<selectedUnits.size()&&selectedId==-1;i2++)
|
||||
if(selectedUnits[i2]==u)
|
||||
selectedId=i2;
|
||||
|
||||
if(selectedId!=-1)
|
||||
selectedUnits.erase(selectedUnits.begin()+selectedId);
|
||||
|
||||
delete u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<projectiles.size();i++){
|
||||
Projectile *p=projectiles[i];
|
||||
|
||||
if(!p->isExploded()){
|
||||
p->update();
|
||||
}
|
||||
else{
|
||||
delete p;
|
||||
projectiles.erase(projectiles.begin()+i);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<fx.size();i++){
|
||||
if(getTime()-fx[i].initTime>fx[i].time){
|
||||
/*
|
||||
IParticleSystemSceneNode *node=fx[i].node;
|
||||
|
||||
if(node){
|
||||
node->removeAllAffectors();
|
||||
node->setVisible(false);
|
||||
}
|
||||
|
||||
if(fx[i].sfx){
|
||||
delete fx[i].sfx->getBuffer();
|
||||
delete fx[i].sfx;
|
||||
}
|
||||
|
||||
fx.erase(fx.begin()+i);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::attachGui() {
|
||||
int idOffset = 0;
|
||||
|
||||
if (mainPlayer->getFaction() == 1)
|
||||
idOffset += 7;
|
||||
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
bcb = new BattleshipCreationButton(gameManager, driver->getTexture(iconPath[idOffset]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 540), vector2d<s32>(100, 100), "battleships", true);
|
||||
dcb = new DestroyerCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 1]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 430), vector2d<s32>(100, 100), "destroyers", true);
|
||||
crcb = new CruiserCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 2]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 320), vector2d<s32>(100, 100), "cruisers", true);
|
||||
ccb = new CarrierCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 3]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 210), vector2d<s32>(100, 100), "carriers", true);
|
||||
scb = new SubmarineCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 4]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 100), vector2d<s32>(100, 100), "submarines", true);
|
||||
*/
|
||||
guiState->addButton(bcb);
|
||||
guiState->addButton(dcb);
|
||||
guiState->addButton(crcb);
|
||||
guiState->addButton(ccb);
|
||||
guiState->addButton(scb);
|
||||
}
|
||||
|
||||
void InGameAppState::detachGui() {
|
||||
guiState->removeButton(bcb);
|
||||
guiState->removeButton(dcb);
|
||||
guiState->removeButton(crcb);
|
||||
guiState->removeButton(ccb);
|
||||
guiState->removeButton(scb);
|
||||
}
|
||||
|
||||
void InGameAppState::toggleMainMenu() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
|
||||
if (!isMainMenuActive) {
|
||||
isMainMenuActive = true;
|
||||
gm->getStateManager()->dettachState(activeState);
|
||||
Vector2 pos = Vector2(100, 100);
|
||||
//detachGui();
|
||||
resumeButton = new ResumeButton(guiState, this, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
|
||||
consoleButton = new ConsoleButton(guiState, this, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
|
||||
optionsButton = new InGameOptionsButton(guiState, this, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
|
||||
mainMenuButton = new MainMenuButton(guiState, this, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
|
||||
exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
|
||||
guiState->addButton(resumeButton);
|
||||
guiState->addButton(consoleButton);
|
||||
guiState->addButton(optionsButton);
|
||||
guiState->addButton(mainMenuButton);
|
||||
guiState->addButton(exitButton);
|
||||
//gameManager->getDevice()->getSceneManager()->getActiveCamera()->setVisible(false);
|
||||
}
|
||||
else {
|
||||
isMainMenuActive = false;
|
||||
gm->getStateManager()->attachState(activeState);
|
||||
//attachGui();
|
||||
guiState->removeAllCheckboxes();
|
||||
guiState->removeAllListboxes();
|
||||
guiState->removeAllSliders();
|
||||
guiState->removeAllTextboxes();
|
||||
guiState->removeButton("Enter");
|
||||
guiState->removeButton("Console");
|
||||
guiState->removeButton("Main menu");
|
||||
guiState->removeButton("Options");
|
||||
guiState->removeButton("Exit");
|
||||
guiState->removeButton("Resume");
|
||||
//gameManager->getDevice()->getSceneManager()->getActiveCamera()->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAction(Mapping::Bind bind, bool isPressed) {
|
||||
switch(bind){
|
||||
case Mapping::TOGGLE_MAIN_MENU:
|
||||
if(isPressed)toggleMainMenu();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAnalog(Mapping::Bind bind, double str) {}
|
||||
}
|
||||
|
||||
void InGameAppState::onAction(Mapping::Bind bind, bool isPressed) {
|
||||
switch(bind){
|
||||
case Mapping::TOGGLE_MAIN_MENU:
|
||||
if(isPressed)toggleMainMenu();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAnalog(Mapping::Bind bind, double str) {}
|
||||
}
|
||||
|
||||
+134
-137
@@ -11,146 +11,143 @@
|
||||
#include "optionsButton.h"
|
||||
#include <vector>
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
struct Fx {
|
||||
s64 initTime, time;
|
||||
//irr::scene::IParticleSystemSceneNode *node=nullptr;
|
||||
sf::Sound *sfx = nullptr;
|
||||
};
|
||||
|
||||
class InGameAppState : public AbstractAppState {
|
||||
namespace battleship{
|
||||
struct Fx {
|
||||
s64 initTime, time;
|
||||
//irr::scene::IParticleSystemSceneNode *node=nullptr;
|
||||
sf::Sound *sfx = nullptr;
|
||||
};
|
||||
|
||||
class InGameAppState : public AbstractAppState {
|
||||
public:
|
||||
InGameAppState(std::vector<std::string>, std::vector<std::string>);
|
||||
~InGameAppState();
|
||||
void onAttachment();
|
||||
void onDetachment();
|
||||
void update();
|
||||
void onAction(Mapping::Bind, bool);
|
||||
void onAnalog(Mapping::Bind, double);
|
||||
std::vector<Unit*> getSelectedUnits(Player*);
|
||||
inline std::vector<Player*> getPlayers() {return players;}
|
||||
inline std::vector<Projectile*>& getProjectiles(){return projectiles;}
|
||||
inline void addFx(Fx fx){this->fx.push_back(fx);}
|
||||
inline void addProjectile(Projectile *p){projectiles.push_back(p);}
|
||||
private:
|
||||
class ResumeButton : public vb01Gui::Button {
|
||||
public:
|
||||
InGameAppState(std::vector<std::string>, std::vector<std::string>);
|
||||
~InGameAppState();
|
||||
void onAttachment();
|
||||
void onDetachment();
|
||||
void update();
|
||||
void onAction(Mapping::Bind, bool);
|
||||
void onAnalog(Mapping::Bind, double);
|
||||
std::vector<content::Unit*> getSelectedUnits(content::Player*);
|
||||
inline std::vector<content::Player*> getPlayers() {return players;}
|
||||
inline std::vector<content::Projectile*>& getProjectiles(){return projectiles;}
|
||||
inline void addFx(Fx fx){this->fx.push_back(fx);}
|
||||
inline void addProjectile(content::Projectile *p){projectiles.push_back(p);}
|
||||
ResumeButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
GuiAppState *getGuiState();
|
||||
private:
|
||||
class ResumeButton : public vb01Gui::Button {
|
||||
public:
|
||||
ResumeButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
GuiAppState *getGuiState();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
|
||||
class ConsoleButton : public vb01Gui::Button {
|
||||
public:
|
||||
ConsoleButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
|
||||
class MainMenuButton : public vb01Gui::Button {
|
||||
public:
|
||||
MainMenuButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
|
||||
class InGameOptionsButton : public gui::OptionsButton {
|
||||
public:
|
||||
InGameOptionsButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
class ReturnButton : public vb01Gui::Button {
|
||||
public:
|
||||
ReturnButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
ReturnButton *returnButton;
|
||||
};
|
||||
|
||||
class UnitCreationButton : public vb01Gui::Button {
|
||||
public:
|
||||
UnitCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
void update();
|
||||
private:
|
||||
Image *icon;
|
||||
};
|
||||
|
||||
class BattleshipCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
BattleshipCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class DestroyerCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
DestroyerCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class CruiserCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
CruiserCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class CarrierCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
CarrierCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class SubmarineCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
SubmarineCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
ResumeButton *resumeButton;
|
||||
ConsoleButton *consoleButton;
|
||||
InGameOptionsButton *optionsButton;
|
||||
MainMenuButton *mainMenuButton;
|
||||
gui::ExitButton *exitButton;
|
||||
BattleshipCreationButton *bcb;
|
||||
DestroyerCreationButton *dcb;
|
||||
CruiserCreationButton *crcb;
|
||||
CarrierCreationButton *ccb;
|
||||
SubmarineCreationButton *scb;
|
||||
inline std::vector<content::Player*> getPlayerList(){return players;}
|
||||
bool isMainMenuActive = false;
|
||||
void toggleMainMenu();
|
||||
void attachGui();
|
||||
void detachGui();
|
||||
std::vector<content::Player*> players;
|
||||
std::vector<std::string> difficultyLevels, factions;
|
||||
std::vector<content::Projectile*> projectiles;
|
||||
std::vector<Fx> fx;
|
||||
content::Player *mainPlayer;
|
||||
content::Map *map;
|
||||
int playerId;
|
||||
ActiveGameState* activeState;
|
||||
GuiAppState* guiState;
|
||||
public:
|
||||
inline void setResumeButton(ResumeButton *r){this->resumeButton=r;}
|
||||
inline void setConsoleButton(ConsoleButton *c){this->consoleButton=c;}
|
||||
inline void setOptionsButton(InGameOptionsButton *o){this->optionsButton=o;}
|
||||
inline void setMainMenuButton(MainMenuButton *m){this->mainMenuButton=m;}
|
||||
inline void setExitButton(gui::ExitButton *e){this->exitButton=e;}
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
}
|
||||
|
||||
class ConsoleButton : public vb01Gui::Button {
|
||||
public:
|
||||
ConsoleButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
|
||||
class MainMenuButton : public vb01Gui::Button {
|
||||
public:
|
||||
MainMenuButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
|
||||
class InGameOptionsButton : public OptionsButton {
|
||||
public:
|
||||
InGameOptionsButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
class ReturnButton : public vb01Gui::Button {
|
||||
public:
|
||||
ReturnButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
};
|
||||
GuiAppState *guiState;
|
||||
InGameAppState *inGameState;
|
||||
ReturnButton *returnButton;
|
||||
};
|
||||
|
||||
class UnitCreationButton : public vb01Gui::Button {
|
||||
public:
|
||||
UnitCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
void update();
|
||||
private:
|
||||
};
|
||||
|
||||
class BattleshipCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
BattleshipCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class DestroyerCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
DestroyerCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class CruiserCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
CruiserCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class CarrierCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
CarrierCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
class SubmarineCreationButton : public UnitCreationButton {
|
||||
public:
|
||||
SubmarineCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
void onClick();
|
||||
};
|
||||
|
||||
ResumeButton *resumeButton;
|
||||
ConsoleButton *consoleButton;
|
||||
InGameOptionsButton *optionsButton;
|
||||
MainMenuButton *mainMenuButton;
|
||||
ExitButton *exitButton;
|
||||
BattleshipCreationButton *bcb;
|
||||
DestroyerCreationButton *dcb;
|
||||
CruiserCreationButton *crcb;
|
||||
CarrierCreationButton *ccb;
|
||||
SubmarineCreationButton *scb;
|
||||
inline std::vector<Player*> getPlayerList(){return players;}
|
||||
bool isMainMenuActive = false;
|
||||
void toggleMainMenu();
|
||||
void attachGui();
|
||||
void detachGui();
|
||||
std::vector<Player*> players;
|
||||
std::vector<std::string> difficultyLevels, factions;
|
||||
std::vector<Projectile*> projectiles;
|
||||
std::vector<Fx> fx;
|
||||
Player *mainPlayer;
|
||||
Map *map;
|
||||
int playerId;
|
||||
ActiveGameState* activeState;
|
||||
GuiAppState* guiState;
|
||||
public:
|
||||
inline void setResumeButton(ResumeButton *r){this->resumeButton=r;}
|
||||
inline void setConsoleButton(ConsoleButton *c){this->consoleButton=c;}
|
||||
inline void setOptionsButton(InGameOptionsButton *o){this->optionsButton=o;}
|
||||
inline void setMainMenuButton(MainMenuButton *m){this->mainMenuButton=m;}
|
||||
inline void setExitButton(ExitButton *e){this->exitButton=e;}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,148 +5,145 @@
|
||||
#include "jetData.h"
|
||||
#include "aircraftCarrier.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace game::content::unitData;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Jet::Jet(Player *player, Vector3 pos, int unitId, bool onBoard) : Unit(player, pos, unitId) {
|
||||
offsetPos = pos;
|
||||
this->onBoard = onBoard;
|
||||
this->pitchSpeed = unitData::pitchSpeed[id];
|
||||
}
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
void Jet::update() {
|
||||
Unit::update();
|
||||
Vector3 lp = aircraftCarrier->getDirVec() * aircraftCarrier->getRunwayLength() + aircraftCarrier->getJetPos(jetId);
|
||||
Jet::Jet(Player *player, Vector3 pos, int unitId, bool onBoard) : Unit(player, pos, unitId) {
|
||||
offsetPos = pos;
|
||||
this->onBoard = onBoard;
|
||||
this->pitchSpeed = unitData::pitchSpeed[id];
|
||||
}
|
||||
|
||||
if (!onBoard && aircraftCarrier) {
|
||||
if (orders.size() == 0) {
|
||||
Order o;
|
||||
o.type = Order::TYPE::MOVE;
|
||||
o.targetPos.push_back(new Vector3(lp));
|
||||
setOrder(o);
|
||||
}
|
||||
void Jet::update() {
|
||||
Unit::update();
|
||||
Vector3 lp = aircraftCarrier->getDirVec() * aircraftCarrier->getRunwayLength() + aircraftCarrier->getJetPos(jetId);
|
||||
|
||||
if (!landing
|
||||
&&aircraftCarrier
|
||||
&&pos.getDistanceFrom(lp) <= unitData::destinationOffset[id]
|
||||
&&*orders[0].targetPos[0] == lp){
|
||||
float angle = dirVec.getAngleBetween(aircraftCarrier->getDirVec()), maxAngle = PI - anglePrecision[id] / 180 * PI;
|
||||
if (!onBoard && aircraftCarrier) {
|
||||
if (orders.size() == 0) {
|
||||
Order o;
|
||||
o.type = Order::TYPE::MOVE;
|
||||
o.targetPos.push_back(new Vector3(lp));
|
||||
setOrder(o);
|
||||
}
|
||||
|
||||
if(!toTurnPoint && anglePrecision[id] / 180 * PI < angle && angle < maxAngle){
|
||||
float radius = getCircleRadius();
|
||||
Vector3 carrierSideVec = aircraftCarrier->getLeftVec().norm();
|
||||
Vector3 jetSideVec = leftVec.norm();
|
||||
if (!landing
|
||||
&&aircraftCarrier
|
||||
&&pos.getDistanceFrom(lp) <= unitData::destinationOffset[id]
|
||||
&&*orders[0].targetPos[0] == lp){
|
||||
float angle = dirVec.getAngleBetween(aircraftCarrier->getDirVec()), maxAngle = PI - anglePrecision[id] / 180 * PI;
|
||||
|
||||
if(carrierSideVec.getAngleBetween(dirVec) < PI / 2){
|
||||
carrierSideVec = -carrierSideVec;
|
||||
jetSideVec = -jetSideVec;
|
||||
}
|
||||
if(!toTurnPoint && anglePrecision[id] / 180 * PI < angle && angle < maxAngle){
|
||||
float radius = getCircleRadius();
|
||||
Vector3 carrierSideVec = aircraftCarrier->getLeftVec().norm();
|
||||
Vector3 jetSideVec = leftVec.norm();
|
||||
|
||||
Vector3 tanPoint = pos + (jetSideVec + carrierSideVec) * radius;
|
||||
float ang1 = (tanPoint - lp).getAngleBetween(carrierSideVec);
|
||||
float ang2 = dirVec.getAngleBetween(-carrierSideVec);
|
||||
float base = (tanPoint-lp).getLength() * cos(ang1);
|
||||
float hyp = base / cos(ang2);
|
||||
landingPos = (pos + dirVec * hyp);
|
||||
toTurnPoint = true;
|
||||
}
|
||||
else if(PI - angle < anglePrecision[id] / 180 * PI){
|
||||
onBoard = true;
|
||||
landing = true;
|
||||
orientUnit(-aircraftCarrier->getDirVec());
|
||||
if(carrierSideVec.getAngleBetween(dirVec) < PI / 2){
|
||||
carrierSideVec = -carrierSideVec;
|
||||
jetSideVec = -jetSideVec;
|
||||
}
|
||||
|
||||
Vector3 tanPoint = pos + (jetSideVec + carrierSideVec) * radius;
|
||||
float ang1 = (tanPoint - lp).getAngleBetween(carrierSideVec);
|
||||
float ang2 = dirVec.getAngleBetween(-carrierSideVec);
|
||||
float base = (tanPoint-lp).getLength() * cos(ang1);
|
||||
float hyp = base / cos(ang2);
|
||||
landingPos = (pos + dirVec * hyp);
|
||||
toTurnPoint = true;
|
||||
}
|
||||
else if(PI - angle < anglePrecision[id] / 180 * PI){
|
||||
onBoard = true;
|
||||
landing = true;
|
||||
orientUnit(-aircraftCarrier->getDirVec());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Jet::move(Order order, float offset) {
|
||||
if(toTurnPoint)
|
||||
turnAround();
|
||||
else{
|
||||
if(!onBoard)
|
||||
Unit::move(order, offset);
|
||||
else{
|
||||
if(landing)
|
||||
land();
|
||||
else
|
||||
takeOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Jet::lap(Vector3 destDir) {
|
||||
Vector3 center = pos - leftVec * getCircleRadius();
|
||||
Vector3 initCircleDir = -leftVec;
|
||||
float angle = initCircleDir.getAngleBetween(destDir);
|
||||
angle = (Quaternion(angle, upVec) * initCircleDir == destDir ? angle : 2 * PI - angle);
|
||||
Vector3 offsetDir = Quaternion(PI / 2, upVec) * destDir;
|
||||
Vector3 destDirPos = Quaternion(angle, upVec) * dirVec;
|
||||
Vector3 offsetDirPos = Quaternion(angle + PI / 2, upVec) * dirVec;
|
||||
Vector3 hypVec = *orders[0].targetPos[0] - destDirPos;
|
||||
float triAngle = hypVec.getAngleBetween(offsetDir);
|
||||
float distance = cos(triAngle) * hypVec.getLength();
|
||||
Vector3 destPoint = offsetDirPos + offsetDirPos.norm() * distance;
|
||||
float dirAngle = dirVec.getAngleBetween(offsetDir) * 180 / PI;
|
||||
float movementAmount;
|
||||
turn(maxTurnAngle > dirAngle ? dirAngle : maxTurnAngle);
|
||||
|
||||
if(dirAngle > unitData::anglePrecision[id])
|
||||
movementAmount = speed;
|
||||
else{
|
||||
float destDistance = (destPoint - pos).getLength();
|
||||
movementAmount = (speed > destDistance ? destDistance : speed);
|
||||
}
|
||||
|
||||
advance(movementAmount);
|
||||
}
|
||||
|
||||
void Jet::takeOff() {
|
||||
float distance = aircraftCarrier->getRunwayLength() - (pos - aircraftCarrier->getJetPos(jetId)).getLength();
|
||||
float movementAmmount = speed > distance ? distance : speed;
|
||||
advance(movementAmmount);
|
||||
distance -= movementAmmount;
|
||||
|
||||
if (distance <= 0.)
|
||||
onBoard = false;
|
||||
}
|
||||
|
||||
void Jet::land(){
|
||||
float distance = (pos - aircraftCarrier->getJetPos(jetId)).getLength();
|
||||
float movementAmmount = (speed > distance ? distance : speed);
|
||||
advance(movementAmmount);
|
||||
distance -= movementAmmount;
|
||||
|
||||
if (distance <= 0.){
|
||||
landing = false;
|
||||
|
||||
while(!orders.empty())
|
||||
orders.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void Jet::turnAround() {
|
||||
float distance=pos.getDistanceFrom(landingPos);
|
||||
float movementAmmount = (speed > distance ? distance : speed);
|
||||
advance(movementAmmount);
|
||||
distance -= movementAmmount;
|
||||
|
||||
if (distance <= 0.)
|
||||
toTurnPoint = false;
|
||||
}
|
||||
|
||||
void Jet::pitch(float angle) {
|
||||
Quaternion rotQuat = Quaternion(-angle / 180 * PI, leftVec);
|
||||
dirVec = rotQuat*dirVec, upVec = rotQuat*upVec;
|
||||
horAngle = angle;
|
||||
float yAngle = node->getOrientation().y;
|
||||
/*
|
||||
node->setOrientation(vector3df(angle, 0, 0));
|
||||
node->setOrientation(vector3df(angle, yAngle, 0));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void Jet::move(Order order, float offset) {
|
||||
if(toTurnPoint)
|
||||
turnAround();
|
||||
else{
|
||||
if(!onBoard)
|
||||
Unit::move(order, offset);
|
||||
else{
|
||||
if(landing)
|
||||
land();
|
||||
else
|
||||
takeOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Jet::lap(Vector3 destDir) {
|
||||
Vector3 center = pos - leftVec * getCircleRadius();
|
||||
Vector3 initCircleDir = -leftVec;
|
||||
float angle = initCircleDir.getAngleBetween(destDir);
|
||||
angle = (Quaternion(angle, upVec) * initCircleDir == destDir ? angle : 2 * PI - angle);
|
||||
Vector3 offsetDir = Quaternion(PI / 2, upVec) * destDir;
|
||||
Vector3 destDirPos = Quaternion(angle, upVec) * dirVec;
|
||||
Vector3 offsetDirPos = Quaternion(angle + PI / 2, upVec) * dirVec;
|
||||
Vector3 hypVec = *orders[0].targetPos[0] - destDirPos;
|
||||
float triAngle = hypVec.getAngleBetween(offsetDir);
|
||||
float distance = cos(triAngle) * hypVec.getLength();
|
||||
Vector3 destPoint = offsetDirPos + offsetDirPos.norm() * distance;
|
||||
float dirAngle = dirVec.getAngleBetween(offsetDir) * 180 / PI;
|
||||
float movementAmount;
|
||||
turn(maxTurnAngle > dirAngle ? dirAngle : maxTurnAngle);
|
||||
|
||||
if(dirAngle > unitData::anglePrecision[id])
|
||||
movementAmount = speed;
|
||||
else{
|
||||
float destDistance = (destPoint - pos).getLength();
|
||||
movementAmount = (speed > destDistance ? destDistance : speed);
|
||||
}
|
||||
|
||||
advance(movementAmount);
|
||||
}
|
||||
|
||||
void Jet::takeOff() {
|
||||
float distance = aircraftCarrier->getRunwayLength() - (pos - aircraftCarrier->getJetPos(jetId)).getLength();
|
||||
float movementAmmount = speed > distance ? distance : speed;
|
||||
advance(movementAmmount);
|
||||
distance -= movementAmmount;
|
||||
|
||||
if (distance <= 0.)
|
||||
onBoard = false;
|
||||
}
|
||||
|
||||
void Jet::land(){
|
||||
float distance = (pos - aircraftCarrier->getJetPos(jetId)).getLength();
|
||||
float movementAmmount = (speed > distance ? distance : speed);
|
||||
advance(movementAmmount);
|
||||
distance -= movementAmmount;
|
||||
|
||||
if (distance <= 0.){
|
||||
landing = false;
|
||||
|
||||
while(!orders.empty())
|
||||
orders.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void Jet::turnAround() {
|
||||
float distance=pos.getDistanceFrom(landingPos);
|
||||
float movementAmmount = (speed > distance ? distance : speed);
|
||||
advance(movementAmmount);
|
||||
distance -= movementAmmount;
|
||||
|
||||
if (distance <= 0.)
|
||||
toTurnPoint = false;
|
||||
}
|
||||
|
||||
void Jet::pitch(float angle) {
|
||||
Quaternion rotQuat = Quaternion(-angle / 180 * PI, leftVec);
|
||||
dirVec = rotQuat*dirVec, upVec = rotQuat*upVec;
|
||||
horAngle = angle;
|
||||
float yAngle = node->getOrientation().y;
|
||||
/*
|
||||
node->setOrientation(vector3df(angle, 0, 0));
|
||||
node->setOrientation(vector3df(angle, yAngle, 0));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,37 +8,35 @@
|
||||
#include "player.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class AircraftCarrier;
|
||||
|
||||
class Jet : public Unit {
|
||||
public:
|
||||
Jet(Player*, vb01::Vector3, int, bool);
|
||||
// virtual void attack(Order);
|
||||
virtual void update();
|
||||
inline void setJetId(int i){this->jetId = i;}
|
||||
inline void setAircraftCarrier(AircraftCarrier *a){aircraftCarrier = a;}
|
||||
inline bool isOnBoard(){return onBoard;}
|
||||
inline int getJetId(){return jetId;}
|
||||
inline AircraftCarrier* getAircraftCarrier(){return aircraftCarrier;}
|
||||
inline vb01::Vector3 getOffsetPos(){return offsetPos;}
|
||||
private:
|
||||
int jetId;
|
||||
vb01::Vector3 destDir,offsetPos;
|
||||
float horAngle = 0, pitchSpeed;
|
||||
void turnAround();
|
||||
void pitch(float);
|
||||
void lap(vb01::Vector3);
|
||||
protected:
|
||||
AircraftCarrier *aircraftCarrier = nullptr;
|
||||
vb01::Vector3 landingPos;
|
||||
bool onBoard = true, toTurnPoint = false, landing = false;
|
||||
void move(Order, float = 0.);
|
||||
void takeOff();
|
||||
void land();
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class AircraftCarrier;
|
||||
|
||||
class Jet : public Unit {
|
||||
public:
|
||||
Jet(Player*, vb01::Vector3, int, bool);
|
||||
//virtual void attack(Order);
|
||||
virtual void update();
|
||||
inline void setJetId(int i){this->jetId = i;}
|
||||
inline void setAircraftCarrier(AircraftCarrier *a){aircraftCarrier = a;}
|
||||
inline bool isOnBoard(){return onBoard;}
|
||||
inline int getJetId(){return jetId;}
|
||||
inline AircraftCarrier* getAircraftCarrier(){return aircraftCarrier;}
|
||||
inline vb01::Vector3 getOffsetPos(){return offsetPos;}
|
||||
private:
|
||||
int jetId;
|
||||
vb01::Vector3 destDir,offsetPos;
|
||||
float horAngle = 0, pitchSpeed;
|
||||
void turnAround();
|
||||
void pitch(float);
|
||||
void lap(vb01::Vector3);
|
||||
protected:
|
||||
AircraftCarrier *aircraftCarrier = nullptr;
|
||||
vb01::Vector3 landingPos;
|
||||
bool onBoard = true, toTurnPoint = false, landing = false;
|
||||
void move(Order, float = 0.);
|
||||
void takeOff();
|
||||
void land();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
6:巡航ミサイル
|
||||
*/
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
namespace unitData {
|
||||
const float pitchSpeed[numberOfUnits]{0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5};
|
||||
}
|
||||
namespace battleship {
|
||||
namespace unitData {
|
||||
const float pitchSpeed[numberOfUnits]{0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,57 +2,55 @@
|
||||
#ifndef KEY_H
|
||||
#define KEY_H
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
struct Mapping{
|
||||
enum Bind{
|
||||
LEFT_CLICK,
|
||||
SCROLLING_UP,
|
||||
SCROLLING_DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
DELETE_CHAR,
|
||||
CAPS_LOCK,
|
||||
SHIFT_CAPS,
|
||||
SPACE,
|
||||
PLUS,
|
||||
MINUS,
|
||||
DEVSTERISK,
|
||||
TOGGLE_MAIN_MENU,
|
||||
HALT,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
LOOK_AROUND,
|
||||
DRAG_BOX,
|
||||
DESELECT,
|
||||
LEFT_CONTROL,
|
||||
LEFT_SHIFT,
|
||||
SELECT_PATROL_POINTS,
|
||||
LAUNCH,
|
||||
TOGGLE_SUB,
|
||||
INSTALL_AWM,
|
||||
INSTALL_AAM,
|
||||
GROUP_0,
|
||||
GROUP_1,
|
||||
GROUP_2,
|
||||
GROUP_3,
|
||||
GROUP_4,
|
||||
GROUP_5,
|
||||
GROUP_6,
|
||||
GROUP_7,
|
||||
GROUP_8,
|
||||
GROUP_9,
|
||||
LAST_BIND
|
||||
};
|
||||
enum BindType{KEYBOARD, MOUSE_KEY, MOUSE_AXIS, JOYSTICK_KEY, JOYSTICK_AXIS};
|
||||
enum AuxTriggers{MOUSE_AXIS_LEFT = 310, MOUSE_AXIS_RIGHT = 311, MOUSE_AXIS_UP = 312, MOUSE_AXIS_DOWN = 313};
|
||||
|
||||
Bind bind;
|
||||
BindType type;
|
||||
int trigger;
|
||||
bool action, pressed = false;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
struct Mapping{
|
||||
enum Bind{
|
||||
LEFT_CLICK,
|
||||
SCROLLING_UP,
|
||||
SCROLLING_DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
DELETE_CHAR,
|
||||
CAPS_LOCK,
|
||||
SHIFT_CAPS,
|
||||
SPACE,
|
||||
PLUS,
|
||||
MINUS,
|
||||
DEVSTERISK,
|
||||
TOGGLE_MAIN_MENU,
|
||||
HALT,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
LOOK_AROUND,
|
||||
DRAG_BOX,
|
||||
DESELECT,
|
||||
LEFT_CONTROL,
|
||||
LEFT_SHIFT,
|
||||
SELECT_PATROL_POINTS,
|
||||
LAUNCH,
|
||||
TOGGLE_SUB,
|
||||
INSTALL_AWM,
|
||||
INSTALL_AAM,
|
||||
GROUP_0,
|
||||
GROUP_1,
|
||||
GROUP_2,
|
||||
GROUP_3,
|
||||
GROUP_4,
|
||||
GROUP_5,
|
||||
GROUP_6,
|
||||
GROUP_7,
|
||||
GROUP_8,
|
||||
GROUP_9,
|
||||
LAST_BIND
|
||||
};
|
||||
enum BindType{KEYBOARD, MOUSE_KEY, MOUSE_AXIS, JOYSTICK_KEY, JOYSTICK_AXIS};
|
||||
enum AuxTriggers{MOUSE_AXIS_LEFT = 310, MOUSE_AXIS_RIGHT = 311, MOUSE_AXIS_UP = 312, MOUSE_AXIS_DOWN = 313};
|
||||
|
||||
Bind bind;
|
||||
BindType type;
|
||||
int trigger;
|
||||
bool action, pressed = false;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "stateManager.h"
|
||||
#include "guiAppState.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace battleship;
|
||||
|
||||
int main() {
|
||||
GameManager *gameManager = GameManager::getSingleton();
|
||||
@@ -14,7 +14,7 @@ int main() {
|
||||
makeTitlescreenButtons(state);
|
||||
*/
|
||||
while(true){
|
||||
//gameManager->update();
|
||||
gameManager->update();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,43 +4,42 @@
|
||||
#include "gameManager.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Map::Map() {
|
||||
size = Vector2(50, 50);
|
||||
}
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
Map::~Map() {
|
||||
}
|
||||
|
||||
void Map::update() {
|
||||
}
|
||||
|
||||
void Map::load() {
|
||||
string path[]{
|
||||
PATH + "Textures/down.jpg",
|
||||
PATH + "Textures/left.jpg",
|
||||
PATH + "Textures/right.jpg",
|
||||
PATH + "Textures/front.jpg",
|
||||
PATH + "Textures/back.jpg"
|
||||
};
|
||||
|
||||
Root::getSingleton()->createSkybox(path);
|
||||
|
||||
/*
|
||||
waterMesh = smgr->addHillPlaneMesh("", dimension2d<float>(1, 1), dimension2d<u32>(30, 30), 0, .1, dimension2d<float>(2., 2.), dimension2d<float>(10, 10));
|
||||
waterNode = smgr->addWaterSurfaceSceneNode(waterMesh, .1, 900, 3);
|
||||
waterNode->setPosition(vector3df(0, 0, 0));
|
||||
waterNode->setMaterialTexture(0, driver->getTexture(PATH + "Textures/water-texture.png"));
|
||||
waterNode->setMaterialFlag(EMF_LIGHTING, true);
|
||||
waterNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
*/
|
||||
}
|
||||
|
||||
void Map::unload() {}
|
||||
Map::Map() {
|
||||
size = Vector2(50, 50);
|
||||
}
|
||||
|
||||
Map::~Map() {
|
||||
}
|
||||
|
||||
void Map::update() {
|
||||
}
|
||||
|
||||
void Map::load() {
|
||||
string path[]{
|
||||
PATH + "Textures/down.jpg",
|
||||
PATH + "Textures/left.jpg",
|
||||
PATH + "Textures/right.jpg",
|
||||
PATH + "Textures/front.jpg",
|
||||
PATH + "Textures/back.jpg"
|
||||
};
|
||||
|
||||
Root::getSingleton()->createSkybox(path);
|
||||
|
||||
/*
|
||||
waterMesh = smgr->addHillPlaneMesh("", dimension2d<float>(1, 1), dimension2d<u32>(30, 30), 0, .1, dimension2d<float>(2., 2.), dimension2d<float>(10, 10));
|
||||
waterNode = smgr->addWaterSurfaceSceneNode(waterMesh, .1, 900, 3);
|
||||
waterNode->setPosition(vector3df(0, 0, 0));
|
||||
waterNode->setMaterialTexture(0, driver->getTexture(PATH + "Textures/water-texture.png"));
|
||||
waterNode->setMaterialFlag(EMF_LIGHTING, true);
|
||||
waterNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
*/
|
||||
}
|
||||
|
||||
void Map::unload() {}
|
||||
}
|
||||
|
||||
@@ -4,25 +4,23 @@
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class Map {
|
||||
public:
|
||||
Map();
|
||||
~Map();
|
||||
void update();
|
||||
void load();
|
||||
void unload();
|
||||
inline vb01::Vector2 getSize(){return size;}
|
||||
private:
|
||||
vb01::Vector2 size;
|
||||
/*
|
||||
irr::scene::ILightSceneNode *sunLight;
|
||||
irr::scene::IAnimatedMesh *waterMesh;
|
||||
irr::scene::ISceneNode *waterNode;
|
||||
*/
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class Map {
|
||||
public:
|
||||
Map();
|
||||
~Map();
|
||||
void update();
|
||||
void load();
|
||||
void unload();
|
||||
inline vb01::Vector2 getSize(){return size;}
|
||||
private:
|
||||
vb01::Vector2 size;
|
||||
/*
|
||||
irr::scene::ILightSceneNode *sunLight;
|
||||
irr::scene::IAnimatedMesh *waterMesh;
|
||||
irr::scene::ISceneNode *waterNode;
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+20
-24
@@ -3,33 +3,29 @@
|
||||
|
||||
#include "missile.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Missile::Missile(Unit *unit, Node *node, Vector3 *target, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, node, pos, dir, left, up, id, weaponTypeId, weaponId) {
|
||||
this->target = target;
|
||||
this->type = (MissileType)weaponId;
|
||||
this->initTime = getTime();
|
||||
}
|
||||
|
||||
void Missile::update() {
|
||||
Projectile::update();
|
||||
pos = pos + dirVec * speed;
|
||||
node->setPosition(pos);
|
||||
float angle = dirVec.getAngleBetween(*target - pos);
|
||||
Vector3 axis = dirVec.cross(*target - pos).norm();
|
||||
namespace battleship{
|
||||
Missile::Missile(Unit *unit, Node *node, Vector3 *target, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, node, pos, dir, left, up, id, weaponTypeId, weaponId) {
|
||||
this->target = target;
|
||||
this->type = (MissileType)weaponId;
|
||||
this->initTime = getTime();
|
||||
}
|
||||
|
||||
void Missile::update() {
|
||||
Projectile::update();
|
||||
pos = pos + dirVec * speed;
|
||||
node->setPosition(pos);
|
||||
float angle = dirVec.getAngleBetween(*target - pos);
|
||||
Vector3 axis = dirVec.cross(*target - pos).norm();
|
||||
|
||||
if(rotationSpeed / 180 * PI < angle){
|
||||
Quaternion rotQuat = Quaternion(rotationSpeed / 180 * PI, axis);
|
||||
orientProjectile(rotQuat * dirVec);
|
||||
}
|
||||
|
||||
if(!exploded && getTime() - initTime > selfDistructTime)
|
||||
Projectile::explode(nullptr);
|
||||
if(rotationSpeed / 180 * PI < angle){
|
||||
Quaternion rotQuat = Quaternion(rotationSpeed / 180 * PI, axis);
|
||||
orientProjectile(rotQuat * dirVec);
|
||||
}
|
||||
|
||||
if(!exploded && getTime() - initTime > selfDistructTime)
|
||||
Projectile::explode(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,21 @@
|
||||
|
||||
#include "projectile.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
enum MissileType {AAM, AWM};
|
||||
|
||||
class Missile : public Projectile {
|
||||
public:
|
||||
Missile(Unit*, vb01::Node*, vb01::Vector3*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~Missile(){}
|
||||
void update();
|
||||
private:
|
||||
s64 initTime;
|
||||
int selfDistructTime = 10000;
|
||||
vb01::Vector3 *target;
|
||||
float rotationSpeed = 5;
|
||||
MissileType type;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
enum MissileType {AAM, AWM};
|
||||
|
||||
class Missile : public Projectile {
|
||||
public:
|
||||
Missile(Unit*, vb01::Node*, vb01::Vector3*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~Missile(){}
|
||||
void update();
|
||||
private:
|
||||
s64 initTime;
|
||||
int selfDistructTime = 10000;
|
||||
vb01::Vector3 *target;
|
||||
float rotationSpeed = 5;
|
||||
MissileType type;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+13
-14
@@ -2,22 +2,21 @@
|
||||
#ifndef MISSILEDATA_H
|
||||
#define MISSILEDATA_H
|
||||
|
||||
#include "unitData.h"
|
||||
#include "projectileData.h"
|
||||
|
||||
namespace unitSpace{
|
||||
namespace projectileSpace{
|
||||
namespace projectileData{
|
||||
const int selfDestructTime[numberOfUnits][13]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{10000,10000}
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
namespace projectileData{
|
||||
const int selfDestructTime[unitData::numberOfUnits][13]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{10000,10000}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+58
-60
@@ -5,81 +5,79 @@
|
||||
#include "inGameAppState.h"
|
||||
#include "stateManager.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
MissileJet::MissileJet(Player *player, Vector3 pos, int id, bool onBoard) : Jet(player, pos, id, onBoard) {}
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
void MissileJet::attack(Order order) {
|
||||
if(!onBoard && canFire() && missilesInstalled){
|
||||
Vector3 target = *order.targetPos[0];
|
||||
float distance=pos.getDistanceFrom(target);
|
||||
MissileJet::MissileJet(Player *player, Vector3 pos, int id, bool onBoard) : Jet(player, pos, id, onBoard) {}
|
||||
|
||||
if(distance <= range){
|
||||
Vector3 *targetPtr = nullptr;
|
||||
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
void MissileJet::attack(Order order) {
|
||||
if(!onBoard && canFire() && missilesInstalled){
|
||||
Vector3 target = *order.targetPos[0];
|
||||
float distance=pos.getDistanceFrom(target);
|
||||
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits()){
|
||||
bool jet = (u->getType() == UNIT_TYPE::MISSILE_JET || u->getType() == UNIT_TYPE::DEMO_JET);
|
||||
if((jet && type == AAM) && (!jet && type == AWM) && u->getPosPtr() == order.targetPos[0])
|
||||
targetPtr = u->getPosPtr();
|
||||
}
|
||||
|
||||
if(!targetPtr){
|
||||
targetPtr = new Vector3();
|
||||
*targetPtr = target;
|
||||
if(distance <= range){
|
||||
Vector3 *targetPtr = nullptr;
|
||||
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits()){
|
||||
bool jet = (u->getType() == UNIT_TYPE::MISSILE_JET || u->getType() == UNIT_TYPE::DEMO_JET);
|
||||
if((jet && type == AAM) && (!jet && type == AWM) && u->getPosPtr() == order.targetPos[0])
|
||||
targetPtr = u->getPosPtr();
|
||||
}
|
||||
|
||||
fireMissile(targetPtr);
|
||||
|
||||
if(!targetPtr){
|
||||
targetPtr = new Vector3();
|
||||
*targetPtr = target;
|
||||
}
|
||||
else
|
||||
Unit::attack(order);
|
||||
|
||||
fireMissile(targetPtr);
|
||||
}
|
||||
else if(onBoard)
|
||||
takeOff();
|
||||
else
|
||||
removeOrder(0);
|
||||
Unit::attack(order);
|
||||
}
|
||||
else if(onBoard)
|
||||
takeOff();
|
||||
else
|
||||
removeOrder(0);
|
||||
}
|
||||
|
||||
void MissileJet::fireMissile(Vector3 *t) {
|
||||
Vector3 p = pos + leftVec * projectileData::pos[id][0][missiles - 1].x + upVec * projectileData::pos[id][0][missiles - 1].y - dirVec * projectileData::pos[id][0][missiles - 1].z;
|
||||
addProjectile(new Missile(this, missileNodes[missiles-1], t, p, dirVec, leftVec, upVec, id, 0, 0));
|
||||
missileNodes[missiles-1]->setParent(Root::getSingleton()->getRootNode());
|
||||
missileNodes[missiles-1] = nullptr;
|
||||
missiles--;
|
||||
lastFireTime=getTime();
|
||||
}
|
||||
|
||||
void MissileJet::installMissiles(bool aam){
|
||||
/*
|
||||
if(!missilesInstalled){
|
||||
missiles=2;
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
ISceneManager *smgr = gm->getDevice()->getSceneManager();
|
||||
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
|
||||
void MissileJet::fireMissile(Vector3 *t) {
|
||||
Vector3 p = pos + leftVec * projectileData::pos[id][0][missiles - 1].x + upVec * projectileData::pos[id][0][missiles - 1].y - dirVec * projectileData::pos[id][0][missiles - 1].z;
|
||||
addProjectile(new Missile(this, missileNodes[missiles-1], t, p, dirVec, leftVec, upVec, id, 0, 0));
|
||||
missileNodes[missiles-1]->setParent(Root::getSingleton()->getRootNode());
|
||||
missileNodes[missiles-1] = nullptr;
|
||||
missiles--;
|
||||
lastFireTime=getTime();
|
||||
}
|
||||
|
||||
void MissileJet::installMissiles(bool aam){
|
||||
/*
|
||||
if(!missilesInstalled){
|
||||
missiles=2;
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
ISceneManager *smgr = gm->getDevice()->getSceneManager();
|
||||
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
|
||||
|
||||
for(int i=0;i<missiles;i++){
|
||||
IAnimatedMesh *missileMesh=smgr->getMesh(projectileData::meshPath[id][i]);
|
||||
missileNodes[i]=smgr->addAnimatedMeshSceneNode(missileMesh);
|
||||
ITexture *diffuseTexture = driver->getTexture(projectileData::diffuseMapTextPath[id][i]);
|
||||
for(int i=0;i<missiles;i++){
|
||||
IAnimatedMesh *missileMesh=smgr->getMesh(projectileData::meshPath[id][i]);
|
||||
missileNodes[i]=smgr->addAnimatedMeshSceneNode(missileMesh);
|
||||
ITexture *diffuseTexture = driver->getTexture(projectileData::diffuseMapTextPath[id][i]);
|
||||
|
||||
if (!diffuseTexture)
|
||||
diffuseTexture = driver->getTexture(DEFAULT_TEXTURE);
|
||||
if (!diffuseTexture)
|
||||
diffuseTexture = driver->getTexture(DEFAULT_TEXTURE);
|
||||
|
||||
missileNodes[i]->setMaterialTexture(0, diffuseTexture);
|
||||
missileNodes[i]->setMaterialFlag(EMF_LIGHTING, false);
|
||||
missileNodes[i]->setPosition(projectileData::pos[id][aam][i]);
|
||||
missileNodes[i]->setParent(node);
|
||||
}
|
||||
|
||||
type=(MissileType)aam;
|
||||
missilesInstalled=true;
|
||||
missileNodes[i]->setMaterialTexture(0, diffuseTexture);
|
||||
missileNodes[i]->setMaterialFlag(EMF_LIGHTING, false);
|
||||
missileNodes[i]->setPosition(projectileData::pos[id][aam][i]);
|
||||
missileNodes[i]->setParent(node);
|
||||
}
|
||||
*/
|
||||
|
||||
type=(MissileType)aam;
|
||||
missilesInstalled=true;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
+15
-17
@@ -8,23 +8,21 @@
|
||||
#include "player.h"
|
||||
#include "missile.h"
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
class MissileJet : public Jet {
|
||||
public:
|
||||
MissileJet(Player*, vb01::Vector3, int, bool = 1);
|
||||
void installMissiles(bool);
|
||||
private:
|
||||
void attack(Order);
|
||||
void fireMissile(vb01::Vector3*);
|
||||
inline bool canFire() {return missiles > 0 && vb01::getTime() - lastFireTime > rateOfFire;}
|
||||
MissileType type;
|
||||
vb01::Node *missileNodes[2]{nullptr,nullptr};
|
||||
bool missilesInstalled = false;
|
||||
int missiles = 0, rateOfFire = 2001;
|
||||
s64 lastFireTime = 0;
|
||||
};
|
||||
}
|
||||
namespace battleship {
|
||||
class MissileJet : public Jet {
|
||||
public:
|
||||
MissileJet(Player*, vb01::Vector3, int, bool = 1);
|
||||
void installMissiles(bool);
|
||||
private:
|
||||
void attack(Order);
|
||||
void fireMissile(vb01::Vector3*);
|
||||
inline bool canFire() {return missiles > 0 && vb01::getTime() - lastFireTime > rateOfFire;}
|
||||
MissileType type;
|
||||
vb01::Node *missileNodes[2]{nullptr,nullptr};
|
||||
bool missilesInstalled = false;
|
||||
int missiles = 0, rateOfFire = 2001;
|
||||
s64 lastFireTime = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+196
-197
@@ -2,218 +2,217 @@
|
||||
#include "stateManager.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace vb01Gui;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
OptionsButton::OkButton::OkButton() : Button(Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Ok", true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::OkButton::onClick() {
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
OptionsButton::OkButton::OkButton() : Button(Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Ok", true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::OkButton::onClick() {
|
||||
|
||||
}
|
||||
|
||||
OptionsButton::DefaultsButton::DefaultsButton() : Button(Vector2(200, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Restore defaults", true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::DefaultsButton::onClick() {
|
||||
|
||||
}
|
||||
|
||||
OptionsButton::BackButton::BackButton() : Button(Vector2(350, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Back", true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::BackButton::onClick() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
gm->detachAllBitmapTexts();
|
||||
gm->detachAllImages();
|
||||
*/
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
state->removeButton("Ok");
|
||||
state->removeButton("Restore defaults");
|
||||
OptionsButton *optionsButton = new OptionsButton(Vector2(), Vector2(), "Options", true);
|
||||
optionsButton->onClick();
|
||||
state->removeButton("Back");
|
||||
}
|
||||
|
||||
OptionsButton::TabButton::TabButton(Vector2 pos, Vector2 size, string name) :Button(pos, size, name, true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::TabButton::onClick() {
|
||||
state->removeButton("Back");
|
||||
OkButton *okButton = new OkButton();
|
||||
DefaultsButton *defaultsButton = new DefaultsButton();
|
||||
BackButton *returnButton = new BackButton();
|
||||
//defaultsButton->moveText(-25, 0);
|
||||
state->addButton(okButton);
|
||||
state->addButton(defaultsButton);
|
||||
state->addButton(returnButton);
|
||||
}
|
||||
|
||||
OptionsButton::ControlsTab::ControlsTab() : TabButton(
|
||||
Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10),
|
||||
Vector2(100, 50),
|
||||
"Controls"
|
||||
) {}
|
||||
|
||||
void OptionsButton::ControlsTab::onClick() {
|
||||
TabButton::onClick();
|
||||
std::vector<string> lines;
|
||||
readFile(PATH + "../options.cfg", lines);
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Listbox *listbox = new Listbox(Vector2(gm->getWidth() / 4, gm->getHeight() / 10), Vector2(360, 20), lines, lines.size() < 5 ? lines.size() : 5, PATH + "Fonts/batang.ttf", Listbox::CONTROLS);
|
||||
listbox->openUp();
|
||||
|
||||
state->addListbox(listbox);
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Controls");
|
||||
}
|
||||
|
||||
OptionsButton::MouseTab::MouseTab() : TabButton(
|
||||
Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 60),
|
||||
Vector2(100, 50),
|
||||
"Mouse"
|
||||
) {}
|
||||
|
||||
void OptionsButton::MouseTab::onClick() {
|
||||
TabButton::onClick();
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 4);
|
||||
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Slider *mouseSensitivitySlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), .1, 3.);
|
||||
Textbox *mouseSensitivityTextbox = new Textbox(Vector2(pos.x + 320, pos.y - 10), Vector2(100, 20), font);
|
||||
Checkbox *reverseMouseCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50));
|
||||
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("MouseSensitivity", vector2d<s32>(gm->getWidth() / 3 - 90, gm->getHeight() / 4 - 5), font));
|
||||
gm->attachBitmapText(new BitmapText("ReverseMouse", vector2d<s32>(gm->getWidth() / 3 + 20, gm->getHeight() / 4 + 50), font));
|
||||
*/
|
||||
|
||||
state->addTextbox(mouseSensitivityTextbox);
|
||||
state->addSlider(mouseSensitivitySlider);
|
||||
state->addCheckbox(reverseMouseCheckbox);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Mouse");
|
||||
}
|
||||
|
||||
OptionsButton::VideoTab::VideoTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 120), Vector2(100, 50), "Video") {}
|
||||
void OptionsButton::VideoTab::onClick() {
|
||||
TabButton::onClick();
|
||||
std::vector<string> lines;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
string s;
|
||||
s += i;
|
||||
lines.push_back(s);
|
||||
}
|
||||
|
||||
OptionsButton::DefaultsButton::DefaultsButton() : Button(Vector2(200, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Restore defaults", true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::DefaultsButton::onClick() {
|
||||
|
||||
}
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 8);
|
||||
Listbox *resolutionsListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(100, 20), lines, 5, font);
|
||||
|
||||
OptionsButton::BackButton::BackButton() : Button(Vector2(350, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Back", true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::BackButton::onClick() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
gm->detachAllBitmapTexts();
|
||||
gm->detachAllImages();
|
||||
*/
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
state->removeButton("Ok");
|
||||
state->removeButton("Restore defaults");
|
||||
OptionsButton *optionsButton = new OptionsButton(Vector2(), Vector2(), "Options", true);
|
||||
optionsButton->onClick();
|
||||
state->removeButton("Back");
|
||||
}
|
||||
Checkbox *fullscreenCheckbox = new Checkbox(Vector2(pos.x, pos.y + 30));
|
||||
Checkbox *vsyncCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50));
|
||||
Checkbox *normalMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 70));
|
||||
Checkbox *parallaxMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 90));
|
||||
Checkbox *specularMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 110));
|
||||
|
||||
OptionsButton::TabButton::TabButton(Vector2 pos, Vector2 size, string name) :Button(pos, size, name, true) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::TabButton::onClick() {
|
||||
state->removeButton("Back");
|
||||
OkButton *okButton = new OkButton();
|
||||
DefaultsButton *defaultsButton = new DefaultsButton();
|
||||
BackButton *returnButton = new BackButton();
|
||||
//defaultsButton->moveText(-25, 0);
|
||||
state->addButton(okButton);
|
||||
state->addButton(defaultsButton);
|
||||
state->addButton(returnButton);
|
||||
}
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("Fullscreen", vector2d<s32>(pos.X + 20, pos.Y + 30), font));
|
||||
gm->attachBitmapText(new BitmapText("VSync", vector2d<s32>(pos.X + 20, pos.Y + 50), font));
|
||||
gm->attachBitmapText(new BitmapText("Normal map", vector2d<s32>(pos.X + 20, pos.Y + 70), font));
|
||||
gm->attachBitmapText(new BitmapText("Parallax map", vector2d<s32>(pos.X + 20, pos.Y + 90), font));
|
||||
gm->attachBitmapText(new BitmapText("Specular map", vector2d<s32>(pos.X + 20, pos.Y + 110), font));
|
||||
*/
|
||||
|
||||
OptionsButton::ControlsTab::ControlsTab() : TabButton(
|
||||
Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10),
|
||||
Vector2(100, 50),
|
||||
"Controls"
|
||||
) {}
|
||||
state->addListbox(resolutionsListbox);
|
||||
state->addCheckbox(fullscreenCheckbox);
|
||||
state->addCheckbox(vsyncCheckbox);
|
||||
state->addCheckbox(normalMapCheckbox);
|
||||
state->addCheckbox(parallaxMapCheckbox);
|
||||
state->addCheckbox(specularMapCheckbox);
|
||||
|
||||
void OptionsButton::ControlsTab::onClick() {
|
||||
TabButton::onClick();
|
||||
std::vector<string> lines;
|
||||
readFile(PATH + "../options.cfg", lines);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Video");
|
||||
}
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Listbox *listbox = new Listbox(Vector2(gm->getWidth() / 4, gm->getHeight() / 10), Vector2(360, 20), lines, lines.size() < 5 ? lines.size() : 5, PATH + "Fonts/batang.ttf", Listbox::CONTROLS);
|
||||
listbox->openUp();
|
||||
OptionsButton::AudioTab::AudioTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 180), Vector2(100, 50), "Audio") {}
|
||||
void OptionsButton::AudioTab::onClick() {
|
||||
TabButton::onClick();
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Vector2 pos(gm->getWidth() / 3, gm->getHeight() / 8);
|
||||
Slider *volumeSlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), 0., 2.);
|
||||
Textbox *volumeTextbox = new Textbox(Vector2(pos.x + 320, pos.y), Vector2(100, 20), PATH + "Fonts/batang.ttf");
|
||||
state->addTextbox(volumeTextbox);
|
||||
state->addSlider(volumeSlider);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Audio");
|
||||
}
|
||||
|
||||
state->addListbox(listbox);
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Controls");
|
||||
}
|
||||
OptionsButton::MultiplayerTab::MultiplayerTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 240), Vector2(100, 50), "Multiplayer") {}
|
||||
void OptionsButton::MultiplayerTab::onClick() {
|
||||
TabButton::onClick();
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 6);
|
||||
Textbox *tcpTextbox = new Textbox(Vector2(pos.x, pos.y), Vector2(100, 20), font);
|
||||
Textbox *udpTextbox = new Textbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), font);
|
||||
Textbox *playerNameTextbox = new Textbox(Vector2(pos.x, pos.y + 60), Vector2(100, 20), font);
|
||||
|
||||
OptionsButton::MouseTab::MouseTab() : TabButton(
|
||||
Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 60),
|
||||
Vector2(100, 50),
|
||||
"Mouse"
|
||||
) {}
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("TCP port", vector2d<s32>(pos.X - 50, pos.Y), font));
|
||||
gm->attachBitmapText(new BitmapText("UDP port", vector2d<s32>(pos.X - 50, pos.Y + 30), font));
|
||||
gm->attachBitmapText(new BitmapText("Player name", vector2d<s32>(pos.X - 65, pos.Y + 60), font));
|
||||
*/
|
||||
|
||||
void OptionsButton::MouseTab::onClick() {
|
||||
TabButton::onClick();
|
||||
state->addTextbox(tcpTextbox);
|
||||
state->addTextbox(udpTextbox);
|
||||
state->addTextbox(playerNameTextbox);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
}
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 4);
|
||||
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Slider *mouseSensitivitySlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), .1, 3.);
|
||||
Textbox *mouseSensitivityTextbox = new Textbox(Vector2(pos.x + 320, pos.y - 10), Vector2(100, 20), font);
|
||||
Checkbox *reverseMouseCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50));
|
||||
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("MouseSensitivity", vector2d<s32>(gm->getWidth() / 3 - 90, gm->getHeight() / 4 - 5), font));
|
||||
gm->attachBitmapText(new BitmapText("ReverseMouse", vector2d<s32>(gm->getWidth() / 3 + 20, gm->getHeight() / 4 + 50), font));
|
||||
*/
|
||||
|
||||
state->addTextbox(mouseSensitivityTextbox);
|
||||
state->addSlider(mouseSensitivitySlider);
|
||||
state->addCheckbox(reverseMouseCheckbox);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Mouse");
|
||||
}
|
||||
|
||||
OptionsButton::VideoTab::VideoTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 120), Vector2(100, 50), "Video") {}
|
||||
void OptionsButton::VideoTab::onClick() {
|
||||
TabButton::onClick();
|
||||
std::vector<string> lines;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
string s;
|
||||
s += i;
|
||||
lines.push_back(s);
|
||||
}
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 8);
|
||||
Listbox *resolutionsListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(100, 20), lines, 5, font);
|
||||
|
||||
Checkbox *fullscreenCheckbox = new Checkbox(Vector2(pos.x, pos.y + 30));
|
||||
Checkbox *vsyncCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50));
|
||||
Checkbox *normalMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 70));
|
||||
Checkbox *parallaxMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 90));
|
||||
Checkbox *specularMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 110));
|
||||
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("Fullscreen", vector2d<s32>(pos.X + 20, pos.Y + 30), font));
|
||||
gm->attachBitmapText(new BitmapText("VSync", vector2d<s32>(pos.X + 20, pos.Y + 50), font));
|
||||
gm->attachBitmapText(new BitmapText("Normal map", vector2d<s32>(pos.X + 20, pos.Y + 70), font));
|
||||
gm->attachBitmapText(new BitmapText("Parallax map", vector2d<s32>(pos.X + 20, pos.Y + 90), font));
|
||||
gm->attachBitmapText(new BitmapText("Specular map", vector2d<s32>(pos.X + 20, pos.Y + 110), font));
|
||||
*/
|
||||
|
||||
state->addListbox(resolutionsListbox);
|
||||
state->addCheckbox(fullscreenCheckbox);
|
||||
state->addCheckbox(vsyncCheckbox);
|
||||
state->addCheckbox(normalMapCheckbox);
|
||||
state->addCheckbox(parallaxMapCheckbox);
|
||||
state->addCheckbox(specularMapCheckbox);
|
||||
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Video");
|
||||
}
|
||||
|
||||
OptionsButton::AudioTab::AudioTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 180), Vector2(100, 50), "Audio") {}
|
||||
void OptionsButton::AudioTab::onClick() {
|
||||
TabButton::onClick();
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
Vector2 pos(gm->getWidth() / 3, gm->getHeight() / 8);
|
||||
Slider *volumeSlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), 0., 2.);
|
||||
Textbox *volumeTextbox = new Textbox(Vector2(pos.x + 320, pos.y), Vector2(100, 20), PATH + "Fonts/batang.ttf");
|
||||
state->addTextbox(volumeTextbox);
|
||||
state->addSlider(volumeSlider);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeButton("Audio");
|
||||
}
|
||||
|
||||
OptionsButton::MultiplayerTab::MultiplayerTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 240), Vector2(100, 50), "Multiplayer") {}
|
||||
void OptionsButton::MultiplayerTab::onClick() {
|
||||
TabButton::onClick();
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 6);
|
||||
Textbox *tcpTextbox = new Textbox(Vector2(pos.x, pos.y), Vector2(100, 20), font);
|
||||
Textbox *udpTextbox = new Textbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), font);
|
||||
Textbox *playerNameTextbox = new Textbox(Vector2(pos.x, pos.y + 60), Vector2(100, 20), font);
|
||||
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("TCP port", vector2d<s32>(pos.X - 50, pos.Y), font));
|
||||
gm->attachBitmapText(new BitmapText("UDP port", vector2d<s32>(pos.X - 50, pos.Y + 30), font));
|
||||
gm->attachBitmapText(new BitmapText("Player name", vector2d<s32>(pos.X - 65, pos.Y + 60), font));
|
||||
*/
|
||||
|
||||
state->addTextbox(tcpTextbox);
|
||||
state->addTextbox(udpTextbox);
|
||||
state->addTextbox(playerNameTextbox);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
}
|
||||
|
||||
OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::onClick() {
|
||||
ControlsTab *controlsTab = new ControlsTab();
|
||||
MouseTab *mouseTab = new MouseTab();
|
||||
VideoTab *videoTab = new VideoTab();
|
||||
AudioTab *audioTab = new AudioTab();
|
||||
MultiplayerTab *mupltiplayerTab = new MultiplayerTab();
|
||||
//mupltiplayerTab->moveText(-20, 0);
|
||||
state->addButton(controlsTab);
|
||||
state->addButton(mouseTab);
|
||||
state->addButton(videoTab);
|
||||
state->addButton(audioTab);
|
||||
state->addButton(mupltiplayerTab);
|
||||
state->removeButton(this);
|
||||
}
|
||||
OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
}
|
||||
void OptionsButton::onClick() {
|
||||
ControlsTab *controlsTab = new ControlsTab();
|
||||
MouseTab *mouseTab = new MouseTab();
|
||||
VideoTab *videoTab = new VideoTab();
|
||||
AudioTab *audioTab = new AudioTab();
|
||||
MultiplayerTab *mupltiplayerTab = new MultiplayerTab();
|
||||
//mupltiplayerTab->moveText(-20, 0);
|
||||
state->addButton(controlsTab);
|
||||
state->addButton(mouseTab);
|
||||
state->addButton(videoTab);
|
||||
state->addButton(audioTab);
|
||||
state->addButton(mupltiplayerTab);
|
||||
state->removeButton(this);
|
||||
}
|
||||
}
|
||||
|
||||
+108
-110
@@ -7,118 +7,116 @@
|
||||
#include "guiAppState.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace game{
|
||||
namespace gui {
|
||||
class OptionsButton : public vb01Gui::Button {
|
||||
namespace battleship {
|
||||
class OptionsButton : public vb01Gui::Button {
|
||||
public:
|
||||
OptionsButton(vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
class OkButton : public Button {
|
||||
public:
|
||||
OptionsButton(vb01::Vector2, vb01::Vector2, std::string, bool);
|
||||
class OkButton : public Button {
|
||||
public:
|
||||
OkButton();
|
||||
void onClick();
|
||||
private:
|
||||
core::GuiAppState *state;
|
||||
};
|
||||
class DefaultsButton : public Button {
|
||||
public:
|
||||
DefaultsButton();
|
||||
void onClick();
|
||||
private:
|
||||
core::GuiAppState *state;
|
||||
};
|
||||
class BackButton : public Button {
|
||||
public:
|
||||
BackButton();
|
||||
void onClick();
|
||||
private:
|
||||
core::GuiAppState *state;
|
||||
};
|
||||
class TabButton : public Button {
|
||||
public:
|
||||
TabButton(vb01::Vector2, vb01::Vector2, std::string);
|
||||
void onClick();
|
||||
protected:
|
||||
core::GuiAppState *state;
|
||||
};
|
||||
class ControlsTab : public TabButton {
|
||||
public:
|
||||
ControlsTab();
|
||||
void onClick();
|
||||
};
|
||||
class MouseTab : public TabButton {
|
||||
public:
|
||||
MouseTab();
|
||||
void onClick();
|
||||
private:
|
||||
};
|
||||
class VideoTab : public TabButton {
|
||||
public:
|
||||
VideoTab();
|
||||
void onClick();
|
||||
};
|
||||
class AudioTab : public TabButton {
|
||||
public:
|
||||
AudioTab();
|
||||
void onClick();
|
||||
};
|
||||
class MultiplayerTab : public TabButton {
|
||||
public:
|
||||
MultiplayerTab();
|
||||
void onClick();
|
||||
};
|
||||
virtual void onClick();
|
||||
/*
|
||||
class ReturnButton :public Button {
|
||||
public:
|
||||
ReturnButton(GuiAppState *state, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) :Button(gM, pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
void onClick() {
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllTextboxes();
|
||||
state->removeAllSliders();
|
||||
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
|
||||
SpButton *spButton = new SpButton(state, gameManager, vector2d<s32>(driver->getScreenSize().Width / 16, driver->getScreenSize().Height / 12), vector2d<s32>(150, 40), "Singleplayer", true);
|
||||
OptionsButton *optionsButton = new OptionsButton(state, gameManager, vector2d<s32>(driver->getScreenSize().Width / 16, driver->getScreenSize().Height / 12 * 2), vector2d<s32>(150, 40), "Options", true);
|
||||
ExitButton *exitButton = new ExitButton(gameManager, vector2d<s32>(driver->getScreenSize().Width / 16, driver->getScreenSize().Height / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
|
||||
state->addButton(spButton);
|
||||
state->addButton(optionsButton);
|
||||
state->addButton(exitButton);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
state->removeButton("Back");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
*/
|
||||
/*ControlsTab *controlsTab = new ControlsTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10), vector2d<s32>(100, 50), "Controls", true);
|
||||
MouseTab *mouseTab = new MouseTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 60), vector2d<s32>(100, 50), "Mouse", true);
|
||||
VideoTab *videoTab = new VideoTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 120), vector2d<s32>(100, 50), "Video", true);
|
||||
AudioTab *audioTab = new AudioTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 180), vector2d<s32>(100, 50), "Audio", true);
|
||||
MultiplayerTab *mupltiplayerTab = new MultiplayerTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 240), vector2d<s32>(100, 50), "Multiplayer", true);
|
||||
//ReturnButton *returnButton = new ReturnButton(state, this->gameManager, vector2d<s32>(50, gameManager->getHeight() - 150), vector2d<s32>(140, 50), "Back", true);
|
||||
//state->addButton(returnButton);
|
||||
mupltiplayerTab->moveText(-20, 0);
|
||||
state->addButton(controlsTab);
|
||||
state->addButton(mouseTab);
|
||||
state->addButton(videoTab);
|
||||
state->addButton(audioTab);
|
||||
state->addButton(mupltiplayerTab);
|
||||
state->removeButton("Exit");
|
||||
state->removeButton("Singleplayer");
|
||||
state->removeButton("Options");*/
|
||||
core::GuiAppState *state;
|
||||
OkButton();
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
}
|
||||
class DefaultsButton : public Button {
|
||||
public:
|
||||
DefaultsButton();
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
class BackButton : public Button {
|
||||
public:
|
||||
BackButton();
|
||||
void onClick();
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
class TabButton : public Button {
|
||||
public:
|
||||
TabButton(vb01::Vector2, vb01::Vector2, std::string);
|
||||
void onClick();
|
||||
protected:
|
||||
GuiAppState *state;
|
||||
};
|
||||
class ControlsTab : public TabButton {
|
||||
public:
|
||||
ControlsTab();
|
||||
void onClick();
|
||||
};
|
||||
class MouseTab : public TabButton {
|
||||
public:
|
||||
MouseTab();
|
||||
void onClick();
|
||||
private:
|
||||
};
|
||||
class VideoTab : public TabButton {
|
||||
public:
|
||||
VideoTab();
|
||||
void onClick();
|
||||
};
|
||||
class AudioTab : public TabButton {
|
||||
public:
|
||||
AudioTab();
|
||||
void onClick();
|
||||
};
|
||||
class MultiplayerTab : public TabButton {
|
||||
public:
|
||||
MultiplayerTab();
|
||||
void onClick();
|
||||
};
|
||||
virtual void onClick();
|
||||
/*
|
||||
class ReturnButton :public Button {
|
||||
public:
|
||||
ReturnButton(GuiAppState *state, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) :Button(gM, pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
void onClick() {
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllTextboxes();
|
||||
state->removeAllSliders();
|
||||
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
|
||||
SpButton *spButton = new SpButton(state, gameManager, vector2d<s32>(driver->getScreenSize().Width / 16, driver->getScreenSize().Height / 12), vector2d<s32>(150, 40), "Singleplayer", true);
|
||||
OptionsButton *optionsButton = new OptionsButton(state, gameManager, vector2d<s32>(driver->getScreenSize().Width / 16, driver->getScreenSize().Height / 12 * 2), vector2d<s32>(150, 40), "Options", true);
|
||||
ExitButton *exitButton = new ExitButton(gameManager, vector2d<s32>(driver->getScreenSize().Width / 16, driver->getScreenSize().Height / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
|
||||
state->addButton(spButton);
|
||||
state->addButton(optionsButton);
|
||||
state->addButton(exitButton);
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
state->removeAllListboxes();
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
state->removeButton("Back");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
*/
|
||||
/*ControlsTab *controlsTab = new ControlsTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10), vector2d<s32>(100, 50), "Controls", true);
|
||||
MouseTab *mouseTab = new MouseTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 60), vector2d<s32>(100, 50), "Mouse", true);
|
||||
VideoTab *videoTab = new VideoTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 120), vector2d<s32>(100, 50), "Video", true);
|
||||
AudioTab *audioTab = new AudioTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 180), vector2d<s32>(100, 50), "Audio", true);
|
||||
MultiplayerTab *mupltiplayerTab = new MultiplayerTab(state, this->gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10 + 240), vector2d<s32>(100, 50), "Multiplayer", true);
|
||||
//ReturnButton *returnButton = new ReturnButton(state, this->gameManager, vector2d<s32>(50, gameManager->getHeight() - 150), vector2d<s32>(140, 50), "Back", true);
|
||||
//state->addButton(returnButton);
|
||||
mupltiplayerTab->moveText(-20, 0);
|
||||
state->addButton(controlsTab);
|
||||
state->addButton(mouseTab);
|
||||
state->addButton(videoTab);
|
||||
state->addButton(audioTab);
|
||||
state->addButton(mupltiplayerTab);
|
||||
state->removeButton("Exit");
|
||||
state->removeButton("Singleplayer");
|
||||
state->removeButton("Options");*/
|
||||
GuiAppState *state;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+19
-22
@@ -1,33 +1,30 @@
|
||||
#include "player.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Player::Player(int difficulty, int faction, Vector3 spawnPoint) {
|
||||
this->difficulty = difficulty;
|
||||
this->faction = faction;
|
||||
this->spawnPoint=spawnPoint;
|
||||
}
|
||||
namespace battleship{
|
||||
Player::Player(int difficulty, int faction, Vector3 spawnPoint) {
|
||||
this->difficulty = difficulty;
|
||||
this->faction = faction;
|
||||
this->spawnPoint=spawnPoint;
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
}
|
||||
Player::~Player() {
|
||||
}
|
||||
|
||||
void Player::update() {
|
||||
}
|
||||
void Player::update() {
|
||||
}
|
||||
|
||||
bool Player::isThisPlayersUnit(Unit *u) {
|
||||
bool foundUnit = false;
|
||||
bool Player::isThisPlayersUnit(Unit *u) {
|
||||
bool foundUnit = false;
|
||||
|
||||
if (units.size() > 0) {
|
||||
for (int i = 0; i < units.size() && !foundUnit; i++)
|
||||
if (units[i] == u)
|
||||
foundUnit = true;
|
||||
if (units.size() > 0) {
|
||||
for (int i = 0; i < units.size() && !foundUnit; i++)
|
||||
if (units[i] == u)
|
||||
foundUnit = true;
|
||||
|
||||
return foundUnit;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
return foundUnit;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,29 +7,27 @@
|
||||
#include "gameManager.h"
|
||||
#include "unit.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class Player {
|
||||
public:
|
||||
Player(int, int, vb01::Vector3 = vb01::Vector3::VEC_ZERO);
|
||||
~Player();
|
||||
void update();
|
||||
bool isThisPlayersUnit(Unit*);
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
inline void setId(int i){id=i;}
|
||||
inline int getId(){return id;}
|
||||
inline int getNumberOfUnits(){return units.size();}
|
||||
inline int getFaction(){return faction;}
|
||||
inline int getSide(){return side;}
|
||||
inline vb01::Vector3 getSpawnPoint(){return spawnPoint;}
|
||||
private:
|
||||
int credits, faction, difficulty,side,id;
|
||||
std::vector<Unit*> units;
|
||||
vb01::Vector3 spawnPoint;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class Player {
|
||||
public:
|
||||
Player(int, int, vb01::Vector3 = vb01::Vector3::VEC_ZERO);
|
||||
~Player();
|
||||
void update();
|
||||
bool isThisPlayersUnit(Unit*);
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
inline void setId(int i){id=i;}
|
||||
inline int getId(){return id;}
|
||||
inline int getNumberOfUnits(){return units.size();}
|
||||
inline int getFaction(){return faction;}
|
||||
inline int getSide(){return side;}
|
||||
inline vb01::Vector3 getSpawnPoint(){return spawnPoint;}
|
||||
private:
|
||||
int credits, faction, difficulty,side,id;
|
||||
std::vector<Unit*> units;
|
||||
vb01::Vector3 spawnPoint;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+111
-112
@@ -13,136 +13,135 @@
|
||||
#include "util.h"
|
||||
#include "explosion.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Projectile::Projectile(Unit *unit, Node *node, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) {
|
||||
this->unit=unit;
|
||||
this->id=id;
|
||||
this->weaponTypeId=weaponTypeId;
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
dirVec = dir;
|
||||
leftVec = left;
|
||||
upVec = up;
|
||||
Projectile::Projectile(Unit *unit, Node *node, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) {
|
||||
this->unit=unit;
|
||||
this->id=id;
|
||||
this->weaponTypeId=weaponTypeId;
|
||||
|
||||
this->rayLength=projectileData::length[id][weaponTypeId][weaponId];
|
||||
dirVec = dir;
|
||||
leftVec = left;
|
||||
upVec = up;
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
//this->node=node;
|
||||
this->rayLength=projectileData::length[id][weaponTypeId][weaponId];
|
||||
|
||||
if(!node){
|
||||
/*
|
||||
mesh = smgr->getMesh(projectileData::meshPath[id][weaponTypeId]);
|
||||
this->node = smgr->addAnimatedMeshSceneNode(mesh);
|
||||
*/
|
||||
this->node = new Model((projectileData::meshPath[id][weaponTypeId]));
|
||||
Material *mat = new Material();
|
||||
mat->setLightingEnabled(false);
|
||||
string f[]{projectileData::diffuseMapTextPath[id][weaponTypeId]};
|
||||
Texture *diffuseTexture = new Texture(f, 1);
|
||||
mat->addDiffuseMap(diffuseTexture);
|
||||
this->node->setMaterial(mat);
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
//this->node=node;
|
||||
|
||||
/*
|
||||
if (!diffuseTexture)
|
||||
diffuseTexture = driver->getTexture(DEFAULT_TEXTURE);
|
||||
*/
|
||||
}
|
||||
|
||||
this->node->setPosition(pos);
|
||||
this->pos = pos;
|
||||
this->damage=projectileData::damage[id][weaponTypeId][weaponId];
|
||||
|
||||
initPos = pos;
|
||||
speed = projectileData::speed[id][weaponTypeId][weaponId];
|
||||
float angle = dirVec.getAngleBetween(Vector3(0, 0, -1));
|
||||
angle = Quaternion(angle, upVec) * Vector3(0, 0, -1) == dirVec ? angle : -angle;
|
||||
//this->node->setRotation(vector3df(0, angle / PI * 180, 0));
|
||||
|
||||
string p1 = PATH + "Sounds/" + unitData::name[id] + "s/" + projectileData::name[id][weaponTypeId] + ".ogg";
|
||||
string p2 = PATH + "Sounds/Explosions/explosion03" + to_string(rand() % 4) + ".ogg";
|
||||
this->shotSfxBuffer = new sf::SoundBuffer();
|
||||
this->explosionSfxBuffer=new sf::SoundBuffer();
|
||||
|
||||
if(shotSfxBuffer->loadFromFile(p1.c_str())){
|
||||
shotSfx=new sf::Sound(*shotSfxBuffer);
|
||||
shotSfx->play();
|
||||
}
|
||||
|
||||
if(explosionSfxBuffer->loadFromFile(p2.c_str()))
|
||||
explosionSfx=new sf::Sound(*explosionSfxBuffer);
|
||||
}
|
||||
|
||||
Projectile::~Projectile(){
|
||||
if(!node){
|
||||
/*
|
||||
ISceneManager *smgr = GameManager::getSingleton()->getDevice()->getSceneManager();
|
||||
node->getParent()->removeChild(node);
|
||||
mesh = smgr->getMesh(projectileData::meshPath[id][weaponTypeId]);
|
||||
this->node = smgr->addAnimatedMeshSceneNode(mesh);
|
||||
*/
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
if(unit->isDebuggable())
|
||||
debug();
|
||||
this->node = new Model((projectileData::meshPath[id][weaponTypeId]));
|
||||
Material *mat = new Material();
|
||||
mat->setLightingEnabled(false);
|
||||
string f[]{projectileData::diffuseMapTextPath[id][weaponTypeId]};
|
||||
Texture *diffuseTexture = new Texture(f, 1);
|
||||
mat->addDiffuseMap(diffuseTexture);
|
||||
this->node->setMaterial(mat);
|
||||
|
||||
checkForCollision();
|
||||
}
|
||||
|
||||
void Projectile::checkForCollision() {
|
||||
//ISceneNode *collNode = castRay(GameManager::getSingleton()->getSceneManager(),pos,pos+dirVec*rayLength);
|
||||
/*
|
||||
Ray::castRay(pos, pos + dirVec, );
|
||||
|
||||
if (pos.y < -7 || (collNode&&collNode != unit->getNode()))
|
||||
explode(collNode);
|
||||
if (!diffuseTexture)
|
||||
diffuseTexture = driver->getTexture(DEFAULT_TEXTURE);
|
||||
*/
|
||||
}
|
||||
|
||||
void Projectile::explode(Node *collNode) {
|
||||
exploded = true;
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
vector<Player*> players = ((InGameAppState*) stateManager->getAppState(AppStateTypes::IN_GAME_STATE))->getPlayers();
|
||||
this->node->setPosition(pos);
|
||||
this->pos = pos;
|
||||
this->damage=projectileData::damage[id][weaponTypeId][weaponId];
|
||||
|
||||
for (Player *p : players) {
|
||||
for (Unit *u : p->getUnits())
|
||||
if (collNode == u->getNode())
|
||||
u->takeDamage(damage);
|
||||
}
|
||||
|
||||
InGameAppState *inGameState=((InGameAppState*)stateManager->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
if(id == 8)
|
||||
detonateTorpedo(inGameState,pos);
|
||||
else if(weaponTypeId==1&&(id==2||id==3))
|
||||
detonateDepthCharge(inGameState,pos);
|
||||
else
|
||||
detonate(inGameState,pos,-dirVec);
|
||||
}
|
||||
initPos = pos;
|
||||
speed = projectileData::speed[id][weaponTypeId][weaponId];
|
||||
float angle = dirVec.getAngleBetween(Vector3(0, 0, -1));
|
||||
angle = Quaternion(angle, upVec) * Vector3(0, 0, -1) == dirVec ? angle : -angle;
|
||||
//this->node->setRotation(vector3df(0, angle / PI * 180, 0));
|
||||
|
||||
void Projectile::debug(){
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->draw3DLine(pos,pos+dirVec,SColor(255,0,0,255));
|
||||
driver->draw3DLine(pos,pos+leftVec,SColor(255,255,0,0));
|
||||
driver->draw3DLine(pos,pos+upVec,SColor(255,0,255,0));
|
||||
string p1 = PATH + "Sounds/" + unitData::name[id] + "s/" + projectileData::name[id][weaponTypeId] + ".ogg";
|
||||
string p2 = PATH + "Sounds/Explosions/explosion03" + to_string(rand() % 4) + ".ogg";
|
||||
this->shotSfxBuffer = new sf::SoundBuffer();
|
||||
this->explosionSfxBuffer=new sf::SoundBuffer();
|
||||
|
||||
if(shotSfxBuffer->loadFromFile(p1.c_str())){
|
||||
shotSfx=new sf::Sound(*shotSfxBuffer);
|
||||
shotSfx->play();
|
||||
}
|
||||
|
||||
if(explosionSfxBuffer->loadFromFile(p2.c_str()))
|
||||
explosionSfx=new sf::Sound(*explosionSfxBuffer);
|
||||
}
|
||||
|
||||
Projectile::~Projectile(){
|
||||
/*
|
||||
ISceneManager *smgr = GameManager::getSingleton()->getDevice()->getSceneManager();
|
||||
node->getParent()->removeChild(node);
|
||||
*/
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
if(unit->isDebuggable())
|
||||
debug();
|
||||
|
||||
checkForCollision();
|
||||
}
|
||||
|
||||
void Projectile::checkForCollision() {
|
||||
//ISceneNode *collNode = castRay(GameManager::getSingleton()->getSceneManager(),pos,pos+dirVec*rayLength);
|
||||
/*
|
||||
Ray::castRay(pos, pos + dirVec, );
|
||||
|
||||
if (pos.y < -7 || (collNode&&collNode != unit->getNode()))
|
||||
explode(collNode);
|
||||
*/
|
||||
}
|
||||
|
||||
void Projectile::explode(Node *collNode) {
|
||||
exploded = true;
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
vector<Player*> players = ((InGameAppState*) stateManager->getAppState(AppStateTypes::IN_GAME_STATE))->getPlayers();
|
||||
|
||||
for (Player *p : players) {
|
||||
for (Unit *u : p->getUnits())
|
||||
if (collNode == u->getNode())
|
||||
u->takeDamage(damage);
|
||||
}
|
||||
|
||||
void Projectile::orientProjectile(Vector3 orientVec){
|
||||
Vector3 orientVecProj = Vector3(orientVec.x, 0, orientVec.z).norm();
|
||||
float projAngle = orientVec.getAngleBetween(orientVecProj);
|
||||
float rotAngle = Vector3(0,0,-1).getAngleBetween(orientVecProj);
|
||||
rotAngle *= (orientVec.x<0?1:-1)/PI*180;
|
||||
projAngle*=(orientVec.y>0?1:-1)/PI*180;
|
||||
dirVec = orientVecProj;
|
||||
upVec = Vector3(0,1,0);
|
||||
leftVec = Quaternion(-PI/2, upVec) * dirVec;
|
||||
Quaternion rotQuat=Quaternion(projAngle/180*PI,leftVec);
|
||||
dirVec=rotQuat*dirVec;
|
||||
upVec=rotQuat*upVec;
|
||||
//node->setRotation(vector3df(projAngle,rotAngle,0));
|
||||
}
|
||||
|
||||
InGameAppState *inGameState=((InGameAppState*)stateManager->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
if(id == 8)
|
||||
detonateTorpedo(inGameState,pos);
|
||||
else if(weaponTypeId==1&&(id==2||id==3))
|
||||
detonateDepthCharge(inGameState,pos);
|
||||
else
|
||||
detonate(inGameState,pos,-dirVec);
|
||||
}
|
||||
|
||||
void Projectile::debug(){
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->draw3DLine(pos,pos+dirVec,SColor(255,0,0,255));
|
||||
driver->draw3DLine(pos,pos+leftVec,SColor(255,255,0,0));
|
||||
driver->draw3DLine(pos,pos+upVec,SColor(255,0,255,0));
|
||||
*/
|
||||
}
|
||||
|
||||
void Projectile::orientProjectile(Vector3 orientVec){
|
||||
Vector3 orientVecProj = Vector3(orientVec.x, 0, orientVec.z).norm();
|
||||
float projAngle = orientVec.getAngleBetween(orientVecProj);
|
||||
float rotAngle = Vector3(0,0,-1).getAngleBetween(orientVecProj);
|
||||
rotAngle *= (orientVec.x<0?1:-1)/PI*180;
|
||||
projAngle*=(orientVec.y>0?1:-1)/PI*180;
|
||||
dirVec = orientVecProj;
|
||||
upVec = Vector3(0,1,0);
|
||||
leftVec = Quaternion(-PI/2, upVec) * dirVec;
|
||||
Quaternion rotQuat=Quaternion(projAngle/180*PI,leftVec);
|
||||
dirVec=rotQuat*dirVec;
|
||||
upVec=rotQuat*upVec;
|
||||
//node->setRotation(vector3df(projAngle,rotAngle,0));
|
||||
}
|
||||
}
|
||||
|
||||
+26
-28
@@ -14,35 +14,33 @@ namespace vb01{
|
||||
class Mesh;
|
||||
}
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
class Unit;
|
||||
|
||||
class Projectile {
|
||||
public:
|
||||
Projectile(Unit*, vb01::Node*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
virtual ~Projectile();
|
||||
virtual void update();
|
||||
virtual void debug();
|
||||
void orientProjectile(vb01::Vector3);
|
||||
inline bool isExploded() {return exploded;}
|
||||
inline Unit* getUnit(){return unit;}
|
||||
protected:
|
||||
virtual void checkForCollision();
|
||||
void explode(vb01::Node*);
|
||||
namespace battleship {
|
||||
class Unit;
|
||||
|
||||
class Projectile {
|
||||
public:
|
||||
Projectile(Unit*, vb01::Node*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
virtual ~Projectile();
|
||||
virtual void update();
|
||||
virtual void debug();
|
||||
void orientProjectile(vb01::Vector3);
|
||||
inline bool isExploded() {return exploded;}
|
||||
inline Unit* getUnit(){return unit;}
|
||||
protected:
|
||||
virtual void checkForCollision();
|
||||
void explode(vb01::Node*);
|
||||
|
||||
vb01::Model *node=nullptr;
|
||||
bool exploded = false;
|
||||
const float g = 2.2;
|
||||
float speed, angle, rayLength, scale;
|
||||
int damage,id,weaponTypeId;
|
||||
vb01::Vector3 initPos, pos, dirVec, leftVec, upVec;
|
||||
s64 lastUpdateTime = 0;
|
||||
Unit *unit;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx=nullptr, *explosionSfx=nullptr;
|
||||
};
|
||||
}
|
||||
vb01::Model *node=nullptr;
|
||||
bool exploded = false;
|
||||
const float g = 2.2;
|
||||
float speed, angle, rayLength, scale;
|
||||
int damage,id,weaponTypeId;
|
||||
vb01::Vector3 initPos, pos, dirVec, leftVec, upVec;
|
||||
s64 lastUpdateTime = 0;
|
||||
Unit *unit;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx=nullptr, *explosionSfx=nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+223
-225
@@ -14,245 +14,243 @@
|
||||
6:巡航ミサイル
|
||||
*/
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
namespace projectileData {
|
||||
using namespace game::core;
|
||||
|
||||
const int numberOfTypesOfWeapons = 2;
|
||||
const float speed[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
namespace battleship{
|
||||
namespace projectileData {
|
||||
using namespace configData;
|
||||
|
||||
const int numberOfTypesOfWeapons = 2;
|
||||
const float speed[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{10,10,10,10,10,10,10,10,10,10,10}
|
||||
},
|
||||
{
|
||||
{10,10,10,10,10,10,10,10,10,10,10}
|
||||
},
|
||||
{
|
||||
{10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{5,5}
|
||||
},
|
||||
{
|
||||
{7,7,7,7,7},
|
||||
{}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{.05},
|
||||
{
|
||||
{.1, .1},
|
||||
{.1, .1}
|
||||
}
|
||||
};
|
||||
const float length[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{1,1,1,1,1,1,1,1,1,1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1,1,1,1,1,1,1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1,1}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
{.5}
|
||||
},
|
||||
{
|
||||
{1,1},
|
||||
{1,1}
|
||||
},
|
||||
{}
|
||||
};
|
||||
const float scale[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{1, 1, 1, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5}
|
||||
},
|
||||
{
|
||||
{1, 1, 1, .23, .23, .23, .23, .23, .23, .23, .23, .23, .23}
|
||||
},
|
||||
{
|
||||
{.45, .45, .45, .45}
|
||||
},
|
||||
{
|
||||
{.5, .5, .5, .5}
|
||||
},
|
||||
{
|
||||
{.95, .95}
|
||||
},
|
||||
{
|
||||
{.6, .6, .6, .6, .6}
|
||||
}
|
||||
};
|
||||
const vb01::Vector3 pos[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{
|
||||
{10,10,10,10,10,10,10,10,10,10,10}
|
||||
},
|
||||
{
|
||||
{10,10,10,10,10,10,10,10,10,10,10}
|
||||
},
|
||||
{
|
||||
{10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{5,5}
|
||||
},
|
||||
{
|
||||
{7,7,7,7,7},
|
||||
{}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{.05},
|
||||
{
|
||||
{.1, .1},
|
||||
{.1, .1}
|
||||
vb01::Vector3(0, 0, 1.05),
|
||||
vb01::Vector3(0, 0, 1.05),
|
||||
vb01::Vector3(0, 0, 1.05),
|
||||
vb01::Vector3(0, 0, 1.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5)
|
||||
}
|
||||
};
|
||||
const float length[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
},
|
||||
{
|
||||
{
|
||||
{1,1,1,1,1,1,1,1,1,1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1,1,1,1,1,1,1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1}
|
||||
},
|
||||
{
|
||||
{1,1}
|
||||
},
|
||||
{
|
||||
{1,1,1,1,1}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
{.5}
|
||||
},
|
||||
{
|
||||
{1,1},
|
||||
{1,1}
|
||||
},
|
||||
{}
|
||||
};
|
||||
const float scale[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{1, 1, 1, .5, .5, .5, .5, .5, .5, .5, .5, .5, .5}
|
||||
},
|
||||
{
|
||||
{1, 1, 1, .23, .23, .23, .23, .23, .23, .23, .23, .23, .23}
|
||||
},
|
||||
{
|
||||
{.45, .45, .45, .45}
|
||||
},
|
||||
{
|
||||
{.5, .5, .5, .5}
|
||||
},
|
||||
{
|
||||
{.95, .95}
|
||||
},
|
||||
{
|
||||
{.6, .6, .6, .6, .6}
|
||||
vb01::Vector3(0, 0, 0.79254),
|
||||
vb01::Vector3(0, 0, 0.79254),
|
||||
vb01::Vector3(0, 0, 0.79254),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723)
|
||||
}
|
||||
};
|
||||
const vb01::Vector3 pos[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
vb01::Vector3(0, 0, 1.05),
|
||||
vb01::Vector3(0, 0, 1.05),
|
||||
vb01::Vector3(0, 0, 1.05),
|
||||
vb01::Vector3(0, 0, 1.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5),
|
||||
vb01::Vector3(0, 0, 2.5)
|
||||
}
|
||||
vb01::Vector3(0, 0, -0.36178),
|
||||
vb01::Vector3(0, 0, -0.36178),
|
||||
vb01::Vector3(0, 0, -0.36178),
|
||||
vb01::Vector3(0, 0, -0.36178)
|
||||
},
|
||||
{vb01::Vector3(0, -3, 0)}
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
vb01::Vector3(0, 0, 0.79254),
|
||||
vb01::Vector3(0, 0, 0.79254),
|
||||
vb01::Vector3(0, 0, 0.79254),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723),
|
||||
vb01::Vector3(0, 0, 0.17723)
|
||||
}
|
||||
vb01::Vector3(0, 0, -0.30074),
|
||||
vb01::Vector3(0, 0, -0.30074),
|
||||
vb01::Vector3(0, 0, -0.30074),
|
||||
vb01::Vector3(0, 0, -0.30074)
|
||||
},
|
||||
{vb01::Vector3(0, -2, 0)}
|
||||
},
|
||||
{
|
||||
{vb01::Vector3(0, 0, -0.62118), vb01::Vector3(0, 0, -0.62118)},
|
||||
{
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.36178),
|
||||
vb01::Vector3(0, 0, -0.36178),
|
||||
vb01::Vector3(0, 0, -0.36178),
|
||||
vb01::Vector3(0, 0, -0.36178)
|
||||
},
|
||||
{vb01::Vector3(0, -3, 0)}
|
||||
},
|
||||
vb01::Vector3(0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.88017),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.88017)
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.30074),
|
||||
vb01::Vector3(0, 0, -0.30074),
|
||||
vb01::Vector3(0, 0, -0.30074),
|
||||
vb01::Vector3(0, 0, -0.30074)
|
||||
},
|
||||
{vb01::Vector3(0, -2, 0)}
|
||||
},
|
||||
{
|
||||
{vb01::Vector3(0, 0, -0.62118), vb01::Vector3(0, 0, -0.62118)},
|
||||
{
|
||||
vb01::Vector3(0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.88017),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.88017)
|
||||
}
|
||||
},
|
||||
{
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117)
|
||||
},
|
||||
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
{vb01::Vector3(0,-.3,-1.5)}
|
||||
},
|
||||
{
|
||||
{vb01::Vector3(-.25,0,0),vb01::Vector3(.25,0,0)},
|
||||
{vb01::Vector3(-.25,0,0),vb01::Vector3(.25,0,0)}
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117),
|
||||
vb01::Vector3(0, 0, -0.59117)
|
||||
},
|
||||
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
{vb01::Vector3(0,-.3,-1.5)}
|
||||
},
|
||||
{
|
||||
{vb01::Vector3(-.25,0,0),vb01::Vector3(.25,0,0)},
|
||||
{vb01::Vector3(-.25,0,0),vb01::Vector3(.25,0,0)}
|
||||
},
|
||||
{}
|
||||
};
|
||||
const int damage[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{50, 50, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{50, 50, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{50,50,50,50},
|
||||
{50}
|
||||
},
|
||||
{
|
||||
{50,50,50,50},
|
||||
{50}
|
||||
},
|
||||
{
|
||||
{10,10},
|
||||
{}
|
||||
};
|
||||
const int damage[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
|
||||
{
|
||||
{50, 50, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{50, 50, 50, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}
|
||||
},
|
||||
{
|
||||
{50,50,50,50},
|
||||
{50}
|
||||
},
|
||||
{
|
||||
{50,50,50,50},
|
||||
{50}
|
||||
},
|
||||
{
|
||||
{10,10},
|
||||
{}
|
||||
},
|
||||
{
|
||||
{10,10,10,10,10},
|
||||
{}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
{}
|
||||
},
|
||||
{
|
||||
{50,50},
|
||||
{50,50}
|
||||
},
|
||||
},
|
||||
{
|
||||
{10,10,10,10,10},
|
||||
{}
|
||||
};
|
||||
const std::string name[unitData::numberOfUnits][numberOfTypesOfWeapons]{
|
||||
{"shell"},
|
||||
{"shell"},
|
||||
{"shell"},
|
||||
{"shell"},
|
||||
{"shell","guidedMissile"},
|
||||
{"shell","guidedMissile"},
|
||||
{""},
|
||||
{""},
|
||||
{"torpedo"},
|
||||
{"missile","missile"},
|
||||
};
|
||||
const std::string meshPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
|
||||
{PATH + "Models/Shell/shell.x"},
|
||||
{PATH + "Models/Shell/shell.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Guided missile/guidedMissile.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Guided missile/guidedMissile.x"},
|
||||
{},
|
||||
{},
|
||||
{PATH + "Models/Torpedo/torpedo.x"},
|
||||
{PATH + "Models/Jets/aam.x", PATH + "Models/Jets/awm.x"},
|
||||
};
|
||||
const std::string diffuseMapTextPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
{}
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
{50,50},
|
||||
{50,50}
|
||||
},
|
||||
{}
|
||||
};
|
||||
const std::string name[unitData::numberOfUnits][numberOfTypesOfWeapons]{
|
||||
{"shell"},
|
||||
{"shell"},
|
||||
{"shell"},
|
||||
{"shell"},
|
||||
{"shell","guidedMissile"},
|
||||
{"shell","guidedMissile"},
|
||||
{""},
|
||||
{""},
|
||||
{"torpedo"},
|
||||
{"missile","missile"},
|
||||
};
|
||||
const std::string meshPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
|
||||
{PATH + "Models/Shell/shell.x"},
|
||||
{PATH + "Models/Shell/shell.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Guided missile/guidedMissile.x"},
|
||||
{PATH + "Models/Shell/shell.x", PATH + "Models/Guided missile/guidedMissile.x"},
|
||||
{},
|
||||
{},
|
||||
{PATH + "Models/Torpedo/torpedo.x"},
|
||||
{PATH + "Models/Jets/aam.x", PATH + "Models/Jets/awm.x"},
|
||||
};
|
||||
const std::string diffuseMapTextPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,42 +6,38 @@
|
||||
#include "util.h"
|
||||
#include "unit.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Shell::Shell(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) : Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
|
||||
this->speed = projectileData::speed[id][weaponTypeId][weaponId];
|
||||
node->setScale(Vector3(1, 1, 1) * projectileData::scale[id][weaponTypeId][weaponId]);
|
||||
initTime = getTime();
|
||||
}
|
||||
namespace battleship{
|
||||
Shell::Shell(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) : Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
|
||||
this->speed = projectileData::speed[id][weaponTypeId][weaponId];
|
||||
node->setScale(Vector3(1, 1, 1) * projectileData::scale[id][weaponTypeId][weaponId]);
|
||||
initTime = getTime();
|
||||
}
|
||||
|
||||
void Shell::update() {
|
||||
//x=v*cos(a)*t
|
||||
//y=v*sin(a)*t+0.5(g*t^2)
|
||||
Projectile::update();
|
||||
Vector3 straightVec = Vector3(dirVec.x, 0, dirVec.z).norm();
|
||||
double time = double(getTime() - initTime) / 1000,
|
||||
offsetX = speed * cos(angle) * time,
|
||||
offsetY = speed * sin(angle) * time - .5 * (g * time * time);
|
||||
pos = initPos + straightVec * offsetX + Vector3(0, offsetY, 0);
|
||||
node->setPosition(pos);
|
||||
updateVecs(straightVec, time);
|
||||
checkForCollision();
|
||||
}
|
||||
void Shell::update() {
|
||||
//x=v*cos(a)*t
|
||||
//y=v*sin(a)*t+0.5(g*t^2)
|
||||
Projectile::update();
|
||||
Vector3 straightVec = Vector3(dirVec.x, 0, dirVec.z).norm();
|
||||
double time = double(getTime() - initTime) / 1000,
|
||||
offsetX = speed * cos(angle) * time,
|
||||
offsetY = speed * sin(angle) * time - .5 * (g * time * time);
|
||||
pos = initPos + straightVec * offsetX + Vector3(0, offsetY, 0);
|
||||
node->setPosition(pos);
|
||||
updateVecs(straightVec, time);
|
||||
checkForCollision();
|
||||
}
|
||||
|
||||
void Shell::updateVecs(Vector3 straightVec, float time) {
|
||||
// f'(t)=dy/dx=(v*sin(a)+g*t)/(v*cos(a))
|
||||
float tanAngle = -atan((speed * sin(angle) + g * time) / (speed * cos(angle)));
|
||||
Quaternion rotQuat = Quaternion(tanAngle, leftVec);
|
||||
dirVec = rotQuat*straightVec, upVec = rotQuat * Vector3(0, 1, 0);
|
||||
/*
|
||||
Vector3 rotVec = node->getOrientation();
|
||||
rotVec=vector3df(tanAngle/PI*180,rotVec.Y,rotVec.Z);
|
||||
node->setRotation(rotVec);
|
||||
*/
|
||||
}
|
||||
void Shell::updateVecs(Vector3 straightVec, float time) {
|
||||
// f'(t)=dy/dx=(v*sin(a)+g*t)/(v*cos(a))
|
||||
float tanAngle = -atan((speed * sin(angle) + g * time) / (speed * cos(angle)));
|
||||
Quaternion rotQuat = Quaternion(tanAngle, leftVec);
|
||||
dirVec = rotQuat*straightVec, upVec = rotQuat * Vector3(0, 1, 0);
|
||||
/*
|
||||
Vector3 rotVec = node->getOrientation();
|
||||
rotVec=vector3df(tanAngle/PI*180,rotVec.Y,rotVec.Z);
|
||||
node->setRotation(rotVec);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,16 @@
|
||||
#include "gameManager.h"
|
||||
#include "projectile.h"
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
class Shell : public Projectile {
|
||||
public:
|
||||
Shell(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~Shell(){}
|
||||
virtual void update();
|
||||
protected:
|
||||
s64 initTime;
|
||||
virtual void updateVecs(vb01::Vector3, float);
|
||||
};
|
||||
}
|
||||
namespace battleship {
|
||||
class Shell : public Projectile {
|
||||
public:
|
||||
Shell(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~Shell(){}
|
||||
virtual void update();
|
||||
protected:
|
||||
s64 initTime;
|
||||
virtual void updateVecs(vb01::Vector3, float);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+34
-36
@@ -1,45 +1,43 @@
|
||||
#include "stateManager.h"
|
||||
#include "abstractAppState.h"
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
void StateManager::attachState(AbstractAppState *a) {
|
||||
bool alreadyAttached = false;
|
||||
for (int i = 0; i < appStates.size()&&!alreadyAttached; i++)
|
||||
if (appStates[i] == a)
|
||||
alreadyAttached = true;
|
||||
if (!alreadyAttached) {
|
||||
a->onAttachment();
|
||||
appStates.push_back(a);
|
||||
}
|
||||
namespace battleship{
|
||||
void StateManager::attachState(AbstractAppState *a) {
|
||||
bool alreadyAttached = false;
|
||||
for (int i = 0; i < appStates.size()&&!alreadyAttached; i++)
|
||||
if (appStates[i] == a)
|
||||
alreadyAttached = true;
|
||||
if (!alreadyAttached) {
|
||||
a->onAttachment();
|
||||
appStates.push_back(a);
|
||||
}
|
||||
}
|
||||
|
||||
void StateManager::dettachState(AbstractAppState *a) {
|
||||
bool alreadyDetached = false;
|
||||
for (int i = 0; i < appStates.size()&&!alreadyDetached; i++)
|
||||
if (appStates[i] == a)
|
||||
alreadyDetached = true;
|
||||
if (!alreadyDetached) {
|
||||
a->onDetachment();
|
||||
for (int i = 0; i < appStates.size(); i++)
|
||||
if (a == appStates[i]) {
|
||||
appStates.erase(appStates.begin() + i);
|
||||
}
|
||||
}
|
||||
void StateManager::dettachState(AbstractAppState *a) {
|
||||
bool alreadyDetached = false;
|
||||
for (int i = 0; i < appStates.size()&&!alreadyDetached; i++)
|
||||
if (appStates[i] == a)
|
||||
alreadyDetached = true;
|
||||
if (!alreadyDetached) {
|
||||
a->onDetachment();
|
||||
for (int i = 0; i < appStates.size(); i++)
|
||||
if (a == appStates[i]) {
|
||||
appStates.erase(appStates.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StateManager::update() {
|
||||
for (AbstractAppState *a : appStates)
|
||||
if (a->isAttached() && a)
|
||||
a->update();
|
||||
}
|
||||
void StateManager::update() {
|
||||
for (AbstractAppState *a : appStates)
|
||||
if (a->isAttached() && a)
|
||||
a->update();
|
||||
}
|
||||
|
||||
AbstractAppState* StateManager::getAppState(AppStateTypes t) {
|
||||
AbstractAppState *state = nullptr;
|
||||
for (AbstractAppState *a : appStates)
|
||||
if (a->getType() == t)
|
||||
state = a;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
AbstractAppState* StateManager::getAppState(AppStateTypes t) {
|
||||
AbstractAppState *state = nullptr;
|
||||
for (AbstractAppState *a : appStates)
|
||||
if (a->getType() == t)
|
||||
state = a;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-18
@@ -5,24 +5,22 @@
|
||||
|
||||
#include "abstractAppState.h"
|
||||
|
||||
namespace game{
|
||||
namespace core{
|
||||
class StateManager{
|
||||
public:
|
||||
StateManager(){}
|
||||
void update();
|
||||
void attachState(AbstractAppState*);
|
||||
void dettachState(AbstractAppState*);
|
||||
void dettachState(AppStateTypes);
|
||||
AbstractAppState* getAppState(AppStateTypes);
|
||||
inline AbstractAppState* getAppState(int id){return appStates[id];}
|
||||
inline void setAppState(int i, AbstractAppState *a){appStates[i]=a;}
|
||||
inline int getAppStateNumber(){return appStates.size();}
|
||||
inline std::vector<AbstractAppState*> getAppStates(){return appStates;}
|
||||
private:
|
||||
std::vector<AbstractAppState*> appStates;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class StateManager{
|
||||
public:
|
||||
StateManager(){}
|
||||
void update();
|
||||
void attachState(AbstractAppState*);
|
||||
void dettachState(AbstractAppState*);
|
||||
void dettachState(AppStateTypes);
|
||||
AbstractAppState* getAppState(AppStateTypes);
|
||||
inline AbstractAppState* getAppState(int id){return appStates[id];}
|
||||
inline void setAppState(int i, AbstractAppState *a){appStates[i]=a;}
|
||||
inline int getAppStateNumber(){return appStates.size();}
|
||||
inline std::vector<AbstractAppState*> getAppStates(){return appStates;}
|
||||
private:
|
||||
std::vector<AbstractAppState*> appStates;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+22
-26
@@ -6,37 +6,33 @@
|
||||
#include "torpedo.h"
|
||||
#include "projectileData.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Submarine::Submarine(Player *player, Vector3 pos, int id) : Unit(player,pos, id) {}
|
||||
namespace battleship{
|
||||
Submarine::Submarine(Player *player, Vector3 pos, int id) : Unit(player,pos, id) {}
|
||||
|
||||
void Submarine::attack(Order order) {
|
||||
float angle = dirVec.getAngleBetween(*(order.targetPos[0]) - pos);
|
||||
void Submarine::attack(Order order) {
|
||||
float angle = dirVec.getAngleBetween(*(order.targetPos[0]) - pos);
|
||||
|
||||
if(angle / PI * 180 > 50)
|
||||
Unit::move(order, range);
|
||||
if(angle / PI * 180 > 50)
|
||||
Unit::move(order, range);
|
||||
|
||||
if (canFire()) {
|
||||
Vector3 p = pos + leftVec * projectileData::pos[id][0][0].x + upVec * projectileData::pos[id][0][0].y - dirVec * projectileData::pos[id][0][0].z;
|
||||
addProjectile(new Torpedo(this, p, dirVec, leftVec, upVec, getId(), 0, 0));
|
||||
lastShotTime=getTime();
|
||||
}
|
||||
}
|
||||
|
||||
void Submarine::emerge() {
|
||||
submerged = false;
|
||||
pos.y += 5;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
|
||||
void Submarine::submerge() {
|
||||
submerged = true;
|
||||
pos.y -= 5;
|
||||
node->setPosition(pos);
|
||||
if (canFire()) {
|
||||
Vector3 p = pos + leftVec * projectileData::pos[id][0][0].x + upVec * projectileData::pos[id][0][0].y - dirVec * projectileData::pos[id][0][0].z;
|
||||
addProjectile(new Torpedo(this, p, dirVec, leftVec, upVec, getId(), 0, 0));
|
||||
lastShotTime=getTime();
|
||||
}
|
||||
}
|
||||
|
||||
void Submarine::emerge() {
|
||||
submerged = false;
|
||||
pos.y += 5;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
|
||||
void Submarine::submerge() {
|
||||
submerged = true;
|
||||
pos.y -= 5;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-16
@@ -7,22 +7,20 @@
|
||||
#include "unit.h"
|
||||
#include "player.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class Submarine : public Unit {
|
||||
public:
|
||||
Submarine(Player*, vb01::Vector3, int);
|
||||
inline bool isSubmerged() {return submerged;}
|
||||
void emerge();
|
||||
void submerge();
|
||||
private:
|
||||
void attack(Order);
|
||||
inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;}
|
||||
bool submerged = false;
|
||||
int rateOfFire=2000;
|
||||
s64 lastShotTime=0;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class Submarine : public Unit {
|
||||
public:
|
||||
Submarine(Player*, vb01::Vector3, int);
|
||||
inline bool isSubmerged() {return submerged;}
|
||||
void emerge();
|
||||
void submerge();
|
||||
private:
|
||||
void attack(Order);
|
||||
inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;}
|
||||
bool submerged = false;
|
||||
int rateOfFire=2000;
|
||||
s64 lastShotTime=0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+21
-23
@@ -3,28 +3,26 @@
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
Tooltip::Tooltip(Vector2 pos, string entry){
|
||||
this->pos = pos;
|
||||
/*
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
text=new BitmapText(entry,pos,gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp"));
|
||||
gm->attachBitmapText(text);
|
||||
*/
|
||||
}
|
||||
|
||||
Tooltip::~Tooltip(){
|
||||
//GameManager::getSingleton()->detachBitmapText(text);
|
||||
}
|
||||
|
||||
void Tooltip::update(){
|
||||
/*
|
||||
IVideoDriver *driver=GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
dimension2d<u32> dim=text->getFont()->getDimension(text->getText().c_str());
|
||||
driver->draw2DRectangle(SColor(255,0,0,0),recti(pos.X,pos.Y,pos.X+dim.Width,pos.Y+dim.Height),nullptr);
|
||||
driver->draw2DRectangleOutline(recti(pos-vector2di(1,1),dimension2df(dim.Width+1,dim.Height+1)),SColor(255,255,0,0));
|
||||
*/
|
||||
}
|
||||
namespace battleship{
|
||||
Tooltip::Tooltip(Vector2 pos, string entry){
|
||||
this->pos = pos;
|
||||
/*
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
text=new BitmapText(entry,pos,gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp"));
|
||||
gm->attachBitmapText(text);
|
||||
*/
|
||||
}
|
||||
|
||||
Tooltip::~Tooltip(){
|
||||
//GameManager::getSingleton()->detachBitmapText(text);
|
||||
}
|
||||
|
||||
void Tooltip::update(){
|
||||
/*
|
||||
IVideoDriver *driver=GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
dimension2d<u32> dim=text->getFont()->getDimension(text->getText().c_str());
|
||||
driver->draw2DRectangle(SColor(255,0,0,0),recti(pos.X,pos.Y,pos.X+dim.Width,pos.Y+dim.Height),nullptr);
|
||||
driver->draw2DRectangleOutline(recti(pos-vector2di(1,1),dimension2df(dim.Width+1,dim.Height+1)),SColor(255,255,0,0));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,16 @@
|
||||
|
||||
#include <text.h>
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
class Tooltip{
|
||||
public:
|
||||
Tooltip(vb01::Vector2, std::string);
|
||||
~Tooltip();
|
||||
void update();
|
||||
private:
|
||||
vb01::Vector2 pos;
|
||||
//BitmapText *text;
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class Tooltip{
|
||||
public:
|
||||
Tooltip(vb01::Vector2, std::string);
|
||||
~Tooltip();
|
||||
void update();
|
||||
private:
|
||||
vb01::Vector2 pos;
|
||||
//BitmapText *text;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+8
-11
@@ -2,18 +2,15 @@
|
||||
|
||||
#include "torpedo.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Torpedo::Torpedo(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, nullptr, pos, dir, left, up, id,weaponTypeId,weaponId) {this->damage = 50;}
|
||||
|
||||
void Torpedo::update() {
|
||||
Projectile::update();
|
||||
pos = pos + dirVec * speed;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
namespace battleship{
|
||||
Torpedo::Torpedo(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
|
||||
Projectile(unit, nullptr, pos, dir, left, up, id,weaponTypeId,weaponId) {this->damage = 50;}
|
||||
|
||||
void Torpedo::update() {
|
||||
Projectile::update();
|
||||
pos = pos + dirVec * speed;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,14 @@
|
||||
|
||||
#include "projectile.h"
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class Torpedo : public Projectile {
|
||||
public:
|
||||
Torpedo(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~Torpedo(){}
|
||||
void update();
|
||||
// void explode()
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class Torpedo : public Projectile {
|
||||
public:
|
||||
Torpedo(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
|
||||
~Torpedo(){}
|
||||
void update();
|
||||
//void explode()
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,376 +7,374 @@
|
||||
#include "util.h"
|
||||
#include "unitData.h"
|
||||
|
||||
using namespace game::content::unitData;
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Unit::Unit(Player *player, vb01::Vector3 pos, int id) {
|
||||
this->id = id;
|
||||
this->player = player;
|
||||
this->health = unitData::health[id];
|
||||
this->maxTurnAngle = unitData::maxTurnAngle[id];
|
||||
this->range = unitData::range[id];
|
||||
this->lineOfSight = unitData::lineOfSight[id];
|
||||
this->speed = unitData::speed[id];
|
||||
type = unitData::unitType[id];
|
||||
width = unitData::unitCornerPoints[id][0].x - unitData::unitCornerPoints[id][1].x;
|
||||
height = unitData::unitCornerPoints[id][4].y - unitData::unitCornerPoints[id][0].y;
|
||||
length = unitData::unitCornerPoints[id][3].z - unitData::unitCornerPoints[id][0].z;
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
node = new Model(basePath[id] + meshPath[id]);
|
||||
placeUnit(pos);
|
||||
/*
|
||||
node->setMaterialFlag(EMF_LIGHTING, false);
|
||||
ITriangleSelector *tr = smgr->createTriangleSelector((IAnimatedMeshSceneNode*)node);
|
||||
node->setTriangleSelector(tr);
|
||||
tr->drop();
|
||||
*/
|
||||
string f[]{basePath[id] + "diffuseMap.png"};
|
||||
Texture *diffuseTexture = new Texture(f, 1);
|
||||
Unit::Unit(Player *player, vb01::Vector3 pos, int id) {
|
||||
this->id = id;
|
||||
this->player = player;
|
||||
this->health = unitData::health[id];
|
||||
this->maxTurnAngle = unitData::maxTurnAngle[id];
|
||||
this->range = unitData::range[id];
|
||||
this->lineOfSight = unitData::lineOfSight[id];
|
||||
this->speed = unitData::speed[id];
|
||||
type = unitData::unitType[id];
|
||||
width = unitData::unitCornerPoints[id][0].x - unitData::unitCornerPoints[id][1].x;
|
||||
height = unitData::unitCornerPoints[id][4].y - unitData::unitCornerPoints[id][0].y;
|
||||
length = unitData::unitCornerPoints[id][3].z - unitData::unitCornerPoints[id][0].z;
|
||||
|
||||
/*
|
||||
light = smgr->addLightSceneNode(node, vector3df(0, 2, 0), SColor(255, 255, 255, 255), lineOfSight);
|
||||
light->setVisible(false);
|
||||
node->setVisible(false);
|
||||
*/
|
||||
selectionSfxBuffer = new sf::SoundBuffer();
|
||||
string p = PATH+"Sounds/"+unitData::name[id]+"s/selection.ogg";
|
||||
|
||||
if(selectionSfxBuffer->loadFromFile(p.c_str()))
|
||||
selectionSfx = new sf::Sound(*selectionSfxBuffer);
|
||||
}
|
||||
|
||||
Unit::~Unit() {
|
||||
/*
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
driver->removeTexture(node->getMaterial(0).getTexture(0));
|
||||
node->removeChild(light);
|
||||
node->getParent()->removeChild(node);
|
||||
*/
|
||||
}
|
||||
|
||||
void Unit::update() {
|
||||
if (orders.size() > 0){
|
||||
if(selected&&canDisplayOrderLine()){
|
||||
int r=0,g=0,b=0;
|
||||
|
||||
switch(orders[0].type){
|
||||
case Order::TYPE::MOVE:
|
||||
g=255;
|
||||
break;
|
||||
case Order::TYPE::ATTACK:
|
||||
r=255;
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
b=255;
|
||||
case Order::TYPE::LAUNCH:
|
||||
r=255,g=255;
|
||||
break;
|
||||
}
|
||||
|
||||
//GameManager::getSingleton()->getDevice()->getVideoDriver()->draw3DLine(pos,*(orders[0].targetPos[0]),SColor(255,r,g,b));
|
||||
}
|
||||
|
||||
while (patrolPoints.size() > 0 && orders[0].type != Order::TYPE::PATROL) {
|
||||
patrolPoints.pop_back();
|
||||
patrolPointId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
executeOrders();
|
||||
|
||||
if (health <= 0)
|
||||
blowUp();
|
||||
}
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
node = new Model(basePath[id] + meshPath[id]);
|
||||
placeUnit(pos);
|
||||
/*
|
||||
node->setMaterialFlag(EMF_LIGHTING, false);
|
||||
ITriangleSelector *tr = smgr->createTriangleSelector((IAnimatedMeshSceneNode*)node);
|
||||
node->setTriangleSelector(tr);
|
||||
tr->drop();
|
||||
*/
|
||||
string f[]{basePath[id] + "diffuseMap.png"};
|
||||
Texture *diffuseTexture = new Texture(f, 1);
|
||||
|
||||
/*
|
||||
void Unit::updateScreenCoordinates(ICameraSceneNode *cam, vector3df camDir, vector3df camLeft, vector3df camUp) {
|
||||
vector3df camPos = cam->getPosition();
|
||||
vector3df farLeftUpPoint = cam->getViewFrustum()->getFarLeftUp();
|
||||
vector3df farRightUpPoint = cam->getViewFrustum()->getFarRightUp();
|
||||
vector3df farLeftDownPoint = cam->getViewFrustum()->getFarLeftDown();
|
||||
float camH = camPos.getDistanceFrom(farLeftUpPoint) * cos(getAngleBetween(farLeftUpPoint - camPos, camDir));
|
||||
float unitH = camPos.getDistanceFrom(pos) * cos(getAngleBetween(pos - camPos, camDir));
|
||||
float ratio = unitH / camH;
|
||||
float minRatio = ((cam->getViewFrustum()->getNearLeftUp() - camPos) / (farLeftUpPoint - camPos)).getLength();
|
||||
|
||||
if (minRatio <= ratio && ratio <= 1.) {
|
||||
float width = farRightUpPoint.getDistanceFrom(farLeftUpPoint) * ratio;
|
||||
float height = farLeftUpPoint.getDistanceFrom(farLeftDownPoint) * ratio;
|
||||
vector3df edgePoint = (farLeftUpPoint - camPos) * ratio + camPos;
|
||||
float angle = getAngleBetween(pos - edgePoint, -camLeft);
|
||||
float x = pos.getDistanceFrom(edgePoint) * cos(angle), y = pos.getDistanceFrom(edgePoint) * cos(PI / 2 - angle);
|
||||
|
||||
if (x <= width && y <= height) {
|
||||
selectable = true;
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
screenPos = vector2d<s32>(gm->getWidth() * x / width, gm->getHeight() * y / height);
|
||||
} else
|
||||
selectable = false;
|
||||
} else
|
||||
selectable = false;
|
||||
}
|
||||
light = smgr->addLightSceneNode(node, vector3df(0, 2, 0), SColor(255, 255, 255, 255), lineOfSight);
|
||||
light->setVisible(false);
|
||||
node->setVisible(false);
|
||||
*/
|
||||
selectionSfxBuffer = new sf::SoundBuffer();
|
||||
string p = PATH+"Sounds/"+unitData::name[id]+"s/selection.ogg";
|
||||
|
||||
void Unit::blowUp(){
|
||||
working = false;
|
||||
}
|
||||
if(selectionSfxBuffer->loadFromFile(p.c_str()))
|
||||
selectionSfx = new sf::Sound(*selectionSfxBuffer);
|
||||
}
|
||||
|
||||
Unit::~Unit() {
|
||||
/*
|
||||
void Unit::updateUnitGUIInfo(ICameraSceneNode* cam, vector3df camDir, vector3df camLeft, vector3df camUp) {
|
||||
updateScreenCoordinates(cam, camDir, camLeft, camUp);
|
||||
if (selected) {
|
||||
displayUnitStats();
|
||||
drawCuboid();
|
||||
}
|
||||
}
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
driver->removeTexture(node->getMaterial(0).getTexture(0));
|
||||
node->removeChild(light);
|
||||
node->getParent()->removeChild(node);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
void Unit::displayUnitStats() {
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
SColor white = SColor(255, 255, 255, 255);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(-51, 0), screenPos + vector2d<s32>(50, 0), white);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(-51, 0), screenPos + vector2d<s32>(-51, -20), white);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(-50, -20), screenPos + vector2d<s32>(50, -20), white);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(50, 0), screenPos + vector2d<s32>(50, -20), white);
|
||||
driver->draw2DRectangle(SColor(255, 0, 200, 0), rect<s32>(screenPos.X - 50, screenPos.Y - 19, screenPos.X - 50 + ((float)health / unitData::health[id]) * 100, screenPos.Y));
|
||||
void Unit::update() {
|
||||
if (orders.size() > 0){
|
||||
if(selected&&canDisplayOrderLine()){
|
||||
int r=0,g=0,b=0;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void Unit::drawCuboid() {
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
vector3df vec = unitCornerPoints[id][i];
|
||||
vector3df yVec;
|
||||
vec = leftVec * vec.X + upVec * vec.Y - dirVec * vec.Z;
|
||||
if (0 <= i && i < 4)
|
||||
yVec = vector3df(0, unitCuboidDimensions[id][i].Y, 0);
|
||||
else if (i >= 4)
|
||||
yVec = vector3df(0, -unitCuboidDimensions[id][i].Y, 0);
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 2 * i, vector3df(0, 1, 0));
|
||||
vector3df vec1 = rotQuat * (-leftVec * unitCuboidDimensions[id][i].X), vec2 = rotQuat * (-dirVec * unitCuboidDimensions[id][i].Z);
|
||||
driver->draw3DLine(pos + vec, pos + vec + vec1);
|
||||
driver->draw3DLine(pos + vec, pos + vec + vec2);
|
||||
driver->draw3DLine(pos + vec, pos + vec + yVec);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Unit::debug() {
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
driver->setMaterial(createLineMaterial());
|
||||
float length = unitAxisLength[id];
|
||||
driver->draw3DLine(pos, pos + dirVec * length, SColor(255, 0, 0, 255));
|
||||
driver->draw3DLine(pos, pos + leftVec * length, SColor(255, 255, 0, 0));
|
||||
driver->draw3DLine(pos, pos + upVec * length, SColor(255, 0, 255, 0));
|
||||
*/
|
||||
}
|
||||
|
||||
void Unit::executeOrders() {
|
||||
if (orders.size() > 0) {
|
||||
Order order = orders[0];
|
||||
|
||||
switch (order.type) {
|
||||
case Order::TYPE::ATTACK:
|
||||
attack(order);
|
||||
break;
|
||||
switch(orders[0].type){
|
||||
case Order::TYPE::MOVE:
|
||||
move(order, unitData::destinationOffset[id]);
|
||||
g=255;
|
||||
break;
|
||||
case Order::TYPE::ATTACK:
|
||||
r=255;
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
patrol(order);
|
||||
break;
|
||||
b=255;
|
||||
case Order::TYPE::LAUNCH:
|
||||
launch(order);
|
||||
break;
|
||||
default:
|
||||
r=255,g=255;
|
||||
break;
|
||||
}
|
||||
|
||||
//GameManager::getSingleton()->getDevice()->getVideoDriver()->draw3DLine(pos,*(orders[0].targetPos[0]),SColor(255,r,g,b));
|
||||
}
|
||||
|
||||
while (patrolPoints.size() > 0 && orders[0].type != Order::TYPE::PATROL) {
|
||||
patrolPoints.pop_back();
|
||||
patrolPointId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::setOrder(Order order) {
|
||||
while (orders.size() > 0)
|
||||
orders.pop_back();
|
||||
executeOrders();
|
||||
|
||||
addOrder(order);
|
||||
orderLineDispTime = getTime();
|
||||
}
|
||||
|
||||
void Unit::attack(Order order) {
|
||||
Vector3 target = *order.targetPos[0];
|
||||
|
||||
if (pos.getDistanceFrom(target) >= range)
|
||||
move(order, range);
|
||||
// InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
// for(Player *p : inGameState->getPlayers())
|
||||
// for(Unit *u : p->getUnits())
|
||||
// if(u->getPosPtr()==order.targetPos[0]){}
|
||||
}
|
||||
|
||||
void Unit::move(Order order, float destOffset) {
|
||||
float movementAmmount, radius = getCircleRadius(), angle = 0.;
|
||||
Vector3 dest = *order.targetPos[0];
|
||||
dest.y = pos.y;
|
||||
Vector3 center;
|
||||
|
||||
if (leftVec.getAngleBetween(dest - pos) < PI / 2) {
|
||||
moveDir = MoveDir::LEFT;
|
||||
center = pos + leftVec*radius;
|
||||
} else if (-leftVec.getAngleBetween(dest - pos) < PI / 2) {
|
||||
moveDir = MoveDir::RIGHT;
|
||||
center = pos - leftVec*radius;
|
||||
}
|
||||
|
||||
bool withinCircle = center.getDistanceFrom(dest) < radius ? true : false;
|
||||
|
||||
if (moveDir != MoveDir::FORWARD) {
|
||||
if (withinCircle)
|
||||
angle = dirVec.getAngleBetween(center - dest) / PI * 180;
|
||||
else
|
||||
angle = dirVec.getAngleBetween(dest - pos) / PI * 180;
|
||||
|
||||
angle = isnan(angle) ? 0. : angle;
|
||||
|
||||
if (angle > anglePrecision[id]) {
|
||||
float rotAngle = maxTurnAngle > angle ? angle : maxTurnAngle;
|
||||
angle -= rotAngle;
|
||||
turn(moveDir == MoveDir::RIGHT ? rotAngle : -rotAngle);
|
||||
}
|
||||
}
|
||||
|
||||
if (angle > anglePrecision[id])
|
||||
movementAmmount = speed;
|
||||
else {
|
||||
if (withinCircle) {
|
||||
float inDest = ((center - dest).norm() * radius - (center - dest)).getLength();
|
||||
movementAmmount = speed > inDest ? inDest : speed;
|
||||
} else
|
||||
movementAmmount = speed > pos.getDistanceFrom(dest) ? pos.getDistanceFrom(dest) : speed;
|
||||
}
|
||||
|
||||
advance(movementAmmount);
|
||||
|
||||
if (pos.getDistanceFrom(dest) <= destOffset && orders[0].type == Order::TYPE::MOVE) {
|
||||
moveDir = MoveDir::FORWARD;
|
||||
removeOrder(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::patrol(Order order) {
|
||||
move(order, unitData::destinationOffset[id]);
|
||||
}
|
||||
|
||||
void Unit::launch(Order order) {}
|
||||
|
||||
void Unit::advance(float speed) {
|
||||
pos = pos + dirVec * speed;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
|
||||
void Unit::turn(float angle) {// rad
|
||||
/*
|
||||
Quaternion rotQuat = Quaternion(PI / 180 * angle, Vector3(0, 1, 0));
|
||||
node->setOrientation(Vector3(node->getOrientation().x, node->getRotation().Y + angle, 0));
|
||||
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
|
||||
*/
|
||||
}
|
||||
|
||||
void Unit::halt() {
|
||||
while (orders.size() > 0)
|
||||
removeOrder(orders.size() - 1);
|
||||
}
|
||||
|
||||
float Unit::getCircleRadius() {
|
||||
float radius = 0.;
|
||||
for (int i = 0; i <= 90 / maxTurnAngle; i++)
|
||||
radius += cos(i * (maxTurnAngle / 180 * PI)) * speed;
|
||||
return radius;
|
||||
}
|
||||
|
||||
void Unit::placeUnit(Vector3 p) {
|
||||
node->setPosition(p);
|
||||
pos = p;
|
||||
}
|
||||
|
||||
void Unit::orientUnit(Vector3 orientVec){
|
||||
Vector3 orientVecProj = Vector3(orientVec.x, 0, orientVec.z).norm();
|
||||
float projAngle = orientVec.getAngleBetween(orientVecProj);
|
||||
float rotAngle = Vector3(0,0,-1).getAngleBetween(orientVecProj);
|
||||
|
||||
rotAngle *= (orientVec.x < 0 ? 1 : -1) / PI * 180;
|
||||
projAngle *= (orientVec.y > 0 ? 1 : -1) / PI * 180;
|
||||
dirVec = orientVecProj;
|
||||
upVec = Vector3(0,1,0);
|
||||
leftVec = Quaternion(-PI / 2, upVec) * dirVec;
|
||||
Quaternion rotQuat = Quaternion(projAngle / 180 * PI, leftVec);
|
||||
dirVec = rotQuat * dirVec;
|
||||
upVec = rotQuat * upVec;
|
||||
//node->setRotation(vector3df(projAngle,rotAngle,0));
|
||||
}
|
||||
|
||||
Vector3 Unit::getCorner(int i) {
|
||||
Vector3 corner = unitCornerPoints[id][i];
|
||||
return pos + (leftVec * corner.x + upVec * corner.y - dirVec * corner.z);
|
||||
}
|
||||
|
||||
std::vector<Projectile*> Unit::getProjectiles(){
|
||||
std::vector<Projectile*> projectiles;
|
||||
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
for(Projectile *p: inGameState->getProjectiles())
|
||||
if(p->getUnit()==this)
|
||||
projectiles.push_back(p);
|
||||
|
||||
return projectiles;
|
||||
}
|
||||
|
||||
void Unit::removeOrder(int id) {
|
||||
for (Vector3 *v : orders[id].targetPos) {
|
||||
bool isUnitPos = false;
|
||||
InGameAppState *state = (InGameAppState*) GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE);
|
||||
|
||||
for (Player *p : state->getPlayers())
|
||||
for (Unit *u : p->getUnits())
|
||||
if (v == u->getPosPtr())
|
||||
isUnitPos = true;
|
||||
|
||||
if(!isUnitPos)
|
||||
delete v;
|
||||
}
|
||||
|
||||
orders.erase(orders.begin() + id);
|
||||
}
|
||||
|
||||
void Unit::toggleSelection(bool selection) {
|
||||
selected = selection;
|
||||
|
||||
if(selection && selectionSfx)
|
||||
selectionSfx->play();
|
||||
|
||||
orderLineDispTime=getTime();
|
||||
}
|
||||
|
||||
/*
|
||||
SMaterial Unit::createLineMaterial() {
|
||||
SMaterial mat;
|
||||
mat.Lighting = false;
|
||||
return mat;
|
||||
}
|
||||
*/
|
||||
|
||||
void Unit::addProjectile(Projectile *p) {((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE))->addProjectile(p);}
|
||||
if (health <= 0)
|
||||
blowUp();
|
||||
}
|
||||
|
||||
/*
|
||||
void Unit::updateScreenCoordinates(ICameraSceneNode *cam, vector3df camDir, vector3df camLeft, vector3df camUp) {
|
||||
vector3df camPos = cam->getPosition();
|
||||
vector3df farLeftUpPoint = cam->getViewFrustum()->getFarLeftUp();
|
||||
vector3df farRightUpPoint = cam->getViewFrustum()->getFarRightUp();
|
||||
vector3df farLeftDownPoint = cam->getViewFrustum()->getFarLeftDown();
|
||||
float camH = camPos.getDistanceFrom(farLeftUpPoint) * cos(getAngleBetween(farLeftUpPoint - camPos, camDir));
|
||||
float unitH = camPos.getDistanceFrom(pos) * cos(getAngleBetween(pos - camPos, camDir));
|
||||
float ratio = unitH / camH;
|
||||
float minRatio = ((cam->getViewFrustum()->getNearLeftUp() - camPos) / (farLeftUpPoint - camPos)).getLength();
|
||||
|
||||
if (minRatio <= ratio && ratio <= 1.) {
|
||||
float width = farRightUpPoint.getDistanceFrom(farLeftUpPoint) * ratio;
|
||||
float height = farLeftUpPoint.getDistanceFrom(farLeftDownPoint) * ratio;
|
||||
vector3df edgePoint = (farLeftUpPoint - camPos) * ratio + camPos;
|
||||
float angle = getAngleBetween(pos - edgePoint, -camLeft);
|
||||
float x = pos.getDistanceFrom(edgePoint) * cos(angle), y = pos.getDistanceFrom(edgePoint) * cos(PI / 2 - angle);
|
||||
|
||||
if (x <= width && y <= height) {
|
||||
selectable = true;
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
screenPos = vector2d<s32>(gm->getWidth() * x / width, gm->getHeight() * y / height);
|
||||
} else
|
||||
selectable = false;
|
||||
} else
|
||||
selectable = false;
|
||||
}
|
||||
*/
|
||||
|
||||
void Unit::blowUp(){
|
||||
working = false;
|
||||
}
|
||||
|
||||
/*
|
||||
void Unit::updateUnitGUIInfo(ICameraSceneNode* cam, vector3df camDir, vector3df camLeft, vector3df camUp) {
|
||||
updateScreenCoordinates(cam, camDir, camLeft, camUp);
|
||||
if (selected) {
|
||||
displayUnitStats();
|
||||
drawCuboid();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void Unit::displayUnitStats() {
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
SColor white = SColor(255, 255, 255, 255);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(-51, 0), screenPos + vector2d<s32>(50, 0), white);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(-51, 0), screenPos + vector2d<s32>(-51, -20), white);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(-50, -20), screenPos + vector2d<s32>(50, -20), white);
|
||||
driver->draw2DLine(screenPos + vector2d<s32>(50, 0), screenPos + vector2d<s32>(50, -20), white);
|
||||
driver->draw2DRectangle(SColor(255, 0, 200, 0), rect<s32>(screenPos.X - 50, screenPos.Y - 19, screenPos.X - 50 + ((float)health / unitData::health[id]) * 100, screenPos.Y));
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void Unit::drawCuboid() {
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
vector3df vec = unitCornerPoints[id][i];
|
||||
vector3df yVec;
|
||||
vec = leftVec * vec.X + upVec * vec.Y - dirVec * vec.Z;
|
||||
if (0 <= i && i < 4)
|
||||
yVec = vector3df(0, unitCuboidDimensions[id][i].Y, 0);
|
||||
else if (i >= 4)
|
||||
yVec = vector3df(0, -unitCuboidDimensions[id][i].Y, 0);
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 2 * i, vector3df(0, 1, 0));
|
||||
vector3df vec1 = rotQuat * (-leftVec * unitCuboidDimensions[id][i].X), vec2 = rotQuat * (-dirVec * unitCuboidDimensions[id][i].Z);
|
||||
driver->draw3DLine(pos + vec, pos + vec + vec1);
|
||||
driver->draw3DLine(pos + vec, pos + vec + vec2);
|
||||
driver->draw3DLine(pos + vec, pos + vec + yVec);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Unit::debug() {
|
||||
/*
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
driver->setMaterial(createLineMaterial());
|
||||
float length = unitAxisLength[id];
|
||||
driver->draw3DLine(pos, pos + dirVec * length, SColor(255, 0, 0, 255));
|
||||
driver->draw3DLine(pos, pos + leftVec * length, SColor(255, 255, 0, 0));
|
||||
driver->draw3DLine(pos, pos + upVec * length, SColor(255, 0, 255, 0));
|
||||
*/
|
||||
}
|
||||
|
||||
void Unit::executeOrders() {
|
||||
if (orders.size() > 0) {
|
||||
Order order = orders[0];
|
||||
|
||||
switch (order.type) {
|
||||
case Order::TYPE::ATTACK:
|
||||
attack(order);
|
||||
break;
|
||||
case Order::TYPE::MOVE:
|
||||
move(order, unitData::destinationOffset[id]);
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
patrol(order);
|
||||
break;
|
||||
case Order::TYPE::LAUNCH:
|
||||
launch(order);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::setOrder(Order order) {
|
||||
while (orders.size() > 0)
|
||||
orders.pop_back();
|
||||
|
||||
addOrder(order);
|
||||
orderLineDispTime = getTime();
|
||||
}
|
||||
|
||||
void Unit::attack(Order order) {
|
||||
Vector3 target = *order.targetPos[0];
|
||||
|
||||
if (pos.getDistanceFrom(target) >= range)
|
||||
move(order, range);
|
||||
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
for(Player *p : inGameState->getPlayers())
|
||||
for(Unit *u : p->getUnits())
|
||||
if(u->getPosPtr()==order.targetPos[0]){}
|
||||
}
|
||||
|
||||
void Unit::move(Order order, float destOffset) {
|
||||
float movementAmmount, radius = getCircleRadius(), angle = 0.;
|
||||
Vector3 dest = *order.targetPos[0];
|
||||
dest.y = pos.y;
|
||||
Vector3 center;
|
||||
|
||||
if (leftVec.getAngleBetween(dest - pos) < PI / 2) {
|
||||
moveDir = MoveDir::LEFT;
|
||||
center = pos + leftVec*radius;
|
||||
} else if (-leftVec.getAngleBetween(dest - pos) < PI / 2) {
|
||||
moveDir = MoveDir::RIGHT;
|
||||
center = pos - leftVec*radius;
|
||||
}
|
||||
|
||||
bool withinCircle = center.getDistanceFrom(dest) < radius ? true : false;
|
||||
|
||||
if (moveDir != MoveDir::FORWARD) {
|
||||
if (withinCircle)
|
||||
angle = dirVec.getAngleBetween(center - dest) / PI * 180;
|
||||
else
|
||||
angle = dirVec.getAngleBetween(dest - pos) / PI * 180;
|
||||
|
||||
angle = isnan(angle) ? 0. : angle;
|
||||
|
||||
if (angle > anglePrecision[id]) {
|
||||
float rotAngle = maxTurnAngle > angle ? angle : maxTurnAngle;
|
||||
angle -= rotAngle;
|
||||
turn(moveDir == MoveDir::RIGHT ? rotAngle : -rotAngle);
|
||||
}
|
||||
}
|
||||
|
||||
if (angle > anglePrecision[id])
|
||||
movementAmmount = speed;
|
||||
else {
|
||||
if (withinCircle) {
|
||||
float inDest = ((center - dest).norm() * radius - (center - dest)).getLength();
|
||||
movementAmmount = speed > inDest ? inDest : speed;
|
||||
} else
|
||||
movementAmmount = speed > pos.getDistanceFrom(dest) ? pos.getDistanceFrom(dest) : speed;
|
||||
}
|
||||
|
||||
advance(movementAmmount);
|
||||
|
||||
if (pos.getDistanceFrom(dest) <= destOffset && orders[0].type == Order::TYPE::MOVE) {
|
||||
moveDir = MoveDir::FORWARD;
|
||||
removeOrder(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::patrol(Order order) {
|
||||
move(order, unitData::destinationOffset[id]);
|
||||
}
|
||||
|
||||
void Unit::launch(Order order) {}
|
||||
|
||||
void Unit::advance(float speed) {
|
||||
pos = pos + dirVec * speed;
|
||||
node->setPosition(pos);
|
||||
}
|
||||
|
||||
void Unit::turn(float angle) {// rad
|
||||
/*
|
||||
Quaternion rotQuat = Quaternion(PI / 180 * angle, Vector3(0, 1, 0));
|
||||
node->setOrientation(Vector3(node->getOrientation().x, node->getRotation().Y + angle, 0));
|
||||
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
|
||||
*/
|
||||
}
|
||||
|
||||
void Unit::halt() {
|
||||
while (orders.size() > 0)
|
||||
removeOrder(orders.size() - 1);
|
||||
}
|
||||
|
||||
float Unit::getCircleRadius() {
|
||||
float radius = 0.;
|
||||
for (int i = 0; i <= 90 / maxTurnAngle; i++)
|
||||
radius += cos(i * (maxTurnAngle / 180 * PI)) * speed;
|
||||
return radius;
|
||||
}
|
||||
|
||||
void Unit::placeUnit(Vector3 p) {
|
||||
node->setPosition(p);
|
||||
pos = p;
|
||||
}
|
||||
|
||||
void Unit::orientUnit(Vector3 orientVec){
|
||||
Vector3 orientVecProj = Vector3(orientVec.x, 0, orientVec.z).norm();
|
||||
float projAngle = orientVec.getAngleBetween(orientVecProj);
|
||||
float rotAngle = Vector3(0,0,-1).getAngleBetween(orientVecProj);
|
||||
|
||||
rotAngle *= (orientVec.x < 0 ? 1 : -1) / PI * 180;
|
||||
projAngle *= (orientVec.y > 0 ? 1 : -1) / PI * 180;
|
||||
dirVec = orientVecProj;
|
||||
upVec = Vector3(0,1,0);
|
||||
leftVec = Quaternion(-PI / 2, upVec) * dirVec;
|
||||
Quaternion rotQuat = Quaternion(projAngle / 180 * PI, leftVec);
|
||||
dirVec = rotQuat * dirVec;
|
||||
upVec = rotQuat * upVec;
|
||||
//node->setRotation(vector3df(projAngle,rotAngle,0));
|
||||
}
|
||||
|
||||
Vector3 Unit::getCorner(int i) {
|
||||
Vector3 corner = unitCornerPoints[id][i];
|
||||
return pos + (leftVec * corner.x + upVec * corner.y - dirVec * corner.z);
|
||||
}
|
||||
|
||||
std::vector<Projectile*> Unit::getProjectiles(){
|
||||
std::vector<Projectile*> projectiles;
|
||||
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
|
||||
|
||||
for(Projectile *p: inGameState->getProjectiles())
|
||||
if(p->getUnit()==this)
|
||||
projectiles.push_back(p);
|
||||
|
||||
return projectiles;
|
||||
}
|
||||
|
||||
void Unit::removeOrder(int id) {
|
||||
for (Vector3 *v : orders[id].targetPos) {
|
||||
bool isUnitPos = false;
|
||||
InGameAppState *state = (InGameAppState*) GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE);
|
||||
|
||||
for (Player *p : state->getPlayers())
|
||||
for (Unit *u : p->getUnits())
|
||||
if (v == u->getPosPtr())
|
||||
isUnitPos = true;
|
||||
|
||||
if(!isUnitPos)
|
||||
delete v;
|
||||
}
|
||||
|
||||
orders.erase(orders.begin() + id);
|
||||
}
|
||||
|
||||
void Unit::toggleSelection(bool selection) {
|
||||
selected = selection;
|
||||
|
||||
if(selection && selectionSfx)
|
||||
selectionSfx->play();
|
||||
|
||||
orderLineDispTime=getTime();
|
||||
}
|
||||
|
||||
/*
|
||||
SMaterial Unit::createLineMaterial() {
|
||||
SMaterial mat;
|
||||
mat.Lighting = false;
|
||||
return mat;
|
||||
}
|
||||
*/
|
||||
|
||||
void Unit::addProjectile(Projectile *p) {((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE))->addProjectile(p);}
|
||||
}
|
||||
|
||||
@@ -10,104 +10,100 @@
|
||||
#include "gameManager.h"
|
||||
#include "projectile.h"
|
||||
|
||||
using namespace game::content::unitData;
|
||||
|
||||
namespace vb01{
|
||||
class Mesh;
|
||||
class Node;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
class Player;
|
||||
|
||||
struct Order {
|
||||
enum class TYPE {ATTACK, MOVE, PATROL, LAUNCH};
|
||||
TYPE type;
|
||||
std::vector<vb01::Vector3*> targetPos;
|
||||
};
|
||||
|
||||
enum class MoveDir {FORWARD, LEFT, RIGHT};
|
||||
|
||||
enum class Corner {FRONT_LEFT, FRONT_RIGHT, REAR_LEFT, REAR_RIGHT};
|
||||
|
||||
class Unit {
|
||||
public:
|
||||
Unit(Player*, vb01::Vector3, int);
|
||||
~Unit();
|
||||
virtual void update();
|
||||
virtual void blowUp();
|
||||
//virtual void updateUnitGUIInfo(ICameraSceneNode*, vector3df, vector3df, vector3df);
|
||||
virtual void debug();
|
||||
virtual void halt();
|
||||
void toggleSelection(bool);
|
||||
void setOrder(Order);
|
||||
void placeUnit(vb01::Vector3);
|
||||
void orientUnit(vb01::Vector3);
|
||||
void addProjectile(Projectile*);
|
||||
float getCircleRadius();
|
||||
vb01::Vector3 getCorner(int);
|
||||
std::vector<Projectile*> getProjectiles();
|
||||
inline bool isSelected(){return selected;}
|
||||
inline bool isSelectable(){return selectable;}
|
||||
inline bool isDebuggable(){return debugging;}
|
||||
inline bool isWorking(){return working;}
|
||||
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
||||
inline void addOrder(Order o){orders.push_back(o);}
|
||||
inline vb01::Vector3 getPos() {return pos;}
|
||||
inline vb01::Vector3* getPosPtr() {return &pos;}
|
||||
//inline ILightSceneNode* getLight() {return light;}
|
||||
inline float getLineOfSight() {return lineOfSight;}
|
||||
inline float getWidth() {return width;}
|
||||
inline float getHeight() {return height;}
|
||||
inline float getLength() {return length;}
|
||||
inline vb01::Node* getNode() {return node;}
|
||||
inline Player* getPlayer(){return player;}
|
||||
inline unitData::UNIT_TYPE getType() {return type;}
|
||||
inline void toggleDebugging(bool d){this->debugging=d;}
|
||||
inline void takeDamage(int damage) {health -= damage;}
|
||||
inline int getId() {return id;}
|
||||
inline int getPlayerId() {return playerId;}
|
||||
inline vb01::Vector3 getDirVec() {return dirVec;}
|
||||
inline vb01::Vector3 getLeftVec() {return leftVec;}
|
||||
inline vb01::Vector3 getUpVec() {return upVec;}
|
||||
private:
|
||||
//void updateScreenCoordinates(ICameraSceneNode*, vector3df, vector3df, vector3df);
|
||||
void displayUnitStats();
|
||||
inline int getNextPatrolPointId() {return patrolPointId == patrolPoints.size() - 1 ? 0 : patrolPointId + 1;}
|
||||
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
||||
//ILightSceneNode *light;
|
||||
const int orderVecDispLength=2000;
|
||||
sf::SoundBuffer *selectionSfxBuffer;
|
||||
sf::Sound *selectionSfx=nullptr;
|
||||
protected:
|
||||
Player *player;
|
||||
MoveDir moveDir = MoveDir::FORWARD;
|
||||
//vb01::Material createLineMaterial();
|
||||
unitData::UNIT_TYPE type;
|
||||
vb01::Camera *cam = nullptr;
|
||||
vb01::Vector2 screenPos;
|
||||
std::vector<Order> orders;
|
||||
std::vector<vb01::Vector3> patrolPoints;
|
||||
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);
|
||||
int health, cost, id, patrolPointId = 0, playerId;
|
||||
s64 orderLineDispTime=0;
|
||||
vb01::Mesh *mesh;
|
||||
vb01::Node *node;
|
||||
bool selected = false, selectable, debugging = false, working=true;
|
||||
float lineOfSight, speed, maxTurnAngle, range, width, height, length;
|
||||
void removeOrder(int);
|
||||
virtual void executeOrders();
|
||||
virtual void attack(Order);
|
||||
virtual void move(Order, float = 0.);
|
||||
virtual void patrol(Order);
|
||||
virtual void launch(Order);
|
||||
virtual void turn(float);
|
||||
virtual void advance(float);
|
||||
void drawCuboid();
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
class Player;
|
||||
|
||||
struct Order {
|
||||
enum class TYPE {ATTACK, MOVE, PATROL, LAUNCH};
|
||||
TYPE type;
|
||||
std::vector<vb01::Vector3*> targetPos;
|
||||
};
|
||||
|
||||
enum class MoveDir {FORWARD, LEFT, RIGHT};
|
||||
|
||||
enum class Corner {FRONT_LEFT, FRONT_RIGHT, REAR_LEFT, REAR_RIGHT};
|
||||
|
||||
class Unit {
|
||||
public:
|
||||
Unit(Player*, vb01::Vector3, int);
|
||||
~Unit();
|
||||
virtual void update();
|
||||
virtual void blowUp();
|
||||
//virtual void updateUnitGUIInfo(ICameraSceneNode*, vector3df, vector3df, vector3df);
|
||||
virtual void debug();
|
||||
virtual void halt();
|
||||
void toggleSelection(bool);
|
||||
void setOrder(Order);
|
||||
void placeUnit(vb01::Vector3);
|
||||
void orientUnit(vb01::Vector3);
|
||||
void addProjectile(Projectile*);
|
||||
float getCircleRadius();
|
||||
vb01::Vector3 getCorner(int);
|
||||
std::vector<Projectile*> getProjectiles();
|
||||
inline bool isSelected(){return selected;}
|
||||
inline bool isSelectable(){return selectable;}
|
||||
inline bool isDebuggable(){return debugging;}
|
||||
inline bool isWorking(){return working;}
|
||||
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
||||
inline void addOrder(Order o){orders.push_back(o);}
|
||||
inline vb01::Vector3 getPos() {return pos;}
|
||||
inline vb01::Vector3* getPosPtr() {return &pos;}
|
||||
//inline ILightSceneNode* getLight() {return light;}
|
||||
inline float getLineOfSight() {return lineOfSight;}
|
||||
inline float getWidth() {return width;}
|
||||
inline float getHeight() {return height;}
|
||||
inline float getLength() {return length;}
|
||||
inline vb01::Node* getNode() {return node;}
|
||||
inline Player* getPlayer(){return player;}
|
||||
inline unitData::UNIT_TYPE getType() {return type;}
|
||||
inline void toggleDebugging(bool d){this->debugging=d;}
|
||||
inline void takeDamage(int damage) {health -= damage;}
|
||||
inline int getId() {return id;}
|
||||
inline int getPlayerId() {return playerId;}
|
||||
inline vb01::Vector3 getDirVec() {return dirVec;}
|
||||
inline vb01::Vector3 getLeftVec() {return leftVec;}
|
||||
inline vb01::Vector3 getUpVec() {return upVec;}
|
||||
private:
|
||||
//void updateScreenCoordinates(ICameraSceneNode*, vector3df, vector3df, vector3df);
|
||||
void displayUnitStats();
|
||||
inline int getNextPatrolPointId() {return patrolPointId == patrolPoints.size() - 1 ? 0 : patrolPointId + 1;}
|
||||
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
||||
//ILightSceneNode *light;
|
||||
const int orderVecDispLength=2000;
|
||||
sf::SoundBuffer *selectionSfxBuffer;
|
||||
sf::Sound *selectionSfx=nullptr;
|
||||
protected:
|
||||
Player *player;
|
||||
MoveDir moveDir = MoveDir::FORWARD;
|
||||
//vb01::Material createLineMaterial();
|
||||
unitData::UNIT_TYPE type;
|
||||
vb01::Camera *cam = nullptr;
|
||||
vb01::Vector2 screenPos;
|
||||
std::vector<Order> orders;
|
||||
std::vector<vb01::Vector3> patrolPoints;
|
||||
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);
|
||||
int health, cost, id, patrolPointId = 0, playerId;
|
||||
s64 orderLineDispTime=0;
|
||||
vb01::Mesh *mesh;
|
||||
vb01::Node *node;
|
||||
bool selected = false, selectable, debugging = false, working=true;
|
||||
float lineOfSight, speed, maxTurnAngle, range, width, height, length;
|
||||
void removeOrder(int);
|
||||
virtual void executeOrders();
|
||||
virtual void attack(Order);
|
||||
virtual void move(Order, float = 0.);
|
||||
virtual void patrol(Order);
|
||||
virtual void launch(Order);
|
||||
virtual void turn(float);
|
||||
virtual void advance(float);
|
||||
void drawCuboid();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+270
-272
@@ -16,278 +16,276 @@
|
||||
*/
|
||||
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
namespace unitData {
|
||||
using namespace game::core;
|
||||
|
||||
const int numberOfUnits = 11;
|
||||
enum class UNIT_TYPE {VESSEL, DESTROYER, CRUISER, AIRCRAFT_CARRIER, SUBMARINE, MISSILE_JET, DEMO_JET};
|
||||
const UNIT_TYPE unitType[numberOfUnits]{
|
||||
UNIT_TYPE::VESSEL, UNIT_TYPE::VESSEL,
|
||||
UNIT_TYPE::DESTROYER, UNIT_TYPE::DESTROYER,
|
||||
UNIT_TYPE::CRUISER, UNIT_TYPE::CRUISER,
|
||||
UNIT_TYPE::AIRCRAFT_CARRIER, UNIT_TYPE::AIRCRAFT_CARRIER,
|
||||
UNIT_TYPE::SUBMARINE,
|
||||
UNIT_TYPE::MISSILE_JET, UNIT_TYPE::DEMO_JET
|
||||
};
|
||||
const int health[numberOfUnits]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500};
|
||||
const float speed[numberOfUnits]{.025, .025, .05, .05, .1, .1, .1, .1, .1, .1, .15};
|
||||
const float destinationOffset[numberOfUnits]{.75, .75, 1, 1, .1, .1, .1, .1, .1, .5, .5};
|
||||
const float anglePrecision[numberOfUnits]{.1, .1, .1, .1, .1, .1, .1, .1, .1, 3,3};
|
||||
const int cost[numberOfUnits]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500};
|
||||
const float maxTurnAngle[numberOfUnits]{1, 1, .5, .5, 1, 1, .5, .5, 1, 2, 2};
|
||||
const float range[numberOfUnits]{15, 15, 14, 14, 13, 13, 12, 12,15,25};
|
||||
const vb01::Vector3 unitCornerPoints[numberOfUnits][8]{
|
||||
{
|
||||
vb01::Vector3(.9, -1, -6),
|
||||
vb01::Vector3(-.9, -1, -6),
|
||||
vb01::Vector3(-.9, -1, 5.8),
|
||||
vb01::Vector3(.9, -1, 5.8),
|
||||
vb01::Vector3(.9, 3.5, -6),
|
||||
vb01::Vector3(-.9, 3.5, -6),
|
||||
vb01::Vector3(-.9, 3.5, 5.8),
|
||||
vb01::Vector3(.9, 3.5, 5.8)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.5, -7.05),
|
||||
vb01::Vector3(-.5, -.5, -7.05),
|
||||
vb01::Vector3(-.5, -.5, 6.4),
|
||||
vb01::Vector3(.5, -.5, 6.4),
|
||||
vb01::Vector3(.5, 3, -7.05),
|
||||
vb01::Vector3(-.5, 3, -7.05),
|
||||
vb01::Vector3(-.5, 3, 6.4),
|
||||
vb01::Vector3(.5, 3, 6.4)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.5, -3.4),
|
||||
vb01::Vector3(-.5, -.5, -3.4),
|
||||
vb01::Vector3(-.5, -.5, 3.4),
|
||||
vb01::Vector3(.5, -.4, 3.4),
|
||||
vb01::Vector3(.5, 2.1, -3.4),
|
||||
vb01::Vector3(-.5, 2, -3.4),
|
||||
vb01::Vector3(-.5, 2, 3.4),
|
||||
vb01::Vector3(.5, 2, 3.4)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.25, -4.8),
|
||||
vb01::Vector3(-.5, -.25, -4.8),
|
||||
vb01::Vector3(-.5, -.25, 4.7),
|
||||
vb01::Vector3(.5, -.25, 4.7),
|
||||
vb01::Vector3(.5, .8, -4.8),
|
||||
vb01::Vector3(-.5, .8, -4.8),
|
||||
vb01::Vector3(-.5, .8, 4.7),
|
||||
vb01::Vector3(.5, .8, 4.7)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.7, -.3, -4),
|
||||
vb01::Vector3(-.7, -.3, -4),
|
||||
vb01::Vector3(-.7, -.3, 3.4),
|
||||
vb01::Vector3(.7, -.3, 3.4),
|
||||
vb01::Vector3(.7, 2.9, -4),
|
||||
vb01::Vector3(-.7, 2.9, -4),
|
||||
vb01::Vector3(-.7, 2.9, 3.4),
|
||||
vb01::Vector3(.7, 2.9, 3.4)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.5, -6.1),
|
||||
vb01::Vector3(-.5, -.5, -6.1),
|
||||
vb01::Vector3(-.5, -.5, 5.2),
|
||||
vb01::Vector3(.5, -.5, 5.2),
|
||||
vb01::Vector3(.5, 2.2, -6.1),
|
||||
vb01::Vector3(-.5, 2.2, -6.1),
|
||||
vb01::Vector3(-.5, 2.2, 5.2),
|
||||
vb01::Vector3(.5, 2.2, 5.2)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(2, -.5, -10),
|
||||
vb01::Vector3(-2, -.5, -10),
|
||||
vb01::Vector3(-2, -.5, 9),
|
||||
vb01::Vector3(2, -.5, 9),
|
||||
vb01::Vector3(2, 5.5, -10),
|
||||
vb01::Vector3(-2, 5.5, -10),
|
||||
vb01::Vector3(-2, 5.5, 9),
|
||||
vb01::Vector3(2, 5.5, 9)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(2, -1, -10),
|
||||
vb01::Vector3(-2, -1, -10),
|
||||
vb01::Vector3(-2, -1, 9),
|
||||
vb01::Vector3(2, -1, 9),
|
||||
vb01::Vector3(2, 4.5, -10),
|
||||
vb01::Vector3(-2, 4.5, -10),
|
||||
vb01::Vector3(-2, 4.5, 9),
|
||||
vb01::Vector3(2, 4.5, 9)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.25, -.5, -2),
|
||||
vb01::Vector3(-.25, -.5, -2),
|
||||
vb01::Vector3(-.25, -.5, 3),
|
||||
vb01::Vector3(.25, -.5, 3),
|
||||
vb01::Vector3(.25, .7, -2),
|
||||
vb01::Vector3(-.25, .7, -2),
|
||||
vb01::Vector3(-.25, .7, 3),
|
||||
vb01::Vector3(.25, .7, 3)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.6,-.1,-1.3),
|
||||
vb01::Vector3(-.6,-.1,-1.3),
|
||||
vb01::Vector3(-.6,-.1,.8),
|
||||
vb01::Vector3(.6,-.1,.8),
|
||||
vb01::Vector3(.6,.3,-1.3),
|
||||
vb01::Vector3(-.6,.3,-1.3),
|
||||
vb01::Vector3(-.6,.3,.8),
|
||||
vb01::Vector3(.6,.3,.8)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5,-.1,-1.3),
|
||||
vb01::Vector3(-.5,-.1,-1.3),
|
||||
vb01::Vector3(-.5,-.1,.7),
|
||||
vb01::Vector3(.5,-.1,.7),
|
||||
vb01::Vector3(.5,.15,-1.3),
|
||||
vb01::Vector3(-.5,.15,-1.3),
|
||||
vb01::Vector3(-.5,.15,.7),
|
||||
vb01::Vector3(.5,.15,.7)
|
||||
}
|
||||
};
|
||||
const vb01::Vector3 unitCuboidDimensions[numberOfUnits][8]{
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1)
|
||||
}
|
||||
};
|
||||
const float unitAxisLength[numberOfUnits]{8, 8,6,6,5, 5,8, 8, 7,2,2};
|
||||
const float lineOfSight[numberOfUnits]{5, 8, 4, 4, 3, 3, 6, 6, 3, 3, 8};
|
||||
const std::string name[numberOfUnits]{
|
||||
"Battleship", "Battleship",
|
||||
"Destroyer", "Destroyer",
|
||||
"Cruiser", "Cruiser",
|
||||
"Aircraft carrier", "Aircraft carrier",
|
||||
"Submarine",
|
||||
"Jet", "Jet"
|
||||
};
|
||||
const std::string meshPath[numberOfUnits]{
|
||||
"hull00.x", "hull01.x",
|
||||
"hull00.x", "hull01.x",
|
||||
"hull00.x", "hull01.x",
|
||||
"hull00.x", "hull01.x",
|
||||
"hull.x",
|
||||
"jet00.x", "jet01.x"
|
||||
};
|
||||
const std::string basePath[numberOfUnits]{
|
||||
PATH + "Models/Battleships/", PATH + "Models/Battleships/",
|
||||
PATH + "Models/Destroyers/", PATH + "Models/Destroyers/",
|
||||
PATH + "Models/Cruisers/", PATH + "Models/Cruisers/",
|
||||
PATH + "Models/Aircraft carriers/", PATH + "Models/Aircraft carriers/",
|
||||
PATH + "Models/Submarines/",
|
||||
PATH + "Models/Jets/", PATH + "Models/Jets/"};
|
||||
}
|
||||
namespace battleship {
|
||||
namespace unitData {
|
||||
using namespace configData;
|
||||
|
||||
const int numberOfUnits = 11;
|
||||
enum class UNIT_TYPE {VESSEL, DESTROYER, CRUISER, AIRCRAFT_CARRIER, SUBMARINE, MISSILE_JET, DEMO_JET};
|
||||
const UNIT_TYPE unitType[numberOfUnits]{
|
||||
UNIT_TYPE::VESSEL, UNIT_TYPE::VESSEL,
|
||||
UNIT_TYPE::DESTROYER, UNIT_TYPE::DESTROYER,
|
||||
UNIT_TYPE::CRUISER, UNIT_TYPE::CRUISER,
|
||||
UNIT_TYPE::AIRCRAFT_CARRIER, UNIT_TYPE::AIRCRAFT_CARRIER,
|
||||
UNIT_TYPE::SUBMARINE,
|
||||
UNIT_TYPE::MISSILE_JET, UNIT_TYPE::DEMO_JET
|
||||
};
|
||||
const int health[numberOfUnits]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500};
|
||||
const float speed[numberOfUnits]{.025, .025, .05, .05, .1, .1, .1, .1, .1, .1, .15};
|
||||
const float destinationOffset[numberOfUnits]{.75, .75, 1, 1, .1, .1, .1, .1, .1, .5, .5};
|
||||
const float anglePrecision[numberOfUnits]{.1, .1, .1, .1, .1, .1, .1, .1, .1, 3,3};
|
||||
const int cost[numberOfUnits]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500};
|
||||
const float maxTurnAngle[numberOfUnits]{1, 1, .5, .5, 1, 1, .5, .5, 1, 2, 2};
|
||||
const float range[numberOfUnits]{15, 15, 14, 14, 13, 13, 12, 12,15,25};
|
||||
const vb01::Vector3 unitCornerPoints[numberOfUnits][8]{
|
||||
{
|
||||
vb01::Vector3(.9, -1, -6),
|
||||
vb01::Vector3(-.9, -1, -6),
|
||||
vb01::Vector3(-.9, -1, 5.8),
|
||||
vb01::Vector3(.9, -1, 5.8),
|
||||
vb01::Vector3(.9, 3.5, -6),
|
||||
vb01::Vector3(-.9, 3.5, -6),
|
||||
vb01::Vector3(-.9, 3.5, 5.8),
|
||||
vb01::Vector3(.9, 3.5, 5.8)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.5, -7.05),
|
||||
vb01::Vector3(-.5, -.5, -7.05),
|
||||
vb01::Vector3(-.5, -.5, 6.4),
|
||||
vb01::Vector3(.5, -.5, 6.4),
|
||||
vb01::Vector3(.5, 3, -7.05),
|
||||
vb01::Vector3(-.5, 3, -7.05),
|
||||
vb01::Vector3(-.5, 3, 6.4),
|
||||
vb01::Vector3(.5, 3, 6.4)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.5, -3.4),
|
||||
vb01::Vector3(-.5, -.5, -3.4),
|
||||
vb01::Vector3(-.5, -.5, 3.4),
|
||||
vb01::Vector3(.5, -.4, 3.4),
|
||||
vb01::Vector3(.5, 2.1, -3.4),
|
||||
vb01::Vector3(-.5, 2, -3.4),
|
||||
vb01::Vector3(-.5, 2, 3.4),
|
||||
vb01::Vector3(.5, 2, 3.4)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.25, -4.8),
|
||||
vb01::Vector3(-.5, -.25, -4.8),
|
||||
vb01::Vector3(-.5, -.25, 4.7),
|
||||
vb01::Vector3(.5, -.25, 4.7),
|
||||
vb01::Vector3(.5, .8, -4.8),
|
||||
vb01::Vector3(-.5, .8, -4.8),
|
||||
vb01::Vector3(-.5, .8, 4.7),
|
||||
vb01::Vector3(.5, .8, 4.7)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.7, -.3, -4),
|
||||
vb01::Vector3(-.7, -.3, -4),
|
||||
vb01::Vector3(-.7, -.3, 3.4),
|
||||
vb01::Vector3(.7, -.3, 3.4),
|
||||
vb01::Vector3(.7, 2.9, -4),
|
||||
vb01::Vector3(-.7, 2.9, -4),
|
||||
vb01::Vector3(-.7, 2.9, 3.4),
|
||||
vb01::Vector3(.7, 2.9, 3.4)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5, -.5, -6.1),
|
||||
vb01::Vector3(-.5, -.5, -6.1),
|
||||
vb01::Vector3(-.5, -.5, 5.2),
|
||||
vb01::Vector3(.5, -.5, 5.2),
|
||||
vb01::Vector3(.5, 2.2, -6.1),
|
||||
vb01::Vector3(-.5, 2.2, -6.1),
|
||||
vb01::Vector3(-.5, 2.2, 5.2),
|
||||
vb01::Vector3(.5, 2.2, 5.2)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(2, -.5, -10),
|
||||
vb01::Vector3(-2, -.5, -10),
|
||||
vb01::Vector3(-2, -.5, 9),
|
||||
vb01::Vector3(2, -.5, 9),
|
||||
vb01::Vector3(2, 5.5, -10),
|
||||
vb01::Vector3(-2, 5.5, -10),
|
||||
vb01::Vector3(-2, 5.5, 9),
|
||||
vb01::Vector3(2, 5.5, 9)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(2, -1, -10),
|
||||
vb01::Vector3(-2, -1, -10),
|
||||
vb01::Vector3(-2, -1, 9),
|
||||
vb01::Vector3(2, -1, 9),
|
||||
vb01::Vector3(2, 4.5, -10),
|
||||
vb01::Vector3(-2, 4.5, -10),
|
||||
vb01::Vector3(-2, 4.5, 9),
|
||||
vb01::Vector3(2, 4.5, 9)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.25, -.5, -2),
|
||||
vb01::Vector3(-.25, -.5, -2),
|
||||
vb01::Vector3(-.25, -.5, 3),
|
||||
vb01::Vector3(.25, -.5, 3),
|
||||
vb01::Vector3(.25, .7, -2),
|
||||
vb01::Vector3(-.25, .7, -2),
|
||||
vb01::Vector3(-.25, .7, 3),
|
||||
vb01::Vector3(.25, .7, 3)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.6,-.1,-1.3),
|
||||
vb01::Vector3(-.6,-.1,-1.3),
|
||||
vb01::Vector3(-.6,-.1,.8),
|
||||
vb01::Vector3(.6,-.1,.8),
|
||||
vb01::Vector3(.6,.3,-1.3),
|
||||
vb01::Vector3(-.6,.3,-1.3),
|
||||
vb01::Vector3(-.6,.3,.8),
|
||||
vb01::Vector3(.6,.3,.8)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.5,-.1,-1.3),
|
||||
vb01::Vector3(-.5,-.1,-1.3),
|
||||
vb01::Vector3(-.5,-.1,.7),
|
||||
vb01::Vector3(.5,-.1,.7),
|
||||
vb01::Vector3(.5,.15,-1.3),
|
||||
vb01::Vector3(-.5,.15,-1.3),
|
||||
vb01::Vector3(-.5,.15,.7),
|
||||
vb01::Vector3(.5,.15,.7)
|
||||
}
|
||||
};
|
||||
const vb01::Vector3 unitCuboidDimensions[numberOfUnits][8]{
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1),
|
||||
vb01::Vector3(1, 1, 1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1),
|
||||
vb01::Vector3(.1, .1, .1)
|
||||
}
|
||||
};
|
||||
const float unitAxisLength[numberOfUnits]{8, 8,6,6,5, 5,8, 8, 7,2,2};
|
||||
const float lineOfSight[numberOfUnits]{5, 8, 4, 4, 3, 3, 6, 6, 3, 3, 8};
|
||||
const std::string name[numberOfUnits]{
|
||||
"Battleship", "Battleship",
|
||||
"Destroyer", "Destroyer",
|
||||
"Cruiser", "Cruiser",
|
||||
"Aircraft carrier", "Aircraft carrier",
|
||||
"Submarine",
|
||||
"Jet", "Jet"
|
||||
};
|
||||
const std::string meshPath[numberOfUnits]{
|
||||
"hull00.x", "hull01.x",
|
||||
"hull00.x", "hull01.x",
|
||||
"hull00.x", "hull01.x",
|
||||
"hull00.x", "hull01.x",
|
||||
"hull.x",
|
||||
"jet00.x", "jet01.x"
|
||||
};
|
||||
const std::string basePath[numberOfUnits]{
|
||||
PATH + "Models/Battleships/", PATH + "Models/Battleships/",
|
||||
PATH + "Models/Destroyers/", PATH + "Models/Destroyers/",
|
||||
PATH + "Models/Cruisers/", PATH + "Models/Cruisers/",
|
||||
PATH + "Models/Aircraft carriers/", PATH + "Models/Aircraft carriers/",
|
||||
PATH + "Models/Submarines/",
|
||||
PATH + "Models/Jets/", PATH + "Models/Jets/"};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,137 +10,58 @@
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace game;
|
||||
using namespace game::gui;
|
||||
using namespace game::core;
|
||||
|
||||
namespace game{
|
||||
namespace util{
|
||||
void makeTitlescreenButtons(GuiAppState *state) {
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
class SpButton : public Button {
|
||||
public:
|
||||
SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
void makeTitlescreenButtons(GuiAppState *state) {
|
||||
|
||||
void onClick() {
|
||||
vector<string> difficulties, factions;
|
||||
class SpButton : public Button {
|
||||
public:
|
||||
SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
class PlayButton : public Button {
|
||||
public:
|
||||
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
this->lengths[0]=lengths[0];
|
||||
this->lengths[1]=lengths[1];
|
||||
void onClick() {
|
||||
vector<string> difficulties, factions;
|
||||
|
||||
difficultiesListboxes=difficulties;
|
||||
factionsListboxes=factions;
|
||||
}
|
||||
class PlayButton : public Button {
|
||||
public:
|
||||
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
|
||||
this->lengths[0]=lengths[0];
|
||||
this->lengths[1]=lengths[1];
|
||||
|
||||
void onClick() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
//gm->detachAllBitmapTexts();
|
||||
state->removeButton("Back");
|
||||
// gameManager->dettachState(state);
|
||||
std::vector<string> difficulties, factions;
|
||||
difficultiesListboxes=difficulties;
|
||||
factionsListboxes=factions;
|
||||
}
|
||||
|
||||
/*
|
||||
for(int i=0;i<lengths[0];i++)
|
||||
difficulties.push_back(difficultiesListboxes[i]->getContents()[difficultiesListboxes[i]->getSelectedOption()]);
|
||||
void onClick() {
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
//gm->detachAllBitmapTexts();
|
||||
state->removeButton("Back");
|
||||
gm->getStateManager()->dettachState(state);
|
||||
std::vector<string> difficulties, factions;
|
||||
|
||||
for(int i=0;i<lengths[1];i++)
|
||||
factions.push_back(factionsListboxes[i]->getSelectedOption());
|
||||
*/
|
||||
/*
|
||||
for(int i=0;i<lengths[0];i++)
|
||||
difficulties.push_back(difficultiesListboxes[i]->getContents()[difficultiesListboxes[i]->getSelectedOption()]);
|
||||
|
||||
gm->getStateManager()->attachState(new InGameAppState(difficulties, factions));
|
||||
state->removeAllListboxes();
|
||||
delete[] difficultiesListboxes;
|
||||
delete[] factionsListboxes;
|
||||
state->removeButton("Play");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
Listbox **difficultiesListboxes, **factionsListboxes;
|
||||
int lengths[2];
|
||||
};
|
||||
for(int i=0;i<lengths[1];i++)
|
||||
factions.push_back(factionsListboxes[i]->getSelectedOption());
|
||||
*/
|
||||
|
||||
class ReturnButton : public Button {
|
||||
public:
|
||||
|
||||
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllListboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
//GameManager::getSingleton()->detachAllBitmapTexts();
|
||||
makeTitlescreenButtons(state);
|
||||
state->removeButton("Play");
|
||||
state->removeButton("Back");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
//IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
|
||||
Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8);
|
||||
difficulties.push_back("Easy");
|
||||
difficulties.push_back("Medium");
|
||||
difficulties.push_back("Hard");
|
||||
factions.push_back("0");
|
||||
factions.push_back("1");
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("Difficulty", vector2d<s32>(pos.X, pos.Y - 20), font));
|
||||
gm->attachBitmapText(new BitmapText("Faction", vector2d<s32>(pos.X + 110, pos.Y - 20), font));
|
||||
gm->attachBitmapText(new BitmapText("Player", vector2d<s32>(pos.X - 40, pos.Y), font));
|
||||
gm->attachBitmapText(new BitmapText("CPU", vector2d<s32>(pos.X - 20, pos.Y + 30), font));
|
||||
*/
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Listbox *cpuDifficulty = new Listbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), difficulties, 3, font);
|
||||
Listbox *cpuFaction = new Listbox(Vector2(pos.x + 110, pos.y + 30), Vector2(100, 20), factions, 2, font);
|
||||
Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font);
|
||||
Listbox **difficultyListboxes=new Listbox*[1];
|
||||
Listbox **factionListboxes=new Listbox*[2];
|
||||
difficultyListboxes[0]=cpuDifficulty;
|
||||
factionListboxes[0]=playerFaction;
|
||||
factionListboxes[1]=cpuFaction;
|
||||
int lengths[]{1,2};
|
||||
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
|
||||
ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);
|
||||
state->addButton(playButton);
|
||||
state->addButton(returnButton);
|
||||
state->addListbox(cpuDifficulty);
|
||||
state->addListbox(cpuFaction);
|
||||
state->addListbox(playerFaction);
|
||||
state->removeButton("Options");
|
||||
state->removeButton("Exit");
|
||||
state->removeButton("Singleplayer");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
|
||||
class MainMenuOptionsButton : public OptionsButton {
|
||||
public:
|
||||
|
||||
MainMenuOptionsButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
ReturnButton *returnButton = new ReturnButton(state, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
|
||||
state->addButton(returnButton);
|
||||
state->removeButton("Singleplayer");
|
||||
state->removeButton("Exit");
|
||||
OptionsButton::onClick();
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
gm->getStateManager()->attachState(new InGameAppState(difficulties, factions));
|
||||
state->removeAllListboxes();
|
||||
delete[] difficultiesListboxes;
|
||||
delete[] factionsListboxes;
|
||||
state->removeButton("Play");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
Listbox **difficultiesListboxes, **factionsListboxes;
|
||||
int lengths[2];
|
||||
};
|
||||
|
||||
class ReturnButton : public Button {
|
||||
public:
|
||||
@@ -154,56 +75,132 @@ namespace game{
|
||||
state->removeAllListboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
|
||||
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
|
||||
state->addButton(optionsButton);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
|
||||
state->addButton(spButton);
|
||||
state->addButton(exitButton);
|
||||
//GameManager::getSingleton()->detachAllBitmapTexts();
|
||||
makeTitlescreenButtons(state);
|
||||
state->removeButton("Play");
|
||||
state->removeButton("Back");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
//IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
|
||||
Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8);
|
||||
difficulties.push_back("Easy");
|
||||
difficulties.push_back("Medium");
|
||||
difficulties.push_back("Hard");
|
||||
factions.push_back("0");
|
||||
factions.push_back("1");
|
||||
/*
|
||||
gm->attachBitmapText(new BitmapText("Difficulty", vector2d<s32>(pos.X, pos.Y - 20), font));
|
||||
gm->attachBitmapText(new BitmapText("Faction", vector2d<s32>(pos.X + 110, pos.Y - 20), font));
|
||||
gm->attachBitmapText(new BitmapText("Player", vector2d<s32>(pos.X - 40, pos.Y), font));
|
||||
gm->attachBitmapText(new BitmapText("CPU", vector2d<s32>(pos.X - 20, pos.Y + 30), font));
|
||||
*/
|
||||
string font = PATH + "Fonts/batang.ttf";
|
||||
Listbox *cpuDifficulty = new Listbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), difficulties, 3, font);
|
||||
Listbox *cpuFaction = new Listbox(Vector2(pos.x + 110, pos.y + 30), Vector2(100, 20), factions, 2, font);
|
||||
Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font);
|
||||
Listbox **difficultyListboxes=new Listbox*[1];
|
||||
Listbox **factionListboxes=new Listbox*[2];
|
||||
difficultyListboxes[0]=cpuDifficulty;
|
||||
factionListboxes[0]=playerFaction;
|
||||
factionListboxes[1]=cpuFaction;
|
||||
int lengths[]{1,2};
|
||||
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
|
||||
ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);
|
||||
state->addButton(playButton);
|
||||
state->addButton(returnButton);
|
||||
state->addListbox(cpuDifficulty);
|
||||
state->addListbox(cpuFaction);
|
||||
state->addListbox(playerFaction);
|
||||
state->removeButton("Options");
|
||||
state->removeButton("Exit");
|
||||
state->removeButton("Singleplayer");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
|
||||
class MainMenuOptionsButton : public OptionsButton {
|
||||
public:
|
||||
|
||||
MainMenuOptionsButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
ReturnButton *returnButton = new ReturnButton(state, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
|
||||
state->addButton(returnButton);
|
||||
state->removeButton("Singleplayer");
|
||||
state->removeButton("Exit");
|
||||
OptionsButton::onClick();
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
|
||||
class ReturnButton : public Button {
|
||||
public:
|
||||
|
||||
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
|
||||
this->state = state;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
state->removeAllCheckboxes();
|
||||
state->removeAllListboxes();
|
||||
state->removeAllSliders();
|
||||
state->removeAllTextboxes();
|
||||
state->removeButton("Controls");
|
||||
state->removeButton("Mouse");
|
||||
state->removeButton("Video");
|
||||
state->removeButton("Audio");
|
||||
state->removeButton("Multiplayer");
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
|
||||
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
|
||||
state->addButton(optionsButton);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
|
||||
state->addButton(spButton);
|
||||
state->addButton(exitButton);
|
||||
state->removeButton("Back");
|
||||
}
|
||||
private:
|
||||
GuiAppState *state;
|
||||
};
|
||||
};
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
|
||||
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
|
||||
state->addButton(optionsButton);
|
||||
state->addButton(spButton);
|
||||
state->addButton(exitButton);
|
||||
}
|
||||
|
||||
/*
|
||||
bool isWithinRect(vector3df c1,vector3df c2, vector3df p, vector3df dir){
|
||||
float mainAngle=getAngleBetween(c1-c2,dir);
|
||||
float mainHyp=(c1-c2).getLength();
|
||||
float mainWidth=cos(mainAngle)*mainHyp,mainLength=sin(mainAngle)*mainHyp;
|
||||
vector3df center=(c2-c1)/2+c1;
|
||||
float angle=getAngleBetween(center-p,dir);
|
||||
float hyp=(center-p).getLength();
|
||||
float width=cos(angle)*hyp,length=sin(angle)*hyp;
|
||||
return width<=mainWidth/2&&length<=mainLength/2?true:false;
|
||||
}
|
||||
bool isWithinCuboid(vector3df c0, vector3df c1,vector3df c2,vector3df c3, vector3df p0){
|
||||
vector3df aVec=c1-c0,bVec=c2-c0,cVec=c3-c0,pVec=p0-c0;
|
||||
float a=aVec.getLength(),b=bVec.getLength(),c=cVec.getLength(),p=pVec.getLength();
|
||||
float aAngle=getAngleBetween(pVec,aVec);
|
||||
float bAngle=getAngleBetween(pVec,bVec);
|
||||
float cAngle=getAngleBetween(pVec,cVec);
|
||||
bool withinA=aAngle<=PI/2&&p*cos(aAngle)<=a;
|
||||
bool withinB=bAngle<=PI/2&&p*cos(bAngle)<=b;
|
||||
bool withinC=cAngle<=PI/2&&p*cos(cAngle)<=c;
|
||||
return withinA&&withinB&&withinC;
|
||||
}
|
||||
*/
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
|
||||
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
|
||||
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
|
||||
state->addButton(optionsButton);
|
||||
state->addButton(spButton);
|
||||
state->addButton(exitButton);
|
||||
}
|
||||
|
||||
/*
|
||||
bool isWithinRect(vector3df c1,vector3df c2, vector3df p, vector3df dir){
|
||||
float mainAngle=getAngleBetween(c1-c2,dir);
|
||||
float mainHyp=(c1-c2).getLength();
|
||||
float mainWidth=cos(mainAngle)*mainHyp,mainLength=sin(mainAngle)*mainHyp;
|
||||
vector3df center=(c2-c1)/2+c1;
|
||||
float angle=getAngleBetween(center-p,dir);
|
||||
float hyp=(center-p).getLength();
|
||||
float width=cos(angle)*hyp,length=sin(angle)*hyp;
|
||||
return width<=mainWidth/2&&length<=mainLength/2?true:false;
|
||||
}
|
||||
bool isWithinCuboid(vector3df c0, vector3df c1,vector3df c2,vector3df c3, vector3df p0){
|
||||
vector3df aVec=c1-c0,bVec=c2-c0,cVec=c3-c0,pVec=p0-c0;
|
||||
float a=aVec.getLength(),b=bVec.getLength(),c=cVec.getLength(),p=pVec.getLength();
|
||||
float aAngle=getAngleBetween(pVec,aVec);
|
||||
float bAngle=getAngleBetween(pVec,bVec);
|
||||
float cAngle=getAngleBetween(pVec,cVec);
|
||||
bool withinA=aAngle<=PI/2&&p*cos(aAngle)<=a;
|
||||
bool withinB=bAngle<=PI/2&&p*cos(bAngle)<=b;
|
||||
bool withinC=cAngle<=PI/2&&p*cos(cAngle)<=c;
|
||||
return withinA&&withinB&&withinC;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
namespace game{
|
||||
namespace battleship{
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
@@ -18,18 +18,14 @@ namespace game{
|
||||
typedef int s32;
|
||||
typedef long long s64;
|
||||
|
||||
namespace core{
|
||||
class GameManager;
|
||||
class GuiAppState;
|
||||
}
|
||||
class GameManager;
|
||||
class GuiAppState;
|
||||
|
||||
namespace util{
|
||||
void makeTitlescreenButtons(core::GuiAppState*);
|
||||
/*
|
||||
bool isWithinRect(irr::core::vector3df,irr::core::vector3df,irr::core::vector3df,irr::core::vector3df);
|
||||
bool isWithinCuboid(irr::core::vector3df,irr::core::vector3df,irr::core::vector3df,irr::core::vector3df,irr::core::vector3df);
|
||||
*/
|
||||
}
|
||||
void makeTitlescreenButtons(GuiAppState*);
|
||||
/*
|
||||
bool isWithinRect(irr::core::vector3df,irr::core::vector3df,irr::core::vector3df,irr::core::vector3df);
|
||||
bool isWithinCuboid(irr::core::vector3df,irr::core::vector3df,irr::core::vector3df,irr::core::vector3df,irr::core::vector3df);
|
||||
*/
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+204
-206
@@ -10,229 +10,227 @@
|
||||
#include "guidedMissile.h"
|
||||
#include "projectileData.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::util;
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
Vessel::Turret::Turret(Unit *vessel, int unitId, int turretId) {
|
||||
this->vessel = vessel;
|
||||
//hullNode = vessel->getNode();
|
||||
this->unitId = unitId;
|
||||
this->turretId = turretId;
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
turretMesh = smgr->getMesh(basePath[unitId] + turretNames[unitId][turretId] + ".x");
|
||||
turretNode = smgr->addAnimatedMeshSceneNode(turretMesh);
|
||||
turretNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
*/
|
||||
string fr[]{basePath[unitId] + turretNames[unitId][turretId] + "DiffuseMap.png"};
|
||||
Texture *turretDiffuseTexture = new Texture(fr);
|
||||
Vessel::Turret::Turret(Unit *vessel, int unitId, int turretId) {
|
||||
this->vessel = vessel;
|
||||
//hullNode = vessel->getNode();
|
||||
this->unitId = unitId;
|
||||
this->turretId = turretId;
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
/*
|
||||
turretMesh = smgr->getMesh(basePath[unitId] + turretNames[unitId][turretId] + ".x");
|
||||
turretNode = smgr->addAnimatedMeshSceneNode(turretMesh);
|
||||
turretNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
*/
|
||||
string fr[]{basePath[unitId] + turretNames[unitId][turretId] + "DiffuseMap.png"};
|
||||
Texture *turretDiffuseTexture = new Texture(fr);
|
||||
|
||||
/*
|
||||
turretNode->setParent(vessel->getNode());
|
||||
turretNode->setPosition(turretPos[unitId][turretId]);
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 180 * turretAngleOffset[unitId][turretId], vector3df(0, 1, 0));
|
||||
turretNode->setRotation(vector3df(0, turretAngleOffset[unitId][turretId], 0));
|
||||
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
|
||||
rotationSpeed = unitData::turretRotationSpeed[unitId][turretId];
|
||||
maxAngle = unitData::turretMaxAngle[unitId][turretId];
|
||||
this->rateOfFire = unitData::turretRateOfFire[unitId][turretId];
|
||||
*/
|
||||
|
||||
/*
|
||||
for (int i = 0; i < numberOfMantlets[unitId][turretId]; i++) {
|
||||
IAnimatedMesh *mantletMesh = smgr->getMesh(basePath[unitId] + mantletNames[unitId][turretId] + ".x");
|
||||
IAnimatedMesh *barrelMesh = smgr->getMesh(basePath[unitId] + barrelNames[unitId][turretId] + ".x");
|
||||
ISceneNode *mantletNode = initMantletNode(driver, smgr, mantletMesh, unitId, turretId);
|
||||
ISceneNode *barrelNode = initBarrelNode(driver, smgr, barrelMesh, mantletNode, unitId, turretId);
|
||||
turretMantletMeshes.push_back(mantletMesh);
|
||||
turretMantletNodes.push_back(mantletNode);
|
||||
turretBarrelMeshes.push_back(barrelMesh);
|
||||
turretBarrelNodes.push_back(barrelNode);
|
||||
}
|
||||
|
||||
if (turretMantletNodes.size() > 1) {
|
||||
turretMantletNodes[0]->setPosition(turretMantletNodes[0]->getPosition() + vector3df(mantletPosSideOffset[unitId][turretId], 0, 0));
|
||||
turretMantletNodes[1]->setPosition(turretMantletNodes[1]->getPosition() - vector3df(mantletPosSideOffset[unitId][turretId], 0, 0));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
fxNode=smgr->addParticleSystemSceneNode(false);
|
||||
emitter=fxNode->createPointEmitter(dirVec,
|
||||
10,10,
|
||||
SColor(0,255,255,255),
|
||||
SColor(0,255,255,255),
|
||||
500,500,0,
|
||||
dimension2df(5,5),
|
||||
dimension2df(10,10));
|
||||
fxNode->setEmitter(emitter);
|
||||
emitter->drop();
|
||||
affector=fxNode->createFadeOutParticleAffector();
|
||||
fxNode->addAffector(affector);
|
||||
affector->drop();
|
||||
fxNode->setParent(turretMantletNodes[0]);
|
||||
fxNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
fxNode->setMaterialFlag(EMF_ZWRITE_ENABLE, false);
|
||||
fxNode->setMaterialTexture(0, driver->getTexture(PATH+"Textures/Explosions/fire.bmp"));
|
||||
fxNode->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
|
||||
fxNode->setVisible(false);
|
||||
*/
|
||||
|
||||
sfxBuffer = new sf::SoundBuffer();
|
||||
|
||||
if(sfxBuffer->loadFromFile(getExplosionSfxPath().c_str()))
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
}
|
||||
|
||||
/*
|
||||
ISceneNode* Vessel::Turret::initMantletNode(IVideoDriver *driver, ISceneManager *smgr, IAnimatedMesh *mantletMesh, int unitId, int turretId) {
|
||||
ISceneNode *mantletNode = smgr->addAnimatedMeshSceneNode(mantletMesh);
|
||||
mantletNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
ITexture *mantletDiffuseTexture = driver->getTexture(basePath[unitId] + mantletNames[unitId][turretId] + "DiffuseMap.png");
|
||||
if (mantletDiffuseTexture)
|
||||
mantletNode->setMaterialTexture(0, mantletDiffuseTexture);
|
||||
else
|
||||
mantletNode->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
|
||||
mantletNode->setParent(turretNode);
|
||||
mantletNode->setPosition(mantletPos[unitId][turretId]);
|
||||
return mantletNode;
|
||||
turretNode->setParent(vessel->getNode());
|
||||
turretNode->setPosition(turretPos[unitId][turretId]);
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 180 * turretAngleOffset[unitId][turretId], vector3df(0, 1, 0));
|
||||
turretNode->setRotation(vector3df(0, turretAngleOffset[unitId][turretId], 0));
|
||||
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
|
||||
rotationSpeed = unitData::turretRotationSpeed[unitId][turretId];
|
||||
maxAngle = unitData::turretMaxAngle[unitId][turretId];
|
||||
this->rateOfFire = unitData::turretRateOfFire[unitId][turretId];
|
||||
*/
|
||||
|
||||
/*
|
||||
for (int i = 0; i < numberOfMantlets[unitId][turretId]; i++) {
|
||||
IAnimatedMesh *mantletMesh = smgr->getMesh(basePath[unitId] + mantletNames[unitId][turretId] + ".x");
|
||||
IAnimatedMesh *barrelMesh = smgr->getMesh(basePath[unitId] + barrelNames[unitId][turretId] + ".x");
|
||||
ISceneNode *mantletNode = initMantletNode(driver, smgr, mantletMesh, unitId, turretId);
|
||||
ISceneNode *barrelNode = initBarrelNode(driver, smgr, barrelMesh, mantletNode, unitId, turretId);
|
||||
turretMantletMeshes.push_back(mantletMesh);
|
||||
turretMantletNodes.push_back(mantletNode);
|
||||
turretBarrelMeshes.push_back(barrelMesh);
|
||||
turretBarrelNodes.push_back(barrelNode);
|
||||
}
|
||||
|
||||
ISceneNode* Vessel::Turret::initBarrelNode(IVideoDriver *driver, ISceneManager *smgr, IAnimatedMesh *barrelMesh, ISceneNode *mantletNode, int unitId, int turretId) {
|
||||
ISceneNode *barrelNode = smgr->addAnimatedMeshSceneNode(barrelMesh);
|
||||
barrelNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
ITexture *barrelDiffuseTexture = driver->getTexture(basePath[unitId] + barrelNames[unitId][turretId] + "DiffuseMap.png");
|
||||
if (barrelDiffuseTexture)
|
||||
barrelNode->setMaterialTexture(0, barrelDiffuseTexture);
|
||||
else
|
||||
barrelNode->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
|
||||
barrelNode->setParent(mantletNode);
|
||||
barrelNode->setPosition(barrelPos[unitId][turretId]);
|
||||
return barrelNode;
|
||||
if (turretMantletNodes.size() > 1) {
|
||||
turretMantletNodes[0]->setPosition(turretMantletNodes[0]->getPosition() + vector3df(mantletPosSideOffset[unitId][turretId], 0, 0));
|
||||
turretMantletNodes[1]->setPosition(turretMantletNodes[1]->getPosition() - vector3df(mantletPosSideOffset[unitId][turretId], 0, 0));
|
||||
}
|
||||
*/
|
||||
|
||||
void Vessel::Turret::rotate(double angle) {
|
||||
Quaternion rotQuat = Quaternion(PI / 180 * angle, Vector3(0, 1, 0));
|
||||
//turret->setOrientation(vector3df(0, turret->getRotation().Y + angle, 0));
|
||||
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
|
||||
this->angle += angle;
|
||||
}
|
||||
|
||||
void Vessel::Turret::update() {
|
||||
Node *rootNode = Root::getSingleton()->getRootNode();
|
||||
turretPosition = rootNode->localToGlobalPosition(turret->getPosition());
|
||||
float hullAngle = PI / 180 /* hullNode->getRotation().Y*/;
|
||||
float turretAngle = PI / 180 * angle;
|
||||
/*
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(hullAngle + turretAngle, vector3df(0, 1, 0));
|
||||
quaternion offsetQuat = offsetQuat.fromAngleAxis(PI / 180 * unitData::turretAngleOffset[unitId][turretId], vector3df(0, 1, 0));
|
||||
dirVec = rotQuat * (offsetQuat * vector3df(0, 0, -1)), leftVec = rotQuat * (offsetQuat * vector3df(1, 0, 0));
|
||||
emitter->setDirection(dirVec);
|
||||
// if(getTime()-lastShotTime>30&&fxNode->isVisible())
|
||||
// fxNode->setVisible(false);
|
||||
// */
|
||||
}
|
||||
|
||||
void Vessel::Turret::debug(const Material &mat) {
|
||||
/*
|
||||
float length = turretAxisLength[unitId][turretId]*0 + 1;
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
driver->setMaterial(mat);
|
||||
driver->draw3DLine(turretPosition, turretPosition + dirVec*length, SColor(255, 0, 0, 255));
|
||||
driver->draw3DLine(turretPosition, turretPosition + leftVec*length, SColor(255, 255, 0, 0));
|
||||
driver->draw3DLine(turretPosition, turretPosition + upVec*length, SColor(255, 0, 255, 0));
|
||||
*/
|
||||
}
|
||||
|
||||
Vector3* Vessel::Turret::getInitDirs(){
|
||||
Vector3 *initDirs = new Vector3[2];
|
||||
switch(unitData::initDirs[unitId][turretId]){
|
||||
case unitData::FORWARD:
|
||||
initDirs[0]=vessel->getDirVec();
|
||||
initDirs[1]=vessel->getLeftVec();
|
||||
break;
|
||||
case unitData::BACKWARD:
|
||||
initDirs[0]=-vessel->getDirVec();
|
||||
initDirs[1]=-vessel->getLeftVec();
|
||||
break;
|
||||
case unitData::LEFT:
|
||||
initDirs[0]=vessel->getLeftVec();
|
||||
initDirs[1]=-vessel->getDirVec();
|
||||
break;
|
||||
case unitData::RIGHT:
|
||||
initDirs[0]=-vessel->getLeftVec();
|
||||
initDirs[1]=vessel->getDirVec();
|
||||
break;
|
||||
}
|
||||
return initDirs;
|
||||
}
|
||||
/*
|
||||
fxNode=smgr->addParticleSystemSceneNode(false);
|
||||
emitter=fxNode->createPointEmitter(dirVec,
|
||||
10,10,
|
||||
SColor(0,255,255,255),
|
||||
SColor(0,255,255,255),
|
||||
500,500,0,
|
||||
dimension2df(5,5),
|
||||
dimension2df(10,10));
|
||||
fxNode->setEmitter(emitter);
|
||||
emitter->drop();
|
||||
affector=fxNode->createFadeOutParticleAffector();
|
||||
fxNode->addAffector(affector);
|
||||
affector->drop();
|
||||
fxNode->setParent(turretMantletNodes[0]);
|
||||
fxNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
fxNode->setMaterialFlag(EMF_ZWRITE_ENABLE, false);
|
||||
fxNode->setMaterialTexture(0, driver->getTexture(PATH+"Textures/Explosions/fire.bmp"));
|
||||
fxNode->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
|
||||
fxNode->setVisible(false);
|
||||
*/
|
||||
|
||||
void Vessel::Turret::fire() {
|
||||
/*
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(barrelAngle / 180 * PI, leftVec);
|
||||
int barId = 0;
|
||||
vector3df startPos = vessel->getPos() + vessel->getLeftVec() * turretNode->getPosition().X + vessel->getUpVec() * turretNode->getPosition().Y - vessel->getDirVec() * turretNode->getPosition().Z;
|
||||
startPos += rotQuat * (leftVec * turretMantletNodes[barId]->getPosition().X + upVec * turretMantletNodes[barId]->getPosition().Y + dirVec * turretMantletNodes[barId]->getPosition().Z);
|
||||
startPos += rotQuat * (leftVec * turretBarrelNodes[barId]->getPosition().X + upVec * turretBarrelNodes[barId]->getPosition().Y + dirVec * turretBarrelNodes[barId]->getPosition().Z);
|
||||
startPos += rotQuat * (leftVec * projectileData::pos[unitId][0][turretId].X + upVec * projectileData::pos[unitId][0][turretId].Y + dirVec * projectileData::pos[unitId][0][turretId].Z);
|
||||
vessel->addProjectile(new Shell(vessel, startPos, rotQuat*dirVec, rotQuat*leftVec, rotQuat*upVec, unitId, 0, turretId));
|
||||
// fxNode->setVisible(true);
|
||||
if(sfx) sfx->play();
|
||||
lastShotTime = getTime();
|
||||
*/
|
||||
}
|
||||
sfxBuffer = new sf::SoundBuffer();
|
||||
|
||||
Vessel::Vessel(Player *player, Vector3 pos, int id) : Unit(player,pos, id) {
|
||||
if (numberOfTurrets[id] > 0)
|
||||
for (int i = 0; i < numberOfTurrets[id]; i++)
|
||||
turrets.push_back(new Turret(this, id, i));
|
||||
}
|
||||
if(sfxBuffer->loadFromFile(getExplosionSfxPath().c_str()))
|
||||
sfx = new sf::Sound(*sfxBuffer);
|
||||
}
|
||||
|
||||
void Vessel::update() {
|
||||
Unit::update();
|
||||
for (Turret *t : turrets) {
|
||||
t->update();
|
||||
if ((orders.size() > 0 && orders[0].type != Order::TYPE::ATTACK) || orders.size() == 0) {
|
||||
float rotAngle = abs(t->getAngle()) < t->getRotationSpeed() ? abs(t->getAngle()) : t->getRotationSpeed();
|
||||
t->rotate(t->getAngle() > 0 ? -rotAngle : rotAngle);
|
||||
}
|
||||
/*
|
||||
ISceneNode* Vessel::Turret::initMantletNode(IVideoDriver *driver, ISceneManager *smgr, IAnimatedMesh *mantletMesh, int unitId, int turretId) {
|
||||
ISceneNode *mantletNode = smgr->addAnimatedMeshSceneNode(mantletMesh);
|
||||
mantletNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
ITexture *mantletDiffuseTexture = driver->getTexture(basePath[unitId] + mantletNames[unitId][turretId] + "DiffuseMap.png");
|
||||
if (mantletDiffuseTexture)
|
||||
mantletNode->setMaterialTexture(0, mantletDiffuseTexture);
|
||||
else
|
||||
mantletNode->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
|
||||
mantletNode->setParent(turretNode);
|
||||
mantletNode->setPosition(mantletPos[unitId][turretId]);
|
||||
return mantletNode;
|
||||
}
|
||||
|
||||
ISceneNode* Vessel::Turret::initBarrelNode(IVideoDriver *driver, ISceneManager *smgr, IAnimatedMesh *barrelMesh, ISceneNode *mantletNode, int unitId, int turretId) {
|
||||
ISceneNode *barrelNode = smgr->addAnimatedMeshSceneNode(barrelMesh);
|
||||
barrelNode->setMaterialFlag(EMF_LIGHTING, false);
|
||||
ITexture *barrelDiffuseTexture = driver->getTexture(basePath[unitId] + barrelNames[unitId][turretId] + "DiffuseMap.png");
|
||||
if (barrelDiffuseTexture)
|
||||
barrelNode->setMaterialTexture(0, barrelDiffuseTexture);
|
||||
else
|
||||
barrelNode->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
|
||||
barrelNode->setParent(mantletNode);
|
||||
barrelNode->setPosition(barrelPos[unitId][turretId]);
|
||||
return barrelNode;
|
||||
}
|
||||
*/
|
||||
|
||||
void Vessel::Turret::rotate(double angle) {
|
||||
Quaternion rotQuat = Quaternion(PI / 180 * angle, Vector3(0, 1, 0));
|
||||
//turret->setOrientation(vector3df(0, turret->getRotation().Y + angle, 0));
|
||||
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
|
||||
this->angle += angle;
|
||||
}
|
||||
|
||||
void Vessel::Turret::update() {
|
||||
Node *rootNode = Root::getSingleton()->getRootNode();
|
||||
turretPosition = rootNode->localToGlobalPosition(turret->getPosition());
|
||||
float hullAngle = PI / 180 /* hullNode->getRotation().Y*/;
|
||||
float turretAngle = PI / 180 * angle;
|
||||
/*
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(hullAngle + turretAngle, vector3df(0, 1, 0));
|
||||
quaternion offsetQuat = offsetQuat.fromAngleAxis(PI / 180 * unitData::turretAngleOffset[unitId][turretId], vector3df(0, 1, 0));
|
||||
dirVec = rotQuat * (offsetQuat * vector3df(0, 0, -1)), leftVec = rotQuat * (offsetQuat * vector3df(1, 0, 0));
|
||||
emitter->setDirection(dirVec);
|
||||
if(getTime()-lastShotTime>30&&fxNode->isVisible())
|
||||
fxNode->setVisible(false);
|
||||
*/
|
||||
}
|
||||
|
||||
void Vessel::Turret::debug(const Material &mat) {
|
||||
/*
|
||||
float length = turretAxisLength[unitId][turretId]*0 + 1;
|
||||
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
|
||||
driver->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
driver->setMaterial(mat);
|
||||
driver->draw3DLine(turretPosition, turretPosition + dirVec*length, SColor(255, 0, 0, 255));
|
||||
driver->draw3DLine(turretPosition, turretPosition + leftVec*length, SColor(255, 255, 0, 0));
|
||||
driver->draw3DLine(turretPosition, turretPosition + upVec*length, SColor(255, 0, 255, 0));
|
||||
*/
|
||||
}
|
||||
|
||||
Vector3* Vessel::Turret::getInitDirs(){
|
||||
Vector3 *initDirs = new Vector3[2];
|
||||
switch(unitData::initDirs[unitId][turretId]){
|
||||
case unitData::FORWARD:
|
||||
initDirs[0]=vessel->getDirVec();
|
||||
initDirs[1]=vessel->getLeftVec();
|
||||
break;
|
||||
case unitData::BACKWARD:
|
||||
initDirs[0]=-vessel->getDirVec();
|
||||
initDirs[1]=-vessel->getLeftVec();
|
||||
break;
|
||||
case unitData::LEFT:
|
||||
initDirs[0]=vessel->getLeftVec();
|
||||
initDirs[1]=-vessel->getDirVec();
|
||||
break;
|
||||
case unitData::RIGHT:
|
||||
initDirs[0]=-vessel->getLeftVec();
|
||||
initDirs[1]=vessel->getDirVec();
|
||||
break;
|
||||
}
|
||||
return initDirs;
|
||||
}
|
||||
|
||||
void Vessel::Turret::fire() {
|
||||
/*
|
||||
quaternion rotQuat = rotQuat.fromAngleAxis(barrelAngle / 180 * PI, leftVec);
|
||||
int barId = 0;
|
||||
vector3df startPos = vessel->getPos() + vessel->getLeftVec() * turretNode->getPosition().X + vessel->getUpVec() * turretNode->getPosition().Y - vessel->getDirVec() * turretNode->getPosition().Z;
|
||||
startPos += rotQuat * (leftVec * turretMantletNodes[barId]->getPosition().X + upVec * turretMantletNodes[barId]->getPosition().Y + dirVec * turretMantletNodes[barId]->getPosition().Z);
|
||||
startPos += rotQuat * (leftVec * turretBarrelNodes[barId]->getPosition().X + upVec * turretBarrelNodes[barId]->getPosition().Y + dirVec * turretBarrelNodes[barId]->getPosition().Z);
|
||||
startPos += rotQuat * (leftVec * projectileData::pos[unitId][0][turretId].X + upVec * projectileData::pos[unitId][0][turretId].Y + dirVec * projectileData::pos[unitId][0][turretId].Z);
|
||||
vessel->addProjectile(new Shell(vessel, startPos, rotQuat*dirVec, rotQuat*leftVec, rotQuat*upVec, unitId, 0, turretId));
|
||||
fxNode->setVisible(true);
|
||||
if(sfx) sfx->play();
|
||||
lastShotTime = getTime();
|
||||
*/
|
||||
}
|
||||
|
||||
Vessel::Vessel(Player *player, Vector3 pos, int id) : Unit(player,pos, id) {
|
||||
if (numberOfTurrets[id] > 0)
|
||||
for (int i = 0; i < numberOfTurrets[id]; i++)
|
||||
turrets.push_back(new Turret(this, id, i));
|
||||
}
|
||||
|
||||
void Vessel::update() {
|
||||
Unit::update();
|
||||
for (Turret *t : turrets) {
|
||||
t->update();
|
||||
if ((orders.size() > 0 && orders[0].type != Order::TYPE::ATTACK) || orders.size() == 0) {
|
||||
float rotAngle = abs(t->getAngle()) < t->getRotationSpeed() ? abs(t->getAngle()) : t->getRotationSpeed();
|
||||
t->rotate(t->getAngle() > 0 ? -rotAngle : rotAngle);
|
||||
}
|
||||
}
|
||||
|
||||
void Vessel::attack(Order order) {
|
||||
Vector3 target = *order.targetPos[0];
|
||||
Unit::attack(order);
|
||||
|
||||
for (Turret *t : turrets) {
|
||||
Vector3 *initDirs = t->getInitDirs();
|
||||
bool right = t->getLeftVec().getAngleBetween(target - t->getPos()) > PI / 2;
|
||||
float angle = initDirs[0].getAngleBetween(target - t->getPos()) / PI * 180;
|
||||
float rotAngle = t->getRotationSpeed() > angle ? angle : t->getRotationSpeed()*(right?1:-1);
|
||||
|
||||
if (-t->getMaxAngle() <= t->getAngle() + rotAngle
|
||||
&& t->getAngle() + rotAngle <= t->getMaxAngle()) {
|
||||
t->rotate(rotAngle);
|
||||
|
||||
if (t->canFire()) t->fire();
|
||||
}
|
||||
|
||||
delete[] initDirs;
|
||||
}
|
||||
}
|
||||
|
||||
void Vessel::debug() {
|
||||
/*
|
||||
for (Turret *t : turrets)
|
||||
t->debug(createLineMaterial());
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void Vessel::attack(Order order) {
|
||||
Vector3 target = *order.targetPos[0];
|
||||
Unit::attack(order);
|
||||
|
||||
for (Turret *t : turrets) {
|
||||
Vector3 *initDirs = t->getInitDirs();
|
||||
bool right = t->getLeftVec().getAngleBetween(target - t->getPos()) > PI / 2;
|
||||
float angle = initDirs[0].getAngleBetween(target - t->getPos()) / PI * 180;
|
||||
float rotAngle = t->getRotationSpeed() > angle ? angle : t->getRotationSpeed()*(right?1:-1);
|
||||
|
||||
if (-t->getMaxAngle() <= t->getAngle() + rotAngle
|
||||
&& t->getAngle() + rotAngle <= t->getMaxAngle()) {
|
||||
t->rotate(rotAngle);
|
||||
|
||||
if (t->canFire()) t->fire();
|
||||
}
|
||||
|
||||
delete[] initDirs;
|
||||
}
|
||||
}
|
||||
|
||||
void Vessel::debug() {
|
||||
/*
|
||||
for (Turret *t : turrets)
|
||||
t->debug(createLineMaterial());
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,57 +13,55 @@ namespace vb01{
|
||||
class ParticleEmitter;
|
||||
}
|
||||
|
||||
namespace game{
|
||||
namespace content {
|
||||
class Vessel : public Unit {
|
||||
namespace battleship {
|
||||
class Vessel : public Unit {
|
||||
public:
|
||||
Vessel(Player*, vb01::Vector3, int);
|
||||
void update();
|
||||
protected:
|
||||
void attack(Order);
|
||||
private:
|
||||
void debug();
|
||||
|
||||
class Turret {
|
||||
public:
|
||||
Vessel(Player*, vb01::Vector3, int);
|
||||
Turret(Unit*, int, int);
|
||||
void update();
|
||||
protected:
|
||||
void attack(Order);
|
||||
void fire();
|
||||
void rotate(double);
|
||||
void debug(const vb01::Material&);
|
||||
vb01::Vector3* getInitDirs();
|
||||
inline vb01::Vector3 getDirVec(){return dirVec;}
|
||||
inline vb01::Vector3 getLeftVec(){return leftVec;}
|
||||
inline vb01::Vector3 getUpVec(){return upVec;}
|
||||
inline vb01::Vector3 getPos(){return turretPosition;}
|
||||
inline float getMaxAngle(){return maxAngle;}
|
||||
inline float getRotationSpeed(){return rotationSpeed;}
|
||||
inline float getAngle(){return angle;}
|
||||
inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;}
|
||||
private:
|
||||
void debug();
|
||||
|
||||
class Turret {
|
||||
public:
|
||||
Turret(Unit*, int, int);
|
||||
void update();
|
||||
void fire();
|
||||
void rotate(double);
|
||||
void debug(const vb01::Material&);
|
||||
vb01::Vector3* getInitDirs();
|
||||
inline vb01::Vector3 getDirVec(){return dirVec;}
|
||||
inline vb01::Vector3 getLeftVec(){return leftVec;}
|
||||
inline vb01::Vector3 getUpVec(){return upVec;}
|
||||
inline vb01::Vector3 getPos(){return turretPosition;}
|
||||
inline float getMaxAngle(){return maxAngle;}
|
||||
inline float getRotationSpeed(){return rotationSpeed;}
|
||||
inline float getAngle(){return angle;}
|
||||
inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;}
|
||||
private:
|
||||
inline std::string getExplosionSfxPath(){return core::PATH + "Sounds/Explosions/explosion0" + std::to_string(rand() % 4) + ".ogg";}
|
||||
vb01::Node *fxNode;
|
||||
vb01::ParticleEmitter *emitter;
|
||||
Unit *vessel;
|
||||
vb01::Model *turret, *hull;
|
||||
std::vector<vb01::Model*> turretMantlets, turretBarrels;
|
||||
std::vector<vb01::Vector3> turretMantletPos;
|
||||
vb01::Vector3 turretBarrelPos, turretPosition;
|
||||
vb01::Vector3 upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, -1), initDir, leftVec = vb01::Vector3(1, 0, 0);
|
||||
float angle = 0., barrelAngle = 0., maxAngle, rotationSpeed,maxBarrelAngle;
|
||||
int rateOfFire, damage, unitId, turretId;
|
||||
/*
|
||||
vb01::Model* initMantletNode(irr::scene::IAnimatedMesh*, int, int);
|
||||
vb01::Model* initBarrelNode(irr::scene::IAnimatedMesh*, irr::scene::ISceneNode*, int, int);
|
||||
*/
|
||||
s64 lastShotTime;
|
||||
sf::SoundBuffer *sfxBuffer;
|
||||
sf::Sound *sfx = nullptr;
|
||||
};
|
||||
|
||||
std::vector<Turret*> turrets;
|
||||
inline std::string getExplosionSfxPath(){return configData::PATH + "Sounds/Explosions/explosion0" + std::to_string(rand() % 4) + ".ogg";}
|
||||
vb01::Node *fxNode;
|
||||
vb01::ParticleEmitter *emitter;
|
||||
Unit *vessel;
|
||||
vb01::Model *turret, *hull;
|
||||
std::vector<vb01::Model*> turretMantlets, turretBarrels;
|
||||
std::vector<vb01::Vector3> turretMantletPos;
|
||||
vb01::Vector3 turretBarrelPos, turretPosition;
|
||||
vb01::Vector3 upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, -1), initDir, leftVec = vb01::Vector3(1, 0, 0);
|
||||
float angle = 0., barrelAngle = 0., maxAngle, rotationSpeed,maxBarrelAngle;
|
||||
int rateOfFire, damage, unitId, turretId;
|
||||
/*
|
||||
vb01::Model* initMantletNode(irr::scene::IAnimatedMesh*, int, int);
|
||||
vb01::Model* initBarrelNode(irr::scene::IAnimatedMesh*, irr::scene::ISceneNode*, int, int);
|
||||
*/
|
||||
s64 lastShotTime;
|
||||
sf::SoundBuffer *sfxBuffer;
|
||||
sf::Sound *sfx = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<Turret*> turrets;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+409
-411
@@ -14,417 +14,415 @@
|
||||
6:巡航ミサイル
|
||||
*/
|
||||
|
||||
namespace game{
|
||||
namespace content{
|
||||
namespace unitData {
|
||||
enum InitDir{FORWARD,BACKWARD,LEFT,RIGHT};
|
||||
const int numberOfTurrets[numberOfUnits]{13, 13, 4, 4, 2, 5};
|
||||
const int maxNumTurrets=13;
|
||||
const InitDir initDirs[numberOfUnits][maxNumTurrets]{
|
||||
{FORWARD,FORWARD,BACKWARD,LEFT,LEFT,LEFT,LEFT,LEFT,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT},
|
||||
{FORWARD,FORWARD,BACKWARD,LEFT,LEFT,LEFT,LEFT,LEFT,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT},
|
||||
{FORWARD,FORWARD,BACKWARD,BACKWARD},
|
||||
{FORWARD,FORWARD,BACKWARD,BACKWARD},
|
||||
{FORWARD,BACKWARD},
|
||||
{FORWARD,FORWARD,FORWARD,BACKWARD,BACKWARD},
|
||||
};
|
||||
const std::string turretNames[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
"bigTurret00",
|
||||
"bigTurret00",
|
||||
"bigTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00"
|
||||
},
|
||||
{
|
||||
"bigTurret01",
|
||||
"bigTurret01",
|
||||
"bigTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01"
|
||||
},
|
||||
{"turret00", "turret00", "turret00", "turret00"},
|
||||
{"turret01", "turret01", "turret01", "turret01"},
|
||||
{"turret00", "turret00"},
|
||||
{"turret01", "turret01", "turret01", "turret01", "turret01"}
|
||||
};
|
||||
const vb01::Vector3 turretPos[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
vb01::Vector3(0, .77703, -3.24292),
|
||||
vb01::Vector3(0, 0.96741, -1.67253),
|
||||
vb01::Vector3(0, 0.77703, 3.29185),
|
||||
vb01::Vector3(0.90322, 0.78121, -0.17934),
|
||||
vb01::Vector3(0.90322, 0.78121, 0.42676),
|
||||
vb01::Vector3(0.90322, 0.78121, 1.03286),
|
||||
vb01::Vector3(0.90322, 0.78121, 1.63896),
|
||||
vb01::Vector3(0.90322, 0.78121, 2.24506),
|
||||
vb01::Vector3(-0.90322, 0.78121, -0.17934),
|
||||
vb01::Vector3(-0.90322, 0.78121, 0.42676),
|
||||
vb01::Vector3(-0.90322, 0.78121, 1.03286),
|
||||
vb01::Vector3(-0.90322, 0.78121, 1.63896),
|
||||
vb01::Vector3(-0.90322, 0.78121, 2.24506)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.70974, -2.73371),
|
||||
vb01::Vector3(0, 0.915258, -1.62768),
|
||||
vb01::Vector3(0, 0.70974, 3.33251),
|
||||
vb01::Vector3(0.58824, 0.76908, 0.30145),
|
||||
vb01::Vector3(0.58824, 0.98059, 0.58992),
|
||||
vb01::Vector3(0.58824, 0.76908, 0.8634),
|
||||
vb01::Vector3(0.58824, 0.98059, 1.13294),
|
||||
vb01::Vector3(0.58824, 0.76908, 1.40591),
|
||||
vb01::Vector3(-0.58824, 0.76908, 0.30145),
|
||||
vb01::Vector3(-0.58824, 0.98059, 0.58992),
|
||||
vb01::Vector3(-0.58824, 0.76908, 0.8634),
|
||||
vb01::Vector3(-0.58824, 0.98059, 1.13294),
|
||||
vb01::Vector3(-0.58824, 0.76908, 1.40591)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.04967, -2.08348),
|
||||
vb01::Vector3(0, 0.25291, -1.26886),
|
||||
vb01::Vector3(0, 0.25291, 1.61533),
|
||||
vb01::Vector3(0, 0.04967, 2.42996)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.53012, -2.92538),
|
||||
vb01::Vector3(0, 0.707, -2.45061),
|
||||
vb01::Vector3(0, 0.55879, 2.16916),
|
||||
vb01::Vector3(0, 0.3808, 2.72071)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.73788, -2.79825),
|
||||
vb01::Vector3(0, 0.73788, 2.79825)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.52632, -3.64706),
|
||||
vb01::Vector3(0, 0.71625, -2.81714),
|
||||
vb01::Vector3(0, 0.86667, -1.92772),
|
||||
vb01::Vector3(0, 0.7724, 2.53618),
|
||||
vb01::Vector3(0, 0.52632, 3.41345)
|
||||
}
|
||||
};
|
||||
const float turretAngleOffset[numberOfUnits][maxNumTurrets]{
|
||||
{0, 0, 180, -90, -90, -90, -90, -90, 90, 90, 90, 90, 90},
|
||||
{0, 0, 180, -90, -90, -90, -90, -90, 90, 90, 90, 90, 90},
|
||||
{0, 0, 180, 180},
|
||||
{0, 0, 180, 180},
|
||||
{0, 180},
|
||||
{0, 0, 0, 180, 180}
|
||||
};
|
||||
const float turretMaxAngle[numberOfUnits][maxNumTurrets]{
|
||||
{135, 135, 135, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{135, 135, 135, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{135, 135, 135, 135},
|
||||
{135, 135, 135, 135},
|
||||
{135, 135},
|
||||
{135, 135, 135, 135, 135}
|
||||
};
|
||||
const float turretRotationSpeed[numberOfUnits][maxNumTurrets]{
|
||||
{1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
||||
{1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
||||
{2, 2, 2, 2},
|
||||
{2, 2, 2, 2},
|
||||
{2, 2},
|
||||
{2, 2, 2, 2, 2}
|
||||
};
|
||||
const int turretDamage[numberOfUnits][maxNumTurrets]{
|
||||
{200, 200, 200, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50},
|
||||
{200, 200, 200, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50},
|
||||
{100, 100, 100, 100},
|
||||
{100, 100, 100, 100},
|
||||
{90, 90},
|
||||
{90, 90, 90, 90, 90}
|
||||
};
|
||||
const int turretRateOfFire[numberOfUnits][maxNumTurrets]{
|
||||
{1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000},
|
||||
{1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000},
|
||||
{800, 800, 800, 800},
|
||||
{800, 800, 800, 800},
|
||||
{500,500},
|
||||
{700,700,700,700,700}
|
||||
};
|
||||
const float turretAxisLength[numberOfUnits][maxNumTurrets]{
|
||||
{5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 3},
|
||||
{3, 3, 3, 3},
|
||||
{3, 3},
|
||||
{3, 3, 3, 3, 3},
|
||||
};
|
||||
const int numberOfMantlets[numberOfUnits][maxNumTurrets]{
|
||||
{3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{2, 2, 2, 2},
|
||||
{2, 2, 2, 2},
|
||||
{1, 1},
|
||||
{3, 3, 3, 3, 3}
|
||||
};
|
||||
const std::string mantletNames[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
"bigMantlet00",
|
||||
"bigMantlet00",
|
||||
"bigMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00"
|
||||
},
|
||||
{
|
||||
"bigMantlet01",
|
||||
"bigMantlet01",
|
||||
"bigMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01"
|
||||
},
|
||||
{"mantlet00", "mantlet00", "mantlet00", "mantlet00"},
|
||||
{"mantlet01", "mantlet01", "mantlet01", "mantlet01"},
|
||||
{"mantlet00", "mantlet00"},
|
||||
{"mantlet01", "mantlet01", "mantlet01", "mantlet01", "mantlet01"}
|
||||
};
|
||||
const vb01::Vector3 mantletPos[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
vb01::Vector3(0, 0.19722f, -0.38441f),
|
||||
vb01::Vector3(0, 0.183f, -0.38876f),
|
||||
vb01::Vector3(0, 0.183f, -0.38876f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.111116, -0.335219),
|
||||
vb01::Vector3(0, 0.111116, -0.335219),
|
||||
vb01::Vector3(0, 0.111116, -0.335219),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f),
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f),
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f),
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.14613, -0.0217),
|
||||
vb01::Vector3(0, 0.14613, -0.0217),
|
||||
vb01::Vector3(0, 0.14613, -0.0217),
|
||||
vb01::Vector3(0, 0.14613, -0.0217)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.2842f, -0.1274f),
|
||||
vb01::Vector3(0, 0.2842f, -0.1274f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379)
|
||||
}
|
||||
};
|
||||
const float mantletPosSideOffset[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
0.23346f,
|
||||
0.23346f,
|
||||
0.23346f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f
|
||||
},
|
||||
{
|
||||
0.176833,
|
||||
0.176833,
|
||||
0.176833,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001
|
||||
},
|
||||
{
|
||||
0.07673f,
|
||||
0.07673f,
|
||||
0.07673f,
|
||||
0.07673f
|
||||
},
|
||||
{
|
||||
0.08095,
|
||||
0.08095,
|
||||
0.08095,
|
||||
0.08095
|
||||
},
|
||||
{0, 0},
|
||||
{0.11829, 0.11829, 0.11829, 0.11829, 0.11829}
|
||||
};
|
||||
const float mantletMaxAngle[numberOfUnits][maxNumTurrets]{
|
||||
{45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{40, 40, 40, 40},
|
||||
{40, 40, 40, 40},
|
||||
{40, 40},
|
||||
{40, 40, 40, 40, 40}
|
||||
};
|
||||
const vb01::Vector3 barrelPos[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.16689f),
|
||||
vb01::Vector3(0, 0, -0.16689f),
|
||||
vb01::Vector3(0, 0, -0.16689f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f)},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.246837),
|
||||
vb01::Vector3(0, 0, -0.246837),
|
||||
vb01::Vector3(0, 0, -0.246837),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.12806f),
|
||||
vb01::Vector3(0, 0, -0.12806f),
|
||||
vb01::Vector3(0, 0, -0.12806f),
|
||||
vb01::Vector3(0, 0, -0.12806f)},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.11048),
|
||||
vb01::Vector3(0, 0, -0.11048),
|
||||
vb01::Vector3(0, 0, -0.11048),
|
||||
vb01::Vector3(0, 0, -0.11048)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.23015f),
|
||||
vb01::Vector3(0, 0, -0.23015f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595)
|
||||
}
|
||||
};
|
||||
const std::string barrelNames[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
"bigBarrel00",
|
||||
"bigBarrel00",
|
||||
"bigBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00"
|
||||
},
|
||||
{
|
||||
"bigBarrel01",
|
||||
"bigBarrel01",
|
||||
"bigBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01"
|
||||
},
|
||||
{"barrel00", "barrel00", "barrel00", "barrel00"},
|
||||
{"barrel01", "barrel01", "barrel01", "barrel01"},
|
||||
{"barrel00", "barrel00"},
|
||||
{"barrel01", "barrel01", "barrel01", "barrel01", "barrel01"}
|
||||
};
|
||||
const vb01::Vector3 guidedMissilePos[numberOfUnits][6]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
vb01::Vector3(0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.88017),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.88017)
|
||||
},
|
||||
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
|
||||
};
|
||||
}
|
||||
namespace battleship{
|
||||
namespace unitData {
|
||||
enum InitDir{FORWARD,BACKWARD,LEFT,RIGHT};
|
||||
const int numberOfTurrets[numberOfUnits]{13, 13, 4, 4, 2, 5};
|
||||
const int maxNumTurrets=13;
|
||||
const InitDir initDirs[numberOfUnits][maxNumTurrets]{
|
||||
{FORWARD,FORWARD,BACKWARD,LEFT,LEFT,LEFT,LEFT,LEFT,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT},
|
||||
{FORWARD,FORWARD,BACKWARD,LEFT,LEFT,LEFT,LEFT,LEFT,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT},
|
||||
{FORWARD,FORWARD,BACKWARD,BACKWARD},
|
||||
{FORWARD,FORWARD,BACKWARD,BACKWARD},
|
||||
{FORWARD,BACKWARD},
|
||||
{FORWARD,FORWARD,FORWARD,BACKWARD,BACKWARD},
|
||||
};
|
||||
const std::string turretNames[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
"bigTurret00",
|
||||
"bigTurret00",
|
||||
"bigTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00",
|
||||
"smallTurret00"
|
||||
},
|
||||
{
|
||||
"bigTurret01",
|
||||
"bigTurret01",
|
||||
"bigTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01",
|
||||
"smallTurret01"
|
||||
},
|
||||
{"turret00", "turret00", "turret00", "turret00"},
|
||||
{"turret01", "turret01", "turret01", "turret01"},
|
||||
{"turret00", "turret00"},
|
||||
{"turret01", "turret01", "turret01", "turret01", "turret01"}
|
||||
};
|
||||
const vb01::Vector3 turretPos[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
vb01::Vector3(0, .77703, -3.24292),
|
||||
vb01::Vector3(0, 0.96741, -1.67253),
|
||||
vb01::Vector3(0, 0.77703, 3.29185),
|
||||
vb01::Vector3(0.90322, 0.78121, -0.17934),
|
||||
vb01::Vector3(0.90322, 0.78121, 0.42676),
|
||||
vb01::Vector3(0.90322, 0.78121, 1.03286),
|
||||
vb01::Vector3(0.90322, 0.78121, 1.63896),
|
||||
vb01::Vector3(0.90322, 0.78121, 2.24506),
|
||||
vb01::Vector3(-0.90322, 0.78121, -0.17934),
|
||||
vb01::Vector3(-0.90322, 0.78121, 0.42676),
|
||||
vb01::Vector3(-0.90322, 0.78121, 1.03286),
|
||||
vb01::Vector3(-0.90322, 0.78121, 1.63896),
|
||||
vb01::Vector3(-0.90322, 0.78121, 2.24506)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.70974, -2.73371),
|
||||
vb01::Vector3(0, 0.915258, -1.62768),
|
||||
vb01::Vector3(0, 0.70974, 3.33251),
|
||||
vb01::Vector3(0.58824, 0.76908, 0.30145),
|
||||
vb01::Vector3(0.58824, 0.98059, 0.58992),
|
||||
vb01::Vector3(0.58824, 0.76908, 0.8634),
|
||||
vb01::Vector3(0.58824, 0.98059, 1.13294),
|
||||
vb01::Vector3(0.58824, 0.76908, 1.40591),
|
||||
vb01::Vector3(-0.58824, 0.76908, 0.30145),
|
||||
vb01::Vector3(-0.58824, 0.98059, 0.58992),
|
||||
vb01::Vector3(-0.58824, 0.76908, 0.8634),
|
||||
vb01::Vector3(-0.58824, 0.98059, 1.13294),
|
||||
vb01::Vector3(-0.58824, 0.76908, 1.40591)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.04967, -2.08348),
|
||||
vb01::Vector3(0, 0.25291, -1.26886),
|
||||
vb01::Vector3(0, 0.25291, 1.61533),
|
||||
vb01::Vector3(0, 0.04967, 2.42996)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.53012, -2.92538),
|
||||
vb01::Vector3(0, 0.707, -2.45061),
|
||||
vb01::Vector3(0, 0.55879, 2.16916),
|
||||
vb01::Vector3(0, 0.3808, 2.72071)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.73788, -2.79825),
|
||||
vb01::Vector3(0, 0.73788, 2.79825)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.52632, -3.64706),
|
||||
vb01::Vector3(0, 0.71625, -2.81714),
|
||||
vb01::Vector3(0, 0.86667, -1.92772),
|
||||
vb01::Vector3(0, 0.7724, 2.53618),
|
||||
vb01::Vector3(0, 0.52632, 3.41345)
|
||||
}
|
||||
};
|
||||
const float turretAngleOffset[numberOfUnits][maxNumTurrets]{
|
||||
{0, 0, 180, -90, -90, -90, -90, -90, 90, 90, 90, 90, 90},
|
||||
{0, 0, 180, -90, -90, -90, -90, -90, 90, 90, 90, 90, 90},
|
||||
{0, 0, 180, 180},
|
||||
{0, 0, 180, 180},
|
||||
{0, 180},
|
||||
{0, 0, 0, 180, 180}
|
||||
};
|
||||
const float turretMaxAngle[numberOfUnits][maxNumTurrets]{
|
||||
{135, 135, 135, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{135, 135, 135, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{135, 135, 135, 135},
|
||||
{135, 135, 135, 135},
|
||||
{135, 135},
|
||||
{135, 135, 135, 135, 135}
|
||||
};
|
||||
const float turretRotationSpeed[numberOfUnits][maxNumTurrets]{
|
||||
{1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
||||
{1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
||||
{2, 2, 2, 2},
|
||||
{2, 2, 2, 2},
|
||||
{2, 2},
|
||||
{2, 2, 2, 2, 2}
|
||||
};
|
||||
const int turretDamage[numberOfUnits][maxNumTurrets]{
|
||||
{200, 200, 200, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50},
|
||||
{200, 200, 200, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50},
|
||||
{100, 100, 100, 100},
|
||||
{100, 100, 100, 100},
|
||||
{90, 90},
|
||||
{90, 90, 90, 90, 90}
|
||||
};
|
||||
const int turretRateOfFire[numberOfUnits][maxNumTurrets]{
|
||||
{1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000},
|
||||
{1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000},
|
||||
{800, 800, 800, 800},
|
||||
{800, 800, 800, 800},
|
||||
{500,500},
|
||||
{700,700,700,700,700}
|
||||
};
|
||||
const float turretAxisLength[numberOfUnits][maxNumTurrets]{
|
||||
{5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 3},
|
||||
{3, 3, 3, 3},
|
||||
{3, 3},
|
||||
{3, 3, 3, 3, 3},
|
||||
};
|
||||
const int numberOfMantlets[numberOfUnits][maxNumTurrets]{
|
||||
{3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{2, 2, 2, 2},
|
||||
{2, 2, 2, 2},
|
||||
{1, 1},
|
||||
{3, 3, 3, 3, 3}
|
||||
};
|
||||
const std::string mantletNames[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
"bigMantlet00",
|
||||
"bigMantlet00",
|
||||
"bigMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00",
|
||||
"smallMantlet00"
|
||||
},
|
||||
{
|
||||
"bigMantlet01",
|
||||
"bigMantlet01",
|
||||
"bigMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01",
|
||||
"smallMantlet01"
|
||||
},
|
||||
{"mantlet00", "mantlet00", "mantlet00", "mantlet00"},
|
||||
{"mantlet01", "mantlet01", "mantlet01", "mantlet01"},
|
||||
{"mantlet00", "mantlet00"},
|
||||
{"mantlet01", "mantlet01", "mantlet01", "mantlet01", "mantlet01"}
|
||||
};
|
||||
const vb01::Vector3 mantletPos[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
vb01::Vector3(0, 0.19722f, -0.38441f),
|
||||
vb01::Vector3(0, 0.183f, -0.38876f),
|
||||
vb01::Vector3(0, 0.183f, -0.38876f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f),
|
||||
vb01::Vector3(0, 0.06484f, -0.08587f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.111116, -0.335219),
|
||||
vb01::Vector3(0, 0.111116, -0.335219),
|
||||
vb01::Vector3(0, 0.111116, -0.335219),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749),
|
||||
vb01::Vector3(0, 0.025217, -0.071749)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f),
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f),
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f),
|
||||
vb01::Vector3(0, 0.22782f, -0.12394f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.14613, -0.0217),
|
||||
vb01::Vector3(0, 0.14613, -0.0217),
|
||||
vb01::Vector3(0, 0.14613, -0.0217),
|
||||
vb01::Vector3(0, 0.14613, -0.0217)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.2842f, -0.1274f),
|
||||
vb01::Vector3(0, 0.2842f, -0.1274f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379),
|
||||
vb01::Vector3(0, 0.09455, -0.19379)
|
||||
}
|
||||
};
|
||||
const float mantletPosSideOffset[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
0.23346f,
|
||||
0.23346f,
|
||||
0.23346f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f,
|
||||
0.04725f
|
||||
},
|
||||
{
|
||||
0.176833,
|
||||
0.176833,
|
||||
0.176833,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001,
|
||||
0.030001
|
||||
},
|
||||
{
|
||||
0.07673f,
|
||||
0.07673f,
|
||||
0.07673f,
|
||||
0.07673f
|
||||
},
|
||||
{
|
||||
0.08095,
|
||||
0.08095,
|
||||
0.08095,
|
||||
0.08095
|
||||
},
|
||||
{0, 0},
|
||||
{0.11829, 0.11829, 0.11829, 0.11829, 0.11829}
|
||||
};
|
||||
const float mantletMaxAngle[numberOfUnits][maxNumTurrets]{
|
||||
{45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45},
|
||||
{40, 40, 40, 40},
|
||||
{40, 40, 40, 40},
|
||||
{40, 40},
|
||||
{40, 40, 40, 40, 40}
|
||||
};
|
||||
const vb01::Vector3 barrelPos[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.16689f),
|
||||
vb01::Vector3(0, 0, -0.16689f),
|
||||
vb01::Vector3(0, 0, -0.16689f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f),
|
||||
vb01::Vector3(0, 0, -0.1021f)},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.246837),
|
||||
vb01::Vector3(0, 0, -0.246837),
|
||||
vb01::Vector3(0, 0, -0.246837),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993),
|
||||
vb01::Vector3(0, 0, -0.054993)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.12806f),
|
||||
vb01::Vector3(0, 0, -0.12806f),
|
||||
vb01::Vector3(0, 0, -0.12806f),
|
||||
vb01::Vector3(0, 0, -0.12806f)},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.11048),
|
||||
vb01::Vector3(0, 0, -0.11048),
|
||||
vb01::Vector3(0, 0, -0.11048),
|
||||
vb01::Vector3(0, 0, -0.11048)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.23015f),
|
||||
vb01::Vector3(0, 0, -0.23015f)
|
||||
},
|
||||
{
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595),
|
||||
vb01::Vector3(0, 0, -0.14595)
|
||||
}
|
||||
};
|
||||
const std::string barrelNames[numberOfUnits][maxNumTurrets]{
|
||||
{
|
||||
"bigBarrel00",
|
||||
"bigBarrel00",
|
||||
"bigBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00",
|
||||
"smallBarrel00"
|
||||
},
|
||||
{
|
||||
"bigBarrel01",
|
||||
"bigBarrel01",
|
||||
"bigBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01",
|
||||
"smallBarrel01"
|
||||
},
|
||||
{"barrel00", "barrel00", "barrel00", "barrel00"},
|
||||
{"barrel01", "barrel01", "barrel01", "barrel01"},
|
||||
{"barrel00", "barrel00"},
|
||||
{"barrel01", "barrel01", "barrel01", "barrel01", "barrel01"}
|
||||
};
|
||||
const vb01::Vector3 guidedMissilePos[numberOfUnits][6]{
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{
|
||||
vb01::Vector3(0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(0.24482, 1.14985, 1.88017),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.32775),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.62698),
|
||||
vb01::Vector3(-0.24482, 1.14985, 1.88017)
|
||||
},
|
||||
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user