factored out a state manager

using GameManager via a singleton
This commit is contained in:
devZoGok
2021-10-30 08:09:30 +03:00
parent 7f8824cb29
commit 179f4c28ac
70 changed files with 654 additions and 474 deletions
+1 -2
View File
@@ -8,8 +8,7 @@ using namespace game::core;
namespace game{
namespace gui{
AbstractBitmapText::AbstractBitmapText(GameManager *gM, stringw text, vector2d<s32> pos, IGUIFont *font) {
gameManager = gM;
AbstractBitmapText::AbstractBitmapText(stringw text, vector2d<s32> pos, IGUIFont *font) {
this->text = text;
this->pos = pos;
this->font = font;
+1 -1
View File
@@ -7,7 +7,7 @@ namespace game{
namespace gui{
class AbstractBitmapText {
public:
AbstractBitmapText(core::GameManager*, irr::core::stringw, irr::core::vector2d<s32>, irr::gui::IGUIFont*);
AbstractBitmapText(irr::core::stringw, irr::core::vector2d<s32>, irr::gui::IGUIFont*);
~AbstractBitmapText();
void update();
inline irr::core::vector2d<s32> getPos(){return pos;}
+2 -3
View File
@@ -7,8 +7,7 @@ using namespace game::core;
namespace game
{
namespace gui{
AbstractImage::AbstractImage(GameManager *gM, ITexture *image, vector2d<s32> pos, vector2d<s32> size) {
gameManager = gM;
AbstractImage::AbstractImage(ITexture *image, vector2d<s32> pos, vector2d<s32> size) {
this->image = image;
this->pos = pos;
this->size = size;
@@ -18,7 +17,7 @@ namespace game
}
void AbstractImage::update() {
irr::video::IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
irr::video::IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->draw2DImage(image, pos);
}
}
+1 -2
View File
@@ -9,7 +9,7 @@ namespace game
namespace gui{
class AbstractImage {
public:
AbstractImage(core::GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>);
AbstractImage(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>);
~AbstractImage();
void update();
inline irr::video::ITexture* getImage(){return image;}
@@ -20,7 +20,6 @@ namespace game
inline void setSize(irr::core::vector2d<s32> s){this->size=s;}
inline irr::core::stringw getPath(){return path;}
private:
core::GameManager *gameManager;
irr::video::ITexture *image;
irr::core::vector2d<s32> pos, size;
irr::core::stringw path;
+74 -51
View File
@@ -1,5 +1,6 @@
#include "activeGameState.h"
#include "inGameAppState.h"
#include "stateManager.h"
#include "util.h"
#include "cruiser.h"
#include "destroyer.h"
@@ -21,7 +22,7 @@ namespace game{
namespace core{
const int size=50;
ActiveGameState::UnitButton::UnitButton(GameManager *gm,ActiveGameState *activeState,vector2di pos, vector2di size, irr::core::stringw name,int faction,int unitId) : gui::Button(gm,pos,size,name,true){
ActiveGameState::UnitButton::UnitButton(ActiveGameState *activeState,vector2di pos, vector2di size, irr::core::stringw name,int faction,int unitId) : gui::Button(pos,size,name,true){
this->activeState=activeState;
this->faction=faction;
this->unitId=unitId;
@@ -33,19 +34,19 @@ namespace game{
Unit *u;
switch(unitData::unitType[unitId]){
case unitData::UNIT_TYPE::VESSEL:
u=new Vessel(gameManager,player,spawnPoint,unitId);
u=new Vessel(player,spawnPoint,unitId);
break;
case unitData::UNIT_TYPE::DESTROYER:
u=new Destroyer(gameManager,player,spawnPoint,unitId);
u=new Destroyer(player,spawnPoint,unitId);
break;
case unitData::UNIT_TYPE::CRUISER:
u=new Cruiser(gameManager,player,spawnPoint,unitId);
u=new Cruiser(player,spawnPoint,unitId);
break;
case unitData::UNIT_TYPE::AIRCRAFT_CARRIER:
u=new AircraftCarrier(gameManager,player,spawnPoint,unitId);
u=new AircraftCarrier(player,spawnPoint,unitId);
break;
case unitData::UNIT_TYPE::SUBMARINE:
u=new Submarine(gameManager,player,spawnPoint,unitId);
u=new Submarine(player,spawnPoint,unitId);
break;
}
player->addUnit(u);
@@ -53,23 +54,25 @@ namespace game{
void ActiveGameState::UnitButton::onMouseOver(){
if(!mouseOverDone){
GuiAppState *guiState=((GuiAppState*)gameManager->getAppState(AppStateTypes::GUI_STATE));
guiState->addTooltip(new gui::Tooltip(gameManager,pos-vector2di(100,0),name));
GameManager *gm = GameManager::getSingleton();
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->addTooltip(new gui::Tooltip(pos-vector2di(100,0),name));
}
}
void ActiveGameState::UnitButton::onMouseAway(){
if(!mouseAwayDone){
GuiAppState *guiState=((GuiAppState*)gameManager->getAppState(AppStateTypes::GUI_STATE));
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->removeAllTooltips();
}
}
ActiveGameState::UnitActionButton::UnitActionButton(GameManager *gm, unitData::UNIT_TYPE type, vector2di pos, vector2di size, stringw name, stringw path) : gui::Button(gm,pos,size,name,true){
ActiveGameState::UnitActionButton::UnitActionButton(unitData::UNIT_TYPE type, vector2di pos, vector2di size, stringw name, stringw path) : gui::Button(pos,size,name,true){
this->type=type;
IVideoDriver *driver=gameManager->getDevice()->getVideoDriver();
activeState=((ActiveGameState*)gm->getAppState(AppStateTypes::ACTIVE_STATE));
setImageButton(new Image(gameManager,driver->getTexture(path),pos,vector2di(50,50)));
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
activeState=((ActiveGameState*)gm->getStateManager()->getAppState(AppStateTypes::ACTIVE_STATE));
setImageButton(new Image(driver->getTexture(path),pos,vector2di(50,50)));
}
void ActiveGameState::UnitActionButton::onClick(){
@@ -81,27 +84,28 @@ namespace game{
void ActiveGameState::UnitActionButton::onMouseOver(){
if(!mouseOverDone){
GuiAppState *guiState=((GuiAppState*)gameManager->getAppState(AppStateTypes::GUI_STATE));
guiState->addTooltip(new gui::Tooltip(gameManager,pos-vector2di(100,0),name));
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->addTooltip(new gui::Tooltip(pos-vector2di(100,0),name));
}
}
void ActiveGameState::UnitActionButton::onMouseAway(){
if(!mouseAwayDone){
GuiAppState *guiState=((GuiAppState*)gameManager->getAppState(AppStateTypes::GUI_STATE));
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->removeAllTooltips();
}
}
ActiveGameState::ActiveGameState(GameManager *gM, GuiAppState *guiState, Map *map, vector<Player*> players, int playerId) {
gameManager = gM;
ActiveGameState::ActiveGameState(GuiAppState *guiState, Map *map, vector<Player*> players, int playerId) {
type = AppStateTypes::ACTIVE_STATE;
this->guiState = guiState;
this->map = map;
this->players = players;
cam = gM->getDevice()->getSceneManager()->addCameraSceneNodeFPS(0, 100, 0.f, -1, nullptr, 10, false, 0.6f);
GameManager *gm = GameManager::getSingleton();
cam = gm->getDevice()->getSceneManager()->addCameraSceneNodeFPS(0, 100, 0.f, -1, nullptr, 10, false, 0.6f);
cam->setInputReceiverEnabled(false);
gameManager->getDevice()->getCursorControl()->setVisible(true);
gm->getDevice()->getCursorControl()->setVisible(true);
this->playerId = playerId;
mainPlayer = players[playerId];
cam->setPosition(vector3df(0, 5, 0));
@@ -114,18 +118,22 @@ namespace game{
void ActiveGameState::onAttachment() {
AbstractAppState::onAttachment();
IVideoDriver *driver=gameManager->getDevice()->getVideoDriver();
int faction=mainPlayer->getFaction(),width=gameManager->getWidth(),heigh=gameManager->getHeight(),size=50;
stringw names[5]={"Battleship","Destroyer","Cruiser","Carrier","Submarine"};
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
int faction = mainPlayer->getFaction(), width = gm->getWidth(), height = gm->getHeight(),size=50;
stringw names[5] = {"Battleship","Destroyer","Cruiser","Carrier","Submarine"};
for(int i=0;i<5;i++){
int id=2*i+(i==4&&faction==1?0:faction);
vector2di pos=vector2di(width-size-1,1+i*size),sizeVec=vector2di(size,size);
UnitButton *button=new UnitButton(gameManager,this,pos,sizeVec,names[i],faction,id);
UnitButton *button=new UnitButton(this,pos,sizeVec,names[i],faction,id);
if(i==3)
names[i]="aircraftCarrier";
else
names[i].make_lower();
button->setImageButton(new Image(gameManager,driver->getTexture(PATH+"Textures/Icons/"+names[i]+"0"+stringw(faction)+".png"),pos,sizeVec));
button->setImageButton(new Image(driver->getTexture(PATH+"Textures/Icons/"+names[i]+"0"+stringw(faction)+".png"),pos,sizeVec));
guiState->addButton(button);
}
}
@@ -183,7 +191,7 @@ namespace game{
}
void ActiveGameState::renderUnits(vector<Unit*> units) {
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
ISceneManager *smgr = GameManager::getSingleton()->getDevice()->getSceneManager();
for (Unit *rendUn : units) {
vector3df rendUnPos = rendUn->getPos();
rendUnPos.Y = 0;
@@ -202,8 +210,10 @@ namespace game{
}
void ActiveGameState::renderGUIBorders(){
IVideoDriver *driver=gameManager->getDevice()->getVideoDriver();
int width=gameManager->getWidth(),height=gameManager->getHeight(),size=50;
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
int width = gm->getWidth(), height = gm->getHeight(), size = 50;
for(int i=0;i<height/size;i++){
driver->draw2DRectangleOutline(recti(vector2di(width-(2*size+3),size*i),dimension2di(size+2,size+2)));
driver->draw2DRectangleOutline(recti(vector2di(width-(size+2),size*i),dimension2di(size+2,size+2)));
@@ -213,7 +223,7 @@ namespace game{
void ActiveGameState::renderActionButtons(){
class MakeJetButton : public UnitActionButton{
public:
MakeJetButton(GameManager *gm,int faction,unitData::UNIT_TYPE type,vector2di pos, vector2di size):UnitActionButton(gm,type,pos,size,"Jet",PATH+"Textures/Icons/jet0"+stringw(faction)+".png"){
MakeJetButton(int faction,unitData::UNIT_TYPE type,vector2di pos, vector2di size):UnitActionButton(type,pos,size,"Jet",PATH+"Textures/Icons/jet0"+stringw(faction)+".png"){
}
~MakeJetButton(){}
void onClick(){
@@ -225,7 +235,7 @@ namespace game{
};
class LaunchButton : public UnitActionButton{
public:
LaunchButton(GameManager *gm,int faction,unitData::UNIT_TYPE type,vector2di pos,vector2di size) : UnitActionButton(gm,type,pos,size,"Launch",PATH+"Textures/Icons/guidedMissile0"+stringw(faction)+".png"){}
LaunchButton(int faction,unitData::UNIT_TYPE type,vector2di pos,vector2di size) : UnitActionButton(type,pos,size,"Launch",PATH+"Textures/Icons/guidedMissile0"+stringw(faction)+".png"){}
~LaunchButton(){}
void onClick(){
UnitActionButton::onClick();
@@ -235,7 +245,7 @@ namespace game{
};
class MissileButton : public UnitActionButton{
public:
MissileButton(GameManager *gm,bool aam,vector2di pos,vector2di size,stringw name,stringw path) : UnitActionButton(gm,unitData::UNIT_TYPE::MISSILE_JET,pos,size,name,path){
MissileButton(bool aam,vector2di pos,vector2di size,stringw name,stringw path) : UnitActionButton(unitData::UNIT_TYPE::MISSILE_JET,pos,size,name,path){
this->aam=aam;
}
~MissileButton(){}
@@ -247,8 +257,11 @@ namespace game{
private:
bool aam;
};
int width=gameManager->getWidth(),height=gameManager->getHeight(),slotSize=size+2,faction=mainPlayer->getFaction();
bool carriers=false,cruisers=false,missileJets=false;
GameManager *gm = GameManager::getSingleton();
int width = gm->getWidth(), height = gm->getHeight(), slotSize = size + 2, faction = mainPlayer->getFaction();
bool carriers=false, cruisers=false, missileJets=false;
for(int i=0;i<selectedUnits.size()&&!(carriers&&cruisers&&missileJets);i++){
if(selectedUnits[i]->getType()==unitData::UNIT_TYPE::AIRCRAFT_CARRIER)
carriers=true;
@@ -258,7 +271,7 @@ namespace game{
missileJets=true;
}
if(carriers&&!actionButtons[0]){
actionButtons[0]=new MakeJetButton(gameManager,faction,unitData::UNIT_TYPE::AIRCRAFT_CARRIER,vector2di(width-2*slotSize,0),vector2di(size,size));
actionButtons[0]=new MakeJetButton(faction,unitData::UNIT_TYPE::AIRCRAFT_CARRIER,vector2di(width-2*slotSize,0),vector2di(size,size));
guiState->addButton(actionButtons[0]);
}
else if(!carriers&&actionButtons[0]){
@@ -266,7 +279,7 @@ namespace game{
actionButtons[0]=nullptr;
}
if(cruisers&&!actionButtons[1]){
actionButtons[1]=new LaunchButton(gameManager,faction,unitData::UNIT_TYPE::CRUISER,vector2di(width-2*slotSize,slotSize),vector2di(size,size));
actionButtons[1]=new LaunchButton(faction,unitData::UNIT_TYPE::CRUISER,vector2di(width-2*slotSize,slotSize),vector2di(size,size));
guiState->addButton(actionButtons[1]);
}
else if(!cruisers&&actionButtons[1]){
@@ -274,8 +287,8 @@ namespace game{
actionButtons[1]=nullptr;
}
if(missileJets&&!actionButtons[2]){
actionButtons[2]=new MissileButton(gameManager,true,vector2di(width-2*slotSize,slotSize*3),vector2di(size,size),"AAM",PATH+"Textures/Icons/aam.png");
actionButtons[3]=new MissileButton(gameManager,false,vector2di(width-2*slotSize,slotSize*4),vector2di(size,size),"AWM",PATH+"Textures/Icons/awm.png");
actionButtons[2]=new MissileButton(true,vector2di(width-2*slotSize,slotSize*3),vector2di(size,size),"AAM",PATH+"Textures/Icons/aam.png");
actionButtons[3]=new MissileButton(false,vector2di(width-2*slotSize,slotSize*4),vector2di(size,size),"AWM",PATH+"Textures/Icons/awm.png");
guiState->addButton(actionButtons[2]);
guiState->addButton(actionButtons[3]);
}
@@ -297,8 +310,10 @@ namespace game{
}
void ActiveGameState::updateSelectionBox() {
vector2d<s32> mousePos = gameManager->getDevice()->getCursorControl()->getPosition();
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
GameManager *gm = GameManager::getSingleton();
vector2d<s32> mousePos = gm->getDevice()->getCursorControl()->getPosition();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
if (mousePos.X >= clickPoint.X && mousePos.Y >= clickPoint.Y) {
selectionBoxOrigin = vector2d<s32>(clickPoint.X, clickPoint.Y);
selectionBoxEnd = vector2d<s32>(mousePos.X, mousePos.Y);
@@ -316,10 +331,12 @@ namespace game{
}
void ActiveGameState::updateVectors() {
vector2d<s32> cursorPos = gameManager->getDevice()->getCursorControl()->getPosition();
GameManager *gm = GameManager::getSingleton();
vector2d<s32> cursorPos = gm->getDevice()->getCursorControl()->getPosition();
camDir = (cam->getTarget() - cam->getPosition()).normalize();
float vecAngle = getAngleBetween(vector3df(0, 0, 1), vector3df(camDir.X, 0, camDir.Z));
quaternion rotQuat;
if (quaternion(0, 0, 0, 0).fromAngleAxis(vecAngle, vector3df(0, 1, 0)) * vector3df(0, 0, 1) != vector3df(camDir.X, 0, camDir.Z).normalize()) {
rotQuat.fromAngleAxis(-vecAngle + PI / 2, vector3df(0, 1, 0));
camLeft = rotQuat * vector3df(0, 0, -1);
@@ -329,19 +346,19 @@ namespace game{
}
vector3df forwVec = quaternion(0, 0, 0, 0).fromAngleAxis(PI / 2, vector3df(0, 1, 0)) * camLeft;
camUp = quaternion(0, 0, 0, 0).fromAngleAxis(PI / 2, camLeft.normalize()) * camDir;
if (cursorPos.X == 0 && cursorPos.Y < gameManager->getHeight() && cursorPos.Y > 0) {
if (cursorPos.X == 0 && cursorPos.Y < gm->getHeight() && cursorPos.Y > 0) {
cam->setPosition(cam->getPosition() + camLeft * camPanSpeed);
cam->setTarget(cam->getPosition() + camDir);
}//<-
if (cursorPos.X >= gameManager->getWidth() - 1 && cursorPos.Y < gameManager->getHeight() && cursorPos.Y > 0) {
if (cursorPos.X >= gm->getWidth() - 1 && cursorPos.Y < gm->getHeight() && cursorPos.Y > 0) {
cam->setPosition(cam->getPosition() - camLeft * camPanSpeed);
cam->setTarget(cam->getPosition() + camDir);
}//->
if (cursorPos.X > 0 && cursorPos.X < gameManager->getWidth() && cursorPos.Y == 0) {
if (cursorPos.X > 0 && cursorPos.X < gm->getWidth() && cursorPos.Y == 0) {
cam->setPosition(cam->getPosition() + (forwVec.normalize()) * camPanSpeed);
cam->setTarget(cam->getPosition() + camDir);
}//^
if (cursorPos.X > 0 && cursorPos.X < gameManager->getWidth() && cursorPos.Y >= gameManager->getHeight() - 1) {
if (cursorPos.X > 0 && cursorPos.X < gm->getWidth() && cursorPos.Y >= gm->getHeight() - 1) {
cam->setPosition(cam->getPosition() - (forwVec.normalize()) * camPanSpeed);
cam->setTarget(cam->getPosition() + camDir);
}
@@ -368,13 +385,14 @@ namespace game{
vector3df topLeft=cam->getViewFrustum()->getNearLeftUp();
vector3df topRight=cam->getViewFrustum()->getNearRightUp();
vector3df bottomLeft=cam->getViewFrustum()->getNearLeftDown();
vector2d<int> mousePos=gameManager->getDevice()->getCursorControl()->getPosition();
GameManager *gm = GameManager::getSingleton();
vector2d<int> mousePos = gm->getDevice()->getCursorControl()->getPosition();
vector3df p=topLeft;
p+=(topRight-topLeft)*((float)mousePos.X/gameManager->getWidth());
p+=(bottomLeft-topLeft)*((float)mousePos.Y/gameManager->getHeight());
p+=(topRight-topLeft)*((float)mousePos.X / gm->getWidth());
p+=(bottomLeft-topLeft)*((float)mousePos.Y / gm->getHeight());
vector3df orderDir=(p-camPos).normalize();
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
ISceneCollisionManager *collMan = smgr->getSceneCollisionManager();
line3d<float> ray;
ray.start = camPos;
@@ -382,6 +400,7 @@ namespace game{
triangle3df t;
vector3df collPoint;
ISceneNode *collNode = collMan->getSceneNodeAndCollisionPointFromRay(ray, collPoint, t, 0, 0);
if (collNode) {
for (Player *p : players)
for (int i = 0; i < p->getNumberOfUnits(); i++)
@@ -392,6 +411,7 @@ namespace game{
else {
if(orderDir.Y>0)
orderDir.Y*=-1;
float angle = getAngleBetween(vector3df(0, -1, 0), orderDir);
float hyp = camPos.Y / cos(angle);
vector3df *v=new vector3df(orderDir * hyp + camPos);
@@ -400,21 +420,24 @@ namespace game{
}
if (!selectingPatrolPoints) {
Order::TYPE t = Order::TYPE::MOVE;
if (selectingGuidedMissileTarget)
t = Order::TYPE::LAUNCH;
else if (controlPressed)
t = Order::TYPE::ATTACK;
issueOrder(t, orderPos, false);
}
}
void ActiveGameState::onAction(Bind bind, bool isPressed) {
InGameAppState *inGameState = (InGameAppState*) gameManager->getAppState(AppStateTypes::IN_GAME_STATE);
GameManager *gm = GameManager::getSingleton();
InGameAppState *inGameState = (InGameAppState*) gm->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE);
switch(bind){
case DRAG_BOX:
isSelectionBox = isPressed;
if (isPressed) {
clickPoint = gameManager->getDevice()->getCursorControl()->getPosition();
clickPoint = gm->getDevice()->getCursorControl()->getPosition();
if (!selectedUnits.empty())
addPos();
}
@@ -454,7 +477,7 @@ namespace game{
break;
case LOOK_AROUND:
cam->setInputReceiverEnabled(isPressed);
gameManager->getDevice()->getCursorControl()->setVisible(!isPressed);
gm->getDevice()->getCursorControl()->setVisible(!isPressed);
lookingAround=isPressed;
break;
case HALT:
+3 -4
View File
@@ -12,7 +12,7 @@ namespace game{
namespace core{
class ActiveGameState : public AbstractAppState {
public:
ActiveGameState(core::GameManager*, GuiAppState*, content::Map*, std::vector<content::Player*> players, int);
ActiveGameState(GuiAppState*, content::Map*, std::vector<content::Player*> players, int);
~ActiveGameState();
void onAttachment();
void onDetachment();
@@ -26,7 +26,7 @@ namespace game{
private:
class UnitButton : public gui::Button{
public:
UnitButton(GameManager*,ActiveGameState*,vector2di, vector2di, irr::core::stringw,int,int);
UnitButton(ActiveGameState*,vector2di, vector2di, irr::core::stringw,int,int);
~UnitButton();
virtual void onClick();
virtual void onMouseOver();
@@ -37,7 +37,7 @@ namespace game{
};
class UnitActionButton : public gui::Button{
public:
UnitActionButton(GameManager*, content::unitData::UNIT_TYPE, irr::core::vector2di, irr::core::vector2di, irr::core::stringw, irr::core::stringw);
UnitActionButton(content::unitData::UNIT_TYPE, irr::core::vector2di, irr::core::vector2di, irr::core::stringw, irr::core::stringw);
~UnitActionButton();
virtual void onClick();
virtual void onMouseOver();
@@ -56,7 +56,6 @@ namespace game{
void addPos();
void issueOrder(content::Order::TYPE, std::vector<irr::core::vector3df*>, bool);
void lookAround(bool);
GameManager *gameManager;
GuiAppState *guiState;
content::Map *map;
std::vector<content::Player*> players;
+3 -3
View File
@@ -7,7 +7,7 @@ using namespace game::core;
namespace game{
namespace content{
AircraftCarrier::AircraftCarrier(GameManager *gM, Player *player,vector3df pos, int unitId) : Vessel(gM, player,pos, unitId) {
AircraftCarrier::AircraftCarrier(Player *player,vector3df pos, int unitId) : Vessel(player,pos, unitId) {
maxNumJets=unitData::numJets[unitId];
jets=new Jet*[maxNumJets];
for(int i=0;i<maxNumJets;i++)
@@ -31,10 +31,10 @@ namespace game{
Jet *j = nullptr;
if (this->id == 6) {
id = 9;
j = (MissileJet*)new MissileJet(gameManager, player,getJetPos(slot), id);
j = (MissileJet*)new MissileJet(player,getJetPos(slot), id);
} else {
id = 10;
j = (DemoJet*)new DemoJet(gameManager, player,getJetPos(slot), id);
j = (DemoJet*)new DemoJet(player,getJetPos(slot), id);
}
j->setJetId(slot);
jets[slot]=j;
+1 -1
View File
@@ -10,7 +10,7 @@ namespace game{
namespace content{
class AircraftCarrier : public Vessel {
public:
AircraftCarrier(core::GameManager*, Player*, irr::core::vector3df, int);
AircraftCarrier(Player*, irr::core::vector3df, int);
~AircraftCarrier();
void makeJet();
inline void setJet(int i, Jet *j){this->jets[i]=j;}
+5 -4
View File
@@ -11,8 +11,7 @@ namespace game{
namespace gui{
Button::Button() {}
Button::Button(GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) {
gameManager = gM;
Button::Button(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) {
color = new SColor(255, 200, 200, 200);
this->name = name;
this->pos = pos;
@@ -26,11 +25,13 @@ namespace game{
}
void Button::update() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
if (!imageButton) {
driver->draw2DRectangle(*color, rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
if (separate) {
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
font->draw(name, rect<s32>(pos.X + size.X / 4 + textXOffset, pos.Y + size.Y / 4 + textYOffset, size.X, size.Y), SColor(255, 250, 250, 250));
}
} else
+1 -2
View File
@@ -14,7 +14,7 @@ namespace game{
class Button {
public:
Button();
Button(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
Button(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
~Button();
virtual void onClick(){}
virtual void onMouseOver(){}
@@ -45,7 +45,6 @@ namespace game{
protected:
irr::core::stringw name;
irr::core::vector2d<s32> pos, size;
core::GameManager *gameManager = nullptr;
irr::video::SColor *color = nullptr;
bool mouseOverDone=false,mouseAwayDone=false;
};
+4 -5
View File
@@ -7,7 +7,7 @@ using namespace game::core;
namespace game{
namespace gui{
Checkbox::CheckboxButton::CheckboxButton(GameManager *gM, Checkbox *ch, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) :Button(gM, pos, size, name, separate) {
Checkbox::CheckboxButton::CheckboxButton(Checkbox *ch, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) :Button(pos, size, name, separate) {
checkbox = ch;
}
@@ -15,10 +15,9 @@ namespace game{
checkbox->check();
}
Checkbox::Checkbox(GameManager *gM,vector2d<s32> pos){
gameManager = gM;
Checkbox::Checkbox(vector2d<s32> pos){
this->pos = pos;
checkboxButton = new CheckboxButton(gM, this, pos, vector2d<s32>(length,length), "CheckboxButton", false);
checkboxButton = new CheckboxButton(this, pos, vector2d<s32>(length,length), "CheckboxButton", false);
}
Checkbox::~Checkbox() {
@@ -26,7 +25,7 @@ namespace game{
}
void Checkbox::update() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->draw2DRectangle(SColor(255, 100, 100, 100), rect<s32>(pos.X, pos.Y, pos.X + length, pos.Y + length), nullptr);
if (checked) {
driver->draw2DLine(pos, vector2d<s32>(pos.X + length, pos.Y + length),SColor(255,255,255,255));
+2 -3
View File
@@ -8,7 +8,7 @@ namespace game{
namespace gui {
class Checkbox {
public:
Checkbox(core::GameManager*, irr::core::vector2d<s32>);
Checkbox(irr::core::vector2d<s32>);
~Checkbox();
void update();
virtual void check(){checked=!checked;}
@@ -16,14 +16,13 @@ namespace game{
private:
class CheckboxButton : public Button {
public:
CheckboxButton(core::GameManager*, Checkbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
CheckboxButton(Checkbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
Checkbox *checkbox = nullptr;
};
const int length=15;
bool checked = false;
core::GameManager *gameManager;
irr::core::vector2d<s32> pos;
CheckboxButton *checkboxButton;
public:
+8 -9
View File
@@ -18,8 +18,7 @@ using namespace std;
namespace game{
namespace gui{
ConsoleCommand::ConsoleCommand(GameManager *gM, Listbox *l, vector<Player*> players, stringw name, vector<stringw> args) {
gameManager = gM;
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, stringw name, vector<stringw> args) {
listbox = l;
this->players = players;
this->name = name;
@@ -56,27 +55,27 @@ namespace game{
Unit *u = nullptr;
switch (unitType[unitId]) {
case UNIT_TYPE::VESSEL:
u = new Vessel(gameManager, players[playerId],pos, unitId);
u = new Vessel(players[playerId],pos, unitId);
break;
case UNIT_TYPE::DESTROYER:
u = new Destroyer(gameManager, players[playerId], pos, unitId);
u = new Destroyer(players[playerId], pos, unitId);
break;
case UNIT_TYPE::CRUISER:
u = new Cruiser(gameManager, players[playerId],pos, unitId);
u = new Cruiser(players[playerId],pos, unitId);
break;
case UNIT_TYPE::SUBMARINE:
u = new Submarine(gameManager, players[playerId], pos, unitId);
u = new Submarine(players[playerId], pos, unitId);
break;
case UNIT_TYPE::AIRCRAFT_CARRIER:
{
u = new AircraftCarrier(gameManager, players[playerId],pos, unitId);
u = new AircraftCarrier(players[playerId],pos, unitId);
break;
}
case UNIT_TYPE::MISSILE_JET:
u = new MissileJet(gameManager, players[playerId],pos, unitId, false);
u = new MissileJet(players[playerId],pos, unitId, false);
break;
case UNIT_TYPE::DEMO_JET:
u = new DemoJet(gameManager, players[playerId],pos, unitId, false);
u = new DemoJet(players[playerId],pos, unitId, false);
break;
default:
break;
+4 -4
View File
@@ -2,23 +2,23 @@
#ifndef CONSOLE_COMMAND_H
#define CONSOLE_COMMAND_H
#include <irrlicht.h>
#include <vector>
#include "gameManager.h"
#include "unit.h"
#include "listbox.h"
#include "player.h"
#include <irrlicht.h>
#include <vector>
namespace game
{
namespace gui{
class ConsoleCommand{
public:
ConsoleCommand(core::GameManager*,Listbox*,std::vector<content::Player*>,irr::core::stringw,std::vector<irr::core::stringw>);
ConsoleCommand(Listbox*,std::vector<content::Player*>,irr::core::stringw,std::vector<irr::core::stringw>);
~ConsoleCommand();
void execute();
private:
core::GameManager *gameManager;
Listbox *listbox;
void printConsoleMessage(irr::core::stringw);
std::vector<content::Player*> players;
+2 -2
View File
@@ -10,7 +10,7 @@ using namespace game::util;
namespace game{
namespace content{
Cruiser::Cruiser(GameManager *gM, Player *player, vector3df pos, int id) : Vessel(gM, player, pos, id) {
Cruiser::Cruiser(Player *player, vector3df pos, int id) : Vessel(player, pos, id) {
guidedMissiles = unitData::maxGuidedMissiles[id];
}
@@ -19,7 +19,7 @@ namespace game{
float angle = getAngleBetween(*order.targetPos[0], dirVec);
quaternion rotQuat = rotQuat.fromAngleAxis(dirVec.X < 0 ? angle : -angle, vector3df(0, 1, 0));
vector3df 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(gameManager, this, pos + basePos, *order.targetPos[0], rotQuat * vector3df(0, 1, 0), rotQuat * vector3df(1, 0, 0), rotQuat * vector3df(0, 0, -1), getId(), 1, 0));
addProjectile(new GuidedMissile(this, pos + basePos, *order.targetPos[0], rotQuat * vector3df(0, 1, 0), rotQuat * vector3df(1, 0, 0), rotQuat * vector3df(0, 0, -1), getId(), 1, 0));
removeOrder(0);
// guidedMissiles--;
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace game
namespace content {
class Cruiser : public Vessel {
public:
Cruiser(core::GameManager*, Player*,vector3df, int);
Cruiser(Player*,vector3df, int);
void launch(Order);
private:
bool canFire();
+8 -3
View File
@@ -1,5 +1,6 @@
#include "demoJet.h"
#include "inGameAppState.h"
#include "stateManager.h"
#include "util.h"
using namespace game::core;
@@ -7,7 +8,7 @@ using namespace game::util;
namespace game{
namespace content{
DemoJet::DemoJet(GameManager *gM, Player *player,vector3df pos, int id, bool onBoard) :Jet(gM, player,pos, id,onBoard) {}
DemoJet::DemoJet(Player *player,vector3df pos, int id, bool onBoard) : Jet(player,pos, id,onBoard) {}
void DemoJet::attack(Order order){
if(!onBoard){
@@ -27,14 +28,18 @@ namespace game{
void DemoJet::update(){
Jet::update();
if(!onBoard&&!orders.empty()&&orders[0].type==Order::TYPE::ATTACK){
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
ISceneNode *collNode = castRay(smgr,pos,pos+dirVec*length);
if(collNode&&collNode!=node){
InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
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);
blowUp();
}
else if(pos.Y<0)
+1 -1
View File
@@ -9,7 +9,7 @@ namespace game{
namespace content {
class DemoJet : public Jet {
public:
DemoJet(core::GameManager*, Player*,vector3df, int, bool = 1);
DemoJet(Player*,vector3df, int, bool = 1);
void attack(Order);
void update();
private:
+9 -3
View File
@@ -1,4 +1,5 @@
#include "depthCharge.h"
#include "stateManager.h"
#include "inGameAppState.h"
#include "util.h"
@@ -9,8 +10,8 @@ using namespace irr::scene;
namespace game{
namespace content{
DepthCharge::DepthCharge(GameManager *gM, Unit *unit, vector3df pos,vector3df dir, vector3df left, vector3df up, int id,int weaponTypeId,int weaponId) :
Projectile(gM, unit, nullptr, pos, dir, left, up, id,weaponTypeId,weaponId) {
DepthCharge::DepthCharge(Unit *unit, vector3df pos,vector3df dir, vector3df left, vector3df up, int id,int weaponTypeId,int weaponId) :
Projectile(unit, nullptr, pos, dir, left, up, id,weaponTypeId,weaponId) {
speed=0;
initTime=getTime();
}
@@ -23,24 +24,29 @@ namespace game{
checkForCollision();
}
void DepthCharge::checkForCollision() {
InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
ISceneNode *collNode=nullptr;
bool detonated=false;
if(pos.Y<-10)
detonated=true;
if(!detonated)
for(Player *p : inGameState->getPlayers())
for(Unit *u : p->getUnits()){
if(u==unit) continue;
vector3df p0=u->getCorner(0);
vector3df p1=u->getCorner(1);
vector3df p3=u->getCorner(3);
vector3df p4=u->getCorner(4);
if(isWithinCuboid(p0,p1,p3,p4,pos)){
detonated=true;
collNode=u->getNode();
}
}
if(detonated)
explode(collNode);
}
+1 -1
View File
@@ -8,7 +8,7 @@ namespace game{
namespace content{
class DepthCharge : public Projectile {
public:
DepthCharge(core::GameManager*, Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
DepthCharge(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
void update();
private:
s64 initTime;
+4 -3
View File
@@ -5,6 +5,7 @@
#include "defConfigs.h"
#include "depthCharge.h"
#include "inGameAppState.h"
#include "stateManager.h"
#include "projectileData.h"
#include "util.h"
@@ -15,7 +16,7 @@ using namespace game::content::unitData;
namespace game{
namespace content{
Destroyer::Destroyer(GameManager *gM, Player *player,vector3df pos,int id) :Vessel(gM, player,pos, id) {
Destroyer::Destroyer(Player *player,vector3df pos,int id) :Vessel(player,pos, id) {
this->maxDepthCharges=unitData::maxDepthCharges[id];
depthCharges=maxDepthCharges;
this->rateOfDrops=unitData::rateOfDrops[id];
@@ -29,7 +30,7 @@ namespace game{
void Destroyer::attack(Order order){
vector3df t=*order.targetPos[0];
bool sub=false;
InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
for(Player *p : inGameState->getPlayers())
for(Unit *u : p->getUnits())
if(u->getType()==UNIT_TYPE::SUBMARINE&&order.targetPos[0]==u->getPosPtr())
@@ -44,7 +45,7 @@ namespace game{
float angle=rand()%360;
float radius=1;
vector3df offsetVec=vector3df(cos(angle),0,sin(angle))*radius;
addProjectile(new DepthCharge(gameManager,this,pos+projectileData::pos[id][1][1]+offsetVec,dirVec,leftVec,upVec,id,1,0));
addProjectile(new DepthCharge(this,pos+projectileData::pos[id][1][1]+offsetVec,dirVec,leftVec,upVec,id,1,0));
lastDropTime=getTime();
if(depthCharges==maxDepthCharges)
reloadStartTime=getTime();
+1 -1
View File
@@ -12,7 +12,7 @@ namespace game
namespace content {
class Destroyer : public Vessel {
public:
Destroyer(core::GameManager*, Player*,vector3df, int);
Destroyer(Player*,vector3df, int);
void dropDepthCharge();
void attack(Order);
void update();
+22 -12
View File
@@ -1,4 +1,5 @@
#include "eventListener.h"
#include "stateManager.h"
using namespace irr;
@@ -12,25 +13,30 @@ namespace game{
bool EventListener::OnEvent(const SEvent& event) {
int offsetTrigger = -1;
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
if (event.EventType == EET_KEY_INPUT_EVENT) {
for (int i = 0; i < gameManager->getAppStateNumber(); i++) {
for (Key *k : gameManager->getAppState(i)->getKeys()) {
for (int i = 0; i < stateManager->getAppStateNumber(); i++) {
for (Key *k : stateManager->getAppState(i)->getKeys()) {
if (k->key && k->trigger == event.KeyInput.Key) {
if (!k->analog) {
if (!event.KeyInput.PressedDown)
k->beingUsed=false;
if (!k->beingUsed) {
if (event.KeyInput.PressedDown)
k->beingUsed=true;
k->pressed=event.KeyInput.PressedDown;
gameManager->getAppState(i)->onAction(k->bind, k->pressed);
stateManager->getAppState(i)->onAction(k->bind, k->pressed);
}
} else {
k->pressed=event.KeyInput.PressedDown;
gameManager->getAppState(i)->onAnalog(k->bind, 0.);
stateManager->getAppState(i)->onAnalog(k->bind, 0.);
}
}
gameManager->getAppState(i)->onRawKeyPress(event.KeyInput);
stateManager->getAppState(i)->onRawKeyPress(event.KeyInput);
}
}
}
@@ -68,18 +74,20 @@ namespace game{
offsetTrigger = 4;
break;
}
for (int i = 0; i < gameManager->getAppStateNumber(); i++) {
for (Key *k : gameManager->getAppState(i)->getKeys()) {
for (int i = 0; i < stateManager->getAppStateNumber(); i++) {
for (Key *k : stateManager->getAppState(i)->getKeys()) {
if (offsetTrigger == k->trigger) {
if (!k->analog) {
k->pressed=isPressed;
gameManager->getAppState(i)->onAction(k->bind, k->pressed);
stateManager->getAppState(i)->onAction(k->bind, k->pressed);
} else {
k->beingUsed=isPressed;
}
}
if(offsetTrigger<=2)
gameManager->getAppState(i)->onRawMousePress(event.MouseInput);
stateManager->getAppState(i)->onRawMousePress(event.MouseInput);
}
}
}
@@ -87,10 +95,12 @@ namespace game{
}
void EventListener::update() {
for (int i = 0; i < gameManager->getAppStateNumber(); i++) {
for (Key *k : gameManager->getAppState(i)->getKeys()) {
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
for (int i = 0; i < stateManager->getAppStateNumber(); i++) {
for (Key *k : stateManager->getAppState(i)->getKeys()) {
if (k->beingUsed && k->analog) {
gameManager->getAppState(i)->onAnalog(k->bind, 0.);
stateManager->getAppState(i)->onAnalog(k->bind, 0.);
}
}
}
+2 -2
View File
@@ -6,11 +6,11 @@ using namespace game::core;
namespace game
{
namespace gui{
ExitButton::ExitButton(GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
ExitButton::ExitButton(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
}
void ExitButton::onClick() {
gameManager->getDevice()->closeDevice();
GameManager::getSingleton()->getDevice()->closeDevice();
}
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ namespace game
namespace gui {
class ExitButton : public Button {
public:
ExitButton(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ExitButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
};
}
+23 -38
View File
@@ -1,7 +1,9 @@
#include <algorithm>
#include <irrlicht.h>
#include "gameManager.h"
#include "guiAppState.h"
#include "stateManager.h"
#include "eventListener.h"
#include "abstractBitmapText.h"
#include "abstractImage.h"
@@ -12,8 +14,24 @@ using namespace irr;
namespace game{
namespace core{
GameManager::GameManager(IrrlichtDevice *dev) {
device = dev;
GameManager *gameManager = nullptr;
GameManager* GameManager::getSingleton(){
if(!gameManager)
gameManager = new GameManager();
return gameManager;
}
GameManager::GameManager() {
IrrlichtDevice *device = createDevice(video::EDT_OPENGL, irr::core::dimension2d<u32>(800,600), 32, false, true, true, nullptr);
device->setResizable(true);
irr::video::IVideoDriver *driver = device->getVideoDriver();
irr::scene::ISceneManager *smgr = device->getSceneManager();
irr::gui::IGUIEnvironment *guiEnv = device->getGUIEnvironment();
device->setWindowCaption(L"(((A)))");
stateManager = new StateManager();
listener = new EventListener(this);
device->setEventReceiver(listener);
width = device->getVideoDriver()->getScreenSize().Width;
@@ -22,31 +40,6 @@ namespace game{
GameManager::~GameManager() {}
void GameManager::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 GameManager::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 GameManager::detachBitmapText(AbstractBitmapText *bitmapText) {
for (int i = 0; i < bitmapTexts.size(); i++)
if (bitmapText == bitmapTexts[i]) {
@@ -79,21 +72,13 @@ namespace game{
void GameManager::update() {
listener->update();
for (AbstractAppState *a : appStates)
if (a->isAttached() && a)
a->update();
stateManager->update();
for (BitmapText *b : bitmapTexts)
b->update();
for (Image *i : images)
i->update();
}
AbstractAppState* GameManager::getAppState(AppStateTypes t) {
AbstractAppState *state = nullptr;
for (AbstractAppState *a : appStates)
if (a->getType() == t)
state = a;
return state;
}
}
}
+7 -9
View File
@@ -21,14 +21,11 @@ namespace game{
namespace core{
class EventListener;
class StateManager;
class GameManager {
public:
GameManager(irr::IrrlichtDevice*);
~GameManager();
void attachState(AbstractAppState*);
void dettachState(AbstractAppState*);
void dettachState(AppStateTypes);
static GameManager* getSingleton();
inline void attachBitmapText(gui::AbstractBitmapText *a){bitmapTexts.push_back(a);}
void detachBitmapText(gui::AbstractBitmapText*);
void detachAllBitmapTexts();
@@ -39,16 +36,17 @@ namespace game{
inline irr::IrrlichtDevice* getDevice(){return device;}
inline irr::scene::ISceneManager* getSceneManager(){return device->getSceneManager();}
inline void setDevice(irr::IrrlichtDevice *d){this->device=d;}
inline AbstractAppState* getAppState(int id){return appStates[id];}
AbstractAppState* getAppState(AppStateTypes);
inline void setAppState(int i, AbstractAppState *a){appStates[i]=a;}
inline int getAppStateNumber(){return appStates.size();}
inline int getWidth(){return width;}
inline int getHeight(){return height;}
inline EventListener* getListener(){return listener;}
inline bool isServerSide(){return serverSide;}
inline StateManager* getStateManager(){return stateManager;}
private:
GameManager();
~GameManager();
irr::IrrlichtDevice *device = nullptr;
StateManager *stateManager = nullptr;
std::vector<AbstractAppState*> appStates;
int width, height;
std::vector<gui::AbstractBitmapText*> bitmapTexts;
+17 -8
View File
@@ -11,50 +11,59 @@ namespace game{
namespace core{
irr::u16 mousePos[2]{};
GuiAppState::GuiAppState(GameManager* gM) {
gameManager = gM;
GuiAppState::GuiAppState() {
type = AppStateTypes::GUI_STATE;
}
GuiAppState::~GuiAppState() {}
void GuiAppState::update() {
mousePos[0] = gameManager->getDevice()->getCursorControl()->getPosition().X;
mousePos[1] = gameManager->getDevice()->getCursorControl()->getPosition().Y;
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[0] > b->getPos().X && mousePos[0] < b->getPos().X + b->getSize().X;
bool withinY=mousePos[1] > b->getPos().Y && mousePos[1] < 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->getDevice()->getCursorControl()->setVisible(true);
GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(true);
attachKeyboardKeys();
}
void GuiAppState::onDetachment() {
AbstractAppState::onDetachment();
AbstractAppState::detachAllKeys();
gameManager->getDevice()->getCursorControl()->setVisible(false);
GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(false);
}
void GuiAppState::attachKeyboardKeys() {
@@ -258,7 +267,7 @@ namespace game{
for (int i = 0; i < buttons.size(); i++) {
if (b == buttons[i]) {
if (b->isImageButton())
gameManager->detachImage(b->getImage());
GameManager::getSingleton()->detachImage(b->getImage());
delete b;
buttons.erase(buttons.begin() + i);
}
@@ -269,7 +278,7 @@ namespace game{
for (int i = 0; i < buttons.size(); i++) {
if (name == buttons[i]->getName() && buttons[i]->isSeparate()) {
if (buttons[i]->isImageButton())
gameManager->detachImage(buttons[i]->getImage());
GameManager::getSingleton()->detachImage(buttons[i]->getImage());
delete buttons[i];
buttons.erase(buttons.begin() + i);
}
+1 -2
View File
@@ -15,7 +15,7 @@ namespace game{
namespace core{
class GuiAppState : public AbstractAppState {
public:
GuiAppState(GameManager*);
GuiAppState();
~GuiAppState();
void onAttachment();
void onDetachment();
@@ -53,7 +53,6 @@ namespace game{
void checkKeyboard(gui::Textbox*, Bind, bool);
void updateControlsListbox(int);
GameManager *gameManager;
std::vector<gui::Button*> buttons;
std::vector<gui::Listbox*> listboxes;
std::vector<gui::Checkbox*> checkboxes;
+2 -2
View File
@@ -10,8 +10,8 @@ using namespace irr::core;
namespace game{
namespace content{
GuidedMissile::GuidedMissile(GameManager *gM, Unit *unit, vector3df pos, vector3df target, vector3df dirVec, vector3df leftVec, vector3df upVec, int id, int weaponTypeId, int weaponId) :
Projectile(gM, unit, nullptr, pos, dirVec, leftVec, upVec, id, weaponTypeId, weaponId) {
GuidedMissile::GuidedMissile(Unit *unit, vector3df pos, vector3df target, vector3df dirVec, vector3df leftVec, vector3df 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);
+1 -1
View File
@@ -8,7 +8,7 @@ namespace game{
namespace content{
class GuidedMissile : public Projectile {
public:
GuidedMissile(core::GameManager*, Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
GuidedMissile(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
~GuidedMissile(){}
void update();
private:
+75 -46
View File
@@ -1,9 +1,10 @@
#include <algorithm>
#include "stateManager.h"
#include "inGameAppState.h"
#include "consoleCommand.h"
#include "vessel.h"
#include "aircraftCarrier.h"
#include "vessel.h"
using namespace game::gui;
using namespace game::util;
@@ -13,7 +14,7 @@ using namespace std;
namespace game{
namespace core{
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -26,7 +27,7 @@ namespace game{
return guiState;
}
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -36,7 +37,7 @@ namespace game{
class ConsoleCommandEntryButton : public Button {
public:
ConsoleCommandEntryButton(GameManager *gM, InGameAppState *inGameState, Textbox *t, Listbox *l, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->inGameState = inGameState;
textbox = t;
listbox = l;
@@ -66,7 +67,7 @@ namespace game{
}
} else
name = textbox->getEntry();
ConsoleCommand c(gameManager, listbox, inGameState->getPlayerList(), name, args);
ConsoleCommand c(listbox, inGameState->getPlayerList(), name, args);
}
private:
InGameAppState *inGameState;
@@ -78,16 +79,16 @@ namespace game{
for (int i = 0; i < emptyEntries; i++)
list.push_back("");
vector2d<s32> pos(300, 100);
Listbox *consoleListbox = new Listbox(gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(420, 20), list, 20);
Listbox *consoleListbox = new Listbox(vector2d<s32>(pos.X, pos.Y), vector2d<s32>(420, 20), list, 20);
consoleListbox->openUp();
guiState->addListbox(consoleListbox);
Textbox *consoleTextbox = new Textbox(gameManager, vector2d<s32>(pos.X, pos.Y + 20 * (emptyEntries + 1)), vector2d<s32>(300, 20));
Textbox *consoleTextbox = new Textbox(vector2d<s32>(pos.X, pos.Y + 20 * (emptyEntries + 1)), vector2d<s32>(300, 20));
guiState->addTextbox(consoleTextbox);
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(gameManager, inGameState, consoleTextbox, consoleListbox, vector2d<s32>(pos.X + 320, pos.Y + 20 * (emptyEntries + 1)), vector2d<s32>(100, 20), "Enter", true);
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, vector2d<s32>(pos.X + 320, pos.Y + 20 * (emptyEntries + 1)), vector2d<s32>(100, 20), "Enter", true);
guiState->addButton(entryButton);
}
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -103,11 +104,11 @@ namespace game{
guiState->removeButton("Audio");
guiState->removeButton("Multiplayer");
vector2d<s32> pos(100, 100);
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(150, 50), "Resume", true);
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, gameManager, vector2d<s32>(pos.X, pos.Y + 60), vector2d<s32>(150, 50), "Console", true);
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, gameManager, vector2d<s32>(pos.X, pos.Y + 120), vector2d<s32>(150, 50), "Options", true);
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, gameManager, vector2d<s32>(pos.X, pos.Y + 180), vector2d<s32>(150, 50), "Main menu", true);
ExitButton *exitButton = new ExitButton(gameManager, vector2d<s32>(pos.X, pos.Y + 240), vector2d<s32>(150, 50), "Exit", true);
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(150, 50), "Resume", true);
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, vector2d<s32>(pos.X, pos.Y + 60), vector2d<s32>(150, 50), "Console", true);
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, vector2d<s32>(pos.X, pos.Y + 120), vector2d<s32>(150, 50), "Options", true);
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, vector2d<s32>(pos.X, pos.Y + 180), vector2d<s32>(150, 50), "Main menu", true);
ExitButton *exitButton = new ExitButton(vector2d<s32>(pos.X, pos.Y + 240), vector2d<s32>(150, 50), "Exit", true);
inGameState->setResumeButton(resumeButton);
inGameState->setConsoleButton(consoleButton);
inGameState->setOptionsButton(optionsButton);
@@ -121,13 +122,13 @@ namespace game{
guiState->removeButton("Back");
}
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : OptionsButton(gM, pos, size, name, separate) {
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : OptionsButton(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
void InGameAppState::InGameOptionsButton::onClick() {
returnButton = new ReturnButton(guiState, inGameState, gameManager, vector2d<s32>(50, gameManager->getHeight() - 150), vector2d<s32>(150, 50), "Back", true);
returnButton = new ReturnButton(guiState, inGameState, vector2d<s32>(50, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(150, 50), "Back", true);
guiState->addButton(returnButton);
guiState->removeButton("Resume");
guiState->removeButton("Console");
@@ -136,7 +137,7 @@ namespace game{
OptionsButton::onClick();
}
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -145,8 +146,8 @@ namespace game{
}
InGameAppState::UnitCreationButton::UnitCreationButton(GameManager *gM, ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
setImageButton(new Image(gameManager, icon, pos, size));
InGameAppState::UnitCreationButton::UnitCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
setImageButton(new Image(icon, pos, size));
}
void InGameAppState::UnitCreationButton::onClick() {
@@ -156,43 +157,42 @@ namespace game{
Button::update();
}
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(GameManager *gM, ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(gM, icon, pos, size, name, separate) {
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::BattleshipCreationButton::onClick() {
}
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(GameManager *gM, ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(gM, icon, pos, size, name, separate) {
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::DestroyerCreationButton::onClick() {
}
InGameAppState::CruiserCreationButton::CruiserCreationButton(GameManager *gM, ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(gM, icon, pos, size, name, separate) {
InGameAppState::CruiserCreationButton::CruiserCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::CruiserCreationButton::onClick() {
}
InGameAppState::CarrierCreationButton::CarrierCreationButton(GameManager *gM, ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(gM, icon, pos, size, name, separate) {
InGameAppState::CarrierCreationButton::CarrierCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::CarrierCreationButton::onClick() {
}
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(GameManager *gM, ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(gM, icon, pos, size, name, separate) {
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::SubmarineCreationButton::onClick() {
}
InGameAppState::InGameAppState(GameManager *gM, vector<stringw> difficultyLevels, vector<stringw> factions) {
gameManager = gM;
InGameAppState::InGameAppState(vector<stringw> difficultyLevels, vector<stringw> factions) {
type = AppStateTypes::IN_GAME_STATE;
this->playerId = 0;
this->difficultyLevels = difficultyLevels;
@@ -204,8 +204,9 @@ namespace game{
void InGameAppState::onAttachment() {
AbstractAppState::onAttachment();
map = new Map(gameManager);
map = new Map();
map->load();
for (int i = 0; i < factions.size(); i++) {
int faction;
int difficulty;
@@ -219,15 +220,17 @@ namespace game{
else
difficulty = 2;
}
faction = factions[i][0] - 48;
Player *p = new Player(gameManager, difficulty, faction);
Player *p = new Player(difficulty, faction);
players.push_back(p);
p->setId(players.size() - 1);
}
mainPlayer = players[playerId];
guiState = ((GuiAppState*)gameManager->getAppState(AppStateTypes::GUI_STATE));
activeState = new ActiveGameState(gameManager, guiState, map, players, playerId);
gameManager->attachState(activeState);
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() {
@@ -237,28 +240,37 @@ namespace game{
void InGameAppState::update() {
if (map)
map->update();
if (isMainMenuActive) {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
driver->draw2DRectangle(SColor(100, 0, 0, 0), rect<s32>(0, 0, gameManager->getWidth(), gameManager->getHeight()));
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;
@@ -266,8 +278,10 @@ namespace game{
}
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();
}
@@ -276,23 +290,30 @@ namespace game{
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();
}
@@ -301,17 +322,21 @@ namespace game{
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);
}
}
@@ -319,9 +344,11 @@ namespace game{
void InGameAppState::attachGui() {
int idOffset = 0;
if (mainPlayer->getFaction() == 1)
idOffset += 7;
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
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);
@@ -345,16 +372,18 @@ namespace game{
}
void InGameAppState::toggleMainMenu() {
GameManager *gm = GameManager::getSingleton();
if (!isMainMenuActive) {
isMainMenuActive = true;
gameManager->dettachState(activeState);
gm->getStateManager()->dettachState(activeState);
vector2d<s32> pos(100, 100);
//detachGui();
resumeButton = new ResumeButton(guiState, this, gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(150, 50), "Resume", true);
consoleButton = new ConsoleButton(guiState, this, gameManager, vector2d<s32>(pos.X, pos.Y + 60), vector2d<s32>(150, 50), "Console", true);
optionsButton = new InGameOptionsButton(guiState, this, gameManager, vector2d<s32>(pos.X, pos.Y + 120), vector2d<s32>(150, 50), "Options", true);
mainMenuButton = new MainMenuButton(guiState, this, gameManager, vector2d<s32>(pos.X, pos.Y + 180), vector2d<s32>(150, 50), "Main menu", true);
exitButton = new ExitButton(gameManager, vector2d<s32>(pos.X, pos.Y + 240), vector2d<s32>(150, 50), "Exit", true);
resumeButton = new ResumeButton(guiState, this, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(150, 50), "Resume", true);
consoleButton = new ConsoleButton(guiState, this, vector2d<s32>(pos.X, pos.Y + 60), vector2d<s32>(150, 50), "Console", true);
optionsButton = new InGameOptionsButton(guiState, this, vector2d<s32>(pos.X, pos.Y + 120), vector2d<s32>(150, 50), "Options", true);
mainMenuButton = new MainMenuButton(guiState, this, vector2d<s32>(pos.X, pos.Y + 180), vector2d<s32>(150, 50), "Main menu", true);
exitButton = new ExitButton(vector2d<s32>(pos.X, pos.Y + 240), vector2d<s32>(150, 50), "Exit", true);
guiState->addButton(resumeButton);
guiState->addButton(consoleButton);
guiState->addButton(optionsButton);
@@ -364,7 +393,7 @@ namespace game{
}
else {
isMainMenuActive = false;
gameManager->attachState(activeState);
gm->getStateManager()->attachState(activeState);
//attachGui();
guiState->removeAllCheckboxes();
guiState->removeAllListboxes();
+13 -13
View File
@@ -21,7 +21,7 @@ namespace game{
class InGameAppState : public AbstractAppState {
public:
InGameAppState(GameManager*, std::vector<irr::core::stringw>, std::vector<irr::core::stringw>);
InGameAppState(std::vector<irr::core::stringw>, std::vector<irr::core::stringw>);
~InGameAppState();
void onAttachment();
void onDetachment();
@@ -36,7 +36,7 @@ namespace game{
private:
class ResumeButton : public gui::Button {
public:
ResumeButton(GuiAppState*, InGameAppState*, GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ResumeButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
GuiAppState *getGuiState();
private:
@@ -46,7 +46,7 @@ namespace game{
class ConsoleButton : public gui::Button {
public:
ConsoleButton(GuiAppState*, InGameAppState*, GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ConsoleButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
GuiAppState *guiState;
@@ -55,7 +55,7 @@ namespace game{
class MainMenuButton : public gui::Button {
public:
MainMenuButton(GuiAppState*, InGameAppState*, GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
MainMenuButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
GuiAppState *guiState;
@@ -64,12 +64,12 @@ namespace game{
class InGameOptionsButton : public gui::OptionsButton {
public:
InGameOptionsButton(GuiAppState*, InGameAppState*, GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
InGameOptionsButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
class ReturnButton : public gui::Button {
public:
ReturnButton(GuiAppState*, InGameAppState*, GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ReturnButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
GuiAppState *guiState;
@@ -82,7 +82,7 @@ namespace game{
class UnitCreationButton : public gui::Button {
public:
UnitCreationButton(GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
UnitCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
void update();
private:
@@ -91,33 +91,34 @@ namespace game{
class BattleshipCreationButton : public UnitCreationButton {
public:
BattleshipCreationButton(GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
BattleshipCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
};
class DestroyerCreationButton : public UnitCreationButton {
public:
DestroyerCreationButton(GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
DestroyerCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
};
class CruiserCreationButton : public UnitCreationButton {
public:
CruiserCreationButton(GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
CruiserCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
};
class CarrierCreationButton : public UnitCreationButton {
public:
CarrierCreationButton(GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
CarrierCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
};
class SubmarineCreationButton : public UnitCreationButton {
public:
SubmarineCreationButton(GameManager*, irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
SubmarineCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
};
ResumeButton *resumeButton;
ConsoleButton *consoleButton;
InGameOptionsButton *optionsButton;
@@ -138,7 +139,6 @@ namespace game{
std::vector<content::Projectile*> projectiles;
std::vector<Fx> fx;
content::Player *mainPlayer;
GameManager *gameManager;
content::Map *map;
int playerId;
ActiveGameState* activeState;
+1 -1
View File
@@ -8,7 +8,7 @@ using namespace game::content::unitData;
namespace game{
namespace content{
Jet::Jet(GameManager *gM, Player *player, vector3df pos, int unitId, bool onBoard) : Unit(gM, player, pos, unitId) {
Jet::Jet(Player *player, vector3df pos, int unitId, bool onBoard) : Unit(player, pos, unitId) {
offsetPos = pos;
this->onBoard = onBoard;
this->pitchSpeed = unitData::pitchSpeed[id];
+1 -1
View File
@@ -13,7 +13,7 @@ namespace game{
class Jet : public Unit {
public:
Jet(core::GameManager*, Player*,vector3df, int, bool);
Jet(Player*,vector3df, int, bool);
// virtual void attack(Order);
virtual void update();
inline void setJetId(int i){this->jetId=i;}
+20 -16
View File
@@ -10,7 +10,7 @@ using namespace std;
namespace game{
namespace gui{
Listbox::ListboxButton::ListboxButton(GameManager *gM, Listbox *l, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
Listbox::ListboxButton::ListboxButton(Listbox *l, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
listbox = l;
}
@@ -21,58 +21,62 @@ namespace game{
listbox->close();
}
Listbox::ScrollingButton::ScrollingButton(GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
Listbox::ScrollingButton::ScrollingButton(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
}
void Listbox::ScrollingButton::onClick() {
}
Listbox::Listbox(GameManager *gM, vector2d<s32> pos, vector2d<s32> size, vector<stringw> lines, int maxDisplay, bool controlsListbox) {
gameManager = gM;
Listbox::Listbox(vector2d<s32> pos, vector2d<s32> size, vector<stringw> lines, int maxDisplay, bool controlsListbox) {
this->pos = pos;
this->size = size;
this->lines = lines;
this->maxDisplay = maxDisplay;
this->controlsListbox=controlsListbox;
listboxButton = new ListboxButton(gM, this, pos, size, "ListboxButton", false);
scrollingButton = new ScrollingButton(gM, vector2d<s32>(pos.X + size.X - 20, pos.Y + 20), vector2d<s32>(20, 20.0 * (maxDisplay - 2) / (lines.size() - maxDisplay)), "scrollingButton", false);
listboxButton = new ListboxButton(this, pos, size, "ListboxButton", false);
scrollingButton = new ScrollingButton(vector2d<s32>(pos.X + size.X - 20, pos.Y + 20), vector2d<s32>(20, 20.0 * (maxDisplay - 2) / (lines.size() - maxDisplay)), "scrollingButton", false);
}
Listbox::~Listbox() {}
void Listbox::update() {
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
GameManager *gm = GameManager::getSingleton();
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp");
if (open) {
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(*listboxButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y * maxDisplay), nullptr);
int mousePosX = gameManager->getDevice()->getCursorControl()->getPosition().X, mousePosY = gameManager->getDevice()->getCursorControl()->getPosition().Y;
gm->getDevice()->getVideoDriver()->draw2DRectangle(*listboxButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y * maxDisplay), nullptr);
int mousePosX = gm->getDevice()->getCursorControl()->getPosition().X, mousePosY = gm->getDevice()->getCursorControl()->getPosition().Y;
for (int i = 0; i < maxDisplay; i++) {
if (mousePosY > pos.Y + size.Y * i && mousePosY < pos.Y + size.Y * (i + 1)){
selectedOption=scrollOffset+i;
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y + size.Y * i, pos.X + size.X - 20, pos.Y + size.Y * (i + 1)), nullptr);
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y + size.Y * i, pos.X + size.X - 20, pos.Y + size.Y * (i + 1)), nullptr);
}
else if (mousePosY < pos.Y){
selectedOption=scrollOffset;
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y, pos.X + size.X - 20, pos.Y + size.Y), nullptr);
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y, pos.X + size.X - 20, pos.Y + size.Y), nullptr);
}
else if (mousePosY > pos.Y + size.Y * maxDisplay){
selectedOption=scrollOffset+maxDisplay-1;
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y + size.Y * (maxDisplay - 1), pos.X + size.X - 20, pos.Y + size.Y * (maxDisplay + 0)), nullptr);
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 125, 0), rect<s32>(pos.X, pos.Y + size.Y * (maxDisplay - 1), pos.X + size.X - 20, pos.Y + size.Y * (maxDisplay + 0)), nullptr);
}
}
for (int i = 0; i < maxDisplay; i++) {
for (int i = 0; i < maxDisplay; i++)
font->draw(lines[i + scrollOffset], rect<s32>(pos.X, pos.Y + size.Y*i, pos.X + size.X, pos.Y + size.Y * (i + 1)), SColor(255, 255, 255, 255));
}
if (scrollOffset > 0) {
vector2d<s32> scrollingButtonPos = scrollingButton->getPos();
scrollingButtonPos.Y = pos.Y + 20 + scrollingButton->getSize().Y * (scrollOffset - 1);
scrollingButton->setPos(scrollingButtonPos);
}
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 150, 150, 150), rect<s32>(
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 150, 150, 150), rect<s32>(
scrollingButton->getPos().X, scrollingButton->getPos().Y, scrollingButton->getPos().X + scrollingButton->getSize().X,
scrollingButton->getPos().Y + scrollingButton->getSize().Y));
} else {
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(*listboxButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
gm->getDevice()->getVideoDriver()->draw2DRectangle(*listboxButton->getColor(), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
font->draw(lines[selectedOption], rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), SColor(255, 255, 255, 255));
}
}
+3 -4
View File
@@ -8,7 +8,7 @@ namespace game{
namespace gui {
class Listbox {
public:
Listbox(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, std::vector<irr::core::stringw>, int,bool=false);
Listbox(irr::core::vector2d<s32>, irr::core::vector2d<s32>, std::vector<irr::core::stringw>, int,bool=false);
~Listbox();
void update();
void openUp();
@@ -24,14 +24,14 @@ namespace game{
private:
class ListboxButton : public Button {
public:
ListboxButton(core::GameManager*, Listbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ListboxButton(Listbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
Listbox *listbox = nullptr;
};
class ScrollingButton : public Button {
public:
ScrollingButton(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ScrollingButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
};
@@ -41,7 +41,6 @@ namespace game{
irr::core::vector2d<s32> pos, size;
ListboxButton *listboxButton = nullptr;
Button *scrollingButton = nullptr;
core::GameManager *gameManager;
public:
inline ListboxButton* getListboxButton(){return listboxButton;}
inline bool isControlsListbox(){return controlsListbox;}
+11 -15
View File
@@ -1,7 +1,7 @@
#include <irrlicht.h>
#include "util.h"
#include "gameManager.h"
#include "stateManager.h"
#include "guiAppState.h"
using namespace irr;
@@ -13,25 +13,21 @@ using namespace game::util;
using namespace irr::video;
int main() {
IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(800,600), 32, false, true, true, nullptr);
device->setResizable(true);
IVideoDriver *driver = device->getVideoDriver();
ISceneManager *smgr = device->getSceneManager();
IGUIEnvironment *guiEnv = device->getGUIEnvironment();
device->setWindowCaption(L"(((A)))");
GameManager *gameManager = new GameManager(device);
GuiAppState *state = new GuiAppState(gameManager);
gameManager->attachState(state);
makeTitlescreenButtons(gameManager, state);
//smgr->getMesh(PATH+"Models/Battel");
GameManager *gameManager = GameManager::getSingleton();
GuiAppState *state = new GuiAppState();
gameManager->getStateManager()->attachState(state);
makeTitlescreenButtons(state);
IrrlichtDevice *device = gameManager->getDevice();
IVideoDriver *driver = device->getVideoDriver();
while (device->run()) {
driver->beginScene(true, true, 0);
smgr->drawAll();
guiEnv->drawAll();
device->getSceneManager()->drawAll();
device->getGUIEnvironment()->drawAll();
gameManager->update();
driver->endScene();
}
device->drop();
delete gameManager;
return 0;
}
+6 -4
View File
@@ -1,6 +1,8 @@
#include "map.h"
#include "gameManager.h"
#include "defConfigs.h"
using namespace irr;
using namespace irr::core;
using namespace irr::video;
using namespace irr::scene;
@@ -9,8 +11,7 @@ using namespace game::core;
namespace game{
namespace content{
Map::Map(GameManager *gM) {
gameManager = gM;
Map::Map() {
size = vector2d<s32>(50, 50);
}
@@ -21,9 +22,10 @@ namespace game{
}
void Map::load() {
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
smgr->setAmbientLight(SColor(255, 100, 100, 100));
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
// sunLight=smgr->addLightSceneNode(0,vector3df(0,20,0),SColor(255,255,255,255));
// sunLight->setLightType(E_LIGHT_TYPE::ELT_COUNT);
ISceneNode *skybox = smgr->addSkyBoxSceneNode(driver->getTexture(PATH + "Textures/up.jpg")
+3 -5
View File
@@ -3,21 +3,19 @@
#define MAP_H
#include <irrlicht.h>
#include "gameManager.h"
namespace game{
namespace content{
class Map {
public:
Map(core::GameManager*);
Map();
~Map();
void update();
void load();
void unload();
inline irr::core::vector2d<s32> getSize(){return size;}
inline irr::core::vector2d<irr::s32> getSize(){return size;}
private:
core::GameManager *gameManager;
irr::core::vector2d<s32> size;
irr::core::vector2d<irr::s32> size;
irr::scene::ILightSceneNode *sunLight;
irr::scene::IAnimatedMesh *waterMesh;
irr::scene::ISceneNode *waterNode;
+4 -2
View File
@@ -7,8 +7,8 @@ using namespace irr::scene;
namespace game{
namespace content{
Missile::Missile(GameManager *gM, Unit *unit, ISceneNode *node, vector3df *target,vector3df pos,vector3df dir, vector3df left, vector3df up,int id,int weaponTypeId,int weaponId) :
Projectile(gM, unit, node, pos, dir, left, up,id,weaponTypeId,weaponId) {
Missile::Missile(Unit *unit, ISceneNode *node, vector3df *target,vector3df pos,vector3df dir, vector3df left, vector3df 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();
@@ -20,10 +20,12 @@ namespace game{
node->setPosition(pos);
float angle=getAngleBetween(dirVec,*target-pos);
vector3df axis=dirVec.crossProduct(*target-pos).normalize();
if(rotationSpeed/180*PI<angle){
quaternion rotQuat=quaternion().fromAngleAxis(rotationSpeed/180*PI,axis);
orientProjectile(rotQuat*dirVec);
}
if(!exploded&&getTime()-initTime>selfDistructTime)
Projectile::explode(nullptr);
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace game{
class Missile : public Projectile {
public:
Missile(core::GameManager*, Unit*, irr::scene::ISceneNode*, irr::core::vector3df*,irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Missile(Unit*, irr::scene::ISceneNode*, irr::core::vector3df*,irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
~Missile(){}
void update();
private:
+11 -6
View File
@@ -1,6 +1,7 @@
#include "missileJet.h"
#include "projectileData.h"
#include "inGameAppState.h"
#include "stateManager.h"
using namespace game::core;
using namespace game::util;
@@ -8,7 +9,7 @@ using namespace irr::scene;
namespace game{
namespace content{
MissileJet::MissileJet(GameManager *gM, Player *player, vector3df pos, int id, bool onBoard) : Jet(gM, player, pos, id, onBoard) {}
MissileJet::MissileJet(Player *player, vector3df pos, int id, bool onBoard) : Jet(player, pos, id, onBoard) {}
void MissileJet::attack(Order order) {
if(!onBoard&&canFire()&&missilesInstalled){
@@ -16,7 +17,7 @@ namespace game{
float distance=pos.getDistanceFrom(target);
if(distance <= range){
vector3df *targetPtr=nullptr;
InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
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;
@@ -39,9 +40,9 @@ namespace game{
}
void MissileJet::fireMissile(vector3df *t) {
ISceneManager *smgr=gameManager->getDevice()->getSceneManager();
ISceneManager *smgr=GameManager::getSingleton()->getDevice()->getSceneManager();
vector3df p = pos + projectileData::pos[id][0][missiles - 1].X * leftVec + projectileData::pos[id][0][missiles - 1].Y * upVec - projectileData::pos[id][0][missiles - 1].Z*dirVec;
addProjectile(new Missile(gameManager, this, missileNodes[missiles-1], t, p, dirVec, leftVec, upVec, id, 0, 0));
addProjectile(new Missile(this, missileNodes[missiles-1], t, p, dirVec, leftVec, upVec, id, 0, 0));
missileNodes[missiles-1]->setParent(smgr->getRootSceneNode());
missileNodes[missiles-1]=nullptr;
missiles--;
@@ -51,14 +52,18 @@ namespace game{
void MissileJet::installMissiles(bool aam){
if(!missilesInstalled){
missiles=2;
ISceneManager *smgr=gameManager->getDevice()->getSceneManager();
IVideoDriver *driver=gameManager->getDevice()->getVideoDriver();
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]);
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]);
+1 -1
View File
@@ -10,7 +10,7 @@ namespace game{
namespace content {
class MissileJet : public Jet {
public:
MissileJet(core::GameManager*, Player*,vector3df, int, bool = 1);
MissileJet(Player*,vector3df, int, bool = 1);
void installMissiles(bool);
private:
void attack(Order);
+80 -58
View File
@@ -1,4 +1,5 @@
#include "optionsButton.h"
#include "stateManager.h"
#include "util.h"
using namespace game::core;
@@ -10,56 +11,64 @@ using namespace irr::gui;
namespace game{
namespace gui{
OptionsButton::OkButton::OkButton(GameManager *gm) :Button(gm, vector2d<s32>(50, gm->getHeight() - 150), vector2d<s32>(140, 50), "Ok", true) {
this->state = ((GuiAppState*)gm->getAppState(AppStateTypes::GUI_STATE));
OptionsButton::OkButton::OkButton() :Button(vector2d<s32>(50, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(140, 50), "Ok", true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::OkButton::onClick() {
}
OptionsButton::DefaultsButton::DefaultsButton(GameManager *gm) :Button(gm, vector2d<s32>(200, gm->getHeight() - 150), vector2d<s32>(140, 50), "Restore defaults", true) {
this->state = ((GuiAppState*)gm->getAppState(AppStateTypes::GUI_STATE));
OptionsButton::DefaultsButton::DefaultsButton() :Button(vector2d<s32>(200, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(140, 50), "Restore defaults", true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::DefaultsButton::onClick() {
}
OptionsButton::BackButton::BackButton(GameManager *gm) :Button(gm, vector2d<s32>(350, gm->getHeight() - 150), vector2d<s32>(140, 50), "Back", true) {
this->state = ((GuiAppState*)gm->getAppState(AppStateTypes::GUI_STATE));
OptionsButton::BackButton::BackButton() :Button(vector2d<s32>(350, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(140, 50), "Back", true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::BackButton::onClick() {
gameManager->detachAllBitmapTexts();
gameManager->detachAllImages();
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(gameManager, vector2d<s32>(), vector2d<s32>(), "Options", true);
OptionsButton *optionsButton = new OptionsButton(vector2d<s32>(), vector2d<s32>(), "Options", true);
optionsButton->onClick();
state->removeButton("Back");
}
OptionsButton::TabButton::TabButton(GameManager *gm, vector2d<s32> pos, vector2d<s32> size, stringw name) :Button(gm, pos, size, name, true) {
this->state = ((GuiAppState*)gm->getAppState(AppStateTypes::GUI_STATE));
OptionsButton::TabButton::TabButton(vector2d<s32> pos, vector2d<s32> size, stringw 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(gameManager);
DefaultsButton *defaultsButton = new DefaultsButton(gameManager);
BackButton *returnButton = new BackButton(gameManager);
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(GameManager *gm) :TabButton(gm, vector2d<s32>(gm->getWidth() / 4, gm->getHeight() / 10), vector2d<s32>(100, 50), "Controls") {}
OptionsButton::ControlsTab::ControlsTab() : TabButton(
vector2d<s32>(GameManager::getSingleton()->getWidth() / 4,
GameManager::getSingleton()->getHeight() / 10),
vector2d<s32>(100, 50),
"Controls"
) {}
void OptionsButton::ControlsTab::onClick() {
TabButton::onClick();
std::vector<stringw> lines=readFile(std::string((PATH+path("../options.cfg")).c_str()));
Listbox *listbox = new Listbox(gameManager, vector2d<s32>(gameManager->getWidth() / 4, gameManager->getHeight() / 10), vector2d<s32>(360, 20), lines, lines.size()<5?lines.size():5,true);
GameManager *gm = GameManager::getSingleton();
Listbox *listbox = new Listbox(vector2d<s32>(gm->getWidth() / 4, gm->getHeight() / 10), vector2d<s32>(360, 20), lines, lines.size()<5?lines.size():5,true);
listbox->openUp();
state->addListbox(listbox);
state->removeButton("Mouse");
@@ -69,16 +78,22 @@ namespace game{
state->removeButton("Controls");
}
OptionsButton::MouseTab::MouseTab(GameManager *gm) :TabButton(gm, vector2d<s32>(gm->getWidth() / 4, gm->getHeight() / 10 + 60), vector2d<s32>(100, 50), "Mouse") {}
OptionsButton::MouseTab::MouseTab() : TabButton(
vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 60),
vector2d<s32>(100, 50),
"Mouse"
) {}
void OptionsButton::MouseTab::onClick() {
TabButton::onClick();
vector2d<s32> pos(gameManager->getWidth() / 3, gameManager->getHeight() / 4);
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
Slider *mouseSensitivitySlider = new Slider(gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(300, 10), .1, 3.);
Textbox *mouseSensitivityTextbox = new Textbox(gameManager, vector2d<s32>(pos.X + 320, pos.Y - 10), vector2d<s32>(100, 20));
Checkbox *reverseMouseCheckbox = new Checkbox(gameManager, vector2d<s32>(pos.X, pos.Y + 50));
gameManager->attachBitmapText(new BitmapText(gameManager, "MouseSensitivity", vector2d<s32>(gameManager->getWidth() / 3 - 90, gameManager->getHeight() / 4 - 5), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "ReverseMouse", vector2d<s32>(gameManager->getWidth() / 3 + 20, gameManager->getHeight() / 4 + 50), font));
GameManager *gm = GameManager::getSingleton();
vector2d<s32> pos(gm->getWidth() / 3, gm->getHeight() / 4);
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
Slider *mouseSensitivitySlider = new Slider(vector2d<s32>(pos.X, pos.Y), vector2d<s32>(300, 10), .1, 3.);
Textbox *mouseSensitivityTextbox = new Textbox(vector2d<s32>(pos.X + 320, pos.Y - 10), vector2d<s32>(100, 20));
Checkbox *reverseMouseCheckbox = new Checkbox(vector2d<s32>(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);
@@ -89,7 +104,7 @@ namespace game{
state->removeButton("Mouse");
}
OptionsButton::VideoTab::VideoTab(GameManager *gm) :TabButton(gm, vector2d<s32>(gm->getWidth() / 4, gm->getHeight() / 10 + 120), vector2d<s32>(100, 50), "Video") {}
OptionsButton::VideoTab::VideoTab() :TabButton(vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 120), vector2d<s32>(100, 50), "Video") {}
void OptionsButton::VideoTab::onClick() {
TabButton::onClick();
std::vector<stringw> lines;
@@ -98,25 +113,30 @@ namespace game{
s += i;
lines.push_back(s);
}
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> pos(gameManager->getWidth() / 3, gameManager->getHeight() / 8);
Listbox *resolutionsListbox = new Listbox(gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(100, 20), lines, 5);
Checkbox *fullscreenCheckbox = new Checkbox(gameManager, vector2d<s32>(pos.X, pos.Y + 30));
Checkbox *vsyncCheckbox = new Checkbox(gameManager, vector2d<s32>(pos.X, pos.Y + 50));
Checkbox *normalMapCheckbox = new Checkbox(gameManager, vector2d<s32>(pos.X, pos.Y + 70));
Checkbox *parallaxMapCheckbox = new Checkbox(gameManager, vector2d<s32>(pos.X, pos.Y + 90));
Checkbox *specularMapCheckbox = new Checkbox(gameManager, vector2d<s32>(pos.X, pos.Y + 110));
gameManager->attachBitmapText(new BitmapText(gameManager, "Fullscreen", vector2d<s32>(pos.X + 20, pos.Y + 30), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "VSync", vector2d<s32>(pos.X + 20, pos.Y + 50), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "Normal map", vector2d<s32>(pos.X + 20, pos.Y + 70), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "Parallax map", vector2d<s32>(pos.X + 20, pos.Y + 90), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "Specular map", vector2d<s32>(pos.X + 20, pos.Y + 110), font));
GameManager *gm = GameManager::getSingleton();
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> pos(gm->getWidth() / 3, gm->getHeight() / 8);
Listbox *resolutionsListbox = new Listbox(vector2d<s32>(pos.X, pos.Y), vector2d<s32>(100, 20), lines, 5);
Checkbox *fullscreenCheckbox = new Checkbox(vector2d<s32>(pos.X, pos.Y + 30));
Checkbox *vsyncCheckbox = new Checkbox(vector2d<s32>(pos.X, pos.Y + 50));
Checkbox *normalMapCheckbox = new Checkbox(vector2d<s32>(pos.X, pos.Y + 70));
Checkbox *parallaxMapCheckbox = new Checkbox(vector2d<s32>(pos.X, pos.Y + 90));
Checkbox *specularMapCheckbox = new Checkbox(vector2d<s32>(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");
@@ -124,12 +144,13 @@ namespace game{
state->removeButton("Video");
}
OptionsButton::AudioTab::AudioTab(GameManager *gm) :TabButton(gm, vector2d<s32>(gm->getWidth() / 4, gm->getHeight() / 10 + 180), vector2d<s32>(100, 50), "Audio") {}
OptionsButton::AudioTab::AudioTab() :TabButton(vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 180), vector2d<s32>(100, 50), "Audio") {}
void OptionsButton::AudioTab::onClick() {
TabButton::onClick();
vector2d<s32> pos(gameManager->getWidth() / 3, gameManager->getHeight() / 8);
Slider *volumeSlider = new Slider(gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(300, 10), 0., 2.);
Textbox *volumeTextbox = new Textbox(gameManager, vector2d<s32>(pos.X + 320, pos.Y), vector2d<s32>(100, 20));
GameManager *gm = GameManager::getSingleton();
vector2d<s32> pos(gm->getWidth() / 3, gm->getHeight() / 8);
Slider *volumeSlider = new Slider(vector2d<s32>(pos.X, pos.Y), vector2d<s32>(300, 10), 0., 2.);
Textbox *volumeTextbox = new Textbox(vector2d<s32>(pos.X + 320, pos.Y), vector2d<s32>(100, 20));
state->addTextbox(volumeTextbox);
state->addSlider(volumeSlider);
state->removeButton("Controls");
@@ -139,17 +160,18 @@ namespace game{
state->removeButton("Audio");
}
OptionsButton::MultiplayerTab::MultiplayerTab(GameManager *gm) :TabButton(gm, vector2d<s32>(gm->getWidth() / 4, gm->getHeight() / 10 + 240), vector2d<s32>(100, 50), "Multiplayer") {}
OptionsButton::MultiplayerTab::MultiplayerTab() : TabButton(vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 240), vector2d<s32>(100, 50), "Multiplayer") {}
void OptionsButton::MultiplayerTab::onClick() {
TabButton::onClick();
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> pos(gameManager->getWidth() / 3, gameManager->getHeight() / 6);
Textbox *tcpTextbox = new Textbox(gameManager, vector2d<s32>(pos.X, pos.Y), vector2d<s32>(100, 20));
Textbox *udpTextbox = new Textbox(gameManager, vector2d<s32>(pos.X, pos.Y + 30), vector2d<s32>(100, 20));
Textbox *playerNameTextbox = new Textbox(gameManager, vector2d<s32>(pos.X, pos.Y + 60), vector2d<s32>(100, 20));
gameManager->attachBitmapText(new BitmapText(gameManager, "TCP port", vector2d<s32>(pos.X - 50, pos.Y), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "UDP port", vector2d<s32>(pos.X - 50, pos.Y + 30), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "Player name", vector2d<s32>(pos.X - 65, pos.Y + 60), font));
GameManager *gm = GameManager::getSingleton();
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> pos(gm->getWidth() / 3, gm->getHeight() / 6);
Textbox *tcpTextbox = new Textbox(vector2d<s32>(pos.X, pos.Y), vector2d<s32>(100, 20));
Textbox *udpTextbox = new Textbox(vector2d<s32>(pos.X, pos.Y + 30), vector2d<s32>(100, 20));
Textbox *playerNameTextbox = new Textbox(vector2d<s32>(pos.X, pos.Y + 60), vector2d<s32>(100, 20));
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);
@@ -160,15 +182,15 @@ namespace game{
state->removeButton("Multiplayer");
}
OptionsButton::OptionsButton(GameManager *gm, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) :Button(gm, pos, size, name, separate) {
this->state = ((GuiAppState*)gm->getAppState(AppStateTypes::GUI_STATE));
OptionsButton::OptionsButton(vector2d<s32> pos, vector2d<s32> size, stringw 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(this->gameManager);
MouseTab *mouseTab = new MouseTab(this->gameManager);
VideoTab *videoTab = new VideoTab(this->gameManager);
AudioTab *audioTab = new AudioTab(this->gameManager);
MultiplayerTab *mupltiplayerTab = new MultiplayerTab(this->gameManager);
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);
+10 -10
View File
@@ -10,59 +10,59 @@ namespace game{
namespace gui {
class OptionsButton : public Button {
public:
OptionsButton(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
OptionsButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
class OkButton : public Button {
public:
OkButton(core::GameManager*);
OkButton();
void onClick();
private:
core::GuiAppState *state;
};
class DefaultsButton : public Button {
public:
DefaultsButton(core::GameManager*);
DefaultsButton();
void onClick();
private:
core::GuiAppState *state;
};
class BackButton : public Button {
public:
BackButton(core::GameManager*);
BackButton();
void onClick();
private:
core::GuiAppState *state;
};
class TabButton : public Button {
public:
TabButton(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw);
TabButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw);
void onClick();
protected:
core::GuiAppState *state;
};
class ControlsTab : public TabButton {
public:
ControlsTab(core::GameManager*);
ControlsTab();
void onClick();
};
class MouseTab : public TabButton {
public:
MouseTab(core::GameManager*);
MouseTab();
void onClick();
private:
};
class VideoTab : public TabButton {
public:
VideoTab(core::GameManager*);
VideoTab();
void onClick();
};
class AudioTab : public TabButton {
public:
AudioTab(core::GameManager*);
AudioTab();
void onClick();
};
class MultiplayerTab : public TabButton {
public:
MultiplayerTab(core::GameManager*);
MultiplayerTab();
void onClick();
};
virtual void onClick();
+1 -2
View File
@@ -4,8 +4,7 @@ using namespace game::core;
namespace game{
namespace content{
Player::Player(GameManager *gM, int difficulty, int faction,vector3df spawnPoint) {
gameManager = gM;
Player::Player(int difficulty, int faction,vector3df spawnPoint) {
this->difficulty = difficulty;
this->faction = faction;
this->spawnPoint=spawnPoint;
+2 -2
View File
@@ -4,6 +4,7 @@
#include <irrlicht.h>
#include <vector>
#include "gameManager.h"
#include "unit.h"
@@ -11,7 +12,7 @@ namespace game{
namespace content{
class Player {
public:
Player(core::GameManager*, int, int,irr::core::vector3df=irr::core::vector3df(0,0,0));
Player(int, int,irr::core::vector3df=irr::core::vector3df(0,0,0));
~Player();
void update();
bool isThisPlayersUnit(Unit*);
@@ -28,7 +29,6 @@ namespace game{
int credits, faction, difficulty,side,id;
std::vector<Unit*> units;
irr::core::vector3df spawnPoint;
core::GameManager *gameManager;
};
}
}
+15 -9
View File
@@ -1,6 +1,7 @@
#include <algorithm>
#include "projectile.h"
#include "stateManager.h"
#include "projectileData.h"
#include "inGameAppState.h"
#include "unit.h"
@@ -17,8 +18,7 @@ using namespace sf;
namespace game{
namespace content{
Projectile::Projectile(GameManager *gM, Unit *unit, ISceneNode *node, vector3df pos, vector3df dir, vector3df left, vector3df up, int id, int weaponTypeId, int weaponId) {
gameManager = gM;
Projectile::Projectile(Unit *unit, ISceneNode *node, vector3df pos, vector3df dir, vector3df left, vector3df up, int id, int weaponTypeId, int weaponId) {
this->unit=unit;
this->id=id;
this->weaponTypeId=weaponTypeId;
@@ -26,9 +26,12 @@ namespace game{
leftVec = left;
upVec = up;
this->rayLength=projectileData::length[id][weaponTypeId][weaponId];
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
this->node=node;
if(!node){
mesh = smgr->getMesh(projectileData::meshPath[id][weaponTypeId]);
this->node = smgr->addAnimatedMeshSceneNode(mesh);
@@ -60,31 +63,34 @@ namespace game{
}
Projectile::~Projectile(){
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
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->getSceneManager(),pos,pos+dirVec*rayLength);
ISceneNode *collNode = castRay(GameManager::getSingleton()->getSceneManager(),pos,pos+dirVec*rayLength);
if (pos.Y<-7 || (collNode&&collNode!=unit->getNode()))
explode(collNode);
}
void Projectile::explode(ISceneNode *collNode) {
exploded = true;
vector<Player*> players = ((InGameAppState*) gameManager->getAppState(AppStateTypes::IN_GAME_STATE))->getPlayers();
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);
}
InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
InGameAppState *inGameState=((InGameAppState*)stateManager->getAppState(AppStateTypes::IN_GAME_STATE));
if(id==8)
detonateTorpedo(inGameState,pos);
else if(weaponTypeId==1&&(id==2||id==3))
@@ -94,7 +100,7 @@ namespace game{
}
void Projectile::debug(){
IVideoDriver *driver=gameManager->getDevice()->getVideoDriver();
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));
+1 -2
View File
@@ -14,7 +14,7 @@ namespace game{
class Projectile {
public:
Projectile(core::GameManager*, Unit*, irr::scene::ISceneNode*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Projectile(Unit*, irr::scene::ISceneNode*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
virtual ~Projectile();
virtual void update();
virtual void debug();
@@ -24,7 +24,6 @@ namespace game{
protected:
virtual void checkForCollision();
void explode(irr::scene::ISceneNode*);
core::GameManager *gameManager;
irr::scene::IAnimatedMesh *mesh;
irr::scene::ISceneNode *node=nullptr;
bool exploded = false;
+1 -1
View File
@@ -10,7 +10,7 @@ using namespace irr::core;
namespace game{
namespace content{
Shell::Shell(GameManager *gM, Unit *unit, vector3df pos, vector3df dir, vector3df left, vector3df up, int id, int weaponTypeId, int weaponId) : Projectile(gM, unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
Shell::Shell(Unit *unit, vector3df pos, vector3df dir, vector3df left, vector3df 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(vector3df(1, 1, 1) * projectileData::scale[id][weaponTypeId][weaponId]);
initTime = getTime();
+1 -1
View File
@@ -9,7 +9,7 @@ namespace game{
namespace content {
class Shell : public Projectile {
public:
Shell(core::GameManager*, Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Shell(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
~Shell(){}
virtual void update();
protected:
+11 -9
View File
@@ -11,7 +11,7 @@ using namespace game::core;
namespace game{
namespace gui{
Slider::MovableSliderButton::MovableSliderButton(GameManager *gM, Slider *slider, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
Slider::MovableSliderButton::MovableSliderButton(Slider *slider, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->slider = slider;
}
@@ -20,7 +20,9 @@ namespace game{
}
void Slider::MovableSliderButton::update() {
int posX = gameManager->getDevice()->getCursorControl()->getPosition().X, posY = gameManager->getDevice()->getCursorControl()->getPosition().Y;
GameManager *gm = GameManager::getSingleton();
int posX = gm->getDevice()->getCursorControl()->getPosition().X, posY = gm->getDevice()->getCursorControl()->getPosition().Y;
if (clicked && posY > slider->getPos().Y && posY < slider->getPos().Y + slider->getSize().Y) {
if (posX < slider->getPos().X)
posX = slider->getPos().X;
@@ -30,23 +32,22 @@ namespace game{
}
}
Slider::StaticSliderButton::StaticSliderButton(GameManager *gM, Slider *slider, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
Slider::StaticSliderButton::StaticSliderButton(Slider *slider, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->slider = slider;
}
void Slider::StaticSliderButton::onClick() {
s16 buttonClickPoint = -slider->getPos().X + gameManager->getDevice()->getCursorControl()->getPosition().X;
s16 buttonClickPoint = -slider->getPos().X + GameManager::getSingleton()->getDevice()->getCursorControl()->getPosition().X;
slider->setValue(((double) buttonClickPoint / slider->getSize().X) * slider->getMaxValue());
}
Slider::Slider(GameManager *gM, vector2d<s32> pos, vector2d<s32> size, double minValue, double maxValue) {
gameManager = gM;
Slider::Slider(vector2d<s32> pos, vector2d<s32> size, double minValue, double maxValue) {
this->pos = pos;
this->size = size;
this->minValue = minValue;
this->maxValue = maxValue;
staticSliderButton = new StaticSliderButton(gM, this, pos, size, "StaticSliderButton", false);
movableSliderButton = new MovableSliderButton(gM, this, vector2d<s32>(pos.X + staticSliderButton->getSize().X / 1, pos.Y - 15), vector2d<s32>(10, 40), "MovableSliderButton", false);
staticSliderButton = new StaticSliderButton(this, pos, size, "StaticSliderButton", false);
movableSliderButton = new MovableSliderButton(this, vector2d<s32>(pos.X + staticSliderButton->getSize().X / 1, pos.Y - 15), vector2d<s32>(10, 40), "MovableSliderButton", false);
value = (maxValue - minValue) / 2;
}
@@ -54,7 +55,8 @@ namespace game{
}
void Slider::update() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
if (value < minValue)
value = minValue;
else if (value > maxValue)
+3 -4
View File
@@ -11,7 +11,7 @@ namespace game{
namespace gui{
class Slider {
public:
Slider(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, double, double);
Slider(irr::core::vector2d<s32>, irr::core::vector2d<s32>, double, double);
~Slider();
void update();
inline void addTextbox(Textbox *t){this->textbox=t;}
@@ -27,7 +27,7 @@ namespace game{
private:
class MovableSliderButton : public Button {
public:
MovableSliderButton(core::GameManager*, Slider*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
MovableSliderButton(Slider*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
void update();
private:
@@ -36,7 +36,7 @@ namespace game{
};
class StaticSliderButton : public Button {
public:
StaticSliderButton(core::GameManager*, Slider*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
StaticSliderButton(Slider*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
Slider *slider;
@@ -44,7 +44,6 @@ namespace game{
MovableSliderButton *movableSliderButton = nullptr;
StaticSliderButton *staticSliderButton = nullptr;
double minValue, value, maxValue, increment = .1;
core::GameManager *gameManager = nullptr;
irr::core::vector2d<s32> pos, size;
Textbox *textbox = nullptr;
public:
+45
View File
@@ -0,0 +1,45 @@
#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);
}
}
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();
}
AbstractAppState* StateManager::getAppState(AppStateTypes t) {
AbstractAppState *state = nullptr;
for (AbstractAppState *a : appStates)
if (a->getType() == t)
state = a;
return state;
}
}
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef STATE_MANAGER_H
#define STATE_MANAGER_H
#include <vector>
#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();}
private:
std::vector<AbstractAppState*> appStates;
};
}
}
#endif
+2 -2
View File
@@ -10,7 +10,7 @@ using namespace game::util;
namespace game{
namespace content{
Submarine::Submarine(GameManager *gM, Player *player,vector3df pos, int id) : Unit(gM, player,pos, id) {}
Submarine::Submarine(Player *player,vector3df pos, int id) : Unit(player,pos, id) {}
void Submarine::attack(Order order) {
float angle=getAngleBetween(dirVec,*(order.targetPos[0])-pos);
@@ -18,7 +18,7 @@ namespace game{
Unit::move(order, range);
if (canFire()) {
vector3df p = pos + projectileData::pos[id][0][0].X * leftVec + projectileData::pos[id][0][0].Y * upVec - projectileData::pos[id][0][0].Z*dirVec;
addProjectile(new Torpedo(gameManager, this, p, dirVec, leftVec, upVec, getId(), 0, 0));
addProjectile(new Torpedo(this, p, dirVec, leftVec, upVec, getId(), 0, 0));
lastShotTime=getTime();
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ namespace game{
namespace content{
class Submarine : public Unit {
public:
Submarine(core::GameManager*, Player*, irr::core::vector3df, int);
Submarine(Player*, irr::core::vector3df, int);
inline bool isSubmerged() {return submerged;}
void emerge();
void submerge();
+8 -7
View File
@@ -9,7 +9,7 @@ using namespace irr::video;
namespace game{
namespace gui{
Textbox::TextboxButton::TextboxButton(GameManager *gM, Textbox *t, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
Textbox::TextboxButton::TextboxButton(Textbox *t, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
textbox = t;
}
@@ -20,26 +20,27 @@ namespace game{
textbox->disable();
}
Textbox::Textbox(GameManager *gM, vector2d<s32> pos, vector2d<s32> size) {
gameManager = gM;
Textbox::Textbox(vector2d<s32> pos, vector2d<s32> size) {
this->pos = pos;
this->size = size;
textboxButton = new TextboxButton(gM, this, pos, size, "TextboxButton", false);
font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/bigfont.png");
textboxButton = new TextboxButton(this, pos, size, "TextboxButton", false);
font = GameManager::getSingleton()->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/bigfont.png");
}
Textbox::~Textbox() {}
void Textbox::update() {
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 200, 200), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
GameManager *gm = GameManager::getSingleton();
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 200, 200, 200), rect<s32>(pos.X, pos.Y, pos.X + size.X, pos.Y + size.Y), nullptr);
font->draw(entry, rect<s32>(pos.X, pos.Y - 8, pos.X + size.X, pos.Y - 8 + size.Y), SColor(255, 255, 255, 255));
if (enabled) {
if (canChangeCursor()) {
canShowCursor = !canShowCursor;
lastBlinkTime = getTime();
}
if (canShowCursor)
gameManager->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 100, 100, 100), rect<s32>(pos.X + 20 * (entry.size() - cursorPosOffset), pos.Y, pos.X + 4 + 20 * (entry.size() - cursorPosOffset), pos.Y + size.Y), nullptr);
gm->getDevice()->getVideoDriver()->draw2DRectangle(SColor(255, 100, 100, 100), rect<s32>(pos.X + 20 * (entry.size() - cursorPosOffset), pos.Y, pos.X + 4 + 20 * (entry.size() - cursorPosOffset), pos.Y + size.Y), nullptr);
}
}
+3 -3
View File
@@ -10,7 +10,7 @@ namespace game{
namespace gui {
class Textbox {
public:
Textbox(core::GameManager*, irr::core::vector2d<s32>, irr::core::vector2d<s32>);
Textbox(irr::core::vector2d<s32>, irr::core::vector2d<s32>);
~Textbox();
void update();
void enable();
@@ -27,12 +27,12 @@ namespace game{
private:
class TextboxButton : public Button {
public:
TextboxButton(core::GameManager*, Textbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
TextboxButton(Textbox*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
void onClick();
private:
Textbox *textbox;
};
core::GameManager *gameManager;
irr::gui::IGUIFont *font;
irr::core::vector2d<s32> pos, size;
irr::core::stringw entry = "";
+2 -3
View File
@@ -6,10 +6,9 @@ namespace game{
using namespace irr::video;
using namespace game::core;
Tooltip::Tooltip(GameManager *gm, vector2di pos, stringw entry){
gameManager=gm;
Tooltip::Tooltip(vector2di pos, stringw entry){
this->pos=pos;
text=new BitmapText(gm,entry,pos,gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp"));
text=new BitmapText(entry,pos,GameManager::getSingleton()->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp"));
gameManager->attachBitmapText(text);
}
+1 -1
View File
@@ -7,7 +7,7 @@ namespace game{
namespace gui{
class Tooltip{
public:
Tooltip(core::GameManager*,irr::core::vector2di, irr::core::stringw);
Tooltip(irr::core::vector2di, irr::core::stringw);
~Tooltip();
void update();
private:
+2 -2
View File
@@ -4,8 +4,8 @@ using namespace game::core;
namespace game{
namespace content{
Torpedo::Torpedo(GameManager *gM, Unit *unit, irr::core::vector3df pos, irr::core::vector3df dir, irr::core::vector3df left, irr::core::vector3df up, int id,int weaponTypeId,int weaponId) :
Projectile(gM, unit, nullptr, pos, dir, left, up, id,weaponTypeId,weaponId) {this->damage=50;}
Torpedo::Torpedo(Unit *unit, irr::core::vector3df pos, irr::core::vector3df dir, irr::core::vector3df left, irr::core::vector3df 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();
+1 -1
View File
@@ -8,7 +8,7 @@ namespace game{
namespace content{
class Torpedo : public Projectile {
public:
Torpedo(core::GameManager*, Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Torpedo(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
~Torpedo(){}
void update();
// void explode()
+23 -14
View File
@@ -1,5 +1,6 @@
#include "unit.h"
#include "inGameAppState.h"
#include "stateManager.h"
#include "util.h"
#include "unitData.h"
@@ -10,10 +11,9 @@ using namespace sf;
namespace game{
namespace content{
Unit::Unit(GameManager *gM, Player *player, vector3df pos, int id) {
Unit::Unit(Player *player, vector3df pos, int id) {
this->id = id;
this->player = player;
gameManager = gM;
type = unitData::unitType[id];
this->health = unitData::health[id];
this->maxTurnAngle = unitData::maxTurnAngle[id];
@@ -22,8 +22,10 @@ namespace game{
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;
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
this->speed = unitData::speed[id];
mesh = smgr->getMesh(basePath[id] + meshPath[id]);
node = smgr->addAnimatedMeshSceneNode(mesh);
@@ -33,22 +35,26 @@ namespace game{
node->setTriangleSelector(tr);
tr->drop();
ITexture *diffuseTexture = driver->getTexture(basePath[id] + "diffuseMap.png");
if (diffuseTexture)
node->setMaterialTexture(0, diffuseTexture);
else
node->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
light = smgr->addLightSceneNode(node, vector3df(0, 2, 0), SColor(255, 255, 255, 255), lineOfSight);
light->setVisible(false);
node->setVisible(false);
selectionSfxBuffer=new SoundBuffer();
path p=PATH+"Sounds/"+unitData::name[id]+"s/selection.ogg";
if(selectionSfxBuffer->loadFromFile(p.c_str()))
selectionSfx=new Sound(*selectionSfxBuffer);
}
Unit::~Unit() {
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
// driver->removeTexture(node->getMaterial(0).getTexture(0));
node->removeChild(light);
node->getParent()->removeChild(node);
@@ -71,7 +77,7 @@ namespace game{
r=255,g=255;
break;
}
gameManager->getDevice()->getVideoDriver()->draw3DLine(pos,*(orders[0].targetPos[0]),SColor(255,r,g,b));
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();
@@ -92,15 +98,18 @@ namespace game{
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;
screenPos = vector2d<s32>(gameManager->getWidth() * x / width, gameManager->getHeight() * y / height);
GameManager *gm = GameManager::getSingleton();
screenPos = vector2d<s32>(gm->getWidth() * x / width, gm->getHeight() * y / height);
} else
selectable = false;
} else
@@ -120,7 +129,7 @@ namespace game{
}
void Unit::displayUnitStats() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
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);
@@ -131,7 +140,7 @@ namespace game{
}
void Unit::drawCuboid() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->setTransform(ETS_WORLD, IdentityMatrix);
for (int i = 0; i < 8; i++) {
vector3df vec = unitCornerPoints[id][i];
@@ -150,7 +159,7 @@ namespace game{
}
void Unit::debug() {
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->setTransform(ETS_WORLD, IdentityMatrix);
driver->setMaterial(createLineMaterial());
float length = unitAxisLength[id];
@@ -297,7 +306,7 @@ namespace game{
std::vector<Projectile*> Unit::getProjectiles(){
std::vector<Projectile*> projectiles;
InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
for(Projectile *p: inGameState->getProjectiles())
if(p->getUnit()==this)
projectiles.push_back(p);
@@ -307,7 +316,7 @@ namespace game{
void Unit::removeOrder(int id) {
for (vector3df *v : orders[id].targetPos) {
bool isUnitPos = false;
InGameAppState *state = (InGameAppState*) gameManager->getAppState(AppStateTypes::IN_GAME_STATE);
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())
@@ -331,6 +340,6 @@ namespace game{
return mat;
}
void Unit::addProjectile(Projectile *p) {((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE))->addProjectile(p);}
void Unit::addProjectile(Projectile *p) {((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE))->addProjectile(p);}
}
}
+1 -2
View File
@@ -32,7 +32,7 @@ namespace game{
class Unit {
public:
Unit(core::GameManager*, Player*,vector3df, int);
Unit(Player*,vector3df, int);
~Unit();
virtual void update();
virtual void blowUp();
@@ -80,7 +80,6 @@ namespace game{
sf::SoundBuffer *selectionSfxBuffer;
sf::Sound *selectionSfx=nullptr;
protected:
core::GameManager *gameManager;
Player *player;
MoveDir moveDir = MoveDir::FORWARD;
irr::video::SMaterial createLineMaterial();
+39 -29
View File
@@ -2,6 +2,7 @@
#include "util.h"
#include "gameManager.h"
#include "stateManager.h"
#include "guiAppState.h"
#include "inGameAppState.h"
@@ -51,12 +52,12 @@ namespace game{
outFile.close();
}
void makeTitlescreenButtons(GameManager *gameManager, GuiAppState *state) {
void makeTitlescreenButtons(GuiAppState *state) {
class SpButton : public Button {
public:
SpButton(GuiAppState *state, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
SpButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->state = state;
}
@@ -65,8 +66,8 @@ namespace game{
class PlayButton : public Button {
public:
PlayButton(GameManager *gM, Listbox **difficulties, Listbox **factions, int lengths[2], vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(gM, pos, size, name, separate) {
this->state = ((GuiAppState*)gM->getAppState(AppStateTypes::GUI_STATE));
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], vector2d<s32> pos, vector2d<s32> size, stringw 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];
difficultiesListboxes=difficulties;
@@ -74,15 +75,19 @@ namespace game{
}
void onClick() {
gameManager->detachAllBitmapTexts();
GameManager *gm = GameManager::getSingleton();
gm->detachAllBitmapTexts();
state->removeButton("Back");
// gameManager->dettachState(state);
std::vector<stringw> difficulties,factions;
for(int i=0;i<lengths[0];i++)
difficulties.push_back(difficultiesListboxes[i]->getLine(difficultiesListboxes[i]->getSelectedOption()));
for(int i=0;i<lengths[1];i++)
factions.push_back(stringw(factionsListboxes[i]->getSelectedOption()));
gameManager->attachState(new InGameAppState(gameManager, difficulties, factions));
gm->getStateManager()->attachState(new InGameAppState(difficulties, factions));
state->removeAllListboxes();
delete[] difficultiesListboxes;
delete[] factionsListboxes;
@@ -97,7 +102,7 @@ namespace game{
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) {
ReturnButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->state = state;
}
@@ -106,36 +111,38 @@ namespace game{
state->removeAllListboxes();
state->removeAllSliders();
state->removeAllTextboxes();
gameManager->detachAllBitmapTexts();
makeTitlescreenButtons(gameManager, state);
GameManager::getSingleton()->detachAllBitmapTexts();
makeTitlescreenButtons(state);
state->removeButton("Play");
state->removeButton("Back");
}
private:
GuiAppState *state;
};
IGUIFont *font = gameManager->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> pos(gameManager->getWidth() / 8, gameManager->getHeight() / 8);
GameManager *gm = GameManager::getSingleton();
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> 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");
gameManager->attachBitmapText(new BitmapText(gameManager, "Difficulty", vector2d<s32>(pos.X, pos.Y - 20), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "Faction", vector2d<s32>(pos.X + 110, pos.Y - 20), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "Player", vector2d<s32>(pos.X - 40, pos.Y), font));
gameManager->attachBitmapText(new BitmapText(gameManager, "CPU", vector2d<s32>(pos.X - 20, pos.Y + 30), font));
Listbox *cpuDifficulty = new Listbox(gameManager, vector2d<s32>(pos.X, pos.Y + 30), vector2d<s32>(100, 20), difficulties, 3);
Listbox *cpuFaction = new Listbox(gameManager, vector2d<s32>(pos.X + 110, pos.Y + 30), vector2d<s32>(100, 20), factions, 2);
Listbox *playerFaction = new Listbox(gameManager, vector2d<s32>(pos.X + 110, pos.Y), vector2d<s32>(100, 20), factions, 2);
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));
Listbox *cpuDifficulty = new Listbox(vector2d<s32>(pos.X, pos.Y + 30), vector2d<s32>(100, 20), difficulties, 3);
Listbox *cpuFaction = new Listbox(vector2d<s32>(pos.X + 110, pos.Y + 30), vector2d<s32>(100, 20), factions, 2);
Listbox *playerFaction = new Listbox(vector2d<s32>(pos.X + 110, pos.Y), vector2d<s32>(100, 20), factions, 2);
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(gameManager, difficultyListboxes, factionListboxes, lengths, vector2d<s32>(50, gameManager->getHeight() - 150), vector2d<s32>(140, 50), "Play", true);
ReturnButton *returnButton = new ReturnButton(state, gameManager, vector2d<s32>(200, gameManager->getHeight() - 150), vector2d<s32>(140, 50), "Back", true);
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, vector2d<s32>(50, gm->getHeight() - 150), vector2d<s32>(140, 50), "Play", true);
ReturnButton *returnButton = new ReturnButton(state, vector2d<s32>(200, gm->getHeight() - 150), vector2d<s32>(140, 50), "Back", true);
state->addButton(playButton);
state->addButton(returnButton);
state->addListbox(cpuDifficulty);
@@ -152,12 +159,12 @@ namespace game{
class MainMenuOptionsButton : public OptionsButton {
public:
MainMenuOptionsButton(GuiAppState *state, GameManager *gM, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : OptionsButton(gM, pos, size, name, separate) {
MainMenuOptionsButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : OptionsButton(pos, size, name, separate) {
this->state = state;
}
void onClick() {
ReturnButton *returnButton = new ReturnButton(state, gameManager, vector2d<s32>(50, gameManager->getHeight() - 150), vector2d<s32>(150, 50), "Back", true);
ReturnButton *returnButton = new ReturnButton(state, vector2d<s32>(50, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(150, 50), "Back", true);
state->addButton(returnButton);
state->removeButton("Singleplayer");
state->removeButton("Exit");
@@ -169,7 +176,7 @@ namespace game{
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) {
ReturnButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
this->state = state;
}
@@ -183,10 +190,11 @@ namespace game{
state->removeButton("Video");
state->removeButton("Audio");
state->removeButton("Multiplayer");
SpButton *spButton = new SpButton(state, gameManager, vector2d<s32>(gameManager->getWidth() / 16, gameManager->getHeight() / 12), vector2d<s32>(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, gameManager, vector2d<s32>(gameManager->getWidth() / 16, gameManager->getHeight() / 12 * 2), vector2d<s32>(150, 40), "Options", true);
GameManager *gm = GameManager::getSingleton();
SpButton *spButton = new SpButton(state, vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12), vector2d<s32>(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12 * 2), vector2d<s32>(150, 40), "Options", true);
state->addButton(optionsButton);
ExitButton *exitButton = new ExitButton(gameManager, vector2d<s32>(gameManager->getWidth() / 16, gameManager->getHeight() / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
ExitButton *exitButton = new ExitButton(vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
state->addButton(spButton);
state->addButton(exitButton);
state->removeButton("Back");
@@ -195,9 +203,11 @@ namespace game{
GuiAppState *state;
};
};
SpButton *spButton = new SpButton(state, gameManager, vector2d<s32>(gameManager->getWidth() / 16, gameManager->getHeight() / 12), vector2d<s32>(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, gameManager, vector2d<s32>(gameManager->getWidth() / 16, gameManager->getHeight() / 12 * 2), vector2d<s32>(150, 40), "Options", true);
ExitButton *exitButton = new ExitButton(gameManager, vector2d<s32>(gameManager->getWidth() / 16, gameManager->getHeight() / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
GameManager *gm = GameManager::getSingleton();
SpButton *spButton = new SpButton(state, vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12), vector2d<s32>(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12 * 2), vector2d<s32>(150, 40), "Options", true);
ExitButton *exitButton = new ExitButton(vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
state->addButton(optionsButton);
state->addButton(spButton);
state->addButton(exitButton);
+1 -1
View File
@@ -28,7 +28,7 @@ namespace game{
irr::scene::ISceneNode* castRay(irr::scene::ISceneManager*,irr::core::vector3df,irr::core::vector3df);
std::vector<irr::core::stringw> readFile(std::string,int=0,int=-1);
void writeFile(std::string,std::vector<std::string>);
void makeTitlescreenButtons(core::GameManager*,core::GuiAppState*);
void makeTitlescreenButtons(core::GuiAppState*);
double getAngleBetween(irr::core::vector3df, irr::core::vector3df);
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);
+8 -8
View File
@@ -17,14 +17,14 @@ using namespace sf;
namespace game{
namespace content{
Vessel::Turret::Turret(GameManager *gM, Unit *vessel, int unitId, int turretId) {
gameManager = gM;
Vessel::Turret::Turret(Unit *vessel, int unitId, int turretId) {
this->vessel = vessel;
hullNode = vessel->getNode();
this->unitId = unitId;
this->turretId = turretId;
ISceneManager *smgr = gameManager->getDevice()->getSceneManager();
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
turretMesh = smgr->getMesh(basePath[unitId] + turretNames[unitId][turretId] + ".x");
turretNode = smgr->addAnimatedMeshSceneNode(turretMesh);
turretNode->setMaterialFlag(EMF_LIGHTING, false);
@@ -129,7 +129,7 @@ namespace game{
void Vessel::Turret::debug(const SMaterial &mat) {
float length = turretAxisLength[unitId][turretId]*0 + 1;
IVideoDriver *driver = gameManager->getDevice()->getVideoDriver();
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));
@@ -167,16 +167,16 @@ namespace game{
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(gameManager, vessel, startPos, rotQuat*dirVec, rotQuat*leftVec, rotQuat*upVec, unitId, 0, turretId));
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(GameManager *gM, Player *player,vector3df pos, int id) : Unit(gM, player,pos, id) {
Vessel::Vessel(Player *player,vector3df pos, int id) : Unit(player,pos, id) {
if (numberOfTurrets[id] > 0)
for (int i = 0; i < numberOfTurrets[id]; i++)
turrets.push_back(new Turret(Unit::gameManager, this, id, i));
turrets.push_back(new Turret(this, id, i));
}
void Vessel::update() {
+2 -3
View File
@@ -9,7 +9,7 @@ namespace game{
namespace content {
class Vessel : public Unit {
public:
Vessel(core::GameManager*, Player*,vector3df, int);
Vessel(Player*,vector3df, int);
void update();
protected:
void attack(Order);
@@ -17,7 +17,7 @@ namespace game{
void debug();
class Turret {
public:
Turret(core::GameManager*, Unit*, int, int);
Turret(Unit*, int, int);
void update();
void fire();
void rotate(double);
@@ -36,7 +36,6 @@ namespace game{
irr::scene::IParticleSystemSceneNode *fxNode;
irr::scene::IParticleEmitter *emitter;
irr::scene::IParticleAffector *affector;
core::GameManager *gameManager;
Unit *vessel;
irr::scene::IAnimatedMesh *turretMesh;
irr::scene::ISceneNode *turretNode, *hullNode;