removed many Irrlicht references

This commit is contained in:
devZoGok
2021-10-31 15:13:47 +02:00
parent 0e236a44d6
commit b18b2fe9a8
70 changed files with 1822 additions and 1529 deletions
+16 -6
View File
@@ -1,16 +1,24 @@
cmake_minimum_required(VERSION 2.9)
project(game)
include_directories(/usr/include/irrlicht)
link_directories(/usr/lib/)
set(CMAKE_BUILD_TYPE Debug)
cmake_policy(SET CMP0015 NEW)
include_directories(../vb01)
include_directories(../vb01Gui)
include_directories(/usr/include/freetype2)
include_directories(/usr/include/GLFW)
include_directories(/usr/include/glm)
include_directories(/usr/include/sfml)
include_directories(/usr/include/mysql++)
link_directories(../vb01/build)
link_directories(../vb01Gui/build)
link_directories(/usr/lib)
set(states abstractAppState.cpp activeGameState.cpp inGameAppState.cpp guiAppState.cpp)
set(util util.cpp)
set(gui abstractImage.cpp abstractBitmapText.cpp tooltip.cpp button.cpp listbox.cpp textbox.cpp checkbox.cpp slider.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
set(gui tooltip.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp)
set(core eventListener.cpp gameManager.cpp main.cpp key.cpp stateManager.cpp)
set(ships vessel.cpp destroyer.cpp cruiser.cpp aircraftCarrier.cpp submarine.cpp)
set(projectiles projectile.cpp guidedMissile.cpp depthCharge.cpp missile.cpp shell.cpp torpedo.cpp)
@@ -19,6 +27,8 @@ set(fx explosion.cpp)
set(content player.cpp unit.cpp map.cpp ${ships} ${projectiles} ${aircraft} ${fx})
add_executable(battleship ${states} ${gui} ${core} ${content} ${util})
target_link_libraries(battleship Irrlicht)
target_link_libraries(battleship vb01d)
target_link_libraries(battleship vb01Gui)
target_link_libraries(battleship sfml-system)
target_link_libraries(battleship sfml-audio)
target_link_libraries(battleship glfw)
+29 -12
View File
@@ -1,15 +1,14 @@
#include "abstractAppState.h"
#include "defConfigs.h"
#include "util.h"
#include <irrlicht.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <util.h>
#include "abstractAppState.h"
#include "defConfigs.h"
using namespace irr::core;
using namespace game::util;
using namespace game::core;
using namespace vb01;
using namespace std;
namespace game{
@@ -17,29 +16,47 @@ namespace game{
void AbstractAppState::onAttachment() {
const int stateId=(int)type,numBinds=core::numBinds[stateId];
int firstLine=0,lastLine;
for(int i=0;i<stateId;i++)
firstLine+=core::numConfBinds[i];
// firstLine++;
lastLine=firstLine+core::numConfBinds[stateId];
std::vector<stringw> lines=readFile(PATH_STR+"../options.cfg",firstLine,lastLine);
std::vector<string> lines;
readFile(PATH_STR + "../options.cfg", lines, firstLine,lastLine);
for(int i=0;i<numBinds;i++){
int trigger=core::triggers[stateId][i];
if(i<core::numConfBinds[stateId]&&stateId!=(int)AppStateTypes::GUI_STATE){
int xId=-1;
for(int i2=0;i2<lines[i].size()&&xId==-1;i2++)
if(lines[i].c_str()[i2]=='x')
xId=i2;
char ch[2];
for(int i2=0;i2<2;i2++)
ch[i2]=(char)lines[i].subString(xId+1,2).c_str()[i2];
ch[i2]=(char)lines[i].substr(xId+1,2).c_str()[i2];
stringstream ss;
ss<<ch;
ss>>std::hex>>trigger;
}
Bind bind=binds[stateId][i];
bool isKey=stateId>0?trigger>4:core::triggers[stateId][i],isAnalog=core::isAnalog[stateId][i];
attachedKeys.push_back(new Key(bind,trigger,isKey,isAnalog));
Mapping::Bind bind=binds[stateId][i];
Mapping::BindType type = (stateId > 0 ? Mapping::KEYBOARD : Mapping::MOUSE_KEY);
bool isAnalog = core::isAnalog[stateId][i];
Mapping *m = new Mapping;
m->bind = bind;
m->trigger = trigger;
m->type = type;
m->action = !isAnalog;
attachedKeys.push_back(m);
}
attached = true;
}
@@ -47,7 +64,7 @@ namespace game{
attached = false;
}
void AbstractAppState::detachKey(Key *key) {
void AbstractAppState::detachKey(Mapping *key) {
for (int i = 0; i < attachedKeys.size(); i++)
if (key == attachedKeys[i]) {
delete key;
+11 -9
View File
@@ -2,8 +2,8 @@
#define ABSTRACT_APP_STATE
#include "key.h"
#include <vector>
#include <IEventReceiver.h>
namespace game{
namespace core{
@@ -12,26 +12,28 @@ namespace game{
public:
AbstractAppState(){}
~AbstractAppState(){}
void setKey(int, Key*);
void setKey(int, Mapping*);
AppStateTypes getType() {return type;}
inline bool isAttached(){return attached;}
inline int getKeysNumber(){return attachedKeys.size();}
inline Key* getKey(int i){return attachedKeys[i];}
inline std::vector<Key*>& getKeys(){return attachedKeys;}
inline Mapping* getKey(int i){return attachedKeys[i];}
inline std::vector<Mapping*>& getKeys(){return attachedKeys;}
virtual void onAttachment();
virtual void onDetachment();
virtual void update(){}
virtual void onAction(Bind, bool){}
virtual void onAnalog(Bind, double){}
virtual void onAction(Mapping::Bind, bool){}
virtual void onAnalog(Mapping::Bind, double){}
/*
virtual void onRawKeyPress(irr::SEvent::SKeyInput){}
virtual void onRawMousePress(irr::SEvent::SMouseInput){}
*/
private:
bool attached = false;
std::vector<Key*> attachedKeys;
std::vector<Mapping*> attachedKeys;
protected:
AppStateTypes type;
inline void attachKey(Key *k){attachedKeys.push_back(k);}
void detachKey(Key*);
inline void attachKey(Mapping *k){attachedKeys.push_back(k);}
void detachKey(Mapping*);
void detachAllKeys();
};
}
+162 -108
View File
@@ -1,3 +1,11 @@
#include <root.h>
#include <quaternion.h>
#include <model.h>
#include <algorithm>
#include <ctype.h>
#include <stdlib.h>
#include "activeGameState.h"
#include "inGameAppState.h"
#include "stateManager.h"
@@ -9,20 +17,18 @@
#include "demoJet.h"
#include "missileJet.h"
#include "tooltip.h"
#include <algorithm>
#include <stdlib.h>
using namespace game::core;
using namespace game::util;
using namespace game::content;
using namespace vb01;
using namespace vb01Gui;
using namespace std;
using namespace irr::video;
namespace game{
namespace core{
const int size=50;
const int size = 50;
ActiveGameState::UnitButton::UnitButton(ActiveGameState *activeState,vector2di pos, vector2di size, irr::core::stringw name,int faction,int unitId) : gui::Button(pos,size,name,true){
ActiveGameState::UnitButton::UnitButton(ActiveGameState *activeState, Vector2 pos, Vector2 size, std::string name,int faction,int unitId) : vb01Gui::Button(pos,size,name,true){
this->activeState=activeState;
this->faction=faction;
this->unitId=unitId;
@@ -30,8 +36,9 @@ namespace game{
void ActiveGameState::UnitButton::onClick(){
Player *player=activeState->getPlayer();
vector3df spawnPoint=player->getSpawnPoint();
Vector3 spawnPoint=player->getSpawnPoint();
Unit *u;
switch(unitData::unitType[unitId]){
case unitData::UNIT_TYPE::VESSEL:
u=new Vessel(player,spawnPoint,unitId);
@@ -49,30 +56,37 @@ namespace game{
u=new Submarine(player,spawnPoint,unitId);
break;
}
player->addUnit(u);
}
void ActiveGameState::UnitButton::onMouseOver(){
/*
if(!mouseOverDone){
GameManager *gm = GameManager::getSingleton();
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->addTooltip(new gui::Tooltip(pos-vector2di(100,0),name));
guiState->addTooltip(new gui::Tooltip(pos-Vector2(100,0),name));
}
*/
}
void ActiveGameState::UnitButton::onMouseAway(){
/*
if(!mouseAwayDone){
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->removeAllTooltips();
}
*/
}
ActiveGameState::UnitActionButton::UnitActionButton(unitData::UNIT_TYPE type, vector2di pos, vector2di size, stringw name, stringw path) : gui::Button(pos,size,name,true){
ActiveGameState::UnitActionButton::UnitActionButton(unitData::UNIT_TYPE type, Vector2 pos, Vector2 size, string name, string path) : vb01Gui::Button(pos,size,name,true){
this->type=type;
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
activeState=((ActiveGameState*)gm->getStateManager()->getAppState(AppStateTypes::ACTIVE_STATE));
/*
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
setImageButton(new Image(driver->getTexture(path),pos,vector2di(50,50)));
*/
}
void ActiveGameState::UnitActionButton::onClick(){
@@ -83,17 +97,21 @@ namespace game{
}
void ActiveGameState::UnitActionButton::onMouseOver(){
/*
if(!mouseOverDone){
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->addTooltip(new gui::Tooltip(pos-vector2di(100,0),name));
guiState->addTooltip(new gui::Tooltip(pos-Vector2(100,0),name));
}
*/
}
void ActiveGameState::UnitActionButton::onMouseAway(){
/*
if(!mouseAwayDone){
GuiAppState *guiState=((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
guiState->removeAllTooltips();
}
*/
}
ActiveGameState::ActiveGameState(GuiAppState *guiState, Map *map, vector<Player*> players, int playerId) {
@@ -103,14 +121,17 @@ namespace game{
this->players = players;
GameManager *gm = GameManager::getSingleton();
cam = gm->getDevice()->getSceneManager()->addCameraSceneNodeFPS(0, 100, 0.f, -1, nullptr, 10, false, 0.6f);
Camera *cam = Root::getSingleton()->getCamera();
/*
cam->setInputReceiverEnabled(false);
gm->getDevice()->getCursorControl()->setVisible(true);
*/
this->playerId = playerId;
mainPlayer = players[playerId];
cam->setPosition(vector3df(0, 5, 0));
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 6, vector3df(1, 0, 0));
cam->setTarget(vector3df(0, 5, 0) + rotQuat * vector3df(0, 0, 1));
cam->setPosition(Vector3(0, 5, 0));
Quaternion rotQuat = Quaternion(4 * atan(1) / 6, Vector3(1, 0, 0));
//cam->setTarget(vector3df(0, 5, 0) + rotQuat * vector3df(0, 0, 1));
}
ActiveGameState::~ActiveGameState() {
@@ -119,21 +140,22 @@ namespace game{
void ActiveGameState::onAttachment() {
AbstractAppState::onAttachment();
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"};
string 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(this,pos,sizeVec,names[i],faction,id);
Vector2 pos = Vector2(width - size - 1, 1 + i * size), sizeVec = Vector2(size, size);
UnitButton *button = new UnitButton(this, pos, sizeVec, names[i], faction, id);
if(i==3)
names[i]="aircraftCarrier";
/*
if(i == 3)
names[i] = "aircraftCarrier";
else
names[i].make_lower();
transform(names[i].begin(), names[i].end(), names[i], names[i]);
*/
button->setImageButton(new Image(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);
}
}
@@ -150,8 +172,9 @@ namespace game{
if (isSelectionBox)
updateSelectionBox();
for (Unit *u : units) {
u->updateUnitGUIInfo(cam, camDir, camLeft, camUp);
vector2d<s32> pos = u->getScreenPos();
//u->updateUnitGUIInfo(cam, camDir, camLeft, camUp);
Vector2 pos = u->getScreenPos();
if (mainPlayer->isThisPlayersUnit(u)){
bool selected=false;
for(int i=0;i<selectedUnits.size()&&!selected;i++)
@@ -162,12 +185,14 @@ namespace game{
else if(!selected)
u->toggleSelection(false);
if(isSelectionBox && u->isSelectable() &&
pos.X >= selectionBoxOrigin.X && pos.X <= selectionBoxEnd.X &&
pos.Y >= selectionBoxOrigin.Y && pos.Y <= selectionBoxEnd.Y){
pos.x >= selectionBoxOrigin.x && pos.x <= selectionBoxEnd.x &&
pos.y >= selectionBoxOrigin.y && pos.y <= selectionBoxEnd.y){
if(!selected){
if(!shiftPressed&&u==mainPlayer->getUnit(0))
while(!selectedUnits.empty())
selectedUnits.pop_back();
selectedUnits.push_back(u);
}
}
@@ -175,34 +200,39 @@ namespace game{
if (u->isDebuggable())
u->debug();
}
updateVectors();
renderUnits(units);
if (cam->getPosition().X > map->getSize().X / 2)
cam->setPosition(vector3df(map->getSize().X / 2, cam->getPosition().Y, cam->getPosition().Z));
else if (cam->getPosition().X < -map->getSize().X / 2)
cam->setPosition(vector3df(-map->getSize().X / 2, cam->getPosition().Y, cam->getPosition().Z));
if (cam->getPosition().Z > map->getSize().Y / 2)
cam->setPosition(vector3df(cam->getPosition().X, cam->getPosition().Y, map->getSize().Y / 2));
else if (cam->getPosition().Z < -map->getSize().Y / 2)
cam->setPosition(vector3df(cam->getPosition().X, cam->getPosition().Y, -map->getSize().Y / 2));
cam->setTarget(cam->getPosition() + camDir);
if (cam->getPosition().x > map->getSize().x / 2)
cam->setPosition(Vector3(map->getSize().x / 2, cam->getPosition().y, cam->getPosition().z));
else if (cam->getPosition().x < -map->getSize().x / 2)
cam->setPosition(Vector3(-map->getSize().x / 2, cam->getPosition().y, cam->getPosition().z));
if (cam->getPosition().z > map->getSize().y / 2)
cam->setPosition(Vector3(cam->getPosition().x, cam->getPosition().y, map->getSize().y / 2));
else if (cam->getPosition().z < -map->getSize().y / 2)
cam->setPosition(Vector3(cam->getPosition().x, cam->getPosition().y, -map->getSize().y / 2));
//cam->setTarget(cam->getPosition() + camDir);
renderGUIBorders();
renderActionButtons();
}
void ActiveGameState::renderUnits(vector<Unit*> units) {
ISceneManager *smgr = GameManager::getSingleton()->getDevice()->getSceneManager();
//ISceneManager *smgr = GameManager::getSingleton()->getDevice()->getSceneManager();
for (Unit *rendUn : units) {
vector3df rendUnPos = rendUn->getPos();
rendUnPos.Y = 0;
Vector3 rendUnPos = rendUn->getPos();
rendUnPos.y = 0;
if (mainPlayer == rendUn->getPlayer()) {
rendUn->getNode()->setVisible(true);
rendUn->getLight()->setVisible(true);
//rendUn->getLight()->setVisible(true);
} else
for (int i = 0; i < units.size() && units[i] != rendUn && units[i]->getPlayer() == mainPlayer; i++) {
Unit *compUn = units[i];
vector3df compUnPos = compUn->getPos();
compUnPos.Y = 0;
Vector3 compUnPos = compUn->getPos();
compUnPos.y = 0;
float dist = compUnPos.getDistanceFrom(rendUnPos);
rendUn->getNode()->setVisible(dist <= compUn->getLineOfSight() || isInLineOfSight(compUnPos, compUn->getLineOfSight(), rendUn) ? true : false);
}
@@ -210,6 +240,7 @@ namespace game{
}
void ActiveGameState::renderGUIBorders(){
/*
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
int width = gm->getWidth(), height = gm->getHeight(), size = 50;
@@ -218,16 +249,18 @@ namespace game{
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)));
}
*/
}
void ActiveGameState::renderActionButtons(){
class MakeJetButton : public UnitActionButton{
public:
MakeJetButton(int faction,unitData::UNIT_TYPE type,vector2di pos, vector2di size):UnitActionButton(type,pos,size,"Jet",PATH+"Textures/Icons/jet0"+stringw(faction)+".png"){
MakeJetButton(int faction, unitData::UNIT_TYPE type, Vector2 pos, Vector2 size):UnitActionButton(type, pos, size, "Jet", PATH + "Textures/Icons/jet0" + to_string(faction) + ".png"){
}
~MakeJetButton(){}
void onClick(){
UnitActionButton::onClick();
for(int i=0;i<units.size();i++)
((AircraftCarrier*)units[i])->makeJet();
}
@@ -235,7 +268,7 @@ namespace game{
};
class LaunchButton : public UnitActionButton{
public:
LaunchButton(int faction,unitData::UNIT_TYPE type,vector2di pos,vector2di size) : UnitActionButton(type,pos,size,"Launch",PATH+"Textures/Icons/guidedMissile0"+stringw(faction)+".png"){}
LaunchButton(int faction, unitData::UNIT_TYPE type, Vector2 pos, Vector2 size) : UnitActionButton(type, pos, size, "Launch", PATH + "Textures/Icons/guidedMissile0" + to_string(faction) + ".png"){}
~LaunchButton(){}
void onClick(){
UnitActionButton::onClick();
@@ -245,12 +278,13 @@ namespace game{
};
class MissileButton : public UnitActionButton{
public:
MissileButton(bool aam,vector2di pos,vector2di size,stringw name,stringw path) : UnitActionButton(unitData::UNIT_TYPE::MISSILE_JET,pos,size,name,path){
MissileButton(bool aam, Vector2 pos, Vector2 size, string name, string path) : UnitActionButton(unitData::UNIT_TYPE::MISSILE_JET,pos,size,name,path){
this->aam=aam;
}
~MissileButton(){}
void onClick(){
UnitActionButton::onClick();
for(int i=0;i<units.size();i++)
((MissileJet*)units[i])->installMissiles(aam);
}
@@ -271,7 +305,7 @@ namespace game{
missileJets=true;
}
if(carriers&&!actionButtons[0]){
actionButtons[0]=new MakeJetButton(faction,unitData::UNIT_TYPE::AIRCRAFT_CARRIER,vector2di(width-2*slotSize,0),vector2di(size,size));
actionButtons[0] = new MakeJetButton(faction, unitData::UNIT_TYPE::AIRCRAFT_CARRIER, Vector2(width - 2 * slotSize, 0), Vector2(size, size));
guiState->addButton(actionButtons[0]);
}
else if(!carriers&&actionButtons[0]){
@@ -279,7 +313,7 @@ namespace game{
actionButtons[0]=nullptr;
}
if(cruisers&&!actionButtons[1]){
actionButtons[1]=new LaunchButton(faction,unitData::UNIT_TYPE::CRUISER,vector2di(width-2*slotSize,slotSize),vector2di(size,size));
actionButtons[1] = new LaunchButton(faction, unitData::UNIT_TYPE::CRUISER, Vector2(width - 2 * slotSize, slotSize), Vector2(size, size));
guiState->addButton(actionButtons[1]);
}
else if(!cruisers&&actionButtons[1]){
@@ -287,8 +321,8 @@ namespace game{
actionButtons[1]=nullptr;
}
if(missileJets&&!actionButtons[2]){
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");
actionButtons[2]=new MissileButton(true, Vector2(width - 2 * slotSize, slotSize * 3), Vector2(size, size), "AAM", PATH + "Textures/Icons/aam.png");
actionButtons[3]=new MissileButton(false, Vector2(width - 2 * slotSize, slotSize * 4), Vector2(size, size), "AWM", PATH + "Textures/Icons/awm.png");
guiState->addButton(actionButtons[2]);
guiState->addButton(actionButtons[3]);
}
@@ -300,42 +334,49 @@ namespace game{
}
}
bool ActiveGameState::isInLineOfSight(vector3df center, float radius, Unit *u) {
bool ActiveGameState::isInLineOfSight(Vector3 center, float radius, Unit *u) {
bool inside = false;
for (int i = 0; i < 4 && !inside; i++) {
if (center.getDistanceFrom(u->getCorner(i)) <= radius)
inside = true;
}
return inside;
}
void ActiveGameState::updateSelectionBox() {
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);
} else if (mousePos.X < clickPoint.X && mousePos.Y > clickPoint.Y) {
selectionBoxOrigin = vector2d<s32>(mousePos.X, clickPoint.Y);
selectionBoxEnd = vector2d<s32>(clickPoint.X, mousePos.Y);
} else if (mousePos.X >= clickPoint.X && mousePos.Y < clickPoint.Y) {
selectionBoxOrigin = vector2d<s32>(clickPoint.X, mousePos.Y);
selectionBoxEnd = vector2d<s32>(mousePos.X, clickPoint.Y);
if (mousePos.x >= clickPoint.x && mousePos.y >= clickPoint.y) {
selectionBoxOrigin = Vector2(clickPoint.x, clickPoint.y);
selectionBoxEnd = Vector2(mousePos.x, mousePos.y);
} else if (mousePos.x < clickPoint.x && mousePos.y > clickPoint.y) {
selectionBoxOrigin = Vector2(mousePos.x, clickPoint.y);
selectionBoxEnd = Vector2(clickPoint.x, mousePos.y);
} else if (mousePos.x >= clickPoint.x && mousePos.y < clickPoint.y) {
selectionBoxOrigin = Vector2(clickPoint.x, mousePos.y);
selectionBoxEnd = Vector2(mousePos.x, clickPoint.y);
} else {
selectionBoxOrigin = vector2d<s32>(mousePos.X, mousePos.Y);
selectionBoxEnd = vector2d<s32>(clickPoint.X, clickPoint.Y);
selectionBoxOrigin = Vector2(mousePos.x, mousePos.y);
selectionBoxEnd = Vector2(clickPoint.x, clickPoint.y);
}
driver->draw2DRectangle(SColor(10, 255, 255, 255), rect<s32>(selectionBoxOrigin.X, selectionBoxOrigin.Y, selectionBoxEnd.X, selectionBoxEnd.Y), nullptr);
*/
//driver->draw2DRectangle(SColor(10, 255, 255, 255), rect<s32>(selectionBoxOrigin.X, selectionBoxOrigin.Y, selectionBoxEnd.X, selectionBoxEnd.Y), nullptr);
}
void ActiveGameState::updateVectors() {
/*
GameManager *gm = GameManager::getSingleton();
vector2d<s32> cursorPos = gm->getDevice()->getCursorControl()->getPosition();
Vector2 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;
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));
@@ -362,12 +403,14 @@ namespace game{
cam->setPosition(cam->getPosition() - (forwVec.normalize()) * camPanSpeed);
cam->setTarget(cam->getPosition() + camDir);
}
*/
}
void ActiveGameState::issueOrder(Order::TYPE type, vector<vector3df*> pos, bool addOrder) {
void ActiveGameState::issueOrder(Order::TYPE type, vector<Vector3*> pos, bool addOrder) {
Order o;
o.type = type;
o.targetPos = pos;
for (Unit *u : selectedUnits) {
if (type != Order::TYPE::LAUNCH || (u->getId() == 4 || u->getId() == 5)) {
if (addOrder)
@@ -376,18 +419,21 @@ namespace game{
u->setOrder(o);
}
}
for (vector3df *v : orderPos)
for (Vector3 *v : orderPos)
orderPos.pop_back();
}
void ActiveGameState::addPos() {
vector3df camPos = cam->getPosition();
vector3df topLeft=cam->getViewFrustum()->getNearLeftUp();
vector3df topRight=cam->getViewFrustum()->getNearRightUp();
vector3df bottomLeft=cam->getViewFrustum()->getNearLeftDown();
/*
Vector3 camPos = cam->getPosition();
Vector3 topLeft=cam->getViewFrustum()->getNearLeftUp();
Vector3 topRight=cam->getViewFrustum()->getNearRightUp();
Vector3 bottomLeft=cam->getViewFrustum()->getNearLeftDown();
GameManager *gm = GameManager::getSingleton();
vector2d<int> mousePos = gm->getDevice()->getCursorControl()->getPosition();
vector3df p=topLeft;
Vector2 mousePos = gm->getDevice()->getCursorControl()->getPosition();
Vector3 p = topLeft;
p+=(topRight-topLeft)*((float)mousePos.X / gm->getWidth());
p+=(bottomLeft-topLeft)*((float)mousePos.Y / gm->getHeight());
vector3df orderDir=(p-camPos).normalize();
@@ -428,31 +474,37 @@ namespace game{
issueOrder(t, orderPos, false);
}
*/
}
void ActiveGameState::onAction(Bind bind, bool isPressed) {
void ActiveGameState::onAction(Mapping::Bind bind, bool isPressed) {
GameManager *gm = GameManager::getSingleton();
InGameAppState *inGameState = (InGameAppState*) gm->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE);
switch(bind){
case DRAG_BOX:
case Mapping::DRAG_BOX:
isSelectionBox = isPressed;
if (isPressed) {
/*
clickPoint = gm->getDevice()->getCursorControl()->getPosition();
if (!selectedUnits.empty())
addPos();
*/
}
break;
case DESELECT:
case Mapping::DESELECT:
if (isPressed) {
while(!selectedUnits.empty())
selectedUnits.pop_back();
}
break;
case TOGGLE_SUB:
case Mapping::TOGGLE_SUB:
if (isPressed) {
for (Unit *u : selectedUnits) {
if (u->getPlayer()==mainPlayer && u->getType() == unitData::UNIT_TYPE::SUBMARINE) {
if (u->getPlayer() == mainPlayer && u->getType() == unitData::UNIT_TYPE::SUBMARINE) {
Submarine *s = (Submarine*) u;
if (s->isSubmerged())
s->emerge();
else
@@ -461,36 +513,38 @@ namespace game{
}
}
break;
case ZOOM_IN:
case Mapping::ZOOM_IN:
if (zooms > -10) {
cam->setPosition(cam->getPosition() + camDir.normalize()*.5f);
cam->setTarget(cam->getPosition() + camDir);
cam->setPosition(cam->getPosition() + camDir.norm() * .5f);
//cam->setTarget(cam->getPosition() + camDir);
zooms--;
}
break;
case ZOOM_OUT:
case Mapping::ZOOM_OUT:
if (zooms < 10) {
cam->setPosition(cam->getPosition() - (camDir.normalize()*.5f));
cam->setTarget(cam->getPosition() + camDir);
cam->setPosition(cam->getPosition() - (camDir.norm() * .5f));
//cam->setTarget(cam->getPosition() + camDir);
zooms++;
}
break;
case LOOK_AROUND:
case Mapping::LOOK_AROUND:
/*
cam->setInputReceiverEnabled(isPressed);
gm->getDevice()->getCursorControl()->setVisible(!isPressed);
lookingAround=isPressed;
*/
lookingAround = isPressed;
break;
case HALT:
case Mapping::HALT:
for (Unit *u : selectedUnits)
u->halt();
break;
case LEFT_CONTROL:
case Mapping::LEFT_CONTROL:
controlPressed = isPressed;
break;
case LEFT_SHIFT:
case Mapping::LEFT_SHIFT:
shiftPressed=isPressed;
break;
case SELECT_PATROL_POINTS:
case Mapping::SELECT_PATROL_POINTS:
selectingPatrolPoints = isPressed;
if (!isPressed && orderPos.size() > 0) {
/*
@@ -500,33 +554,33 @@ namespace game{
*/
}
break;
case LAUNCH:
case Mapping::LAUNCH:
selectingGuidedMissileTarget = isPressed;
break;
case INSTALL_AAM:
case INSTALL_AWM:
case Mapping::INSTALL_AAM:
case Mapping::INSTALL_AWM:
for(Unit *u : selectedUnits)
if(u->getType()==unitData::UNIT_TYPE::MISSILE_JET)
((MissileJet*)u)->installMissiles(bind==INSTALL_AAM);
if(u->getType() == unitData::UNIT_TYPE::MISSILE_JET)
((MissileJet*)u)->installMissiles(bind == Mapping::INSTALL_AAM);
break;
case GROUP_0:
case GROUP_1:
case GROUP_2:
case GROUP_3:
case GROUP_4:
case GROUP_5:
case GROUP_6:
case GROUP_7:
case GROUP_8:
case GROUP_9:
case Mapping::GROUP_0:
case Mapping::GROUP_1:
case Mapping::GROUP_2:
case Mapping::GROUP_3:
case Mapping::GROUP_4:
case Mapping::GROUP_5:
case Mapping::GROUP_6:
case Mapping::GROUP_7:
case Mapping::GROUP_8:
case Mapping::GROUP_9:
if(isPressed){
int group=bind-GROUP_0;
int group = bind - Mapping::GROUP_0;
if(controlPressed){
unitGroups[group]=selectedUnits;
unitGroups[group] = selectedUnits;
}
else{
if(!shiftPressed)
selectedUnits=unitGroups[group];
selectedUnits = unitGroups[group];
else
for(Unit *u : unitGroups[group])
selectedUnits.push_back(u);
@@ -536,6 +590,6 @@ namespace game{
}
}
void ActiveGameState::onAnalog(Bind bind, double strength) {}
void ActiveGameState::onAnalog(Mapping::Bind bind, double strength) {}
}
}
+19 -17
View File
@@ -2,12 +2,14 @@
#ifndef ACTIVE_GAME_STATE_H
#define ACTIVE_GAME_STATE_H
#include "gameManager.h"
#include <irrlicht.h>
#include "guiAppState.h"
#include "player.h"
#include "map.h"
namespace vb01{
class Node;
}
namespace game{
namespace core{
class ActiveGameState : public AbstractAppState {
@@ -17,27 +19,27 @@ namespace game{
void onAttachment();
void onDetachment();
void update();
void onAction(Bind, bool);
void onAnalog(Bind, double);
void onAction(Mapping::Bind, bool);
void onAnalog(Mapping::Bind, double);
inline void setSelectingLaunchPoint(bool s){this->selectingGuidedMissileTarget=s;}
inline content::Player* getPlayer(){return mainPlayer;}
inline std::vector<content::Unit*>& getSelectedUnits(){return selectedUnits;}
inline std::vector<content::Unit*>& getUnitGroup(int i){return unitGroups[i];}
private:
class UnitButton : public gui::Button{
class UnitButton : public vb01Gui::Button{
public:
UnitButton(ActiveGameState*,vector2di, vector2di, irr::core::stringw,int,int);
UnitButton(ActiveGameState*, vb01::Vector2, vb01::Vector2, std::string, int, int);
~UnitButton();
virtual void onClick();
virtual void onMouseOver();
virtual void onMouseAway();
private:
ActiveGameState *activeState;
int faction,unitId;
int faction, unitId;
};
class UnitActionButton : public gui::Button{
class UnitActionButton : public vb01Gui::Button{
public:
UnitActionButton(content::unitData::UNIT_TYPE, irr::core::vector2di, irr::core::vector2di, irr::core::stringw, irr::core::stringw);
UnitActionButton(content::unitData::UNIT_TYPE, vb01::Vector2, vb01::Vector2, std::string, std::string);
~UnitActionButton();
virtual void onClick();
virtual void onMouseOver();
@@ -54,22 +56,22 @@ namespace game{
void updateVectors();
void updateSelectionBox();
void addPos();
void issueOrder(content::Order::TYPE, std::vector<irr::core::vector3df*>, bool);
void issueOrder(content::Order::TYPE, std::vector<vb01::Vector3*>, bool);
void lookAround(bool);
GuiAppState *guiState;
content::Map *map;
std::vector<content::Player*> players;
content::Player *mainPlayer;
irr::scene::ICameraSceneNode* cam;
irr::core::vector3df camDir = irr::core::vector3df(0, 0, 1), camLeft = irr::core::vector3df(1, 0, 0), camUp = irr::core::vector3df(0, 1, 0);
irr::core::vector2d<s32> clickPoint, selectionBoxOrigin, selectionBoxEnd;
std::vector<irr::core::vector2d<s32>> unitScreenPosVec;
std::vector<vector3df*> orderPos;
std::vector<ILightSceneNode*> unitLightNodes;
vb01::Camera *cam;
vb01::Vector3 camDir = vb01::Vector3(0, 0, 1), camLeft = vb01::Vector3(1, 0, 0), camUp = vb01::Vector3(0, 1, 0);
vb01::Vector2 clickPoint, selectionBoxOrigin, selectionBoxEnd;
std::vector<vb01::Vector2> unitScreenPosVec;
std::vector<vb01::Vector3*> orderPos;
std::vector<vb01::Node*> unitLightNodes;
std::vector<content::Unit*> unitGroups[9], selectedUnits;
UnitActionButton *actionButtons[4]{nullptr,nullptr,nullptr,nullptr};
bool isSelectionBox = false, shiftPressed=false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false,lookingAround=false;
bool isInLineOfSight(irr::core::vector3df, float, content::Unit*);
bool isInLineOfSight(vb01::Vector3, float, content::Unit*);
int playerId, zooms = 0;
};
}
+17 -6
View File
@@ -4,15 +4,20 @@
#include "demoJet.h"
using namespace game::core;
using namespace vb01;
using namespace std;
namespace game{
namespace content{
AircraftCarrier::AircraftCarrier(Player *player,vector3df pos, int unitId) : Vessel(player,pos, unitId) {
maxNumJets=unitData::numJets[unitId];
jets=new Jet*[maxNumJets];
AircraftCarrier::AircraftCarrier(Player *player, Vector3 pos, int unitId) : Vessel(player,pos, unitId) {
maxNumJets = unitData::numJets[unitId];
jets = new Jet*[maxNumJets];
for(int i=0;i<maxNumJets;i++)
jets[i]=nullptr;
runwayLength=unitData::runwayLenght[unitId];
for (int i = 0; i < unitData::numJets[unitId]; i++)
makeJet();
}
@@ -23,12 +28,15 @@ namespace game{
void AircraftCarrier::makeJet(){
int slot=-1;
for(int i=0; i<unitData::numJets[id]&&slot==-1; i++)
if(!jets[i])
slot=i;
if(slot!=-1){
int id = 0;
Jet *j = nullptr;
if (this->id == 6) {
id = 9;
j = (MissileJet*)new MissileJet(player,getJetPos(slot), id);
@@ -36,6 +44,7 @@ namespace game{
id = 10;
j = (DemoJet*)new DemoJet(player,getJetPos(slot), id);
}
j->setJetId(slot);
jets[slot]=j;
j->setAircraftCarrier(this);
@@ -45,12 +54,14 @@ namespace game{
void AircraftCarrier::move(Order order, float offset) {
Unit::move(order, offset);
for (int i=0;i<maxNumJets;i++) {
Jet *j=jets[i];
if (j&&j->isOnBoard()) {
vector3df oP = j->getOffsetPos();
if (j && j->isOnBoard()) {
Vector3 oP = j->getOffsetPos();
j->orientUnit(dirVec);
j->placeUnit(pos + oP.X * leftVec + oP.Y * upVec - oP.Z * dirVec);
j->placeUnit(pos + leftVec * oP.x + upVec * oP.y - dirVec * oP.z);
}
}
}
+2 -2
View File
@@ -10,14 +10,14 @@ namespace game{
namespace content{
class AircraftCarrier : public Vessel {
public:
AircraftCarrier(Player*, irr::core::vector3df, int);
AircraftCarrier(Player*, vb01::Vector3, int);
~AircraftCarrier();
void makeJet();
inline void setJet(int i, Jet *j){this->jets[i]=j;}
inline int getMaxNumJets(){return maxNumJets;}
inline Jet* getJet(int i){return jets[i];}
inline Jet** getJets(){return jets;}
inline irr::core::vector3df getJetPos(int i){return pos+unitData::jetPos[id][i].X * leftVec - unitData::jetPos[id][i].Z * dirVec + unitData::jetPos[id][i].Y*upVec;}
inline vb01::Vector3 getJetPos(int i){return pos + leftVec * unitData::jetPos[id][i].x - dirVec * unitData::jetPos[id][i].z + upVec * unitData::jetPos[id][i].y;}
inline float getRunwayLength(){return runwayLength;}
private:
Jet** jets;
+13 -13
View File
@@ -17,7 +17,7 @@ namespace game{
namespace content {
namespace unitData {
const int numJets[numberOfUnits]{0, 0, 0, 0, 0, 0, 6, 6};
const vector3df jetPos[numberOfUnits][20]{
const vb01::Vector3 jetPos[numberOfUnits][20]{
{},
{},
{},
@@ -25,20 +25,20 @@ namespace game{
{},
{},
{
vector3df(0.13674, 1.60034, 7.78832),
vector3df(1.5889, 1.60034, 7.78832),
vector3df(0.13674, 1.60034, 5.47672),
vector3df(1.5889, 1.60034, 5.47672),
vector3df(0.13674, 1.60034, 3.37257),
vector3df(1.5889, 1.60034, 3.37257)
vb01::Vector3(0.13674, 1.60034, 7.78832),
vb01::Vector3(1.5889, 1.60034, 7.78832),
vb01::Vector3(0.13674, 1.60034, 5.47672),
vb01::Vector3(1.5889, 1.60034, 5.47672),
vb01::Vector3(0.13674, 1.60034, 3.37257),
vb01::Vector3(1.5889, 1.60034, 3.37257)
},
{
vector3df(-0.61651, 2.78469, 7.88753),
vector3df(0.40384, 2.78469, 7.88753),
vector3df(-0.61651, 2.78469, 5.82783),
vector3df(0.40384, 2.78469, 5.82783),
vector3df(-0.61651, 2.78469, 3.87186),
vector3df(0.40384, 2.78469, 3.87186)
vb01::Vector3(-0.61651, 2.78469, 7.88753),
vb01::Vector3(0.40384, 2.78469, 7.88753),
vb01::Vector3(-0.61651, 2.78469, 5.82783),
vb01::Vector3(0.40384, 2.78469, 5.82783),
vb01::Vector3(-0.61651, 2.78469, 3.87186),
vb01::Vector3(0.40384, 2.78469, 3.87186)
}
};
const float runwayLenght[numberOfUnits]{0, 0, 0, 0, 0, 0, 10, 10};
+16 -5
View File
@@ -1,6 +1,7 @@
#include <sstream>
#include <string>
#include <cmath>
#include <vector.h>
#include "consoleCommand.h"
#include "unitData.h"
@@ -11,14 +12,15 @@
#include "demoJet.h"
#include "missileJet.h"
using namespace irr::core;
using namespace game::core;
using namespace game::content;
using namespace std;
using namespace vb01;
using namespace vb01Gui;
namespace game{
namespace gui{
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, stringw name, vector<stringw> args) {
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, string name, vector<string> args) {
listbox = l;
this->players = players;
this->name = name;
@@ -40,8 +42,9 @@ namespace game{
void ConsoleCommand::addUnit() {
int unitId = 0, playerId = 0;
vector3df pos(0, 0, 0);
Vector3 pos(0, 0, 0);
float angle = 0;
for (int i = 0; i < arguments.size(); i++) {
arguments[i].erase(0);
for (int i2 = 0; i2 < arguments[i].size(); i2++) {
@@ -51,8 +54,10 @@ namespace game{
unitId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
}
}
if ((playerId == 0 || playerId == 1) && (unitId >= 0 && unitId <= numberOfUnits)) {
Unit *u = nullptr;
switch (unitType[unitId]) {
case UNIT_TYPE::VESSEL:
u = new Vessel(players[playerId],pos, unitId);
@@ -80,6 +85,7 @@ namespace game{
default:
break;
}
players[playerId]->addUnit(u);
} else if (playerId != 0 && playerId != 1)
printConsoleMessage("Invalid player id");
@@ -91,9 +97,11 @@ namespace game{
if (arguments.size() == 0)
for (Player *pl : players){
vector<Unit*> &units=pl->getUnits();
for (Unit *u : units){
u->toggleDebugging(true);
vector<Projectile*> projectiles=u->getProjectiles();
for(Projectile *pr : projectiles)
pr->debug();
}
@@ -102,18 +110,21 @@ namespace game{
printConsoleMessage("Too many arguments");
}
void ConsoleCommand::printConsoleMessage(stringw message) {
void ConsoleCommand::printConsoleMessage(string message) {
int messageId = 0;
bool foundEmptySlot = false;
for (int i = 0; i < listbox->getContents().size() && !foundEmptySlot; i++)
if (listbox->getContents()[i] == "") {
if (listbox->getContents()[i] == L"") {
messageId = i;
foundEmptySlot = true;
}
/*
if (foundEmptySlot)
listbox->changeLine(messageId, message);
else
listbox->addLine(message);
*/
}
}
}
+6 -8
View File
@@ -2,10 +2,8 @@
#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"
@@ -15,16 +13,16 @@ namespace game
namespace gui{
class ConsoleCommand{
public:
ConsoleCommand(Listbox*,std::vector<content::Player*>,irr::core::stringw,std::vector<irr::core::stringw>);
ConsoleCommand(vb01Gui::Listbox*, std::vector<content::Player*>, std::string, std::vector<std::string>);
~ConsoleCommand();
void execute();
private:
Listbox *listbox;
void printConsoleMessage(irr::core::stringw);
vb01Gui::Listbox *listbox;
void printConsoleMessage(std::string);
std::vector<content::Player*> players;
irr::core::stringw name;
std::vector<stringw> arguments;
irr::core::stringw commandList[2]={"addUnit","debugUnits"};
std::string name;
std::vector<std::string> arguments;
std::string commandList[2] = {"addUnit","debugUnits"};
// #0
void addUnit();
// #1
+8 -6
View File
@@ -1,3 +1,5 @@
#include <quaternion.h>
#include "cruiser.h"
#include "cruiserData.h"
#include "guidedMissile.h"
@@ -5,21 +7,21 @@
#include "projectileData.h"
using namespace game::core;
using namespace irr::core;
using namespace game::util;
using namespace vb01;
namespace game{
namespace content{
Cruiser::Cruiser(Player *player, vector3df pos, int id) : Vessel(player, pos, id) {
Cruiser::Cruiser(Player *player, Vector3 pos, int id) : Vessel(player, pos, id) {
guidedMissiles = unitData::maxGuidedMissiles[id];
}
void Cruiser::launch(Order order) {
if (guidedMissiles > 0) {
float angle = 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(this, pos + basePos, *order.targetPos[0], rotQuat * vector3df(0, 1, 0), rotQuat * vector3df(1, 0, 0), rotQuat * vector3df(0, 0, -1), getId(), 1, 0));
float angle = order.targetPos[0]->getAngleBetween(dirVec);
Quaternion rotQuat = Quaternion(dirVec.x < 0 ? angle : -angle, Vector3(0, 1, 0));
Vector3 basePos = leftVec * projectileData::pos[getId()][1][guidedMissiles - 1].x + upVec * projectileData::pos[getId()][1][guidedMissiles - 1].y - dirVec * projectileData::pos[getId()][1][guidedMissiles - 1].z;
addProjectile(new GuidedMissile(this, pos + basePos, *order.targetPos[0], rotQuat * Vector3(0, 1, 0), rotQuat * Vector3(1, 0, 0), rotQuat * Vector3(0, 0, -1), getId(), 1, 0));
removeOrder(0);
// guidedMissiles--;
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace game
namespace content {
class Cruiser : public Vessel {
public:
Cruiser(Player*,vector3df, int);
Cruiser(Player*, vb01::Vector3, int);
void launch(Order);
private:
bool canFire();
+72 -72
View File
@@ -1,63 +1,63 @@
#pragma once
#ifndef DEF_CONFIGS_H
#define DEF_CONFIGS_H
#include <irrlicht.h>
#include <string>
#include <glfw3.h>
#include "key.h"
namespace game{
namespace core{
const irr::io::path PATH = "/home/dominykas/c++/Battleship/Assets/";
const std::string PATH = "/home/dominykas/c++/Battleship/Assets/";
const std::string PATH_STR = "/home/dominykas/c++/Battleship/Assets/";
const std::string DEFAULT_TEXTURE = PATH + "Textures/defaultTexture.jpg";
const double camPanSpeed = .1;
const irr::io::path DEFAULT_TEXTURE = PATH + "Textures/defaultTexture.jpg";
const static int numAppStates=3,numMaxBinds=23;
static const int numBinds[numAppStates]{12,1,23};
static const int numConfBinds[numAppStates]{0,1,13};
const static Bind binds[numAppStates][numMaxBinds]{
const static int numAppStates = 3, numMaxBinds = 23;
static const int numBinds[numAppStates]{12, 1, 23};
static const int numConfBinds[numAppStates]{0, 1, 13};
const static Mapping::Bind binds[numAppStates][numMaxBinds]{
{
LEFT_CLICK,
SCROLLING_UP,
SCROLLING_DOWN,
LEFT,
RIGHT,
DELETE_CHAR,
CAPS_LOCK,
SHIFT_CAPS,
SPACE,
PLUS,
MINUS,
DEVSTERISK
Mapping::LEFT_CLICK,
Mapping::SCROLLING_UP,
Mapping::SCROLLING_DOWN,
Mapping::LEFT,
Mapping::RIGHT,
Mapping::DELETE_CHAR,
Mapping::CAPS_LOCK,
Mapping::SHIFT_CAPS,
Mapping::SPACE,
Mapping::PLUS,
Mapping::MINUS,
Mapping::DEVSTERISK
},
{
TOGGLE_MAIN_MENU
Mapping::TOGGLE_MAIN_MENU
},
{
HALT,
ZOOM_IN,
ZOOM_OUT,
LOOK_AROUND,
DRAG_BOX,
DESELECT,
LEFT_CONTROL,
LEFT_SHIFT,
SELECT_PATROL_POINTS,
LAUNCH,
TOGGLE_SUB,
INSTALL_AAM,
INSTALL_AWM,
GROUP_0,
GROUP_1,
GROUP_2,
GROUP_3,
GROUP_4,
GROUP_5,
GROUP_6,
GROUP_7,
GROUP_8,
GROUP_9
Mapping::HALT,
Mapping::ZOOM_IN,
Mapping::ZOOM_OUT,
Mapping::LOOK_AROUND,
Mapping::DRAG_BOX,
Mapping::DESELECT,
Mapping::LEFT_CONTROL,
Mapping::LEFT_SHIFT,
Mapping::SELECT_PATROL_POINTS,
Mapping::LAUNCH,
Mapping::TOGGLE_SUB,
Mapping::INSTALL_AAM,
Mapping::INSTALL_AWM,
Mapping::GROUP_0,
Mapping::GROUP_1,
Mapping::GROUP_2,
Mapping::GROUP_3,
Mapping::GROUP_4,
Mapping::GROUP_5,
Mapping::GROUP_6,
Mapping::GROUP_7,
Mapping::GROUP_8,
Mapping::GROUP_9
}
};
const static int triggers[numAppStates][numMaxBinds]{
@@ -65,44 +65,44 @@ namespace game{
0,
3,
4,
irr::KEY_LEFT,
irr::KEY_RIGHT,
irr::KEY_BACK,
irr::KEY_CAPITAL,
irr::KEY_LSHIFT,
irr::KEY_SPACE,
irr::KEY_PLUS,
irr::KEY_MINUS,
irr::KEY_OEM_3
GLFW_KEY_LEFT,
GLFW_KEY_RIGHT,
GLFW_KEY_BACKSPACE,
GLFW_KEY_CAPS_LOCK,
GLFW_KEY_LEFT_SHIFT,
GLFW_KEY_SPACE,
GLFW_KEY_KP_ADD,
GLFW_KEY_MINUS,
GLFW_KEY_3
},
{
irr::KEY_ESCAPE
GLFW_KEY_ESCAPE
},
{
irr::KEY_KEY_H,
GLFW_KEY_H,
3,
4,
1,
0,
2,
irr::KEY_LCONTROL,
irr::KEY_LSHIFT,
irr::KEY_KEY_P,
irr::KEY_KEY_C,
irr::KEY_KEY_S,
irr::KEY_KEY_A,
irr::KEY_KEY_W,
irr::KEY_KEY_0,
irr::KEY_KEY_1,
irr::KEY_KEY_2,
irr::KEY_KEY_3,
irr::KEY_KEY_4,
irr::KEY_KEY_5,
irr::KEY_KEY_6,
irr::KEY_KEY_7,
irr::KEY_KEY_8,
irr::KEY_KEY_9
GLFW_KEY_LEFT_CONTROL,
GLFW_KEY_LEFT_SHIFT,
GLFW_KEY_P,
GLFW_KEY_C,
GLFW_KEY_S,
GLFW_KEY_A,
GLFW_KEY_W,
GLFW_KEY_0,
GLFW_KEY_1,
GLFW_KEY_2,
GLFW_KEY_3,
GLFW_KEY_4,
GLFW_KEY_5,
GLFW_KEY_6,
GLFW_KEY_7,
GLFW_KEY_8,
GLFW_KEY_9
}
};
const static bool isKey[numAppStates][numMaxBinds]{
+16 -10
View File
@@ -1,3 +1,5 @@
#include <quaternion.h>
#include "demoJet.h"
#include "inGameAppState.h"
#include "stateManager.h"
@@ -5,19 +7,21 @@
using namespace game::core;
using namespace game::util;
using namespace vb01;
namespace game{
namespace content{
DemoJet::DemoJet(Player *player,vector3df pos, int id, bool onBoard) : Jet(player,pos, id,onBoard) {}
DemoJet::DemoJet(Player *player, Vector3 pos, int id, bool onBoard) : Jet(player, pos, id,onBoard) {}
void DemoJet::attack(Order order){
if(!onBoard){
Unit::attack(order);
vector3df target=*order.targetPos[0];
float angle=getAngleBetween(dirVec,target-pos);
vector3df axis=dirVec.crossProduct(target-pos);
if(maxTurnAngle<angle/PI*180){
quaternion rotQuat=quaternion(0,0,0,0).fromAngleAxis(maxTurnAngle/180*PI,axis);
Vector3 target = *order.targetPos[0];
float angle = dirVec.getAngleBetween(target - pos);
Vector3 axis = dirVec.cross(target - pos);
if(maxTurnAngle < angle / PI * 180){
Quaternion rotQuat = Quaternion(maxTurnAngle / 180 * PI, axis);
orientUnit(rotQuat*dirVec);
}
}
@@ -29,21 +33,23 @@ namespace game{
Jet::update();
if(!onBoard&&!orders.empty()&&orders[0].type==Order::TYPE::ATTACK){
GameManager *gm = GameManager::getSingleton();
/*
ISceneManager *smgr = gm->getDevice()->getSceneManager();
ISceneNode *collNode = castRay(smgr,pos,pos+dirVec*length);
if(collNode&&collNode!=node){
InGameAppState *inGameState=((InGameAppState*)gm->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
if(collNode && collNode != node){
InGameAppState *inGameState = ((InGameAppState*)gm->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
for(Player *p : inGameState->getPlayers())
for(Unit *u : p->getUnits())
if(u->getNode()==collNode)
if(u->getNode() == collNode)
u->takeDamage(damage);
blowUp();
}
else if(pos.Y<0)
else if(pos.y<0)
blowUp();
*/
}
}
}
+3 -3
View File
@@ -9,12 +9,12 @@ namespace game{
namespace content {
class DemoJet : public Jet {
public:
DemoJet(Player*,vector3df, int, bool = 1);
DemoJet(Player*, vb01::Vector3, int, bool = 1);
void attack(Order);
void update();
private:
float length=1;
int damage=250;
float length = 1;
int damage = 250;
};
}
}
+20 -17
View File
@@ -1,3 +1,5 @@
#include <model.h>
#include "depthCharge.h"
#include "stateManager.h"
#include "inGameAppState.h"
@@ -5,52 +7,53 @@
using namespace game::core;
using namespace game::util;
using namespace irr::core;
using namespace irr::scene;
using namespace vb01;
namespace game{
namespace content{
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();
DepthCharge::DepthCharge(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
speed = 0;
initTime = getTime();
}
void DepthCharge::update(){
//x=x0+vX+a*t*t/2
//y=y0+vY-g*t*t/2
float t = float(getTime() - initTime) / 1000;
pos = initPos + dirVec * speed + vector3df(0, speed * t - .5 * g * t * t, 0);
pos = initPos + dirVec * speed + Vector3(0, speed * t - .5 * g * t * t, 0);
node->setPosition(pos);
checkForCollision();
}
void DepthCharge::checkForCollision() {
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
ISceneNode *collNode=nullptr;
bool detonated=false;
Node *collNode = nullptr;
bool detonated = false;
if(pos.Y<-10)
detonated=true;
if(pos.y < -10)
detonated = true;
if(!detonated)
for(Player *p : inGameState->getPlayers())
for(Unit *u : p->getUnits()){
if(u==unit) continue;
if(u == unit) continue;
vector3df p0=u->getCorner(0);
vector3df p1=u->getCorner(1);
vector3df p3=u->getCorner(3);
vector3df p4=u->getCorner(4);
Vector3 p0 = u->getCorner(0);
Vector3 p1 = u->getCorner(1);
Vector3 p3 = u->getCorner(3);
Vector3 p4 = u->getCorner(4);
/*
if(isWithinCuboid(p0,p1,p3,p4,pos)){
detonated=true;
collNode=u->getNode();
}
*/
}
if(detonated)
explode(collNode);
}
void DepthCharge::explode(ISceneNode *collNode) {
void DepthCharge::explode(Node *collNode) {
Projectile::explode(collNode);
}
}
+2 -2
View File
@@ -8,11 +8,11 @@ namespace game{
namespace content{
class DepthCharge : public Projectile {
public:
DepthCharge(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
DepthCharge(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
void update();
private:
s64 initTime;
void explode(irr::scene::ISceneNode*);
void explode(vb01::Node*);
void checkForCollision();
};
}
+29 -21
View File
@@ -10,58 +10,66 @@
#include "util.h"
using namespace std;
using namespace vb01;
using namespace game::core;
using namespace game::util;
using namespace game::content::unitData;
namespace game{
namespace content{
Destroyer::Destroyer(Player *player,vector3df pos,int id) :Vessel(player,pos, id) {
this->maxDepthCharges=unitData::maxDepthCharges[id];
depthCharges=maxDepthCharges;
this->rateOfDrops=unitData::rateOfDrops[id];
this->reloadRate=unitData::reloadRate[id];
this->maxDepthChargeDropRange=unitData::maxDepthChargeDropRange[id];
Destroyer::Destroyer(Player *player, vb01::Vector3 pos,int id) : Vessel(player, pos, id) {
this->maxDepthCharges = unitData::maxDepthCharges[id];
depthCharges = maxDepthCharges;
this->rateOfDrops = unitData::rateOfDrops[id];
this->reloadRate = unitData::reloadRate[id];
this->maxDepthChargeDropRange = unitData::maxDepthChargeDropRange[id];
}
void Destroyer::update(){
Vessel::update();
reload();
}
void Destroyer::attack(Order order){
vector3df t=*order.targetPos[0];
Vector3 t = *order.targetPos[0];
bool sub=false;
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())
sub=true;
if(u->getType() == UNIT_TYPE::SUBMARINE&&order.targetPos[0] == u->getPosPtr())
sub = true;
if(sub)
dropDepthCharge();
else
Vessel::attack(order);
}
void Destroyer::dropDepthCharge() {
if(canDropDepthCharge()){
float angle=rand()%360;
float radius=1;
vector3df offsetVec=vector3df(cos(angle),0,sin(angle))*radius;
addProjectile(new DepthCharge(this,pos+projectileData::pos[id][1][1]+offsetVec,dirVec,leftVec,upVec,id,1,0));
lastDropTime=getTime();
if(depthCharges==maxDepthCharges)
reloadStartTime=getTime();
float angle = rand() % 360;
float radius = 1;
Vector3 offsetVec = Vector3(cos(angle), 0, sin(angle)) * radius;
addProjectile(new DepthCharge(this, pos + projectileData::pos[id][1][1] + offsetVec, dirVec, leftVec, upVec, id, 1, 0));
lastDropTime = getTime();
if(depthCharges == maxDepthCharges)
reloadStartTime = getTime();
}
}
void Destroyer::reload(){
if(depthCharges<maxDepthCharges){
reloading=true;
if(getTime()-reloadStartTime>reloadRate) {
reloadStartTime+=reloadRate;
if(depthCharges < maxDepthCharges){
reloading = true;
if(getTime() - reloadStartTime > reloadRate) {
reloadStartTime += reloadRate;
depthCharges++;
}
}
else
reloading=false;
reloading = false;
}
}
}
+3 -3
View File
@@ -12,17 +12,17 @@ namespace game
namespace content {
class Destroyer : public Vessel {
public:
Destroyer(Player*,vector3df, int);
Destroyer(Player*, vb01::Vector3, int);
void dropDepthCharge();
void attack(Order);
void update();
private:
void reload();
inline bool canDropDepthCharge(){return util::getTime()-lastDropTime>rateOfDrops;}
inline bool canDropDepthCharge(){return vb01::getTime() - lastDropTime > rateOfDrops;}
bool reloading = false;
float maxDepthChargeDropRange;
int depthCharges, maxDepthCharges, rateOfDrops, reloadRate;
s64 lastShotTime=0, reloadStartTime=0,lastDropTime=0;
s64 lastShotTime = 0, reloadStartTime = 0, lastDropTime = 0;
};
}
}
+108 -91
View File
@@ -1,109 +1,126 @@
#include <cmath>
#include "eventListener.h"
#include "stateManager.h"
using namespace irr;
using namespace std;
namespace game{
namespace core{
EventListener::EventListener(GameManager* gM) {
gameManager = gM;
}
double *posX,*posY,strX,strY;
int width,height;
void foo(GLFWwindow *window,double newPosX,double newPosY){
strX=(*posX-newPosX)/width,strY=(newPosY-*posY)/height;
}
EventListener::~EventListener() {}
InputManager::InputManager(GLFWwindow *window){
this->stateManager = GameManager::getSingleton()->getStateManager();
this->window = window;
posX = new double, posY = new double;
}
bool EventListener::OnEvent(const SEvent& event) {
int offsetTrigger = -1;
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
InputManager::~InputManager(){}
if (event.EventType == EET_KEY_INPUT_EVENT) {
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;
void InputManager::update(){
GameManager *gm = GameManager::getSingleton();
width = gm->getWidth(), height = gm->getHeight();
if (!k->beingUsed) {
if (event.KeyInput.PressedDown)
k->beingUsed=true;
glfwGetCursorPos(window,posX,posY);
int joystick;
int numAxis=3,numButtons=6;
const u8 *buttons;
const float *axis;
k->pressed=event.KeyInput.PressedDown;
stateManager->getAppState(i)->onAction(k->bind, k->pressed);
}
} else {
k->pressed=event.KeyInput.PressedDown;
stateManager->getAppState(i)->onAnalog(k->bind, 0.);
}
}
if(glfwJoystickPresent(GLFW_JOYSTICK_1)){
joystick = GLFW_JOYSTICK_1;
axis = glfwGetJoystickAxes(joystick, &numAxis);
buttons = glfwGetJoystickButtons(joystick, &numButtons);
}
stateManager->getAppState(i)->onRawKeyPress(event.KeyInput);
}
}
}
else if (event.EventType == EET_MOUSE_INPUT_EVENT && event.MouseInput.Event != EMIE_MOUSE_MOVED) {
bool isPressed = false;
switch (event.MouseInput.Event) {
case EMIE_LMOUSE_PRESSED_DOWN:
offsetTrigger = 0;
isPressed = true;
break;
case EMIE_LMOUSE_LEFT_UP:
offsetTrigger = 0;
isPressed = false;
break;
case EMIE_MMOUSE_PRESSED_DOWN:
offsetTrigger = 1;
isPressed = true;
break;
case EMIE_MMOUSE_LEFT_UP:
offsetTrigger = 1;
isPressed = false;
break;
case EMIE_RMOUSE_PRESSED_DOWN:
offsetTrigger = 2;
isPressed = true;
break;
case EMIE_RMOUSE_LEFT_UP:
offsetTrigger = 2;
isPressed = false;
break;
case EMIE_MOUSE_WHEEL:
if (event.MouseInput.Wheel == 1)
offsetTrigger = 3;
else
offsetTrigger = 4;
break;
}
for(int j = 0; j < stateManager->getAppStates().size(); j++){
AbstractAppState *a = stateManager->getAppStates()[j];
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;
stateManager->getAppState(i)->onAction(k->bind, k->pressed);
} else {
k->beingUsed=isPressed;
}
}
for(int i = 0; i < a->getKeysNumber(); i++){
Mapping *m = a->getKey(i);
if(offsetTrigger<=2)
stateManager->getAppState(i)->onRawMousePress(event.MouseInput);
}
}
}
return false;
}
if(m->action){
bool pressed;
void EventListener::update() {
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
switch(m->type){
case Mapping::KEYBOARD:
pressed=glfwGetKey(window,m->trigger);
break;
case Mapping::MOUSE_KEY:
pressed=glfwGetMouseButton(window,m->trigger);
break;
case Mapping::JOYSTICK_KEY:
if(glfwJoystickPresent(GLFW_JOYSTICK_1)){
pressed=buttons[m->trigger];
}
break;
}
for (int i = 0; i < stateManager->getAppStateNumber(); i++) {
for (Key *k : stateManager->getAppState(i)->getKeys()) {
if (k->beingUsed && k->analog) {
stateManager->getAppState(i)->onAnalog(k->bind, 0.);
}
}
}
}
if((pressed&&!m->pressed)||(!pressed&&m->pressed)){
m->pressed=pressed;
a->onAction(m->bind,pressed);
}
}
else{
switch(m->type){
case Mapping::MOUSE_AXIS:
{
float str;
switch(m->trigger){
case Mapping::MOUSE_AXIS_LEFT:
case Mapping::MOUSE_AXIS_RIGHT:
str=strX;
break;
case Mapping::MOUSE_AXIS_UP:
case Mapping::MOUSE_AXIS_DOWN:
str=strY;
break;
}
a->onAnalog(m->bind,str);
break;
}
case Mapping::JOYSTICK_AXIS:
{
int axisId = (m->trigger - (m->trigger % 2 > 0)) / 2;
float str = fabs(axis[axisId]) >= .1 ? axis[axisId] : 0;
if(fabs(str)>0)
a->onAnalog(m->bind,str);
break;
}
}
}
}
/*
for(int i=0;i<350;i++){
if(glfwGetKey(window,i))
a->onRawKeyButton(i);
else if(glfwGetMouseButton(window,i))
a->onRawMouseButton(i);
}
*/
glfwSetCursorPosCallback(window,foo);
/*
if(glfwJoystickPresent(GLFW_JOYSTICK_1)){
for(int i=0;i<numAxis;i++)
if(abs(axis[i])==1)
a->onRawJoystickAxis(i,axis[i]);
for(int i=0;i<numButtons;i++)
if(buttons[i])
a->onRawJoystickButton(i);
}
*/
}
}
}
}
+11 -6
View File
@@ -3,18 +3,23 @@
#include "gameManager.h"
class GLFWwindow;
namespace game{
namespace core{
class EventListener : public irr::IEventReceiver {
class StateManager;
class InputManager {
public:
EventListener(GameManager*);
~EventListener();
virtual bool OnEvent(const irr::SEvent&);
InputManager(GLFWwindow*);
~InputManager();
//virtual bool OnEvent(const irr::SEvent&);
void update();
private:
irr::SEvent* event;
//irr::SEvent* event;
GLFWwindow *window = nullptr;
StateManager *stateManager = nullptr;
bool keyEvent = false, mouseEvent = false;
GameManager* gameManager;
};
}
}
+5 -4
View File
@@ -1,16 +1,17 @@
#include "exitButton.h"
#include <root.h>
using namespace irr::core;
using namespace game::core;
using namespace std;
using namespace vb01;
namespace game
{
namespace gui{
ExitButton::ExitButton(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
ExitButton::ExitButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
}
void ExitButton::onClick() {
GameManager::getSingleton()->getDevice()->closeDevice();
//Root::getSingleton()->set
}
}
}
+4 -3
View File
@@ -2,14 +2,15 @@
#ifndef EXIT_BUTTON_H
#define EXIT_BUTTON_H
#include "button.h"
#include <button.h>
#include <vector.h>
namespace game
{
namespace gui {
class ExitButton : public Button {
class ExitButton : public vb01Gui::Button {
public:
ExitButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ExitButton(vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
};
}
+32 -29
View File
@@ -4,57 +4,60 @@
#include "util.h"
#include "inGameAppState.h"
using namespace irr::io;
using namespace irr::core;
using namespace irr::video;
using namespace irr::scene;
using namespace game::util;
using namespace sf;
using namespace std;
using namespace vb01;
namespace game{
namespace content{
void detonate(InGameAppState *inGameState,vector3df pos,vector3df dir){
SoundBuffer *sfxBuffer=new SoundBuffer();
Sound *sfx=nullptr;
path p=PATH+"Sounds/Explosions/explosion0"+stringw(rand()%4)+".ogg";
void detonate(InGameAppState *inGameState, Vector3 pos, Vector3 dir){
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = nullptr;
string p = PATH + "Sounds/Explosions/explosion0" + to_string(rand() % 4) + ".ogg";
if(sfxBuffer->loadFromFile(p.c_str())){
sfx=new Sound(*sfxBuffer);
sfx = new sf::Sound(*sfxBuffer);
sfx->play();
}
Fx fx;
fx.initTime=getTime();
fx.time=2500;
fx.sfx=sfx;
fx.initTime = getTime();
fx.time = 2500;
fx.sfx = sfx;
inGameState->addFx(fx);
}
void detonateDepthCharge(core::InGameAppState *inGameState, irr::core::vector3df){
SoundBuffer *sfxBuffer=new SoundBuffer();
Sound *sfx=nullptr;
path p=PATH+"Sounds/Destroyers/depthCharge.ogg";
void detonateDepthCharge(core::InGameAppState *inGameState, Vector3){
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = nullptr;
string p = PATH + "Sounds/Destroyers/depthCharge.ogg";
if(sfxBuffer->loadFromFile(p.c_str())){
sfx=new Sound(*sfxBuffer);
sfx = new sf::Sound(*sfxBuffer);
sfx->play();
}
Fx fx;
fx.initTime=getTime();
fx.time=2000;
fx.sfx=sfx;
fx.initTime = getTime();
fx.time = 2000;
fx.sfx = sfx;
inGameState->addFx(fx);
}
void detonateTorpedo(core::InGameAppState *inGameState, irr::core::vector3df){
SoundBuffer *sfxBuffer=new SoundBuffer();
Sound *sfx=nullptr;
path p=PATH+"Sounds/Submarines/torpedo.ogg";
void detonateTorpedo(core::InGameAppState *inGameState, Vector3){
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
sf::Sound *sfx = nullptr;
string p = PATH + "Sounds/Submarines/torpedo.ogg";
if(sfxBuffer->loadFromFile(p.c_str())){
sfx=new Sound(*sfxBuffer);
sfx = new sf::Sound(*sfxBuffer);
sfx->play();
}
Fx fx;
fx.initTime=getTime();
fx.time=250;
fx.sfx=sfx;
fx.initTime = getTime();
fx.time = 250;
fx.sfx = sfx;
inGameState->addFx(fx);
}
}
+4 -4
View File
@@ -2,16 +2,16 @@
#ifndef EXPLOSION_H
#define EXPLOSION_H
#include <irrlicht.h>
#include <vector.h>
namespace game{
namespace core{
class InGameAppState;
}
namespace content{
void detonate(core::InGameAppState*,irr::core::vector3df,irr::core::vector3df);
void detonateDepthCharge(core::InGameAppState*,irr::core::vector3df);
void detonateTorpedo(core::InGameAppState*,irr::core::vector3df);
void detonate(core::InGameAppState*, vb01::Vector3, vb01::Vector3);
void detonateDepthCharge(core::InGameAppState*, vb01::Vector3);
void detonateTorpedo(core::InGameAppState*, vb01::Vector3);
}
}
+10 -16
View File
@@ -1,16 +1,14 @@
#include <algorithm>
#include <irrlicht.h>
#include <root.h>
#include "gameManager.h"
#include "guiAppState.h"
#include "stateManager.h"
#include "eventListener.h"
#include "abstractBitmapText.h"
#include "abstractImage.h"
using namespace std;
using namespace game::gui;
using namespace irr;
using namespace vb01;
namespace game{
namespace core{
@@ -24,22 +22,15 @@ namespace game{
}
GameManager::GameManager() {
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;
height = device->getVideoDriver()->getScreenSize().Height;
Root *root = Root::getSingleton();
root->start(800, 600, "Battleship", "../vb01");
}
GameManager::~GameManager() {}
/*
stateManager = new StateManager();
listener = new EventListener(this);
void GameManager::detachBitmapText(AbstractBitmapText *bitmapText) {
for (int i = 0; i < bitmapTexts.size(); i++)
if (bitmapText == bitmapTexts[i]) {
@@ -69,16 +60,19 @@ namespace game{
images.pop_back();
}
}
*/
void GameManager::update() {
listener->update();
stateManager->update();
/*
for (BitmapText *b : bitmapTexts)
b->update();
for (Image *i : images)
i->update();
*/
}
}
}
+3 -8
View File
@@ -7,7 +7,6 @@
#include "key.h"
#include "util.h"
#include <vector>
#include <irrlicht.h>
#include <string>
namespace game{
@@ -20,7 +19,7 @@ namespace game{
typedef gui::AbstractImage Image;
namespace core{
class EventListener;
class InputManager;
class StateManager;
class GameManager {
@@ -33,25 +32,21 @@ namespace game{
void detachImage(gui::AbstractImage*);
void detachAllImages();
void update();
inline irr::IrrlichtDevice* getDevice(){return device;}
inline irr::scene::ISceneManager* getSceneManager(){return device->getSceneManager();}
inline void setDevice(irr::IrrlichtDevice *d){this->device=d;}
inline int getWidth(){return width;}
inline int getHeight(){return height;}
inline EventListener* getListener(){return listener;}
inline InputManager* 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;
std::vector<gui::AbstractImage*> images;
EventListener *listener = nullptr;
InputManager *listener = nullptr;
bool serverSide;
};
+61 -36
View File
@@ -1,15 +1,17 @@
#include <sstream>
#include <vector.h>
#include "gameManager.h"
#include "guiAppState.h"
using namespace game::gui;
using namespace irr;
using namespace irr::core;
using namespace vb01;
using namespace vb01Gui;
using namespace std;
namespace game{
namespace core{
irr::u16 mousePos[2]{};
Vector2 mousePos;
GuiAppState::GuiAppState() {
type = AppStateTypes::GUI_STATE;
@@ -19,16 +21,19 @@ namespace game{
void GuiAppState::update() {
GameManager *gm = GameManager::getSingleton();
/*
mousePos[0] = gm->getDevice()->getCursorControl()->getPosition().X;
mousePos[1] = gm->getDevice()->getCursorControl()->getPosition().Y;
*/
for (Button *b : buttons) {
if (b->isSeparate())
b->update();
bool withinX=mousePos[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;
bool withinX=mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
bool withinY=mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
/*
if(withinX&&withinY)
b->onMouseOver();
else
@@ -36,6 +41,7 @@ namespace game{
b->setMouseOverDone(withinX&&withinY);
b->setMouseAwayDone(!(withinX&&withinY));
*/
}
for (Listbox *l : listboxes)
@@ -56,43 +62,47 @@ namespace game{
void GuiAppState::onAttachment() {
AbstractAppState::onAttachment();
GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(true);
//GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(true);
attachKeyboardKeys();
}
void GuiAppState::onDetachment() {
AbstractAppState::onDetachment();
AbstractAppState::detachAllKeys();
GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(false);
//GameManager::getSingleton()->getDevice()->getCursorControl()->setVisible(false);
}
void GuiAppState::attachKeyboardKeys() {
int firstId=Bind::LAST_BIND+1,lastId=firstId+numKeys;
/*
int firstId = Bind::LAST_BIND + 1, lastId = firstId + numKeys;
for (int i = firstId; i <= lastId; i++){
int offset=i-firstId;
int trigger=offset<10?int(irr::KEY_KEY_0)+offset:int(irr::KEY_KEY_A)+offset-10;
int trigger = offset < 10 ? int(irr::KEY_KEY_0)+offset:int(irr::KEY_KEY_A)+offset-10;
AbstractAppState::attachKey(new Key((Bind)i, trigger, true, false));
}
*/
}
void GuiAppState::onAction(Bind bind, bool isPressed) {
void GuiAppState::onAction(Mapping::Bind bind, bool isPressed) {
switch(bind){
case LEFT_CLICK:
case Mapping::LEFT_CLICK:
if(isPressed)
for (int i=0;i<buttons.size();i++) {
Button *b=buttons[i];
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;
bool withinX=mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
bool withinY=mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
if (withinX&&withinY)
b->onClick();
}
break;
case SCROLLING_UP:
case Mapping::SCROLLING_UP:
for (Listbox *l : listboxes)
if (l->isOpen())
l->scrollUp();
break;
case SCROLLING_DOWN:
case Mapping::SCROLLING_DOWN:
for (Listbox *l : listboxes)
if (l->isOpen())
l->scrollDown();
@@ -101,44 +111,46 @@ namespace game{
Textbox *t = getOpenTextbox();
if (t)
switch(bind){
case SHIFT_CAPS:
case Mapping::SHIFT_CAPS:
shiftPressed = !shiftPressed;
t->setIsCapitalLeters(isPressed);
//t->setIsCapitalLeters(isPressed);
break;
case LEFT:
if(isPressed)t->moveCursor(true);
case Mapping::LEFT:
//if(isPressed)t->moveCursor(true);
break;
case RIGHT:
if(isPressed)t->moveCursor(false);
case Mapping::RIGHT:
//if(isPressed)t->moveCursor(false);
break;
case CAPS_LOCK:
if(isPressed)t->setIsCapitalLeters(!t->isCapitalLeters());
case Mapping::CAPS_LOCK:
//if(isPressed)t->setIsCapitalLeters(!t->isCapitalLeters());
break;
case SPACE:
case Mapping::SPACE:
if(isPressed)t->type(' ');
break;
case DELETE_CHAR:
case Mapping::DELETE_CHAR:
if(isPressed)t->deleteCharacter();
break;
case PLUS:
case Mapping::PLUS:
if(isPressed) t->type(shiftPressed?'+':'=');
break;
case MINUS:
case Mapping::MINUS:
if(isPressed) t->type(shiftPressed?'_':'-');
break;
case DEVSTERISK:
case Mapping::DEVSTERISK:
if(isPressed) t->type(shiftPressed?'~':'`');
break;
default:
if(bind>LAST_BIND)checkKeyboard(t, bind, isPressed);
if(bind>Mapping::LAST_BIND)checkKeyboard(t, bind, isPressed);
}
}
void GuiAppState::checkKeyboard(Textbox *t, Bind bind, bool isPressed) {
int firstId=Bind::LAST_BIND+1,lastId=firstId+numKeys;
void GuiAppState::checkKeyboard(Textbox *t, Mapping::Bind bind, bool isPressed) {
int firstId = Mapping::Bind::LAST_BIND+1,lastId=firstId+numKeys;
for (int i = firstId; i <= lastId; i++) {
int offset=i-firstId;
char c = keyChars[offset];
if (bind==i&&isPressed) {
if (shiftPressed) {
switch(offset){
@@ -174,6 +186,7 @@ namespace game{
break;
}
}
t->type(c);
}
}
@@ -181,22 +194,27 @@ namespace game{
void GuiAppState::updateControlsListbox(int trigger){
Listbox *controlsListbox=nullptr;
for(Listbox *l : listboxes)
if(l->isOpen()&&l->isControlsListbox())
if(l->isOpen() /*&& l->isControlsListbox()*/)
controlsListbox=l;
if(controlsListbox){
int selectedOption=controlsListbox->getSelectedOption(),colonId=-1;
stringw line=controlsListbox->getLine(selectedOption);
wstring line = controlsListbox->getContents()[selectedOption];
for(int i=0;i<line.size()&&colonId==-1;i++)
if(line.c_str()[i]==':')
colonId=i;
stringstream ss;
ss<<hex<<trigger;
line=line.subString(0,colonId+1)+stringw("0x")+stringw(ss.str().c_str());
line=line.substr(0,colonId+1)+L"0x"/*+ss.str().c_str()*/;
controlsListbox->changeLine(selectedOption,line);
}
}
/*
void GuiAppState::onRawKeyPress(SEvent::SKeyInput event){
updateControlsListbox(event.Key);
}
@@ -209,6 +227,7 @@ namespace game{
trigger=2;
updateControlsListbox(trigger);
}
*/
Textbox* GuiAppState::getOpenTextbox() {
Textbox* t = nullptr;
@@ -232,7 +251,7 @@ namespace game{
return nullptr;
}
void GuiAppState::onAnalog(Bind bind, double strength) {}
void GuiAppState::onAnalog(Mapping::Bind bind, double strength) {}
void GuiAppState::addButton(Button* b) {
buttons.push_back(b);
@@ -266,20 +285,26 @@ namespace game{
void GuiAppState::removeButton(Button *b) {
for (int i = 0; i < buttons.size(); i++) {
if (b == buttons[i]) {
/*
if (b->isImageButton())
GameManager::getSingleton()->detachImage(b->getImage());
*/
delete b;
buttons.erase(buttons.begin() + i);
}
}
}
void GuiAppState::removeButton(stringw name) {
void GuiAppState::removeButton(string name) {
for (int i = 0; i < buttons.size(); i++) {
if (name == buttons[i]->getName() && buttons[i]->isSeparate()) {
/*
if (buttons[i]->isImageButton())
GameManager::getSingleton()->detachImage(buttons[i]->getImage());
*/
delete buttons[i];
buttons.erase(buttons.begin() + i);
}
}
+33 -29
View File
@@ -2,15 +2,17 @@
#ifndef GUI_APP_STATE_H
#define GUI_APP_STATE_H
#include "gameManager.h"
#include "button.h"
#include "listbox.h"
#include "checkbox.h"
#include "textbox.h"
#include "slider.h"
#include "tooltip.h"
#include <button.h>
#include <listbox.h>
#include <checkbox.h>
#include <textbox.h>
#include <slider.h>
#include <vector>
#include "abstractAppState.h"
#include "tooltip.h"
#include "key.h"
namespace game{
namespace core{
class GuiAppState : public AbstractAppState {
@@ -20,20 +22,20 @@ namespace game{
void onAttachment();
void onDetachment();
void update();
void addButton(gui::Button*);
void removeButton(gui::Button*);
void removeSeparateButton(gui::Button*);
void removeButton(irr::core::stringw);
void addListbox(gui::Listbox*);
void removeListbox(gui::Listbox*);
void addCheckbox(gui::Checkbox*);
void removeCheckbox(gui::Checkbox*);
void addTextbox(gui::Textbox*);
void removeTextbox(gui::Textbox*);
void addSlider(gui::Slider*);
void addButton(vb01Gui::Button*);
void removeButton(vb01Gui::Button*);
void removeSeparateButton(vb01Gui::Button*);
void removeButton(std::string);
void addListbox(vb01Gui::Listbox*);
void removeListbox(vb01Gui::Listbox*);
void addCheckbox(vb01Gui::Checkbox*);
void removeCheckbox(vb01Gui::Checkbox*);
void addTextbox(vb01Gui::Textbox*);
void removeTextbox(vb01Gui::Textbox*);
void addSlider(vb01Gui::Slider*);
void addTooltip(gui::Tooltip*);
void removeTooltip(gui::Tooltip*);
void removeSlider(gui::Slider*);
void removeSlider(vb01Gui::Slider*);
void removeAllButtons();
void removeAllListboxes();
void removeAllCheckboxes();
@@ -42,22 +44,24 @@ namespace game{
void removeAllTooltips();
inline bool isLeftMousePressed(){return leftMousePressed;}
private:
virtual void onAction(Bind, bool);
virtual void onAnalog(Bind, double);
virtual void onAction(Mapping::Bind, bool);
virtual void onAnalog(Mapping::Bind, double);
/*
virtual void onRawKeyPress(irr::SEvent::SKeyInput);
virtual void onRawMousePress(irr::SEvent::SMouseInput);
gui::Textbox* getOpenTextbox();
gui::Listbox* getOpenListbox();
*/
vb01Gui::Textbox* getOpenTextbox();
vb01Gui::Listbox* getOpenListbox();
void attachBindKeys();
void attachKeyboardKeys();
void checkKeyboard(gui::Textbox*, Bind, bool);
void checkKeyboard(vb01Gui::Textbox*, Mapping::Bind, bool);
void updateControlsListbox(int);
std::vector<gui::Button*> buttons;
std::vector<gui::Listbox*> listboxes;
std::vector<gui::Checkbox*> checkboxes;
std::vector<gui::Textbox*> textboxes;
std::vector<gui::Slider*> sliders;
std::vector<vb01Gui::Button*> buttons;
std::vector<vb01Gui::Listbox*> listboxes;
std::vector<vb01Gui::Checkbox*> checkboxes;
std::vector<vb01Gui::Textbox*> textboxes;
std::vector<vb01Gui::Slider*> sliders;
std::vector<gui::Tooltip*> tooltips;
bool leftMousePressed = false, shiftPressed = false;
const static int numKeys=36;
+22 -17
View File
@@ -1,3 +1,5 @@
#include <model.h>
#include "guidedMissile.h"
#include "unit.h"
#include "guidedMissileData.h"
@@ -6,24 +8,27 @@
using namespace game::core;
using namespace game::util;
using namespace game::content;
using namespace irr::core;
using namespace vb01;
using namespace std;
namespace game{
namespace content{
GuidedMissile::GuidedMissile(Unit *unit, vector3df pos, vector3df target, vector3df dirVec, vector3df leftVec, vector3df upVec, int id, int weaponTypeId, int weaponId) :
GuidedMissile::GuidedMissile(Unit *unit, Vector3 pos, Vector3 target, Vector3 dirVec, Vector3 leftVec, Vector3 upVec, int id, int weaponTypeId, int weaponId) :
Projectile(unit, nullptr, pos, dirVec, leftVec, upVec, id, weaponTypeId, weaponId) {
speed = .05;
for (int i = 0; i < 180; i++)
arcLength += speed * cos(turnAngle * i);
this->target = target;
vector3df targVec = vector3df(target.X-initPos.X, 0, target.Z-initPos.Z);
b=targVec.getLength()/2;
x=-b;
dirVec=vector3df(0,1,0);
upVec=-targVec.normalize();
leftVec=quaternion(0,0,0,1).fromAngleAxis(PI/2,dirVec)*upVec;
rayLength=3;
damage=100;
Vector3 targVec = Vector3(target.x - initPos.x, 0, target.z - initPos.z);
b = targVec.getLength() / 2;
x = -b;
dirVec = Vector3(0,1,0);
upVec = -targVec.norm();
leftVec = Quaternion(PI / 2, dirVec) * dirVec;
rayLength = 3;
damage = 100;
}
void GuidedMissile::update() {
@@ -34,18 +39,18 @@ namespace game{
}
void GuidedMissile::updateVecs() {
if(x<b){
vector3df targVec = vector3df(target.X-initPos.X, 0, target.Z-initPos.Z);
pos += targVec.normalize()*speed;
if(x < b){
Vector3 targVec = Vector3(target.x - initPos.x, 0, target.z - initPos.z);
pos = pos + targVec.norm() * speed;
x += speed;
pos.Y=sqrt(1.-x*x/(b*b))*a;
pos.y = sqrt(1. - x * x / (b * b)) * a;
float tanAngle = atan(-a*x/(b*b*sqrt(1.-x*x/(b*b))));
quaternion rotQuat = quaternion().fromAngleAxis(tanAngle, leftVec);
vector3df dirProj=dirVec==vector3df(0,1,0)?upVec:vector3df(dirVec.X,0,dirVec.Z).normalize();
Quaternion rotQuat = Quaternion(tanAngle, leftVec);
Vector3 dirProj = (dirVec == Vector3::VEC_J ? upVec : Vector3(dirVec.x, 0, dirVec.z).norm());
orientProjectile(rotQuat * targVec);
}
else
pos.Y-=speed;
pos.y -= speed;
}
}
}
+2 -2
View File
@@ -8,14 +8,14 @@ namespace game{
namespace content{
class GuidedMissile : public Projectile {
public:
GuidedMissile(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
GuidedMissile(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
~GuidedMissile(){}
void update();
private:
void updateVecs();
bool firstPhase = true;
float a = 4,b,x,turnAngle = 1,arcLength = 0.,maxHeight = 5;
irr::core::vector3df target;
vb01::Vector3 target;
};
}
}
+10 -4
View File
@@ -8,14 +8,20 @@ namespace game
{
namespace content{
namespace projectileData {
const vector3df guidedMissilePos[unitData::numberOfUnits][6]{
const vb01::Vector3 guidedMissilePos[unitData::numberOfUnits][6]{
{},
{},
{},
{},
{ vector3df(0.24482, 1.14985, 1.32775), vector3df(0.24482, 1.14985, 1.62698), vector3df(0.24482, 1.14985, 1.88017),
vector3df(-0.24482, 1.14985, 1.32775), vector3df(-0.24482, 1.14985, 1.62698), vector3df(-0.24482, 1.14985, 1.88017)},
{ vector3df(0.17192, 0.57858, 0.64471), vector3df(-0.17192, 0.57858, 0.64471)}
{
vb01::Vector3(0.24482, 1.14985, 1.32775),
vb01::Vector3(0.24482, 1.14985, 1.62698),
vb01::Vector3(0.24482, 1.14985, 1.88017),
vb01::Vector3(-0.24482, 1.14985, 1.32775),
vb01::Vector3(-0.24482, 1.14985, 1.62698),
vb01::Vector3(-0.24482, 1.14985, 1.88017)
},
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
};
}
}
+65 -48
View File
@@ -1,4 +1,5 @@
#include <algorithm>
#include <button.h>
#include "stateManager.h"
#include "inGameAppState.h"
@@ -9,12 +10,13 @@
using namespace game::gui;
using namespace game::util;
using namespace game::content;
using namespace irr::video;
using namespace vb01;
using namespace vb01Gui;
using namespace std;
namespace game{
namespace core{
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
InGameAppState::ResumeButton::ResumeButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -27,7 +29,7 @@ namespace game{
return guiState;
}
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
InGameAppState::ConsoleButton::ConsoleButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -37,58 +39,67 @@ namespace game{
class ConsoleCommandEntryButton : public Button {
public:
ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
ConsoleCommandEntryButton(InGameAppState *inGameState, Textbox *t, Listbox *l, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->inGameState = inGameState;
textbox = t;
listbox = l;
}
void onClick() {
stringw name;
vector<stringw> args;
wstring name;
vector<string> args;
vector<int> spaceIds;
for (int i = 0; i < textbox->getEntry().size(); i++) {
if (textbox->getEntry()[i] == ' ') {
for (int i = 0; i < textbox->getText().size(); i++) {
if (textbox->getText()[i] == ' ') {
spaceIds.push_back(i);
}
}
if (spaceIds.size() > 0) {
for (int i = 0; i < spaceIds[0]; i++)
name += textbox->getEntry()[i];
name += textbox->getText()[i];
for (int i = 0; i < spaceIds.size() - 1; i++) {
stringw w;
string w;
for (int i2 = spaceIds[i]; i2 < spaceIds[i + 1]; i2++)
w += textbox->getEntry()[i2];
w += textbox->getText()[i2];
args.push_back(w);
}
args.push_back("");
for (int i = spaceIds[spaceIds.size() - 1]; i < textbox->getEntry().size(); i++) {
args[args.size() - 1] += textbox->getEntry()[i];
for (int i = spaceIds[spaceIds.size() - 1]; i < textbox->getText().size(); i++) {
args[args.size() - 1] += textbox->getText()[i];
}
} else
name = textbox->getEntry();
ConsoleCommand c(listbox, inGameState->getPlayerList(), name, args);
name = textbox->getText();
//ConsoleCommand c(listbox, inGameState->getPlayerList(), name, args);
}
private:
InGameAppState *inGameState;
Textbox *textbox;
Listbox *listbox;
};
vector<stringw> list;
vector<string> list;
int emptyEntries = 20;
for (int i = 0; i < emptyEntries; i++)
list.push_back("");
vector2d<s32> pos(300, 100);
Listbox *consoleListbox = new Listbox(vector2d<s32>(pos.X, pos.Y), vector2d<s32>(420, 20), list, 20);
Vector2 pos = Vector2(300, 100);
Listbox *consoleListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(420, 20), list, 20, PATH + "Fonts/batang.ttf");
consoleListbox->openUp();
guiState->addListbox(consoleListbox);
Textbox *consoleTextbox = new Textbox(vector2d<s32>(pos.X, pos.Y + 20 * (emptyEntries + 1)), vector2d<s32>(300, 20));
Textbox *consoleTextbox = new Textbox(Vector2(pos.x, pos.y + 20 * (emptyEntries + 1)), Vector2(300, 20), PATH + "Fonts/batang.ttf");
guiState->addTextbox(consoleTextbox);
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, vector2d<s32>(pos.X + 320, pos.Y + 20 * (emptyEntries + 1)), vector2d<s32>(100, 20), "Enter", true);
ConsoleCommandEntryButton *entryButton = new ConsoleCommandEntryButton(inGameState, consoleTextbox, consoleListbox, Vector2(pos.x + 320, pos.y + 20 * (emptyEntries + 1)), Vector2(100, 20), "Enter", true);
guiState->addButton(entryButton);
}
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
InGameAppState::InGameOptionsButton::ReturnButton::ReturnButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -103,12 +114,12 @@ namespace game{
guiState->removeButton("Video");
guiState->removeButton("Audio");
guiState->removeButton("Multiplayer");
vector2d<s32> pos(100, 100);
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);
Vector2 pos = Vector2(100, 100);
ResumeButton *resumeButton = new ResumeButton(guiState, inGameState, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
ConsoleButton *consoleButton = new ConsoleButton(guiState, inGameState, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
InGameOptionsButton *optionsButton = new InGameOptionsButton(guiState, inGameState, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
MainMenuButton *mainMenuButton = new MainMenuButton(guiState, inGameState, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
ExitButton *exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
inGameState->setResumeButton(resumeButton);
inGameState->setConsoleButton(consoleButton);
inGameState->setOptionsButton(optionsButton);
@@ -122,13 +133,13 @@ namespace game{
guiState->removeButton("Back");
}
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : OptionsButton(pos, size, name, separate) {
InGameAppState::InGameOptionsButton::InGameOptionsButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
void InGameAppState::InGameOptionsButton::onClick() {
returnButton = new ReturnButton(guiState, inGameState, vector2d<s32>(50, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(150, 50), "Back", true);
returnButton = new ReturnButton(guiState, inGameState, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
guiState->addButton(returnButton);
guiState->removeButton("Resume");
guiState->removeButton("Console");
@@ -137,7 +148,7 @@ namespace game{
OptionsButton::onClick();
}
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
InGameAppState::MainMenuButton::MainMenuButton(GuiAppState *guiState, InGameAppState *inGameState, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->guiState = guiState;
this->inGameState = inGameState;
}
@@ -146,8 +157,8 @@ namespace game{
}
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));
InGameAppState::UnitCreationButton::UnitCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
//setImageButton(new Image(icon, pos, size));
}
void InGameAppState::UnitCreationButton::onClick() {
@@ -157,42 +168,42 @@ namespace game{
Button::update();
}
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
InGameAppState::BattleshipCreationButton::BattleshipCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::BattleshipCreationButton::onClick() {
}
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
InGameAppState::DestroyerCreationButton::DestroyerCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::DestroyerCreationButton::onClick() {
}
InGameAppState::CruiserCreationButton::CruiserCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
InGameAppState::CruiserCreationButton::CruiserCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::CruiserCreationButton::onClick() {
}
InGameAppState::CarrierCreationButton::CarrierCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
InGameAppState::CarrierCreationButton::CarrierCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::CarrierCreationButton::onClick() {
}
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(ITexture *icon, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate)
InGameAppState::SubmarineCreationButton::SubmarineCreationButton(string icon, Vector2 pos, Vector2 size, string name, bool separate)
: InGameAppState::UnitCreationButton(icon, pos, size, name, separate) {
}
void InGameAppState::SubmarineCreationButton::onClick() {
}
InGameAppState::InGameAppState(vector<stringw> difficultyLevels, vector<stringw> factions) {
InGameAppState::InGameAppState(vector<string> difficultyLevels, vector<string> factions) {
type = AppStateTypes::IN_GAME_STATE;
this->playerId = 0;
this->difficultyLevels = difficultyLevels;
@@ -210,6 +221,7 @@ namespace game{
for (int i = 0; i < factions.size(); i++) {
int faction;
int difficulty;
if (i == 0)
difficulty = -1;
else {
@@ -226,6 +238,7 @@ namespace game{
players.push_back(p);
p->setId(players.size() - 1);
}
mainPlayer = players[playerId];
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
guiState = ((GuiAppState*)stateManager->getAppState(AppStateTypes::GUI_STATE));
@@ -243,8 +256,10 @@ namespace game{
if (isMainMenuActive) {
GameManager *gm = GameManager::getSingleton();
/*
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
driver->draw2DRectangle(SColor(100, 0, 0, 0), rect<s32>(0, 0, gm->getWidth(), gm->getHeight()));
*/
}
for (Player *p : players)
@@ -325,6 +340,7 @@ namespace game{
for(int i=0;i<fx.size();i++){
if(getTime()-fx[i].initTime>fx[i].time){
/*
IParticleSystemSceneNode *node=fx[i].node;
if(node){
@@ -338,6 +354,7 @@ namespace game{
}
fx.erase(fx.begin()+i);
*/
}
}
}
@@ -348,8 +365,8 @@ namespace game{
if (mainPlayer->getFaction() == 1)
idOffset += 7;
IVideoDriver *driver = GameManager::getSingleton()->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);
crcb = new CruiserCreationButton(gameManager, driver->getTexture(iconPath[idOffset + 2]), vector2d<s32>(gameManager->getWidth() - 100, gameManager->getHeight() - 320), vector2d<s32>(100, 100), "cruisers", true);
@@ -377,13 +394,13 @@ namespace game{
if (!isMainMenuActive) {
isMainMenuActive = true;
gm->getStateManager()->dettachState(activeState);
vector2d<s32> pos(100, 100);
Vector2 pos = Vector2(100, 100);
//detachGui();
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);
resumeButton = new ResumeButton(guiState, this, Vector2(pos.x, pos.y), Vector2(150, 50), "Resume", true);
consoleButton = new ConsoleButton(guiState, this, Vector2(pos.x, pos.y + 60), Vector2(150, 50), "Console", true);
optionsButton = new InGameOptionsButton(guiState, this, Vector2(pos.x, pos.y + 120), Vector2(150, 50), "Options", true);
mainMenuButton = new MainMenuButton(guiState, this, Vector2(pos.x, pos.y + 180), Vector2(150, 50), "Main menu", true);
exitButton = new ExitButton(Vector2(pos.x, pos.y + 240), Vector2(150, 50), "Exit", true);
guiState->addButton(resumeButton);
guiState->addButton(consoleButton);
guiState->addButton(optionsButton);
@@ -409,14 +426,14 @@ namespace game{
}
}
void InGameAppState::onAction(Bind bind, bool isPressed) {
void InGameAppState::onAction(Mapping::Bind bind, bool isPressed) {
switch(bind){
case TOGGLE_MAIN_MENU:
case Mapping::TOGGLE_MAIN_MENU:
if(isPressed)toggleMainMenu();
break;
}
}
void InGameAppState::onAnalog(Bind bind, double str) {}
void InGameAppState::onAnalog(Mapping::Bind bind, double str) {}
}
}
+23 -23
View File
@@ -14,29 +14,29 @@
namespace game{
namespace core{
struct Fx {
s64 initTime,time;
irr::scene::IParticleSystemSceneNode *node=nullptr;
sf::Sound *sfx=nullptr;
s64 initTime, time;
//irr::scene::IParticleSystemSceneNode *node=nullptr;
sf::Sound *sfx = nullptr;
};
class InGameAppState : public AbstractAppState {
public:
InGameAppState(std::vector<irr::core::stringw>, std::vector<irr::core::stringw>);
InGameAppState(std::vector<std::string>, std::vector<std::string>);
~InGameAppState();
void onAttachment();
void onDetachment();
void update();
void onAction(Bind, bool);
void onAnalog(Bind, double);
void onAction(Mapping::Bind, bool);
void onAnalog(Mapping::Bind, double);
std::vector<content::Unit*> getSelectedUnits(content::Player*);
inline std::vector<content::Player*> getPlayers() {return players;}
inline std::vector<content::Projectile*>& getProjectiles(){return projectiles;}
inline void addFx(Fx fx){this->fx.push_back(fx);}
inline void addProjectile(content::Projectile *p){projectiles.push_back(p);}
private:
class ResumeButton : public gui::Button {
class ResumeButton : public vb01Gui::Button {
public:
ResumeButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ResumeButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
GuiAppState *getGuiState();
private:
@@ -44,18 +44,18 @@ namespace game{
InGameAppState *inGameState;
};
class ConsoleButton : public gui::Button {
class ConsoleButton : public vb01Gui::Button {
public:
ConsoleButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ConsoleButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
private:
GuiAppState *guiState;
InGameAppState *inGameState;
};
class MainMenuButton : public gui::Button {
class MainMenuButton : public vb01Gui::Button {
public:
MainMenuButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
MainMenuButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
private:
GuiAppState *guiState;
@@ -64,12 +64,12 @@ namespace game{
class InGameOptionsButton : public gui::OptionsButton {
public:
InGameOptionsButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
InGameOptionsButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
private:
class ReturnButton : public gui::Button {
class ReturnButton : public vb01Gui::Button {
public:
ReturnButton(GuiAppState*, InGameAppState*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
ReturnButton(GuiAppState*, InGameAppState*, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
private:
GuiAppState *guiState;
@@ -80,9 +80,9 @@ namespace game{
ReturnButton *returnButton;
};
class UnitCreationButton : public gui::Button {
class UnitCreationButton : public vb01Gui::Button {
public:
UnitCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
UnitCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
void update();
private:
@@ -91,31 +91,31 @@ namespace game{
class BattleshipCreationButton : public UnitCreationButton {
public:
BattleshipCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
BattleshipCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
};
class DestroyerCreationButton : public UnitCreationButton {
public:
DestroyerCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
DestroyerCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
};
class CruiserCreationButton : public UnitCreationButton {
public:
CruiserCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
CruiserCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
};
class CarrierCreationButton : public UnitCreationButton {
public:
CarrierCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
CarrierCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
};
class SubmarineCreationButton : public UnitCreationButton {
public:
SubmarineCreationButton(irr::video::ITexture*, irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
SubmarineCreationButton(std::string, vb01::Vector2, vb01::Vector2, std::string, bool);
void onClick();
};
@@ -135,7 +135,7 @@ namespace game{
void attachGui();
void detachGui();
std::vector<content::Player*> players;
std::vector<irr::core::stringw> difficultyLevels, factions;
std::vector<std::string> difficultyLevels, factions;
std::vector<content::Projectile*> projectiles;
std::vector<Fx> fx;
content::Player *mainPlayer;
+62 -45
View File
@@ -1,3 +1,6 @@
#include <quaternion.h>
#include <model.h>
#include "jet.h"
#include "jetData.h"
#include "aircraftCarrier.h"
@@ -5,10 +8,11 @@
using namespace game::core;
using namespace game::util;
using namespace game::content::unitData;
using namespace vb01;
namespace game{
namespace content{
Jet::Jet(Player *player, vector3df pos, int unitId, bool onBoard) : Unit(player, pos, unitId) {
Jet::Jet(Player *player, Vector3 pos, int unitId, bool onBoard) : Unit(player, pos, unitId) {
offsetPos = pos;
this->onBoard = onBoard;
this->pitchSpeed = unitData::pitchSpeed[id];
@@ -16,38 +20,43 @@ namespace game{
void Jet::update() {
Unit::update();
vector3df lp = aircraftCarrier->getDirVec() * aircraftCarrier->getRunwayLength() + aircraftCarrier->getJetPos(jetId);
Vector3 lp = aircraftCarrier->getDirVec() * aircraftCarrier->getRunwayLength() + aircraftCarrier->getJetPos(jetId);
if (!onBoard && aircraftCarrier) {
if (orders.size() == 0) {
Order o;
o.type = Order::TYPE::MOVE;
o.targetPos.push_back(new vector3df(lp));
o.targetPos.push_back(new Vector3(lp));
setOrder(o);
}
if (!landing
&&aircraftCarrier
&&pos.getDistanceFrom(lp) <= unitData::destinationOffset[id]
&&*orders[0].targetPos[0] == lp){
float angle=getAngleBetween(dirVec,aircraftCarrier->getDirVec()),maxAngle=PI-anglePrecision[id]/180*PI;
if(!toTurnPoint&&anglePrecision[id]/180*PI<angle&&angle<maxAngle){
float radius=getCircleRadius();
vector3df carrierSideVec=aircraftCarrier->getLeftVec().normalize();
vector3df jetSideVec=leftVec.normalize();
if(getAngleBetween(carrierSideVec,dirVec)<PI/2){
carrierSideVec=-carrierSideVec;
jetSideVec=-jetSideVec;
float angle = dirVec.getAngleBetween(aircraftCarrier->getDirVec()), maxAngle = PI - anglePrecision[id] / 180 * PI;
if(!toTurnPoint && anglePrecision[id] / 180 * PI < angle && angle < maxAngle){
float radius = getCircleRadius();
Vector3 carrierSideVec = aircraftCarrier->getLeftVec().norm();
Vector3 jetSideVec = leftVec.norm();
if(carrierSideVec.getAngleBetween(dirVec) < PI / 2){
carrierSideVec = -carrierSideVec;
jetSideVec = -jetSideVec;
}
vector3df tanPoint=pos+radius*(jetSideVec+carrierSideVec);
float ang1=getAngleBetween(tanPoint-lp,carrierSideVec);
float ang2=getAngleBetween(dirVec,-carrierSideVec);
float base=(tanPoint-lp).getLength()*cos(ang1);
float hyp=base/cos(ang2);
landingPos=(pos+dirVec*hyp);
toTurnPoint=true;
Vector3 tanPoint = pos + (jetSideVec + carrierSideVec) * radius;
float ang1 = (tanPoint - lp).getAngleBetween(carrierSideVec);
float ang2 = dirVec.getAngleBetween(-carrierSideVec);
float base = (tanPoint-lp).getLength() * cos(ang1);
float hyp = base / cos(ang2);
landingPos = (pos + dirVec * hyp);
toTurnPoint = true;
}
else if(PI-angle<anglePrecision[id]/180*PI){
onBoard=true;
landing=true;
else if(PI - angle < anglePrecision[id] / 180 * PI){
onBoard = true;
landing = true;
orientUnit(-aircraftCarrier->getDirVec());
}
}
@@ -69,46 +78,51 @@ namespace game{
}
}
void Jet::lap(vector3df destDir) {
vector3df center = pos - leftVec * getCircleRadius();
vector3df initCircleDir = -leftVec;
float angle = getAngleBetween(initCircleDir, destDir);
angle = quaternion(0, 0, 0, 0).fromAngleAxis(angle, upVec) * initCircleDir == destDir ? angle : 2 * PI - angle;
vector3df offsetDir = quaternion(0, 0, 0, 0).fromAngleAxis(PI / 2, upVec) * destDir;
vector3df destDirPos = quaternion(0, 0, 0, 0).fromAngleAxis(angle, upVec) * dirVec;
vector3df offsetDirPos = quaternion(0, 0, 0, 0).fromAngleAxis(angle + PI / 2, upVec) * dirVec;
vector3df hypVec = *orders[0].targetPos[0] - destDirPos;
float triAngle = getAngleBetween(hypVec, offsetDir);
void Jet::lap(Vector3 destDir) {
Vector3 center = pos - leftVec * getCircleRadius();
Vector3 initCircleDir = -leftVec;
float angle = initCircleDir.getAngleBetween(destDir);
angle = (Quaternion(angle, upVec) * initCircleDir == destDir ? angle : 2 * PI - angle);
Vector3 offsetDir = Quaternion(PI / 2, upVec) * destDir;
Vector3 destDirPos = Quaternion(angle, upVec) * dirVec;
Vector3 offsetDirPos = Quaternion(angle + PI / 2, upVec) * dirVec;
Vector3 hypVec = *orders[0].targetPos[0] - destDirPos;
float triAngle = hypVec.getAngleBetween(offsetDir);
float distance = cos(triAngle) * hypVec.getLength();
vector3df destPoint = offsetDirPos + offsetDirPos.normalize() * distance;
float dirAngle=getAngleBetween(dirVec,offsetDir)*180/PI;
Vector3 destPoint = offsetDirPos + offsetDirPos.norm() * distance;
float dirAngle = dirVec.getAngleBetween(offsetDir) * 180 / PI;
float movementAmount;
turn(maxTurnAngle>dirAngle?dirAngle:maxTurnAngle);
if(dirAngle>unitData::anglePrecision[id])
movementAmount=speed;
turn(maxTurnAngle > dirAngle ? dirAngle : maxTurnAngle);
if(dirAngle > unitData::anglePrecision[id])
movementAmount = speed;
else{
float destDistance=(destPoint-pos).getLength();
movementAmount=speed>destDistance?destDistance:speed;
float destDistance = (destPoint - pos).getLength();
movementAmount = (speed > destDistance ? destDistance : speed);
}
advance(movementAmount);
}
void Jet::takeOff() {
float distance = aircraftCarrier->getRunwayLength()-(pos - aircraftCarrier->getJetPos(jetId)).getLength();
float distance = aircraftCarrier->getRunwayLength() - (pos - aircraftCarrier->getJetPos(jetId)).getLength();
float movementAmmount = speed > distance ? distance : speed;
advance(movementAmmount);
distance -= movementAmmount;
if (distance <= 0.)
onBoard = false;
}
void Jet::land(){
float distance = (pos - aircraftCarrier->getJetPos(jetId)).getLength();
float movementAmmount = speed > distance ? distance : speed;
float movementAmmount = (speed > distance ? distance : speed);
advance(movementAmmount);
distance -= movementAmmount;
if (distance <= 0.){
landing = false;
while(!orders.empty())
orders.pop_back();
}
@@ -116,20 +130,23 @@ namespace game{
void Jet::turnAround() {
float distance=pos.getDistanceFrom(landingPos);
float movementAmmount = speed > distance ? distance : speed;
float movementAmmount = (speed > distance ? distance : speed);
advance(movementAmmount);
distance -= movementAmmount;
if (distance <= 0.)
toTurnPoint = false;
}
void Jet::pitch(float angle) {
quaternion rotQuat = rotQuat.fromAngleAxis(-angle / 180 * PI, leftVec);
Quaternion rotQuat = Quaternion(-angle / 180 * PI, leftVec);
dirVec = rotQuat*dirVec, upVec = rotQuat*upVec;
horAngle = angle;
float yAngle = node->getRotation().Y;
node->setRotation(vector3df(angle, 0, 0));
node->setRotation(vector3df(angle, yAngle, 0));
float yAngle = node->getOrientation().y;
/*
node->setOrientation(vector3df(angle, 0, 0));
node->setOrientation(vector3df(angle, yAngle, 0));
*/
}
}
}
+11 -10
View File
@@ -2,9 +2,10 @@
#ifndef JET_H
#define JET_H
#include <time.h>
#include "unit.h"
#include "player.h"
#include <time.h>
#include "util.h"
namespace game{
@@ -13,26 +14,26 @@ namespace game{
class Jet : public Unit {
public:
Jet(Player*,vector3df, int, bool);
Jet(Player*, vb01::Vector3, int, bool);
// virtual void attack(Order);
virtual void update();
inline void setJetId(int i){this->jetId=i;}
inline void setAircraftCarrier(AircraftCarrier *a){aircraftCarrier=a;}
inline void setJetId(int i){this->jetId = i;}
inline void setAircraftCarrier(AircraftCarrier *a){aircraftCarrier = a;}
inline bool isOnBoard(){return onBoard;}
inline int getJetId(){return jetId;}
inline AircraftCarrier* getAircraftCarrier(){return aircraftCarrier;}
inline vector3df getOffsetPos(){return offsetPos;}
inline vb01::Vector3 getOffsetPos(){return offsetPos;}
private:
int jetId;
vector3df destDir,offsetPos;
vb01::Vector3 destDir,offsetPos;
float horAngle = 0, pitchSpeed;
void turnAround();
void pitch(float);
void lap(vector3df);
void lap(vb01::Vector3);
protected:
AircraftCarrier *aircraftCarrier=nullptr;
vector3df landingPos;
bool onBoard=true,toTurnPoint=false,landing=false;
AircraftCarrier *aircraftCarrier = nullptr;
vb01::Vector3 landingPos;
bool onBoard = true, toTurnPoint = false, landing = false;
void move(Order, float = 0.);
void takeOff();
void land();
+2
View File
@@ -2,6 +2,8 @@
#ifndef JET_DATA_H
#define JET_DATA_H
#include "unitData.h"
/*
0:戦艦
1:駆逐艦
-12
View File
@@ -1,13 +1 @@
#include "key.h"
namespace game{
namespace core{
Key::Key(Bind bind, int trigger, bool key, bool analog) {
this->bind = bind;
this->trigger = trigger;
this->key = key;
this->analog = analog;
beingUsed = false;
}
}
}
+11 -9
View File
@@ -4,7 +4,8 @@
namespace game{
namespace core{
enum Bind{
struct Mapping{
enum Bind{
LEFT_CLICK,
SCROLLING_UP,
SCROLLING_DOWN,
@@ -42,14 +43,15 @@ namespace game{
GROUP_8,
GROUP_9,
LAST_BIND
};
struct Key {
Key(Bind,int,bool,bool);
Bind bind;
int trigger;
bool key, pressed, analog, beingUsed;
};
};
enum BindType{KEYBOARD, MOUSE_KEY, MOUSE_AXIS, JOYSTICK_KEY, JOYSTICK_AXIS};
enum AuxTriggers{MOUSE_AXIS_LEFT = 310, MOUSE_AXIS_RIGHT = 311, MOUSE_AXIS_UP = 312, MOUSE_AXIS_DOWN = 313};
Bind bind;
BindType type;
int trigger;
bool action, pressed = false;
};
}
}
+2 -19
View File
@@ -1,33 +1,16 @@
#include "util.h"
#include "gameManager.h"
#include "stateManager.h"
#include "guiAppState.h"
using namespace irr;
using namespace irr::core;
using namespace irr::gui;
using namespace irr::scene;
using namespace game::core;
using namespace game::util;
using namespace irr::video;
int main() {
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);
device->getSceneManager()->drawAll();
device->getGUIEnvironment()->drawAll();
gameManager->update();
driver->endScene();
}
device->drop();
*/
return 0;
}
+17 -18
View File
@@ -1,18 +1,17 @@
#include <root.h>
#include "map.h"
#include "gameManager.h"
#include "defConfigs.h"
using namespace irr;
using namespace irr::core;
using namespace irr::video;
using namespace irr::scene;
using namespace irr::video;
using namespace game::core;
using namespace std;
using namespace vb01;
namespace game{
namespace content{
Map::Map() {
size = vector2d<s32>(50, 50);
size = Vector2(50, 50);
}
Map::~Map() {
@@ -22,24 +21,24 @@ namespace game{
}
void Map::load() {
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
smgr->setAmbientLight(SColor(255, 100, 100, 100));
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")
, driver->getTexture(PATH + "Textures/down.jpg")
, driver->getTexture(PATH + "Textures/left.jpg")
, driver->getTexture(PATH + "Textures/right.jpg")
, driver->getTexture(PATH + "Textures/front.jpg")
, driver->getTexture(PATH + "Textures/back.jpg"));
string path[]{
PATH + "Textures/down.jpg",
PATH + "Textures/left.jpg",
PATH + "Textures/right.jpg",
PATH + "Textures/front.jpg",
PATH + "Textures/back.jpg"
};
Root::getSingleton()->createSkybox(path);
/*
waterMesh = smgr->addHillPlaneMesh("", dimension2d<float>(1, 1), dimension2d<u32>(30, 30), 0, .1, dimension2d<float>(2., 2.), dimension2d<float>(10, 10));
waterNode = smgr->addWaterSurfaceSceneNode(waterMesh, .1, 900, 3);
waterNode->setPosition(vector3df(0, 0, 0));
waterNode->setMaterialTexture(0, driver->getTexture(PATH + "Textures/water-texture.png"));
waterNode->setMaterialFlag(EMF_LIGHTING, true);
waterNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
*/
}
void Map::unload() {}
+5 -3
View File
@@ -2,7 +2,7 @@
#ifndef MAP_H
#define MAP_H
#include <irrlicht.h>
#include <vector.h>
namespace game{
namespace content{
@@ -13,12 +13,14 @@ namespace game{
void update();
void load();
void unload();
inline irr::core::vector2d<irr::s32> getSize(){return size;}
inline vb01::Vector2 getSize(){return size;}
private:
irr::core::vector2d<irr::s32> size;
vb01::Vector2 size;
/*
irr::scene::ILightSceneNode *sunLight;
irr::scene::IAnimatedMesh *waterMesh;
irr::scene::ISceneNode *waterNode;
*/
};
}
}
+16 -14
View File
@@ -1,32 +1,34 @@
#include <util.h>
#include <model.h>
#include "missile.h"
using namespace game::core;
using namespace game::util;
using namespace irr::core;
using namespace irr::scene;
using namespace vb01;
namespace game{
namespace content{
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();
Missile::Missile(Unit *unit, Node *node, Vector3 *target, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
Projectile(unit, node, pos, dir, left, up, id, weaponTypeId, weaponId) {
this->target = target;
this->type = (MissileType)weaponId;
this->initTime = getTime();
}
void Missile::update() {
Projectile::update();
pos+=dirVec*speed;
pos = pos + dirVec * speed;
node->setPosition(pos);
float angle=getAngleBetween(dirVec,*target-pos);
vector3df axis=dirVec.crossProduct(*target-pos).normalize();
float angle = dirVec.getAngleBetween(*target - pos);
Vector3 axis = dirVec.cross(*target - pos).norm();
if(rotationSpeed/180*PI<angle){
quaternion rotQuat=quaternion().fromAngleAxis(rotationSpeed/180*PI,axis);
orientProjectile(rotQuat*dirVec);
if(rotationSpeed / 180 * PI < angle){
Quaternion rotQuat = Quaternion(rotationSpeed / 180 * PI, axis);
orientProjectile(rotQuat * dirVec);
}
if(!exploded&&getTime()-initTime>selfDistructTime)
if(!exploded && getTime() - initTime > selfDistructTime)
Projectile::explode(nullptr);
}
}
+5 -5
View File
@@ -6,18 +6,18 @@
namespace game{
namespace content{
enum MissileType {AAM,AWM};
enum MissileType {AAM, AWM};
class Missile : public Projectile {
public:
Missile(Unit*, irr::scene::ISceneNode*, irr::core::vector3df*,irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Missile(Unit*, vb01::Node*, vb01::Vector3*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
~Missile(){}
void update();
private:
s64 initTime;
int selfDistructTime=10000;
irr::core::vector3df *target;
float rotationSpeed=5;
int selfDistructTime = 10000;
vb01::Vector3 *target;
float rotationSpeed = 5;
MissileType type;
};
}
+23 -16
View File
@@ -1,3 +1,5 @@
#include <model.h>
#include "missileJet.h"
#include "projectileData.h"
#include "inGameAppState.h"
@@ -5,29 +7,33 @@
using namespace game::core;
using namespace game::util;
using namespace irr::scene;
using namespace vb01;
namespace game{
namespace content{
MissileJet::MissileJet(Player *player, vector3df pos, int id, bool onBoard) : Jet(player, pos, id, onBoard) {}
MissileJet::MissileJet(Player *player, Vector3 pos, int id, bool onBoard) : Jet(player, pos, id, onBoard) {}
void MissileJet::attack(Order order) {
if(!onBoard&&canFire()&&missilesInstalled){
vector3df target = *order.targetPos[0];
if(!onBoard && canFire() && missilesInstalled){
Vector3 target = *order.targetPos[0];
float distance=pos.getDistanceFrom(target);
if(distance <= range){
vector3df *targetPtr=nullptr;
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
Vector3 *targetPtr = nullptr;
InGameAppState *inGameState = ((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
for(Player *p : inGameState->getPlayers())
for(Unit *u : p->getUnits()){
bool jet=u->getType()==UNIT_TYPE::MISSILE_JET||u->getType()==UNIT_TYPE::DEMO_JET;
if((jet&&type==AAM)&&(!jet&&type==AWM)&&u->getPosPtr()==order.targetPos[0])
targetPtr=u->getPosPtr();
bool jet = (u->getType() == UNIT_TYPE::MISSILE_JET || u->getType() == UNIT_TYPE::DEMO_JET);
if((jet && type == AAM) && (!jet && type == AWM) && u->getPosPtr() == order.targetPos[0])
targetPtr = u->getPosPtr();
}
if(!targetPtr){
targetPtr=new vector3df();
*targetPtr=target;
targetPtr = new Vector3();
*targetPtr = target;
}
fireMissile(targetPtr);
}
else
@@ -39,17 +45,17 @@ namespace game{
removeOrder(0);
}
void MissileJet::fireMissile(vector3df *t) {
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;
void MissileJet::fireMissile(Vector3 *t) {
Vector3 p = pos + leftVec * projectileData::pos[id][0][missiles - 1].x + upVec * projectileData::pos[id][0][missiles - 1].y - dirVec * projectileData::pos[id][0][missiles - 1].z;
addProjectile(new Missile(this, missileNodes[missiles-1], t, p, dirVec, leftVec, upVec, id, 0, 0));
missileNodes[missiles-1]->setParent(smgr->getRootSceneNode());
missileNodes[missiles-1]=nullptr;
missileNodes[missiles-1]->setParent(Root::getSingleton()->getRootNode());
missileNodes[missiles-1] = nullptr;
missiles--;
lastFireTime=getTime();
}
void MissileJet::installMissiles(bool aam){
/*
if(!missilesInstalled){
missiles=2;
GameManager *gm = GameManager::getSingleton();
@@ -73,6 +79,7 @@ namespace game{
type=(MissileType)aam;
missilesInstalled=true;
}
*/
}
}
}
+9 -7
View File
@@ -2,6 +2,8 @@
#ifndef MISSILE_JET_H
#define MISSILE_JET_H
#include <util.h>
#include "jet.h"
#include "player.h"
#include "missile.h"
@@ -10,17 +12,17 @@ namespace game{
namespace content {
class MissileJet : public Jet {
public:
MissileJet(Player*,vector3df, int, bool = 1);
MissileJet(Player*, vb01::Vector3, int, bool = 1);
void installMissiles(bool);
private:
void attack(Order);
void fireMissile(vector3df*);
inline bool canFire() {return missiles>0&&util::getTime() - lastFireTime > rateOfFire;}
void fireMissile(vb01::Vector3*);
inline bool canFire() {return missiles > 0 && vb01::getTime() - lastFireTime > rateOfFire;}
MissileType type;
irr::scene::ISceneNode *missileNodes[2]{nullptr,nullptr};
bool missilesInstalled=false;
int missiles=0,rateOfFire=2001;
s64 lastFireTime=0;
vb01::Node *missileNodes[2]{nullptr,nullptr};
bool missilesInstalled = false;
int missiles = 0, rateOfFire = 2001;
s64 lastFireTime = 0;
};
}
}
+60 -46
View File
@@ -3,29 +3,27 @@
#include "util.h"
using namespace game::core;
using namespace game::util;
using namespace irr::core;
using namespace irr::io;
using namespace irr::video;
using namespace irr::gui;
using namespace vb01Gui;
using namespace vb01;
using namespace std;
namespace game{
namespace gui{
OptionsButton::OkButton::OkButton() :Button(vector2d<s32>(50, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(140, 50), "Ok", true) {
OptionsButton::OkButton::OkButton() : Button(Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Ok", true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::OkButton::onClick() {
}
OptionsButton::DefaultsButton::DefaultsButton() :Button(vector2d<s32>(200, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(140, 50), "Restore defaults", true) {
OptionsButton::DefaultsButton::DefaultsButton() : Button(Vector2(200, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Restore defaults", true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::DefaultsButton::onClick() {
}
OptionsButton::BackButton::BackButton() :Button(vector2d<s32>(350, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(140, 50), "Back", true) {
OptionsButton::BackButton::BackButton() : Button(Vector2(350, GameManager::getSingleton()->getHeight() - 150), Vector2(140, 50), "Back", true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::BackButton::onClick() {
@@ -38,12 +36,12 @@ namespace game{
state->removeAllTextboxes();
state->removeButton("Ok");
state->removeButton("Restore defaults");
OptionsButton *optionsButton = new OptionsButton(vector2d<s32>(), vector2d<s32>(), "Options", true);
OptionsButton *optionsButton = new OptionsButton(Vector2(), Vector2(), "Options", true);
optionsButton->onClick();
state->removeButton("Back");
}
OptionsButton::TabButton::TabButton(vector2d<s32> pos, vector2d<s32> size, stringw name) :Button(pos, size, name, true) {
OptionsButton::TabButton::TabButton(Vector2 pos, Vector2 size, string name) :Button(pos, size, name, true) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::TabButton::onClick() {
@@ -51,25 +49,27 @@ namespace game{
OkButton *okButton = new OkButton();
DefaultsButton *defaultsButton = new DefaultsButton();
BackButton *returnButton = new BackButton();
defaultsButton->moveText(-25, 0);
//defaultsButton->moveText(-25, 0);
state->addButton(okButton);
state->addButton(defaultsButton);
state->addButton(returnButton);
}
OptionsButton::ControlsTab::ControlsTab() : TabButton(
vector2d<s32>(GameManager::getSingleton()->getWidth() / 4,
GameManager::getSingleton()->getHeight() / 10),
vector2d<s32>(100, 50),
Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10),
Vector2(100, 50),
"Controls"
) {}
void OptionsButton::ControlsTab::onClick() {
TabButton::onClick();
std::vector<stringw> lines=readFile(std::string((PATH+path("../options.cfg")).c_str()));
std::vector<string> lines;
readFile(PATH + "../options.cfg", lines);
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 *listbox = new Listbox(Vector2(gm->getWidth() / 4, gm->getHeight() / 10), Vector2(360, 20), lines, lines.size() < 5 ? lines.size() : 5, PATH + "Fonts/batang.ttf", Listbox::CONTROLS);
listbox->openUp();
state->addListbox(listbox);
state->removeButton("Mouse");
state->removeButton("Video");
@@ -79,21 +79,27 @@ namespace game{
}
OptionsButton::MouseTab::MouseTab() : TabButton(
vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 60),
vector2d<s32>(100, 50),
Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 60),
Vector2(100, 50),
"Mouse"
) {}
void OptionsButton::MouseTab::onClick() {
TabButton::onClick();
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));
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 4);
string font = PATH + "Fonts/batang.ttf";
Slider *mouseSensitivitySlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), .1, 3.);
Textbox *mouseSensitivityTextbox = new Textbox(Vector2(pos.x + 320, pos.y - 10), Vector2(100, 20), font);
Checkbox *reverseMouseCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50));
/*
gm->attachBitmapText(new BitmapText("MouseSensitivity", vector2d<s32>(gm->getWidth() / 3 - 90, gm->getHeight() / 4 - 5), font));
gm->attachBitmapText(new BitmapText("ReverseMouse", vector2d<s32>(gm->getWidth() / 3 + 20, gm->getHeight() / 4 + 50), font));
*/
state->addTextbox(mouseSensitivityTextbox);
state->addSlider(mouseSensitivitySlider);
state->addCheckbox(reverseMouseCheckbox);
@@ -104,31 +110,35 @@ namespace game{
state->removeButton("Mouse");
}
OptionsButton::VideoTab::VideoTab() :TabButton(vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 120), vector2d<s32>(100, 50), "Video") {}
OptionsButton::VideoTab::VideoTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 120), Vector2(100, 50), "Video") {}
void OptionsButton::VideoTab::onClick() {
TabButton::onClick();
std::vector<stringw> lines;
std::vector<string> lines;
for (int i = 0; i < 10; i++) {
stringw s;
string s;
s += i;
lines.push_back(s);
}
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);
string font = PATH + "Fonts/batang.ttf";
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 8);
Listbox *resolutionsListbox = new Listbox(Vector2(pos.x, pos.y), Vector2(100, 20), lines, 5, font);
Checkbox *fullscreenCheckbox = new Checkbox(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));
Checkbox *fullscreenCheckbox = new Checkbox(Vector2(pos.x, pos.y + 30));
Checkbox *vsyncCheckbox = new Checkbox(Vector2(pos.x, pos.y + 50));
Checkbox *normalMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 70));
Checkbox *parallaxMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 90));
Checkbox *specularMapCheckbox = new Checkbox(Vector2(pos.x, pos.y + 110));
/*
gm->attachBitmapText(new BitmapText("Fullscreen", vector2d<s32>(pos.X + 20, pos.Y + 30), font));
gm->attachBitmapText(new BitmapText("VSync", vector2d<s32>(pos.X + 20, pos.Y + 50), font));
gm->attachBitmapText(new BitmapText("Normal map", vector2d<s32>(pos.X + 20, pos.Y + 70), font));
gm->attachBitmapText(new BitmapText("Parallax map", vector2d<s32>(pos.X + 20, pos.Y + 90), font));
gm->attachBitmapText(new BitmapText("Specular map", vector2d<s32>(pos.X + 20, pos.Y + 110), font));
*/
state->addListbox(resolutionsListbox);
state->addCheckbox(fullscreenCheckbox);
@@ -144,13 +154,13 @@ namespace game{
state->removeButton("Video");
}
OptionsButton::AudioTab::AudioTab() :TabButton(vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 180), vector2d<s32>(100, 50), "Audio") {}
OptionsButton::AudioTab::AudioTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 180), Vector2(100, 50), "Audio") {}
void OptionsButton::AudioTab::onClick() {
TabButton::onClick();
GameManager *gm = GameManager::getSingleton();
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));
Vector2 pos(gm->getWidth() / 3, gm->getHeight() / 8);
Slider *volumeSlider = new Slider(Vector2(pos.x, pos.y), Vector2(300, 10), 0., 2.);
Textbox *volumeTextbox = new Textbox(Vector2(pos.x + 320, pos.y), Vector2(100, 20), PATH + "Fonts/batang.ttf");
state->addTextbox(volumeTextbox);
state->addSlider(volumeSlider);
state->removeButton("Controls");
@@ -160,18 +170,22 @@ namespace game{
state->removeButton("Audio");
}
OptionsButton::MultiplayerTab::MultiplayerTab() : TabButton(vector2d<s32>(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 240), vector2d<s32>(100, 50), "Multiplayer") {}
OptionsButton::MultiplayerTab::MultiplayerTab() : TabButton(Vector2(GameManager::getSingleton()->getWidth() / 4, GameManager::getSingleton()->getHeight() / 10 + 240), Vector2(100, 50), "Multiplayer") {}
void OptionsButton::MultiplayerTab::onClick() {
TabButton::onClick();
GameManager *gm = GameManager::getSingleton();
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));
string font = PATH + "Fonts/batang.ttf";
Vector2 pos = Vector2(gm->getWidth() / 3, gm->getHeight() / 6);
Textbox *tcpTextbox = new Textbox(Vector2(pos.x, pos.y), Vector2(100, 20), font);
Textbox *udpTextbox = new Textbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), font);
Textbox *playerNameTextbox = new Textbox(Vector2(pos.x, pos.y + 60), Vector2(100, 20), font);
/*
gm->attachBitmapText(new BitmapText("TCP port", vector2d<s32>(pos.X - 50, pos.Y), font));
gm->attachBitmapText(new BitmapText("UDP port", vector2d<s32>(pos.X - 50, pos.Y + 30), font));
gm->attachBitmapText(new BitmapText("Player name", vector2d<s32>(pos.X - 65, pos.Y + 60), font));
*/
state->addTextbox(tcpTextbox);
state->addTextbox(udpTextbox);
state->addTextbox(playerNameTextbox);
@@ -182,7 +196,7 @@ namespace game{
state->removeButton("Multiplayer");
}
OptionsButton::OptionsButton(vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
OptionsButton::OptionsButton(Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
}
void OptionsButton::onClick() {
@@ -191,7 +205,7 @@ namespace game{
VideoTab *videoTab = new VideoTab();
AudioTab *audioTab = new AudioTab();
MultiplayerTab *mupltiplayerTab = new MultiplayerTab();
mupltiplayerTab->moveText(-20, 0);
//mupltiplayerTab->moveText(-20, 0);
state->addButton(controlsTab);
state->addButton(mouseTab);
state->addButton(videoTab);
+5 -4
View File
@@ -2,15 +2,16 @@
#ifndef OPTIONS_BUTTON_H
#define OPTIONS_BUTTON_H
#include <button.h>
#include "guiAppState.h"
#include "gameManager.h"
#include "button.h"
namespace game{
namespace gui {
class OptionsButton : public Button {
class OptionsButton : public vb01Gui::Button {
public:
OptionsButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw, bool);
OptionsButton(vb01::Vector2, vb01::Vector2, std::string, bool);
class OkButton : public Button {
public:
OkButton();
@@ -34,7 +35,7 @@ namespace game{
};
class TabButton : public Button {
public:
TabButton(irr::core::vector2d<s32>, irr::core::vector2d<s32>, irr::core::stringw);
TabButton(vb01::Vector2, vb01::Vector2, std::string);
void onClick();
protected:
core::GuiAppState *state;
+4 -1
View File
@@ -1,10 +1,11 @@
#include "player.h"
using namespace game::core;
using namespace vb01;
namespace game{
namespace content{
Player::Player(int difficulty, int faction,vector3df spawnPoint) {
Player::Player(int difficulty, int faction, Vector3 spawnPoint) {
this->difficulty = difficulty;
this->faction = faction;
this->spawnPoint=spawnPoint;
@@ -18,10 +19,12 @@ namespace game{
bool Player::isThisPlayersUnit(Unit *u) {
bool foundUnit = false;
if (units.size() > 0) {
for (int i = 0; i < units.size() && !foundUnit; i++)
if (units[i] == u)
foundUnit = true;
return foundUnit;
} else
return false;
+3 -4
View File
@@ -2,7 +2,6 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <irrlicht.h>
#include <vector>
#include "gameManager.h"
@@ -12,7 +11,7 @@ namespace game{
namespace content{
class Player {
public:
Player(int, int,irr::core::vector3df=irr::core::vector3df(0,0,0));
Player(int, int, vb01::Vector3 = vb01::Vector3::VEC_ZERO);
~Player();
void update();
bool isThisPlayersUnit(Unit*);
@@ -24,11 +23,11 @@ namespace game{
inline int getNumberOfUnits(){return units.size();}
inline int getFaction(){return faction;}
inline int getSide(){return side;}
inline irr::core::vector3df getSpawnPoint(){return spawnPoint;}
inline vb01::Vector3 getSpawnPoint(){return spawnPoint;}
private:
int credits, faction, difficulty,side,id;
std::vector<Unit*> units;
irr::core::vector3df spawnPoint;
vb01::Vector3 spawnPoint;
};
}
}
+60 -36
View File
@@ -1,4 +1,9 @@
#include <algorithm>
#include <node.h>
#include <model.h>
#include <material.h>
#include <quaternion.h>
#include <ray.h>
#include "projectile.h"
#include "stateManager.h"
@@ -9,62 +14,73 @@
#include "explosion.h"
using namespace game::core;
using namespace game::util;
using namespace irr::core;
using namespace irr::io;
using namespace irr::video;
using namespace std;
using namespace sf;
using namespace vb01;
namespace game{
namespace content{
Projectile::Projectile(Unit *unit, ISceneNode *node, vector3df pos, vector3df dir, vector3df left, vector3df up, int id, int weaponTypeId, int weaponId) {
Projectile::Projectile(Unit *unit, Node *node, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) {
this->unit=unit;
this->id=id;
this->weaponTypeId=weaponTypeId;
dirVec = dir;
leftVec = left;
upVec = up;
this->rayLength=projectileData::length[id][weaponTypeId][weaponId];
GameManager *gm = GameManager::getSingleton();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
this->node=node;
//this->node=node;
if(!node){
/*
mesh = smgr->getMesh(projectileData::meshPath[id][weaponTypeId]);
this->node = smgr->addAnimatedMeshSceneNode(mesh);
ITexture *diffuseTexture = driver->getTexture(projectileData::diffuseMapTextPath[id][weaponTypeId]);
*/
this->node = new Model((projectileData::meshPath[id][weaponTypeId]));
Material *mat = new Material();
mat->setLightingEnabled(false);
string f[]{projectileData::diffuseMapTextPath[id][weaponTypeId]};
Texture *diffuseTexture = new Texture(f, 1);
mat->addDiffuseMap(diffuseTexture);
this->node->setMaterial(mat);
/*
if (!diffuseTexture)
diffuseTexture = driver->getTexture(DEFAULT_TEXTURE);
this->node->setMaterialTexture(0, diffuseTexture);
this->node->setMaterialFlag(EMF_LIGHTING, false);
*/
}
this->node->setPosition(pos);
this->pos = pos;
this->damage=projectileData::damage[id][weaponTypeId][weaponId];
initPos = pos;
speed = projectileData::speed[id][weaponTypeId][weaponId];
float angle = getAngleBetween(dirVec, vector3df(0, 0, -1));
angle = quaternion(0, 0, 0, 1).fromAngleAxis(angle, upVec) * vector3df(0, 0, -1) == dirVec ? angle : -angle;
this->node->setRotation(vector3df(0, angle / PI * 180, 0));
float angle = dirVec.getAngleBetween(Vector3(0, 0, -1));
angle = Quaternion(angle, upVec) * Vector3(0, 0, -1) == dirVec ? angle : -angle;
//this->node->setRotation(vector3df(0, angle / PI * 180, 0));
path p1=PATH+"Sounds/"+unitData::name[id]+"s/"+projectileData::name[id][weaponTypeId]+".ogg";
path p2=PATH+"Sounds/Explosions/explosion03"+stringw(rand()%4)+".ogg";
this->shotSfxBuffer=new SoundBuffer();
this->explosionSfxBuffer=new SoundBuffer();
string p1 = PATH + "Sounds/" + unitData::name[id] + "s/" + projectileData::name[id][weaponTypeId] + ".ogg";
string p2 = PATH + "Sounds/Explosions/explosion03" + to_string(rand() % 4) + ".ogg";
this->shotSfxBuffer = new sf::SoundBuffer();
this->explosionSfxBuffer=new sf::SoundBuffer();
if(shotSfxBuffer->loadFromFile(p1.c_str())){
shotSfx=new Sound(*shotSfxBuffer);
shotSfx=new sf::Sound(*shotSfxBuffer);
shotSfx->play();
}
if(explosionSfxBuffer->loadFromFile(p2.c_str()))
explosionSfx=new Sound(*explosionSfxBuffer);
explosionSfx=new sf::Sound(*explosionSfxBuffer);
}
Projectile::~Projectile(){
/*
ISceneManager *smgr = GameManager::getSingleton()->getDevice()->getSceneManager();
node->getParent()->removeChild(node);
*/
}
void Projectile::update() {
@@ -75,23 +91,29 @@ namespace game{
}
void Projectile::checkForCollision() {
ISceneNode *collNode = castRay(GameManager::getSingleton()->getSceneManager(),pos,pos+dirVec*rayLength);
//ISceneNode *collNode = castRay(GameManager::getSingleton()->getSceneManager(),pos,pos+dirVec*rayLength);
/*
Ray::castRay(pos, pos + dirVec, );
if (pos.Y<-7 || (collNode&&collNode!=unit->getNode()))
if (pos.y < -7 || (collNode&&collNode != unit->getNode()))
explode(collNode);
*/
}
void Projectile::explode(ISceneNode *collNode) {
void Projectile::explode(Node *collNode) {
exploded = true;
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
vector<Player*> players = ((InGameAppState*) stateManager->getAppState(AppStateTypes::IN_GAME_STATE))->getPlayers();
for (Player *p : players) {
for (Unit *u : p->getUnits())
if (collNode == u->getNode())
u->takeDamage(damage);
}
InGameAppState *inGameState=((InGameAppState*)stateManager->getAppState(AppStateTypes::IN_GAME_STATE));
if(id==8)
if(id == 8)
detonateTorpedo(inGameState,pos);
else if(weaponTypeId==1&&(id==2||id==3))
detonateDepthCharge(inGameState,pos);
@@ -100,25 +122,27 @@ namespace game{
}
void Projectile::debug(){
/*
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->draw3DLine(pos,pos+dirVec,SColor(255,0,0,255));
driver->draw3DLine(pos,pos+leftVec,SColor(255,255,0,0));
driver->draw3DLine(pos,pos+upVec,SColor(255,0,255,0));
*/
}
void Projectile::orientProjectile(vector3df orientVec){
vector3df orientVecProj=vector3df(orientVec.X,0,orientVec.Z).normalize();
float projAngle=getAngleBetween(orientVec,orientVecProj);
float rotAngle=getAngleBetween(vector3df(0,0,-1),orientVecProj);
rotAngle*=(orientVec.X<0?1:-1)/PI*180;
projAngle*=(orientVec.Y>0?1:-1)/PI*180;
dirVec=orientVecProj;
upVec=vector3df(0,1,0);
leftVec=quaternion(0,0,0,1).fromAngleAxis(-PI/2,upVec)*dirVec;
quaternion rotQuat=quaternion(0,0,0,1).fromAngleAxis(projAngle/180*PI,leftVec);
void Projectile::orientProjectile(Vector3 orientVec){
Vector3 orientVecProj = Vector3(orientVec.x, 0, orientVec.z).norm();
float projAngle = orientVec.getAngleBetween(orientVecProj);
float rotAngle = Vector3(0,0,-1).getAngleBetween(orientVecProj);
rotAngle *= (orientVec.x<0?1:-1)/PI*180;
projAngle*=(orientVec.y>0?1:-1)/PI*180;
dirVec = orientVecProj;
upVec = Vector3(0,1,0);
leftVec = Quaternion(-PI/2, upVec) * dirVec;
Quaternion rotQuat=Quaternion(projAngle/180*PI,leftVec);
dirVec=rotQuat*dirVec;
upVec=rotQuat*upVec;
node->setRotation(vector3df(projAngle,rotAngle,0));
//node->setRotation(vector3df(projAngle,rotAngle,0));
}
}
}
+13 -7
View File
@@ -2,35 +2,41 @@
#ifndef PROJECTILE_H
#define PROJECTILE_H
#include <irrlicht.h>
#include <SFML/Audio.hpp>
#include <vector.h>
#include "gameManager.h"
#include "util.h"
namespace vb01{
class Node;
class Model;
class Mesh;
}
namespace game{
namespace content {
class Unit;
class Projectile {
public:
Projectile(Unit*, irr::scene::ISceneNode*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Projectile(Unit*, vb01::Node*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
virtual ~Projectile();
virtual void update();
virtual void debug();
void orientProjectile(irr::core::vector3df);
void orientProjectile(vb01::Vector3);
inline bool isExploded() {return exploded;}
inline Unit* getUnit(){return unit;}
protected:
virtual void checkForCollision();
void explode(irr::scene::ISceneNode*);
irr::scene::IAnimatedMesh *mesh;
irr::scene::ISceneNode *node=nullptr;
void explode(vb01::Node*);
vb01::Model *node=nullptr;
bool exploded = false;
const float g = 2.2;
float speed, angle, rayLength, scale;
int damage,id,weaponTypeId;
irr::core::vector3df initPos, pos, dirVec, leftVec, upVec;
vb01::Vector3 initPos, pos, dirVec, leftVec, upVec;
s64 lastUpdateTime = 0;
Unit *unit;
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
+56 -59
View File
@@ -17,10 +17,7 @@
namespace game{
namespace content{
namespace projectileData {
using namespace irr;
using namespace irr::core;
using namespace game::core;
using namespace irr::io;
const int numberOfTypesOfWeapons = 2;
const float speed[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
@@ -101,88 +98,88 @@ namespace game{
{.6, .6, .6, .6, .6}
}
};
const vector3df pos[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
const vb01::Vector3 pos[unitData::numberOfUnits][numberOfTypesOfWeapons][13]{
{
{
vector3df(0, 0, 1.05),
vector3df(0, 0, 1.05),
vector3df(0, 0, 1.05),
vector3df(0, 0, 1.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5),
vector3df(0, 0, 2.5)
vb01::Vector3(0, 0, 1.05),
vb01::Vector3(0, 0, 1.05),
vb01::Vector3(0, 0, 1.05),
vb01::Vector3(0, 0, 1.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5),
vb01::Vector3(0, 0, 2.5)
}
},
{
{
vector3df(0, 0, 0.79254),
vector3df(0, 0, 0.79254),
vector3df(0, 0, 0.79254),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723),
vector3df(0, 0, 0.17723)
vb01::Vector3(0, 0, 0.79254),
vb01::Vector3(0, 0, 0.79254),
vb01::Vector3(0, 0, 0.79254),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723),
vb01::Vector3(0, 0, 0.17723)
}
},
{
{
vector3df(0, 0, -0.36178),
vector3df(0, 0, -0.36178),
vector3df(0, 0, -0.36178),
vector3df(0, 0, -0.36178)
vb01::Vector3(0, 0, -0.36178),
vb01::Vector3(0, 0, -0.36178),
vb01::Vector3(0, 0, -0.36178),
vb01::Vector3(0, 0, -0.36178)
},
{vector3df(0, -3, 0)}
{vb01::Vector3(0, -3, 0)}
},
{
{
vector3df(0, 0, -0.30074),
vector3df(0, 0, -0.30074),
vector3df(0, 0, -0.30074),
vector3df(0, 0, -0.30074)
vb01::Vector3(0, 0, -0.30074),
vb01::Vector3(0, 0, -0.30074),
vb01::Vector3(0, 0, -0.30074),
vb01::Vector3(0, 0, -0.30074)
},
{vector3df(0, -2, 0)}
{vb01::Vector3(0, -2, 0)}
},
{
{vector3df(0, 0, -0.62118), vector3df(0, 0, -0.62118)},
{vb01::Vector3(0, 0, -0.62118), vb01::Vector3(0, 0, -0.62118)},
{
vector3df(0.24482, 1.14985, 1.32775),
vector3df(0.24482, 1.14985, 1.62698),
vector3df(0.24482, 1.14985, 1.88017),
vector3df(-0.24482, 1.14985, 1.32775),
vector3df(-0.24482, 1.14985, 1.62698),
vector3df(-0.24482, 1.14985, 1.88017)
vb01::Vector3(0.24482, 1.14985, 1.32775),
vb01::Vector3(0.24482, 1.14985, 1.62698),
vb01::Vector3(0.24482, 1.14985, 1.88017),
vb01::Vector3(-0.24482, 1.14985, 1.32775),
vb01::Vector3(-0.24482, 1.14985, 1.62698),
vb01::Vector3(-0.24482, 1.14985, 1.88017)
}
},
{
{
vector3df(0, 0, -0.59117),
vector3df(0, 0, -0.59117),
vector3df(0, 0, -0.59117),
vector3df(0, 0, -0.59117),
vector3df(0, 0, -0.59117)
vb01::Vector3(0, 0, -0.59117),
vb01::Vector3(0, 0, -0.59117),
vb01::Vector3(0, 0, -0.59117),
vb01::Vector3(0, 0, -0.59117),
vb01::Vector3(0, 0, -0.59117)
},
{vector3df(0.17192, 0.57858, 0.64471), vector3df(-0.17192, 0.57858, 0.64471)}
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
},
{},
{},
{
{vector3df(0,-.3,-1.5)}
{vb01::Vector3(0,-.3,-1.5)}
},
{
{vector3df(-.25,0,0),vector3df(.25,0,0)},
{vector3df(-.25,0,0),vector3df(.25,0,0)}
{vb01::Vector3(-.25,0,0),vb01::Vector3(.25,0,0)},
{vb01::Vector3(-.25,0,0),vb01::Vector3(.25,0,0)}
},
{}
};
@@ -220,7 +217,7 @@ namespace game{
},
{}
};
const stringw name[unitData::numberOfUnits][numberOfTypesOfWeapons]{
const std::string name[unitData::numberOfUnits][numberOfTypesOfWeapons]{
{"shell"},
{"shell"},
{"shell"},
@@ -232,7 +229,7 @@ namespace game{
{"torpedo"},
{"missile","missile"},
};
const path meshPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
const std::string meshPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
{PATH + "Models/Shell/shell.x"},
{PATH + "Models/Shell/shell.x"},
{PATH + "Models/Shell/shell.x", PATH + "Models/Depth charge/depthCharge.x"},
@@ -244,7 +241,7 @@ namespace game{
{PATH + "Models/Torpedo/torpedo.x"},
{PATH + "Models/Jets/aam.x", PATH + "Models/Jets/awm.x"},
};
const path diffuseMapTextPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
const std::string diffuseMapTextPath[unitData::numberOfUnits][numberOfTypesOfWeapons]{
{},
{},
{},
+16 -12
View File
@@ -1,3 +1,5 @@
#include <model.h>
#include "shell.h"
#include "defConfigs.h"
#include "projectileData.h"
@@ -6,13 +8,13 @@
using namespace game::core;
using namespace game::util;
using namespace irr::core;
using namespace vb01;
namespace game{
namespace content{
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) {
Shell::Shell(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) : Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
this->speed = projectileData::speed[id][weaponTypeId][weaponId];
node->setScale(vector3df(1, 1, 1) * projectileData::scale[id][weaponTypeId][weaponId]);
node->setScale(Vector3(1, 1, 1) * projectileData::scale[id][weaponTypeId][weaponId]);
initTime = getTime();
}
@@ -20,24 +22,26 @@ namespace game{
//x=v*cos(a)*t
//y=v*sin(a)*t+0.5(g*t^2)
Projectile::update();
vector3df straightVec = vector3df(dirVec.X, 0, dirVec.Z).normalize();
double time = double(getTime() - initTime)/1000,
offsetX=speed * cos(angle) * time,
offsetY=speed * sin(angle) * time - .5 * (g * time * time);
pos = initPos + straightVec * offsetX + vector3df(0, offsetY, 0);
Vector3 straightVec = Vector3(dirVec.x, 0, dirVec.z).norm();
double time = double(getTime() - initTime) / 1000,
offsetX = speed * cos(angle) * time,
offsetY = speed * sin(angle) * time - .5 * (g * time * time);
pos = initPos + straightVec * offsetX + Vector3(0, offsetY, 0);
node->setPosition(pos);
updateVecs(straightVec, time);
checkForCollision();
}
void Shell::updateVecs(vector3df straightVec, float time) {
void Shell::updateVecs(Vector3 straightVec, float time) {
// f'(t)=dy/dx=(v*sin(a)+g*t)/(v*cos(a))
float tanAngle = -atan((speed * sin(angle) + g * time) / (speed * cos(angle)));
quaternion rotQuat = rotQuat.fromAngleAxis( tanAngle, leftVec);
dirVec = rotQuat*straightVec, upVec = rotQuat * vector3df(0, 1, 0);
vector3df rotVec=node->getRotation();
Quaternion rotQuat = Quaternion(tanAngle, leftVec);
dirVec = rotQuat*straightVec, upVec = rotQuat * Vector3(0, 1, 0);
/*
Vector3 rotVec = node->getOrientation();
rotVec=vector3df(tanAngle/PI*180,rotVec.Y,rotVec.Z);
node->setRotation(rotVec);
*/
}
}
}
+2 -2
View File
@@ -9,12 +9,12 @@ namespace game{
namespace content {
class Shell : public Projectile {
public:
Shell(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Shell(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
~Shell(){}
virtual void update();
protected:
s64 initTime;
virtual void updateVecs(irr::core::vector3df, float);
virtual void updateVecs(vb01::Vector3, float);
};
}
}
+1
View File
@@ -18,6 +18,7 @@ namespace game{
inline AbstractAppState* getAppState(int id){return appStates[id];}
inline void setAppState(int i, AbstractAppState *a){appStates[i]=a;}
inline int getAppStateNumber(){return appStates.size();}
inline std::vector<AbstractAppState*> getAppStates(){return appStates;}
private:
std::vector<AbstractAppState*> appStates;
};
+10 -6
View File
@@ -1,4 +1,5 @@
#include <time.h>
#include <node.h>
#include "submarine.h"
#include "defConfigs.h"
@@ -7,17 +8,20 @@
using namespace game::core;
using namespace game::util;
using namespace vb01;
namespace game{
namespace content{
Submarine::Submarine(Player *player,vector3df pos, int id) : Unit(player,pos, id) {}
Submarine::Submarine(Player *player, Vector3 pos, int id) : Unit(player,pos, id) {}
void Submarine::attack(Order order) {
float angle=getAngleBetween(dirVec,*(order.targetPos[0])-pos);
if(angle/PI*180>50)
float angle = dirVec.getAngleBetween(*(order.targetPos[0]) - pos);
if(angle / PI * 180 > 50)
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;
Vector3 p = pos + leftVec * projectileData::pos[id][0][0].x + upVec * projectileData::pos[id][0][0].y - dirVec * projectileData::pos[id][0][0].z;
addProjectile(new Torpedo(this, p, dirVec, leftVec, upVec, getId(), 0, 0));
lastShotTime=getTime();
}
@@ -25,13 +29,13 @@ namespace game{
void Submarine::emerge() {
submerged = false;
pos.Y += 5;
pos.y += 5;
node->setPosition(pos);
}
void Submarine::submerge() {
submerged = true;
pos.Y -= 5;
pos.y -= 5;
node->setPosition(pos);
}
}
+4 -2
View File
@@ -2,6 +2,8 @@
#ifndef SUBMARINE_H
#define SUBMARINE_H
#include <util.h>
#include "unit.h"
#include "player.h"
@@ -9,13 +11,13 @@ namespace game{
namespace content{
class Submarine : public Unit {
public:
Submarine(Player*, irr::core::vector3df, int);
Submarine(Player*, vb01::Vector3, int);
inline bool isSubmerged() {return submerged;}
void emerge();
void submerge();
private:
void attack(Order);
inline bool canFire(){return util::getTime() - lastShotTime > rateOfFire;}
inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;}
bool submerged = false;
int rateOfFire=2000;
s64 lastShotTime=0;
+9 -6
View File
@@ -1,27 +1,30 @@
#include "tooltip.h"
using namespace std;
using namespace vb01;
namespace game{
namespace gui{
using namespace irr::core;
using namespace irr::video;
using namespace game::core;
Tooltip::Tooltip(vector2di pos, stringw entry){
Tooltip::Tooltip(Vector2 pos, string entry){
this->pos = pos;
/*
GameManager *gm = GameManager::getSingleton();
text=new BitmapText(entry,pos,gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fontcourier.bmp"));
gm->attachBitmapText(text);
*/
}
Tooltip::~Tooltip(){
GameManager::getSingleton()->detachBitmapText(text);
//GameManager::getSingleton()->detachBitmapText(text);
}
void Tooltip::update(){
/*
IVideoDriver *driver=GameManager::getSingleton()->getDevice()->getVideoDriver();
dimension2d<u32> dim=text->getFont()->getDimension(text->getText().c_str());
driver->draw2DRectangle(SColor(255,0,0,0),recti(pos.X,pos.Y,pos.X+dim.Width,pos.Y+dim.Height),nullptr);
driver->draw2DRectangleOutline(recti(pos-vector2di(1,1),dimension2df(dim.Width+1,dim.Height+1)),SColor(255,255,0,0));
*/
}
}
}
+4 -4
View File
@@ -1,18 +1,18 @@
#ifndef TOOLTIP_H
#define TOOLTIP_H
#include "abstractBitmapText.h"
#include <text.h>
namespace game{
namespace gui{
class Tooltip{
public:
Tooltip(irr::core::vector2di, irr::core::stringw);
Tooltip(vb01::Vector2, std::string);
~Tooltip();
void update();
private:
irr::core::vector2di pos;
BitmapText *text;
vb01::Vector2 pos;
//BitmapText *text;
};
}
}
+6 -3
View File
@@ -1,15 +1,18 @@
#include <model.h>
#include "torpedo.h"
using namespace game::core;
using namespace vb01;
namespace game{
namespace content{
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;}
Torpedo::Torpedo(Unit *unit, Vector3 pos, Vector3 dir, Vector3 left, Vector3 up, int id, int weaponTypeId, int weaponId) :
Projectile(unit, nullptr, pos, dir, left, up, id,weaponTypeId,weaponId) {this->damage = 50;}
void Torpedo::update() {
Projectile::update();
pos += dirVec*speed;
pos = pos + dirVec * speed;
node->setPosition(pos);
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ namespace game{
namespace content{
class Torpedo : public Projectile {
public:
Torpedo(Unit*, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, irr::core::vector3df, int, int, int);
Torpedo(Unit*, vb01::Vector3, vb01::Vector3, vb01::Vector3, vb01::Vector3, int, int, int);
~Torpedo(){}
void update();
// void explode()
+96 -59
View File
@@ -1,3 +1,6 @@
#include <model.h>
#include <texture.h>
#include "unit.h"
#include "inGameAppState.h"
#include "stateManager.h"
@@ -7,63 +10,62 @@
using namespace game::content::unitData;
using namespace game::core;
using namespace game::util;
using namespace sf;
using namespace vb01;
using namespace std;
namespace game{
namespace content{
Unit::Unit(Player *player, vector3df pos, int id) {
Unit::Unit(Player *player, vb01::Vector3 pos, int id) {
this->id = id;
this->player = player;
type = unitData::unitType[id];
this->health = unitData::health[id];
this->maxTurnAngle = unitData::maxTurnAngle[id];
this->range = unitData::range[id];
this->lineOfSight = unitData::lineOfSight[id];
width = unitData::unitCornerPoints[id][0].X - unitData::unitCornerPoints[id][1].X;
height = unitData::unitCornerPoints[id][4].Y - unitData::unitCornerPoints[id][0].Y;
length = unitData::unitCornerPoints[id][3].Z - unitData::unitCornerPoints[id][0].Z;
this->speed = unitData::speed[id];
type = unitData::unitType[id];
width = unitData::unitCornerPoints[id][0].x - unitData::unitCornerPoints[id][1].x;
height = unitData::unitCornerPoints[id][4].y - unitData::unitCornerPoints[id][0].y;
length = unitData::unitCornerPoints[id][3].z - unitData::unitCornerPoints[id][0].z;
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);
node = new Model(basePath[id] + meshPath[id]);
placeUnit(pos);
/*
node->setMaterialFlag(EMF_LIGHTING, false);
ITriangleSelector *tr = smgr->createTriangleSelector((IAnimatedMeshSceneNode*)node);
node->setTriangleSelector(tr);
tr->drop();
ITexture *diffuseTexture = driver->getTexture(basePath[id] + "diffuseMap.png");
if (diffuseTexture)
node->setMaterialTexture(0, diffuseTexture);
else
node->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
*/
string f[]{basePath[id] + "diffuseMap.png"};
Texture *diffuseTexture = new Texture(f, 1);
/*
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";
*/
selectionSfxBuffer = new sf::SoundBuffer();
string p = PATH+"Sounds/"+unitData::name[id]+"s/selection.ogg";
if(selectionSfxBuffer->loadFromFile(p.c_str()))
selectionSfx=new Sound(*selectionSfxBuffer);
selectionSfx = new sf::Sound(*selectionSfxBuffer);
}
Unit::~Unit() {
/*
GameManager *gm = GameManager::getSingleton();
ISceneManager *smgr = gm->getDevice()->getSceneManager();
IVideoDriver *driver = gm->getDevice()->getVideoDriver();
// driver->removeTexture(node->getMaterial(0).getTexture(0));
driver->removeTexture(node->getMaterial(0).getTexture(0));
node->removeChild(light);
node->getParent()->removeChild(node);
*/
}
void Unit::update() {
if (orders.size() > 0){
if(selected&&canDisplayOrderLine()){
int r=0,g=0,b=0;
switch(orders[0].type){
case Order::TYPE::MOVE:
g=255;
@@ -77,18 +79,23 @@ namespace game{
r=255,g=255;
break;
}
GameManager::getSingleton()->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();
patrolPointId = 0;
}
}
executeOrders();
if (health <= 0)
blowUp();
}
/*
void Unit::updateScreenCoordinates(ICameraSceneNode *cam, vector3df camDir, vector3df camLeft, vector3df camUp) {
vector3df camPos = cam->getPosition();
vector3df farLeftUpPoint = cam->getViewFrustum()->getFarLeftUp();
@@ -115,11 +122,13 @@ namespace game{
} else
selectable = false;
}
*/
void Unit::blowUp(){
working=false;
working = false;
}
/*
void Unit::updateUnitGUIInfo(ICameraSceneNode* cam, vector3df camDir, vector3df camLeft, vector3df camUp) {
updateScreenCoordinates(cam, camDir, camLeft, camUp);
if (selected) {
@@ -127,7 +136,9 @@ namespace game{
drawCuboid();
}
}
*/
/*
void Unit::displayUnitStats() {
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
SColor white = SColor(255, 255, 255, 255);
@@ -138,7 +149,9 @@ namespace game{
driver->draw2DRectangle(SColor(255, 0, 200, 0), rect<s32>(screenPos.X - 50, screenPos.Y - 19, screenPos.X - 50 + ((float)health / unitData::health[id]) * 100, screenPos.Y));
}
*/
/*
void Unit::drawCuboid() {
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->setTransform(ETS_WORLD, IdentityMatrix);
@@ -157,7 +170,9 @@ namespace game{
driver->draw3DLine(pos + vec, pos + vec + yVec);
}
}
*/
/*
void Unit::debug() {
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->setTransform(ETS_WORLD, IdentityMatrix);
@@ -167,10 +182,12 @@ namespace game{
driver->draw3DLine(pos, pos + leftVec * length, SColor(255, 255, 0, 0));
driver->draw3DLine(pos, pos + upVec * length, SColor(255, 0, 255, 0));
}
*/
void Unit::executeOrders() {
if (orders.size() > 0) {
Order order = orders[0];
switch (order.type) {
case Order::TYPE::ATTACK:
attack(order);
@@ -179,9 +196,7 @@ namespace game{
move(order, unitData::destinationOffset[id]);
break;
case Order::TYPE::PATROL:
{
patrol(order);
}
break;
case Order::TYPE::LAUNCH:
launch(order);
@@ -195,12 +210,14 @@ namespace game{
void Unit::setOrder(Order order) {
while (orders.size() > 0)
orders.pop_back();
addOrder(order);
orderLineDispTime=getTime();
orderLineDispTime = getTime();
}
void Unit::attack(Order order) {
vector3df target=*order.targetPos[0];
Vector3 target = *order.targetPos[0];
if (pos.getDistanceFrom(target) >= range)
move(order, range);
// InGameAppState *inGameState=((InGameAppState*)gameManager->getAppState(AppStateTypes::IN_GAME_STATE));
@@ -211,39 +228,47 @@ namespace game{
void Unit::move(Order order, float destOffset) {
float movementAmmount, radius = getCircleRadius(), angle = 0.;
vector3df dest = *order.targetPos[0];
dest.Y = pos.Y;
vector3df center;
if (getAngleBetween(leftVec, dest - pos) < PI / 2) {
Vector3 dest = *order.targetPos[0];
dest.y = pos.y;
Vector3 center;
if (leftVec.getAngleBetween(dest - pos) < PI / 2) {
moveDir = MoveDir::LEFT;
center = pos + leftVec*radius;
} else if (getAngleBetween(-leftVec, dest - pos) < PI / 2) {
} else if (-leftVec.getAngleBetween(dest - pos) < PI / 2) {
moveDir = MoveDir::RIGHT;
center = pos - leftVec*radius;
}
bool withinCircle = center.getDistanceFrom(dest) < radius ? true : false;
if (moveDir != MoveDir::FORWARD) {
if (withinCircle)
angle = getAngleBetween(dirVec, center - dest) / PI * 180;
angle = dirVec.getAngleBetween(center - dest) / PI * 180;
else
angle = getAngleBetween(dirVec, dest - pos) / PI * 180;
angle = dirVec.getAngleBetween(dest - pos) / PI * 180;
angle = isnan(angle) ? 0. : angle;
if (angle > anglePrecision[id]) {
float rotAngle = maxTurnAngle > angle ? angle : maxTurnAngle;
angle -= rotAngle;
turn(moveDir == MoveDir::RIGHT ? rotAngle : -rotAngle);
}
}
if (angle > anglePrecision[id])
movementAmmount = speed;
else {
if (withinCircle) {
float inDest = ((center - dest).normalize() * radius - (center - dest)).getLength();
float inDest = ((center - dest).norm() * radius - (center - dest)).getLength();
movementAmmount = speed > inDest ? inDest : speed;
} else
movementAmmount = speed > pos.getDistanceFrom(dest) ? pos.getDistanceFrom(dest) : speed;
}
advance(movementAmmount);
if (pos.getDistanceFrom(dest) <= destOffset && orders[0].type == Order::TYPE::MOVE) {
moveDir = MoveDir::FORWARD;
removeOrder(0);
@@ -257,14 +282,16 @@ namespace game{
void Unit::launch(Order order) {}
void Unit::advance(float speed) {
pos += dirVec*speed;
pos = pos + dirVec * speed;
node->setPosition(pos);
}
void Unit::turn(float angle) {// rad
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 180 * angle, vector3df(0, 1, 0));
node->setRotation(vector3df(node->getRotation().X, node->getRotation().Y + angle, 0));
/*
Quaternion rotQuat = Quaternion(PI / 180 * angle, Vector3(0, 1, 0));
node->setOrientation(Vector3(node->getOrientation().x, node->getRotation().Y + angle, 0));
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
*/
}
void Unit::halt() {
@@ -279,66 +306,76 @@ namespace game{
return radius;
}
void Unit::placeUnit(vector3df p) {
void Unit::placeUnit(Vector3 p) {
node->setPosition(p);
pos = p;
}
void Unit::orientUnit(vector3df orientVec){
vector3df orientVecProj=vector3df(orientVec.X,0,orientVec.Z).normalize();
float projAngle=getAngleBetween(orientVec,orientVecProj);
float rotAngle=getAngleBetween(vector3df(0,0,-1),orientVecProj);
rotAngle*=(orientVec.X<0?1:-1)/PI*180;
projAngle*=(orientVec.Y>0?1:-1)/PI*180;
dirVec=orientVecProj;
upVec=vector3df(0,1,0);
leftVec=quaternion(0,0,0,1).fromAngleAxis(-PI/2,upVec)*dirVec;
quaternion rotQuat=quaternion(0,0,0,1).fromAngleAxis(projAngle/180*PI,leftVec);
dirVec=rotQuat*dirVec;
upVec=rotQuat*upVec;
node->setRotation(vector3df(projAngle,rotAngle,0));
void Unit::orientUnit(Vector3 orientVec){
Vector3 orientVecProj = Vector3(orientVec.x, 0, orientVec.z).norm();
float projAngle = orientVec.getAngleBetween(orientVecProj);
float rotAngle = Vector3(0,0,-1).getAngleBetween(orientVecProj);
rotAngle *= (orientVec.x < 0 ? 1 : -1) / PI * 180;
projAngle *= (orientVec.y > 0 ? 1 : -1) / PI * 180;
dirVec = orientVecProj;
upVec = Vector3(0,1,0);
leftVec = Quaternion(-PI / 2, upVec) * dirVec;
Quaternion rotQuat = Quaternion(projAngle / 180 * PI, leftVec);
dirVec = rotQuat * dirVec;
upVec = rotQuat * upVec;
//node->setRotation(vector3df(projAngle,rotAngle,0));
}
vector3df Unit::getCorner(int i) {
vector3df corner=unitCornerPoints[id][i];
return pos+(leftVec*corner.X+upVec*corner.Y-dirVec*corner.Z);
Vector3 Unit::getCorner(int i) {
Vector3 corner = unitCornerPoints[id][i];
return pos + (leftVec * corner.x + upVec * corner.y - dirVec * corner.z);
}
std::vector<Projectile*> Unit::getProjectiles(){
std::vector<Projectile*> projectiles;
InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE));
for(Projectile *p: inGameState->getProjectiles())
if(p->getUnit()==this)
projectiles.push_back(p);
return projectiles;
}
void Unit::removeOrder(int id) {
for (vector3df *v : orders[id].targetPos) {
for (Vector3 *v : orders[id].targetPos) {
bool isUnitPos = false;
InGameAppState *state = (InGameAppState*) GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE);
for (Player *p : state->getPlayers())
for (Unit *u : p->getUnits())
if (v == u->getPosPtr())
isUnitPos = true;
if(!isUnitPos)
delete v;
}
orders.erase(orders.begin() + id);
}
void Unit::toggleSelection(bool selection) {
selected = selection;
if(selection&&selectionSfx)
if(selection && selectionSfx)
selectionSfx->play();
orderLineDispTime=getTime();
}
/*
SMaterial Unit::createLineMaterial() {
SMaterial mat;
mat.Lighting = false;
return mat;
}
*/
void Unit::addProjectile(Projectile *p) {((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::IN_GAME_STATE))->addProjectile(p);}
}
+31 -29
View File
@@ -3,19 +3,21 @@
#define UNIT_H
#include <vector>
#include <irrlicht.h>
#include <util.h>
#include <SFML/Audio.hpp>
#include "unitData.h"
#include "gameManager.h"
#include "projectile.h"
#include "util.h"
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace game::content::unitData;
namespace vb01{
class Mesh;
class Node;
class Camera;
}
namespace game{
namespace content{
class Player;
@@ -23,7 +25,7 @@ namespace game{
struct Order {
enum class TYPE {ATTACK, MOVE, PATROL, LAUNCH};
TYPE type;
std::vector<vector3df*> targetPos;
std::vector<vb01::Vector3*> targetPos;
};
enum class MoveDir {FORWARD, LEFT, RIGHT};
@@ -32,67 +34,67 @@ namespace game{
class Unit {
public:
Unit(Player*,vector3df, int);
Unit(Player*, vb01::Vector3, int);
~Unit();
virtual void update();
virtual void blowUp();
virtual void updateUnitGUIInfo(ICameraSceneNode*, vector3df, vector3df, vector3df);
//virtual void updateUnitGUIInfo(ICameraSceneNode*, vector3df, vector3df, vector3df);
virtual void debug();
virtual void halt();
void toggleSelection(bool);
void setOrder(Order);
void placeUnit(vector3df);
void orientUnit(vector3df);
void placeUnit(vb01::Vector3);
void orientUnit(vb01::Vector3);
void addProjectile(Projectile*);
float getCircleRadius();
vector3df getCorner(int);
vb01::Vector3 getCorner(int);
std::vector<Projectile*> getProjectiles();
inline bool isSelected(){return selected;}
inline bool isSelectable(){return selectable;}
inline bool isDebuggable(){return debugging;}
inline bool isWorking(){return working;}
inline vector2d<s32> getScreenPos(){return screenPos;}
inline vb01::Vector2 getScreenPos(){return screenPos;}
inline void addOrder(Order o){orders.push_back(o);}
inline vector3df getPos() {return pos;}
inline vector3df* getPosPtr() {return &pos;}
inline ILightSceneNode* getLight() {return light;}
inline vb01::Vector3 getPos() {return pos;}
inline vb01::Vector3* getPosPtr() {return &pos;}
//inline ILightSceneNode* getLight() {return light;}
inline float getLineOfSight() {return lineOfSight;}
inline float getWidth() {return width;}
inline float getHeight() {return height;}
inline float getLength() {return length;}
inline ISceneNode* getNode() {return node;}
inline vb01::Node* getNode() {return node;}
inline Player* getPlayer(){return player;}
inline unitData::UNIT_TYPE getType() {return type;}
inline void toggleDebugging(bool d){this->debugging=d;}
inline void takeDamage(int damage) {health -= damage;}
inline int getId() {return id;}
inline int getPlayerId() {return playerId;}
inline vector3df getDirVec() {return dirVec;}
inline vector3df getLeftVec() {return leftVec;}
inline vector3df getUpVec() {return upVec;}
inline vb01::Vector3 getDirVec() {return dirVec;}
inline vb01::Vector3 getLeftVec() {return leftVec;}
inline vb01::Vector3 getUpVec() {return upVec;}
private:
void updateScreenCoordinates(ICameraSceneNode*, vector3df, vector3df, vector3df);
//void updateScreenCoordinates(ICameraSceneNode*, vector3df, vector3df, vector3df);
void displayUnitStats();
inline int getNextPatrolPointId() {return patrolPointId == patrolPoints.size() - 1 ? 0 : patrolPointId + 1;}
inline bool canDisplayOrderLine(){return util::getTime()-orderLineDispTime<orderVecDispLength;}
ILightSceneNode *light;
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
//ILightSceneNode *light;
const int orderVecDispLength=2000;
sf::SoundBuffer *selectionSfxBuffer;
sf::Sound *selectionSfx=nullptr;
protected:
Player *player;
MoveDir moveDir = MoveDir::FORWARD;
irr::video::SMaterial createLineMaterial();
//vb01::Material createLineMaterial();
unitData::UNIT_TYPE type;
ICameraSceneNode *cam = nullptr;
vector2d<s32> screenPos;
vb01::Camera *cam = nullptr;
vb01::Vector2 screenPos;
std::vector<Order> orders;
std::vector<vector3df> patrolPoints;
vector3df pos = vector3df(0, 0, 0), upVec = vector3df(0, 1, 0), dirVec = vector3df(0, 0, -1), leftVec = vector3df(1, 0, 0);
std::vector<vb01::Vector3> patrolPoints;
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, -1), leftVec = vb01::Vector3(1, 0, 0);
int health, cost, id, patrolPointId = 0, playerId;
s64 orderLineDispTime=0;
IAnimatedMesh *mesh;
ISceneNode *node;
vb01::Mesh *mesh;
vb01::Node *node;
bool selected = false, selectable, debugging = false, working=true;
float lineOfSight, speed, maxTurnAngle, range, width, height, length;
void removeOrder(int);
+182 -184
View File
@@ -2,7 +2,7 @@
#ifndef UNIT_DATA_H
#define UNIT_DATA_H
#include <irrlicht.h>
#include <vector.h>
#include "defConfigs.h"
@@ -19,8 +19,6 @@
namespace game{
namespace content {
namespace unitData {
using namespace irr::core;
using namespace irr::io;
using namespace game::core;
const int numberOfUnits = 11;
@@ -40,233 +38,233 @@ namespace game{
const int cost[numberOfUnits]{500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500};
const float maxTurnAngle[numberOfUnits]{1, 1, .5, .5, 1, 1, .5, .5, 1, 2, 2};
const float range[numberOfUnits]{15, 15, 14, 14, 13, 13, 12, 12,15,25};
const vector3df unitCornerPoints[numberOfUnits][8]{
const vb01::Vector3 unitCornerPoints[numberOfUnits][8]{
{
vector3df(.9, -1, -6),
vector3df(-.9, -1, -6),
vector3df(-.9, -1, 5.8),
vector3df(.9, -1, 5.8),
vector3df(.9, 3.5, -6),
vector3df(-.9, 3.5, -6),
vector3df(-.9, 3.5, 5.8),
vector3df(.9, 3.5, 5.8)
vb01::Vector3(.9, -1, -6),
vb01::Vector3(-.9, -1, -6),
vb01::Vector3(-.9, -1, 5.8),
vb01::Vector3(.9, -1, 5.8),
vb01::Vector3(.9, 3.5, -6),
vb01::Vector3(-.9, 3.5, -6),
vb01::Vector3(-.9, 3.5, 5.8),
vb01::Vector3(.9, 3.5, 5.8)
},
{
vector3df(.5, -.5, -7.05),
vector3df(-.5, -.5, -7.05),
vector3df(-.5, -.5, 6.4),
vector3df(.5, -.5, 6.4),
vector3df(.5, 3, -7.05),
vector3df(-.5, 3, -7.05),
vector3df(-.5, 3, 6.4),
vector3df(.5, 3, 6.4)
vb01::Vector3(.5, -.5, -7.05),
vb01::Vector3(-.5, -.5, -7.05),
vb01::Vector3(-.5, -.5, 6.4),
vb01::Vector3(.5, -.5, 6.4),
vb01::Vector3(.5, 3, -7.05),
vb01::Vector3(-.5, 3, -7.05),
vb01::Vector3(-.5, 3, 6.4),
vb01::Vector3(.5, 3, 6.4)
},
{
vector3df(.5, -.5, -3.4),
vector3df(-.5, -.5, -3.4),
vector3df(-.5, -.5, 3.4),
vector3df(.5, -.4, 3.4),
vector3df(.5, 2.1, -3.4),
vector3df(-.5, 2, -3.4),
vector3df(-.5, 2, 3.4),
vector3df(.5, 2, 3.4)
vb01::Vector3(.5, -.5, -3.4),
vb01::Vector3(-.5, -.5, -3.4),
vb01::Vector3(-.5, -.5, 3.4),
vb01::Vector3(.5, -.4, 3.4),
vb01::Vector3(.5, 2.1, -3.4),
vb01::Vector3(-.5, 2, -3.4),
vb01::Vector3(-.5, 2, 3.4),
vb01::Vector3(.5, 2, 3.4)
},
{
vector3df(.5, -.25, -4.8),
vector3df(-.5, -.25, -4.8),
vector3df(-.5, -.25, 4.7),
vector3df(.5, -.25, 4.7),
vector3df(.5, .8, -4.8),
vector3df(-.5, .8, -4.8),
vector3df(-.5, .8, 4.7),
vector3df(.5, .8, 4.7)
vb01::Vector3(.5, -.25, -4.8),
vb01::Vector3(-.5, -.25, -4.8),
vb01::Vector3(-.5, -.25, 4.7),
vb01::Vector3(.5, -.25, 4.7),
vb01::Vector3(.5, .8, -4.8),
vb01::Vector3(-.5, .8, -4.8),
vb01::Vector3(-.5, .8, 4.7),
vb01::Vector3(.5, .8, 4.7)
},
{
vector3df(.7, -.3, -4),
vector3df(-.7, -.3, -4),
vector3df(-.7, -.3, 3.4),
vector3df(.7, -.3, 3.4),
vector3df(.7, 2.9, -4),
vector3df(-.7, 2.9, -4),
vector3df(-.7, 2.9, 3.4),
vector3df(.7, 2.9, 3.4)
vb01::Vector3(.7, -.3, -4),
vb01::Vector3(-.7, -.3, -4),
vb01::Vector3(-.7, -.3, 3.4),
vb01::Vector3(.7, -.3, 3.4),
vb01::Vector3(.7, 2.9, -4),
vb01::Vector3(-.7, 2.9, -4),
vb01::Vector3(-.7, 2.9, 3.4),
vb01::Vector3(.7, 2.9, 3.4)
},
{
vector3df(.5, -.5, -6.1),
vector3df(-.5, -.5, -6.1),
vector3df(-.5, -.5, 5.2),
vector3df(.5, -.5, 5.2),
vector3df(.5, 2.2, -6.1),
vector3df(-.5, 2.2, -6.1),
vector3df(-.5, 2.2, 5.2),
vector3df(.5, 2.2, 5.2)
vb01::Vector3(.5, -.5, -6.1),
vb01::Vector3(-.5, -.5, -6.1),
vb01::Vector3(-.5, -.5, 5.2),
vb01::Vector3(.5, -.5, 5.2),
vb01::Vector3(.5, 2.2, -6.1),
vb01::Vector3(-.5, 2.2, -6.1),
vb01::Vector3(-.5, 2.2, 5.2),
vb01::Vector3(.5, 2.2, 5.2)
},
{
vector3df(2, -.5, -10),
vector3df(-2, -.5, -10),
vector3df(-2, -.5, 9),
vector3df(2, -.5, 9),
vector3df(2, 5.5, -10),
vector3df(-2, 5.5, -10),
vector3df(-2, 5.5, 9),
vector3df(2, 5.5, 9)
vb01::Vector3(2, -.5, -10),
vb01::Vector3(-2, -.5, -10),
vb01::Vector3(-2, -.5, 9),
vb01::Vector3(2, -.5, 9),
vb01::Vector3(2, 5.5, -10),
vb01::Vector3(-2, 5.5, -10),
vb01::Vector3(-2, 5.5, 9),
vb01::Vector3(2, 5.5, 9)
},
{
vector3df(2, -1, -10),
vector3df(-2, -1, -10),
vector3df(-2, -1, 9),
vector3df(2, -1, 9),
vector3df(2, 4.5, -10),
vector3df(-2, 4.5, -10),
vector3df(-2, 4.5, 9),
vector3df(2, 4.5, 9)
vb01::Vector3(2, -1, -10),
vb01::Vector3(-2, -1, -10),
vb01::Vector3(-2, -1, 9),
vb01::Vector3(2, -1, 9),
vb01::Vector3(2, 4.5, -10),
vb01::Vector3(-2, 4.5, -10),
vb01::Vector3(-2, 4.5, 9),
vb01::Vector3(2, 4.5, 9)
},
{
vector3df(.25, -.5, -2),
vector3df(-.25, -.5, -2),
vector3df(-.25, -.5, 3),
vector3df(.25, -.5, 3),
vector3df(.25, .7, -2),
vector3df(-.25, .7, -2),
vector3df(-.25, .7, 3),
vector3df(.25, .7, 3)
vb01::Vector3(.25, -.5, -2),
vb01::Vector3(-.25, -.5, -2),
vb01::Vector3(-.25, -.5, 3),
vb01::Vector3(.25, -.5, 3),
vb01::Vector3(.25, .7, -2),
vb01::Vector3(-.25, .7, -2),
vb01::Vector3(-.25, .7, 3),
vb01::Vector3(.25, .7, 3)
},
{
vector3df(.6,-.1,-1.3),
vector3df(-.6,-.1,-1.3),
vector3df(-.6,-.1,.8),
vector3df(.6,-.1,.8),
vector3df(.6,.3,-1.3),
vector3df(-.6,.3,-1.3),
vector3df(-.6,.3,.8),
vector3df(.6,.3,.8)
vb01::Vector3(.6,-.1,-1.3),
vb01::Vector3(-.6,-.1,-1.3),
vb01::Vector3(-.6,-.1,.8),
vb01::Vector3(.6,-.1,.8),
vb01::Vector3(.6,.3,-1.3),
vb01::Vector3(-.6,.3,-1.3),
vb01::Vector3(-.6,.3,.8),
vb01::Vector3(.6,.3,.8)
},
{
vector3df(.5,-.1,-1.3),
vector3df(-.5,-.1,-1.3),
vector3df(-.5,-.1,.7),
vector3df(.5,-.1,.7),
vector3df(.5,.15,-1.3),
vector3df(-.5,.15,-1.3),
vector3df(-.5,.15,.7),
vector3df(.5,.15,.7)
vb01::Vector3(.5,-.1,-1.3),
vb01::Vector3(-.5,-.1,-1.3),
vb01::Vector3(-.5,-.1,.7),
vb01::Vector3(.5,-.1,.7),
vb01::Vector3(.5,.15,-1.3),
vb01::Vector3(-.5,.15,-1.3),
vb01::Vector3(-.5,.15,.7),
vb01::Vector3(.5,.15,.7)
}
};
const vector3df unitCuboidDimensions[numberOfUnits][8]{
const vb01::Vector3 unitCuboidDimensions[numberOfUnits][8]{
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1),
vector3df(1, 1, 1)
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1),
vb01::Vector3(1, 1, 1)
},
{
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1)
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1)
},
{
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1)
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1)
},
{
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1),
vector3df(.1, .1, .1)
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1),
vb01::Vector3(.1, .1, .1)
}
};
const float unitAxisLength[numberOfUnits]{8, 8,6,6,5, 5,8, 8, 7,2,2};
const float lineOfSight[numberOfUnits]{5, 8, 4, 4, 3, 3, 6, 6, 3, 3, 8};
const stringw name[numberOfUnits]{
const std::string name[numberOfUnits]{
"Battleship", "Battleship",
"Destroyer", "Destroyer",
"Cruiser", "Cruiser",
@@ -274,7 +272,7 @@ namespace game{
"Submarine",
"Jet", "Jet"
};
const path meshPath[numberOfUnits]{
const std::string meshPath[numberOfUnits]{
"hull00.x", "hull01.x",
"hull00.x", "hull01.x",
"hull00.x", "hull01.x",
@@ -282,7 +280,7 @@ namespace game{
"hull.x",
"jet00.x", "jet01.x"
};
const path basePath[numberOfUnits]{
const std::string basePath[numberOfUnits]{
PATH + "Models/Battleships/", PATH + "Models/Battleships/",
PATH + "Models/Destroyers/", PATH + "Models/Destroyers/",
PATH + "Models/Cruisers/", PATH + "Models/Cruisers/",
+35 -69
View File
@@ -1,4 +1,5 @@
#include <cmath>
#include <vector.h>
#include "util.h"
#include "gameManager.h"
@@ -7,69 +8,32 @@
#include "inGameAppState.h"
using namespace std;
using namespace vb01;
using namespace vb01Gui;
using namespace game;
using namespace game::core;
using namespace game::gui;
using namespace irr::gui;
using namespace irr::scene;
using namespace game::core;
namespace game{
namespace util{
ISceneNode* castRay(ISceneManager *smgr, vector3df start, vector3df end){
ISceneCollisionManager *collMan = smgr->getSceneCollisionManager();
line3d<float> ray;
ray.start = start;
ray.end = end;
triangle3df t;
vector3df collPoint;
ISceneNode *collNode = collMan->getSceneNodeAndCollisionPointFromRay(ray, collPoint, t, 0, 0);
return collNode;
}
vector<stringw> readFile(std::string path,int firstLine,int lastLine) {
vector<stringw> fileLines;
ifstream inFile;
inFile.open(path);
if (inFile.is_open()) {
int i=0;
std::string line;
while (getline(inFile,line)) {
if((lastLine!=0&&firstLine<=i&&i<lastLine)||lastLine==-1)
fileLines.push_back(stringw(line.c_str()));
i++;
}
}
inFile.close();
return fileLines;
}
void writeFile(std::string path, vector<std::string> fileLines) {
ofstream outFile;
outFile.open(path);
if (outFile.is_open())
for (int i = 0; i < fileLines.size(); i++)
outFile << fileLines[i] << "\n";
outFile.close();
}
void makeTitlescreenButtons(GuiAppState *state) {
class SpButton : public Button {
public:
SpButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
SpButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->state = state;
}
void onClick() {
vector<stringw> difficulties, factions;
vector<string> difficulties, factions;
class PlayButton : public Button {
public:
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
PlayButton(Listbox **difficulties, Listbox **factions, int lengths[2], Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->state = ((GuiAppState*)GameManager::getSingleton()->getStateManager()->getAppState(AppStateTypes::GUI_STATE));
this->lengths[0]=lengths[0];
this->lengths[1]=lengths[1];
difficultiesListboxes=difficulties;
factionsListboxes=factions;
}
@@ -79,13 +43,15 @@ namespace game{
gm->detachAllBitmapTexts();
state->removeButton("Back");
// gameManager->dettachState(state);
std::vector<stringw> difficulties,factions;
std::vector<string> difficulties, factions;
/*
for(int i=0;i<lengths[0];i++)
difficulties.push_back(difficultiesListboxes[i]->getLine(difficultiesListboxes[i]->getSelectedOption()));
difficulties.push_back(difficultiesListboxes[i]->getContents()[difficultiesListboxes[i]->getSelectedOption()]);
for(int i=0;i<lengths[1];i++)
factions.push_back(stringw(factionsListboxes[i]->getSelectedOption()));
factions.push_back(factionsListboxes[i]->getSelectedOption());
*/
gm->getStateManager()->attachState(new InGameAppState(difficulties, factions));
state->removeAllListboxes();
@@ -102,7 +68,7 @@ namespace game{
class ReturnButton : public Button {
public:
ReturnButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->state = state;
}
@@ -121,28 +87,31 @@ namespace game{
};
GameManager *gm = GameManager::getSingleton();
IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
vector2d<s32> pos(gm->getWidth() / 8, gm->getHeight() / 8);
//IGUIFont *font = gm->getDevice()->getGUIEnvironment()->getFont(PATH + "Fonts/fonthaettenschweiler.bmp");
Vector2 pos(gm->getWidth() / 8, gm->getHeight() / 8);
difficulties.push_back("Easy");
difficulties.push_back("Medium");
difficulties.push_back("Hard");
factions.push_back("0");
factions.push_back("1");
/*
gm->attachBitmapText(new BitmapText("Difficulty", vector2d<s32>(pos.X, pos.Y - 20), font));
gm->attachBitmapText(new BitmapText("Faction", vector2d<s32>(pos.X + 110, pos.Y - 20), font));
gm->attachBitmapText(new BitmapText("Player", vector2d<s32>(pos.X - 40, pos.Y), font));
gm->attachBitmapText(new BitmapText("CPU", vector2d<s32>(pos.X - 20, pos.Y + 30), font));
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);
*/
string font = PATH + "Fonts/batang.ttf";
Listbox *cpuDifficulty = new Listbox(Vector2(pos.x, pos.y + 30), Vector2(100, 20), difficulties, 3, font);
Listbox *cpuFaction = new Listbox(Vector2(pos.x + 110, pos.y + 30), Vector2(100, 20), factions, 2, font);
Listbox *playerFaction = new Listbox(Vector2(pos.x + 110, pos.y), Vector2(100, 20), factions, 2, font);
Listbox **difficultyListboxes=new Listbox*[1];
Listbox **factionListboxes=new Listbox*[2];
difficultyListboxes[0]=cpuDifficulty;
factionListboxes[0]=playerFaction;
factionListboxes[1]=cpuFaction;
int lengths[]{1,2};
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, 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);
PlayButton *playButton = new PlayButton(difficultyListboxes, factionListboxes, lengths, Vector2(50, gm->getHeight() - 150), Vector2(140, 50), "Play", true);
ReturnButton *returnButton = new ReturnButton(state, Vector2(200, gm->getHeight() - 150), Vector2(140, 50), "Back", true);
state->addButton(playButton);
state->addButton(returnButton);
state->addListbox(cpuDifficulty);
@@ -159,12 +128,12 @@ namespace game{
class MainMenuOptionsButton : public OptionsButton {
public:
MainMenuOptionsButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : OptionsButton(pos, size, name, separate) {
MainMenuOptionsButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : OptionsButton(pos, size, name, separate) {
this->state = state;
}
void onClick() {
ReturnButton *returnButton = new ReturnButton(state, vector2d<s32>(50, GameManager::getSingleton()->getHeight() - 150), vector2d<s32>(150, 50), "Back", true);
ReturnButton *returnButton = new ReturnButton(state, Vector2(50, GameManager::getSingleton()->getHeight() - 150), Vector2(150, 50), "Back", true);
state->addButton(returnButton);
state->removeButton("Singleplayer");
state->removeButton("Exit");
@@ -176,7 +145,7 @@ namespace game{
class ReturnButton : public Button {
public:
ReturnButton(GuiAppState *state, vector2d<s32> pos, vector2d<s32> size, stringw name, bool separate) : Button(pos, size, name, separate) {
ReturnButton(GuiAppState *state, Vector2 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, separate) {
this->state = state;
}
@@ -191,10 +160,10 @@ namespace game{
state->removeButton("Audio");
state->removeButton("Multiplayer");
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);
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
state->addButton(optionsButton);
ExitButton *exitButton = new ExitButton(vector2d<s32>(gm->getWidth() / 16, gm->getHeight() / 12 * 3), vector2d<s32>(150, 40), "Exit", true);
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
state->addButton(spButton);
state->addButton(exitButton);
state->removeButton("Back");
@@ -205,19 +174,15 @@ namespace game{
};
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);
SpButton *spButton = new SpButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12), Vector2(150, 40), "Singleplayer", true);
MainMenuOptionsButton *optionsButton = new MainMenuOptionsButton(state, Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 2), Vector2(150, 40), "Options", true);
ExitButton *exitButton = new ExitButton(Vector2(gm->getWidth() / 16, gm->getHeight() / 12 * 3), Vector2(150, 40), "Exit", true);
state->addButton(optionsButton);
state->addButton(spButton);
state->addButton(exitButton);
}
double getAngleBetween(vector3df v1, vector3df v2) {
v1.normalize();
v2.normalize();
return acos(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z);
}
/*
bool isWithinRect(vector3df c1,vector3df c2, vector3df p, vector3df dir){
float mainAngle=getAngleBetween(c1-c2,dir);
float mainHyp=(c1-c2).getLength();
@@ -239,5 +204,6 @@ namespace game{
bool withinC=cAngle<=PI/2&&p*cos(cAngle)<=c;
return withinA&&withinB&&withinC;
}
*/
}
}
+4 -8
View File
@@ -1,12 +1,11 @@
#pragma once
#ifndef UTIL_H
#define UTIL_H
#ifndef UTIL_BATTLESHIP_H
#define UTIL_BATTLESHIP_H
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <irrlicht.h>
#include <chrono>
namespace game{
@@ -25,14 +24,11 @@ namespace game{
}
namespace util{
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::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);
inline s64 getTime(){return (s64)(std::chrono::system_clock::now().time_since_epoch()/std::chrono::milliseconds(1));}
*/
}
}
+50 -28
View File
@@ -1,4 +1,7 @@
#include <algorithm>
#include <quaternion.h>
#include <model.h>
#include <texture.h>
#include "vessel.h"
#include "util.h"
@@ -9,30 +12,28 @@
using namespace game::core;
using namespace game::util;
using namespace irr::core;
using namespace irr::io;
using namespace irr::video;
using namespace irr::scene;
using namespace sf;
using namespace std;
using namespace vb01;
namespace game{
namespace content{
Vessel::Turret::Turret(Unit *vessel, int unitId, int turretId) {
this->vessel = vessel;
hullNode = vessel->getNode();
//hullNode = vessel->getNode();
this->unitId = unitId;
this->turretId = turretId;
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);
ITexture *turretDiffuseTexture = driver->getTexture(basePath[unitId] + turretNames[unitId][turretId] + "DiffuseMap.png");
if (turretDiffuseTexture)
turretNode->setMaterialTexture(0, turretDiffuseTexture);
else
turretNode->setMaterialTexture(0, driver->getTexture(DEFAULT_TEXTURE));
*/
string fr[]{basePath[unitId] + turretNames[unitId][turretId] + "DiffuseMap.png"};
Texture *turretDiffuseTexture = new Texture(fr);
/*
turretNode->setParent(vessel->getNode());
turretNode->setPosition(turretPos[unitId][turretId]);
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 180 * turretAngleOffset[unitId][turretId], vector3df(0, 1, 0));
@@ -41,7 +42,9 @@ namespace game{
rotationSpeed = unitData::turretRotationSpeed[unitId][turretId];
maxAngle = unitData::turretMaxAngle[unitId][turretId];
this->rateOfFire = unitData::turretRateOfFire[unitId][turretId];
*/
/*
for (int i = 0; i < numberOfMantlets[unitId][turretId]; i++) {
IAnimatedMesh *mantletMesh = smgr->getMesh(basePath[unitId] + mantletNames[unitId][turretId] + ".x");
IAnimatedMesh *barrelMesh = smgr->getMesh(basePath[unitId] + barrelNames[unitId][turretId] + ".x");
@@ -52,11 +55,14 @@ namespace game{
turretBarrelMeshes.push_back(barrelMesh);
turretBarrelNodes.push_back(barrelNode);
}
if (turretMantletNodes.size() > 1) {
turretMantletNodes[0]->setPosition(turretMantletNodes[0]->getPosition() + vector3df(mantletPosSideOffset[unitId][turretId], 0, 0));
turretMantletNodes[1]->setPosition(turretMantletNodes[1]->getPosition() - vector3df(mantletPosSideOffset[unitId][turretId], 0, 0));
}
*/
/*
fxNode=smgr->addParticleSystemSceneNode(false);
emitter=fxNode->createPointEmitter(dirVec,
10,10,
@@ -76,12 +82,15 @@ namespace game{
fxNode->setMaterialTexture(0, driver->getTexture(PATH+"Textures/Explosions/fire.bmp"));
fxNode->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
fxNode->setVisible(false);
*/
sfxBuffer=new SoundBuffer();
sfxBuffer = new sf::SoundBuffer();
if(sfxBuffer->loadFromFile(getExplosionSfxPath().c_str()))
sfx=new Sound(*sfxBuffer);
sfx = new sf::Sound(*sfxBuffer);
}
/*
ISceneNode* Vessel::Turret::initMantletNode(IVideoDriver *driver, ISceneManager *smgr, IAnimatedMesh *mantletMesh, int unitId, int turretId) {
ISceneNode *mantletNode = smgr->addAnimatedMeshSceneNode(mantletMesh);
mantletNode->setMaterialFlag(EMF_LIGHTING, false);
@@ -107,27 +116,32 @@ namespace game{
barrelNode->setPosition(barrelPos[unitId][turretId]);
return barrelNode;
}
*/
void Vessel::Turret::rotate(double angle) {
quaternion rotQuat = rotQuat.fromAngleAxis(PI / 180 * angle, vector3df(0, 1, 0));
turretNode->setRotation(vector3df(0, turretNode->getRotation().Y + angle, 0));
Quaternion rotQuat = Quaternion(PI / 180 * angle, Vector3(0, 1, 0));
//turret->setOrientation(vector3df(0, turret->getRotation().Y + angle, 0));
dirVec = rotQuat*dirVec, leftVec = rotQuat*leftVec;
this->angle += angle;
}
void Vessel::Turret::update() {
turretPosition = turretNode->getAbsolutePosition();
float hullAngle = PI / 180 * hullNode->getRotation().Y;
Node *rootNode = Root::getSingleton()->getRootNode();
turretPosition = rootNode->localToGlobalPosition(turret->getPosition());
float hullAngle = PI / 180 /* hullNode->getRotation().Y*/;
float turretAngle = PI / 180 * angle;
/*
quaternion rotQuat = rotQuat.fromAngleAxis(hullAngle + turretAngle, vector3df(0, 1, 0));
quaternion offsetQuat = offsetQuat.fromAngleAxis(PI / 180 * unitData::turretAngleOffset[unitId][turretId], vector3df(0, 1, 0));
dirVec = rotQuat * (offsetQuat * vector3df(0, 0, -1)), leftVec = rotQuat * (offsetQuat * vector3df(1, 0, 0));
emitter->setDirection(dirVec);
// if(getTime()-lastShotTime>30&&fxNode->isVisible())
// fxNode->setVisible(false);
// */
}
void Vessel::Turret::debug(const SMaterial &mat) {
void Vessel::Turret::debug(const Material &mat) {
/*
float length = turretAxisLength[unitId][turretId]*0 + 1;
IVideoDriver *driver = GameManager::getSingleton()->getDevice()->getVideoDriver();
driver->setTransform(ETS_WORLD, IdentityMatrix);
@@ -135,10 +149,11 @@ namespace game{
driver->draw3DLine(turretPosition, turretPosition + dirVec*length, SColor(255, 0, 0, 255));
driver->draw3DLine(turretPosition, turretPosition + leftVec*length, SColor(255, 255, 0, 0));
driver->draw3DLine(turretPosition, turretPosition + upVec*length, SColor(255, 0, 255, 0));
*/
}
vector3df* Vessel::Turret::getInitDirs(){
vector3df *initDirs=new vector3df[2];
Vector3* Vessel::Turret::getInitDirs(){
Vector3 *initDirs = new Vector3[2];
switch(unitData::initDirs[unitId][turretId]){
case unitData::FORWARD:
initDirs[0]=vessel->getDirVec();
@@ -161,6 +176,7 @@ namespace game{
}
void Vessel::Turret::fire() {
/*
quaternion rotQuat = rotQuat.fromAngleAxis(barrelAngle / 180 * PI, leftVec);
int barId = 0;
vector3df startPos = vessel->getPos() + vessel->getLeftVec() * turretNode->getPosition().X + vessel->getUpVec() * turretNode->getPosition().Y - vessel->getDirVec() * turretNode->getPosition().Z;
@@ -171,9 +187,10 @@ namespace game{
// fxNode->setVisible(true);
if(sfx) sfx->play();
lastShotTime = getTime();
*/
}
Vessel::Vessel(Player *player,vector3df pos, int id) : Unit(player,pos, id) {
Vessel::Vessel(Player *player, Vector3 pos, int id) : Unit(player,pos, id) {
if (numberOfTurrets[id] > 0)
for (int i = 0; i < numberOfTurrets[id]; i++)
turrets.push_back(new Turret(this, id, i));
@@ -191,26 +208,31 @@ namespace game{
}
void Vessel::attack(Order order) {
vector3df target=*order.targetPos[0];
Vector3 target = *order.targetPos[0];
Unit::attack(order);
for (Turret *t : turrets) {
vector3df *initDirs=t->getInitDirs();
bool right = getAngleBetween(t->getLeftVec(), target - t->getPos()) > PI / 2;
float angle = getAngleBetween(initDirs[0], target - t->getPos()) / PI * 180;
Vector3 *initDirs = t->getInitDirs();
bool right = t->getLeftVec().getAngleBetween(target - t->getPos()) > PI / 2;
float angle = initDirs[0].getAngleBetween(target - t->getPos()) / PI * 180;
float rotAngle = t->getRotationSpeed() > angle ? angle : t->getRotationSpeed()*(right?1:-1);
if (-t->getMaxAngle() <= t->getAngle() + rotAngle
&& t->getAngle() + rotAngle <= t->getMaxAngle()) {
t->rotate(rotAngle);
if (t->canFire()) t->fire();
}
delete[] initDirs;
}
}
void Vessel::debug() {
// Unit::debug();
/*
for (Turret *t : turrets)
t->debug(createLineMaterial());
*/
}
}
}
+32 -23
View File
@@ -2,56 +2,65 @@
#ifndef VESSEL_H
#define VESSEL_H
#include <vector.h>
#include <util.h>
#include "unit.h"
#include "util.h"
namespace vb01{
class Model;
class Material;
class ParticleEmitter;
}
namespace game{
namespace content {
class Vessel : public Unit {
public:
Vessel(Player*,vector3df, int);
Vessel(Player*, vb01::Vector3, int);
void update();
protected:
void attack(Order);
private:
void debug();
class Turret {
public:
Turret(Unit*, int, int);
void update();
void fire();
void rotate(double);
void debug(const SMaterial&);
vector3df* getInitDirs();
inline vector3df getDirVec(){return dirVec;}
inline vector3df getLeftVec(){return leftVec;}
inline vector3df getUpVec(){return upVec;}
inline vector3df getPos(){return turretPosition;}
void debug(const vb01::Material&);
vb01::Vector3* getInitDirs();
inline vb01::Vector3 getDirVec(){return dirVec;}
inline vb01::Vector3 getLeftVec(){return leftVec;}
inline vb01::Vector3 getUpVec(){return upVec;}
inline vb01::Vector3 getPos(){return turretPosition;}
inline float getMaxAngle(){return maxAngle;}
inline float getRotationSpeed(){return rotationSpeed;}
inline float getAngle(){return angle;}
inline bool canFire(){return util::getTime()-lastShotTime>rateOfFire;}
inline bool canFire(){return vb01::getTime() - lastShotTime > rateOfFire;}
private:
inline irr::io::path getExplosionSfxPath(){return core::PATH+"Sounds/Explosions/explosion0"+stringw(rand()%4)+".ogg";}
irr::scene::IParticleSystemSceneNode *fxNode;
irr::scene::IParticleEmitter *emitter;
irr::scene::IParticleAffector *affector;
inline std::string getExplosionSfxPath(){return core::PATH + "Sounds/Explosions/explosion0" + std::to_string(rand() % 4) + ".ogg";}
vb01::Node *fxNode;
vb01::ParticleEmitter *emitter;
Unit *vessel;
irr::scene::IAnimatedMesh *turretMesh;
irr::scene::ISceneNode *turretNode, *hullNode;
std::vector<irr::scene::IAnimatedMesh*> turretMantletMeshes, turretBarrelMeshes;
std::vector<irr::scene::ISceneNode*> turretMantletNodes, turretBarrelNodes;
std::vector<vector3df> turretMantletPos;
irr::core::vector3df turretBarrelPos, turretPosition;
irr::core::vector3df upVec = irr::core::vector3df(0, 1, 0),dirVec = irr::core::vector3df(0, 0, -1),initDir,leftVec = irr::core::vector3df(1, 0, 0);
vb01::Model *turret, *hull;
std::vector<vb01::Model*> turretMantlets, turretBarrels;
std::vector<vb01::Vector3> turretMantletPos;
vb01::Vector3 turretBarrelPos, turretPosition;
vb01::Vector3 upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, -1), initDir, leftVec = vb01::Vector3(1, 0, 0);
float angle = 0., barrelAngle = 0., maxAngle, rotationSpeed,maxBarrelAngle;
int rateOfFire, damage, unitId, turretId;
ISceneNode* initMantletNode(irr::video::IVideoDriver*, irr::scene::ISceneManager*, irr::scene::IAnimatedMesh*, int, int);
ISceneNode* initBarrelNode(irr::video::IVideoDriver*, ISceneManager*, irr::scene::IAnimatedMesh*, irr::scene::ISceneNode*, int, int);
/*
vb01::Model* initMantletNode(irr::scene::IAnimatedMesh*, int, int);
vb01::Model* initBarrelNode(irr::scene::IAnimatedMesh*, irr::scene::ISceneNode*, int, int);
*/
s64 lastShotTime;
sf::SoundBuffer *sfxBuffer;
sf::Sound *sfx=nullptr;
sf::Sound *sfx = nullptr;
};
std::vector<Turret*> turrets;
};
}
+137 -137
View File
@@ -28,7 +28,7 @@ namespace game{
{FORWARD,BACKWARD},
{FORWARD,FORWARD,FORWARD,BACKWARD,BACKWARD},
};
const stringw turretNames[numberOfUnits][maxNumTurrets]{
const std::string turretNames[numberOfUnits][maxNumTurrets]{
{
"bigTurret00",
"bigTurret00",
@@ -64,59 +64,59 @@ namespace game{
{"turret00", "turret00"},
{"turret01", "turret01", "turret01", "turret01", "turret01"}
};
const vector3df turretPos[numberOfUnits][maxNumTurrets]{
const vb01::Vector3 turretPos[numberOfUnits][maxNumTurrets]{
{
vector3df(0, .77703, -3.24292),
vector3df(0, 0.96741, -1.67253),
vector3df(0, 0.77703, 3.29185),
vector3df(0.90322, 0.78121, -0.17934),
vector3df(0.90322, 0.78121, 0.42676),
vector3df(0.90322, 0.78121, 1.03286),
vector3df(0.90322, 0.78121, 1.63896),
vector3df(0.90322, 0.78121, 2.24506),
vector3df(-0.90322, 0.78121, -0.17934),
vector3df(-0.90322, 0.78121, 0.42676),
vector3df(-0.90322, 0.78121, 1.03286),
vector3df(-0.90322, 0.78121, 1.63896),
vector3df(-0.90322, 0.78121, 2.24506)
vb01::Vector3(0, .77703, -3.24292),
vb01::Vector3(0, 0.96741, -1.67253),
vb01::Vector3(0, 0.77703, 3.29185),
vb01::Vector3(0.90322, 0.78121, -0.17934),
vb01::Vector3(0.90322, 0.78121, 0.42676),
vb01::Vector3(0.90322, 0.78121, 1.03286),
vb01::Vector3(0.90322, 0.78121, 1.63896),
vb01::Vector3(0.90322, 0.78121, 2.24506),
vb01::Vector3(-0.90322, 0.78121, -0.17934),
vb01::Vector3(-0.90322, 0.78121, 0.42676),
vb01::Vector3(-0.90322, 0.78121, 1.03286),
vb01::Vector3(-0.90322, 0.78121, 1.63896),
vb01::Vector3(-0.90322, 0.78121, 2.24506)
},
{
vector3df(0, 0.70974, -2.73371),
vector3df(0, 0.915258, -1.62768),
vector3df(0, 0.70974, 3.33251),
vector3df(0.58824, 0.76908, 0.30145),
vector3df(0.58824, 0.98059, 0.58992),
vector3df(0.58824, 0.76908, 0.8634),
vector3df(0.58824, 0.98059, 1.13294),
vector3df(0.58824, 0.76908, 1.40591),
vector3df(-0.58824, 0.76908, 0.30145),
vector3df(-0.58824, 0.98059, 0.58992),
vector3df(-0.58824, 0.76908, 0.8634),
vector3df(-0.58824, 0.98059, 1.13294),
vector3df(-0.58824, 0.76908, 1.40591)
vb01::Vector3(0, 0.70974, -2.73371),
vb01::Vector3(0, 0.915258, -1.62768),
vb01::Vector3(0, 0.70974, 3.33251),
vb01::Vector3(0.58824, 0.76908, 0.30145),
vb01::Vector3(0.58824, 0.98059, 0.58992),
vb01::Vector3(0.58824, 0.76908, 0.8634),
vb01::Vector3(0.58824, 0.98059, 1.13294),
vb01::Vector3(0.58824, 0.76908, 1.40591),
vb01::Vector3(-0.58824, 0.76908, 0.30145),
vb01::Vector3(-0.58824, 0.98059, 0.58992),
vb01::Vector3(-0.58824, 0.76908, 0.8634),
vb01::Vector3(-0.58824, 0.98059, 1.13294),
vb01::Vector3(-0.58824, 0.76908, 1.40591)
},
{
vector3df(0, 0.04967, -2.08348),
vector3df(0, 0.25291, -1.26886),
vector3df(0, 0.25291, 1.61533),
vector3df(0, 0.04967, 2.42996)
vb01::Vector3(0, 0.04967, -2.08348),
vb01::Vector3(0, 0.25291, -1.26886),
vb01::Vector3(0, 0.25291, 1.61533),
vb01::Vector3(0, 0.04967, 2.42996)
},
{
vector3df(0, 0.53012, -2.92538),
vector3df(0, 0.707, -2.45061),
vector3df(0, 0.55879, 2.16916),
vector3df(0, 0.3808, 2.72071)
vb01::Vector3(0, 0.53012, -2.92538),
vb01::Vector3(0, 0.707, -2.45061),
vb01::Vector3(0, 0.55879, 2.16916),
vb01::Vector3(0, 0.3808, 2.72071)
},
{
vector3df(0, 0.73788, -2.79825),
vector3df(0, 0.73788, 2.79825)
vb01::Vector3(0, 0.73788, -2.79825),
vb01::Vector3(0, 0.73788, 2.79825)
},
{
vector3df(0, 0.52632, -3.64706),
vector3df(0, 0.71625, -2.81714),
vector3df(0, 0.86667, -1.92772),
vector3df(0, 0.7724, 2.53618),
vector3df(0, 0.52632, 3.41345)
vb01::Vector3(0, 0.52632, -3.64706),
vb01::Vector3(0, 0.71625, -2.81714),
vb01::Vector3(0, 0.86667, -1.92772),
vb01::Vector3(0, 0.7724, 2.53618),
vb01::Vector3(0, 0.52632, 3.41345)
}
};
const float turretAngleOffset[numberOfUnits][maxNumTurrets]{
@@ -175,7 +175,7 @@ namespace game{
{1, 1},
{3, 3, 3, 3, 3}
};
const stringw mantletNames[numberOfUnits][maxNumTurrets]{
const std::string mantletNames[numberOfUnits][maxNumTurrets]{
{
"bigMantlet00",
"bigMantlet00",
@@ -211,59 +211,59 @@ namespace game{
{"mantlet00", "mantlet00"},
{"mantlet01", "mantlet01", "mantlet01", "mantlet01", "mantlet01"}
};
const vector3df mantletPos[numberOfUnits][maxNumTurrets]{
const vb01::Vector3 mantletPos[numberOfUnits][maxNumTurrets]{
{
vector3df(0, 0.19722f, -0.38441f),
vector3df(0, 0.183f, -0.38876f),
vector3df(0, 0.183f, -0.38876f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f),
vector3df(0, 0.06484f, -0.08587f)
vb01::Vector3(0, 0.19722f, -0.38441f),
vb01::Vector3(0, 0.183f, -0.38876f),
vb01::Vector3(0, 0.183f, -0.38876f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f),
vb01::Vector3(0, 0.06484f, -0.08587f)
},
{
vector3df(0, 0.111116, -0.335219),
vector3df(0, 0.111116, -0.335219),
vector3df(0, 0.111116, -0.335219),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749),
vector3df(0, 0.025217, -0.071749)
vb01::Vector3(0, 0.111116, -0.335219),
vb01::Vector3(0, 0.111116, -0.335219),
vb01::Vector3(0, 0.111116, -0.335219),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749),
vb01::Vector3(0, 0.025217, -0.071749)
},
{
vector3df(0, 0.22782f, -0.12394f),
vector3df(0, 0.22782f, -0.12394f),
vector3df(0, 0.22782f, -0.12394f),
vector3df(0, 0.22782f, -0.12394f)
vb01::Vector3(0, 0.22782f, -0.12394f),
vb01::Vector3(0, 0.22782f, -0.12394f),
vb01::Vector3(0, 0.22782f, -0.12394f),
vb01::Vector3(0, 0.22782f, -0.12394f)
},
{
vector3df(0, 0.14613, -0.0217),
vector3df(0, 0.14613, -0.0217),
vector3df(0, 0.14613, -0.0217),
vector3df(0, 0.14613, -0.0217)
vb01::Vector3(0, 0.14613, -0.0217),
vb01::Vector3(0, 0.14613, -0.0217),
vb01::Vector3(0, 0.14613, -0.0217),
vb01::Vector3(0, 0.14613, -0.0217)
},
{
vector3df(0, 0.2842f, -0.1274f),
vector3df(0, 0.2842f, -0.1274f)
vb01::Vector3(0, 0.2842f, -0.1274f),
vb01::Vector3(0, 0.2842f, -0.1274f)
},
{
vector3df(0, 0.09455, -0.19379),
vector3df(0, 0.09455, -0.19379),
vector3df(0, 0.09455, -0.19379),
vector3df(0, 0.09455, -0.19379),
vector3df(0, 0.09455, -0.19379)
vb01::Vector3(0, 0.09455, -0.19379),
vb01::Vector3(0, 0.09455, -0.19379),
vb01::Vector3(0, 0.09455, -0.19379),
vb01::Vector3(0, 0.09455, -0.19379),
vb01::Vector3(0, 0.09455, -0.19379)
}
};
const float mantletPosSideOffset[numberOfUnits][maxNumTurrets]{
@@ -320,60 +320,60 @@ namespace game{
{40, 40},
{40, 40, 40, 40, 40}
};
const vector3df barrelPos[numberOfUnits][maxNumTurrets]{
const vb01::Vector3 barrelPos[numberOfUnits][maxNumTurrets]{
{
vector3df(0, 0, -0.16689f),
vector3df(0, 0, -0.16689f),
vector3df(0, 0, -0.16689f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f),
vector3df(0, 0, -0.1021f)},
vb01::Vector3(0, 0, -0.16689f),
vb01::Vector3(0, 0, -0.16689f),
vb01::Vector3(0, 0, -0.16689f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f),
vb01::Vector3(0, 0, -0.1021f)},
{
vector3df(0, 0, -0.246837),
vector3df(0, 0, -0.246837),
vector3df(0, 0, -0.246837),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993),
vector3df(0, 0, -0.054993)
vb01::Vector3(0, 0, -0.246837),
vb01::Vector3(0, 0, -0.246837),
vb01::Vector3(0, 0, -0.246837),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993),
vb01::Vector3(0, 0, -0.054993)
},
{
vector3df(0, 0, -0.12806f),
vector3df(0, 0, -0.12806f),
vector3df(0, 0, -0.12806f),
vector3df(0, 0, -0.12806f)},
vb01::Vector3(0, 0, -0.12806f),
vb01::Vector3(0, 0, -0.12806f),
vb01::Vector3(0, 0, -0.12806f),
vb01::Vector3(0, 0, -0.12806f)},
{
vector3df(0, 0, -0.11048),
vector3df(0, 0, -0.11048),
vector3df(0, 0, -0.11048),
vector3df(0, 0, -0.11048)
vb01::Vector3(0, 0, -0.11048),
vb01::Vector3(0, 0, -0.11048),
vb01::Vector3(0, 0, -0.11048),
vb01::Vector3(0, 0, -0.11048)
},
{
vector3df(0, 0, -0.23015f),
vector3df(0, 0, -0.23015f)
vb01::Vector3(0, 0, -0.23015f),
vb01::Vector3(0, 0, -0.23015f)
},
{
vector3df(0, 0, -0.14595),
vector3df(0, 0, -0.14595),
vector3df(0, 0, -0.14595),
vector3df(0, 0, -0.14595),
vector3df(0, 0, -0.14595)
vb01::Vector3(0, 0, -0.14595),
vb01::Vector3(0, 0, -0.14595),
vb01::Vector3(0, 0, -0.14595),
vb01::Vector3(0, 0, -0.14595),
vb01::Vector3(0, 0, -0.14595)
}
};
const stringw barrelNames[numberOfUnits][maxNumTurrets]{
const std::string barrelNames[numberOfUnits][maxNumTurrets]{
{
"bigBarrel00",
"bigBarrel00",
@@ -409,20 +409,20 @@ namespace game{
{"barrel00", "barrel00"},
{"barrel01", "barrel01", "barrel01", "barrel01", "barrel01"}
};
const vector3df guidedMissilePos[numberOfUnits][6]{
const vb01::Vector3 guidedMissilePos[numberOfUnits][6]{
{},
{},
{},
{},
{
vector3df(0.24482, 1.14985, 1.32775),
vector3df(0.24482, 1.14985, 1.62698),
vector3df(0.24482, 1.14985, 1.88017),
vector3df(-0.24482, 1.14985, 1.32775),
vector3df(-0.24482, 1.14985, 1.62698),
vector3df(-0.24482, 1.14985, 1.88017)
vb01::Vector3(0.24482, 1.14985, 1.32775),
vb01::Vector3(0.24482, 1.14985, 1.62698),
vb01::Vector3(0.24482, 1.14985, 1.88017),
vb01::Vector3(-0.24482, 1.14985, 1.32775),
vb01::Vector3(-0.24482, 1.14985, 1.62698),
vb01::Vector3(-0.24482, 1.14985, 1.88017)
},
{vector3df(0.17192, 0.57858, 0.64471), vector3df(-0.17192, 0.57858, 0.64471)}
{vb01::Vector3(0.17192, 0.57858, 0.64471), vb01::Vector3(-0.17192, 0.57858, 0.64471)}
};
}
}