mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
implemented garrison slot rendering
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
|
|||||||
set(PROJECTILES projectile.cpp)
|
set(PROJECTILES projectile.cpp)
|
||||||
set(FX fx.cpp)
|
set(FX fx.cpp)
|
||||||
set(VEHICLES vehicle.cpp engineer.cpp transport.cpp)
|
set(VEHICLES vehicle.cpp engineer.cpp transport.cpp)
|
||||||
set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp garrisonable.cpp ${VEHICLES})
|
set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp ${VEHICLES})
|
||||||
set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX})
|
set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX})
|
||||||
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,23 @@
|
|||||||
#include "garrisonable.h"
|
#include "garrisonable.h"
|
||||||
|
#include "unit.h"
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
|
|
||||||
|
void Garrisonable::update(){
|
||||||
|
}
|
||||||
|
|
||||||
void Garrisonable::ejectVehicle(int id){
|
void Garrisonable::ejectVehicle(int id){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Garrisonable::prepareGarrisonSlots(){
|
||||||
|
for(int i = 0; i < capacity; i++){
|
||||||
|
Vector2 size = 10 * Vector2::VEC_IJ;
|
||||||
|
Vector2 pos = Vector2(0, 10 * (i));
|
||||||
|
garrisonSlotBackgrounds.push_back(Unit::createBar(pos, size, Vector4(0, 0, 0, 1)));
|
||||||
|
garrisonSlotForegrounds.push_back(Unit::createBar(pos, size, Vector4(0, 1, 0, 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "unit.h"
|
||||||
|
|
||||||
namespace vb01{
|
namespace vb01{
|
||||||
class Node;
|
class Node;
|
||||||
}
|
}
|
||||||
@@ -13,11 +15,15 @@ namespace battleship{
|
|||||||
class Garrisonable{
|
class Garrisonable{
|
||||||
public:
|
public:
|
||||||
Garrisonable(){}
|
Garrisonable(){}
|
||||||
|
~Garrisonable(){}
|
||||||
|
void update();
|
||||||
void ejectVehicle(int);
|
void ejectVehicle(int);
|
||||||
protected:
|
protected:
|
||||||
int capacity;
|
int capacity;
|
||||||
std::vector<Vehicle*> garrisonedVehicles;
|
std::vector<Vehicle*> garrisonedVehicles;
|
||||||
std::vector<vb01::Node*> garrisonSlotForegrounds, garrisonSlotBackgrounds;
|
std::vector<vb01::Node*> garrisonSlotForegrounds, garrisonSlotBackgrounds;
|
||||||
|
|
||||||
|
void prepareGarrisonSlots();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -9,8 +9,10 @@ using namespace std;
|
|||||||
namespace battleship{
|
namespace battleship{
|
||||||
Structure::Structure(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Unit(player, id, pos, rot){
|
Structure::Structure(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Unit(player, id, pos, rot){
|
||||||
this->buildStatus = buildStatus;
|
this->buildStatus = buildStatus;
|
||||||
buildStatusBackground = createBar(Unit::lenHpBar, Vector4(0, 0, 0, 1));
|
|
||||||
buildStatusForeground = createBar(Unit::lenHpBar, Vector4(0, 0, 1, 1));
|
Vector2 size = Vector2(lenHpBar, 10);
|
||||||
|
buildStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||||
|
buildStatusForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Structure::~Structure(){
|
Structure::~Structure(){
|
||||||
|
|||||||
+6
-1
@@ -1,8 +1,13 @@
|
|||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
|
#include <solUtil.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
|
using namespace gameBase;
|
||||||
|
|
||||||
Transport::Transport(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot), Garrisonable(){}
|
Transport::Transport(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -2,12 +2,11 @@
|
|||||||
#define TRANSPORT_H
|
#define TRANSPORT_H
|
||||||
|
|
||||||
#include "vehicle.h"
|
#include "vehicle.h"
|
||||||
#include "garrisonable.h"
|
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
class Transport : public Vehicle, Garrisonable{
|
class Transport : public Vehicle{
|
||||||
public:
|
public:
|
||||||
Transport(Player*, int, vb01::Vector3, vb01::Quaternion);
|
Transport(Player*, int, vb01::Vector3, vb01::Quaternion);
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -30,8 +30,9 @@ namespace battleship{
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
hpBackgroundNode = createBar(lenHpBar, Vector4(0, 0, 0, 1));
|
Vector2 size = Vector2(lenHpBar, 10);
|
||||||
hpForegroundNode = createBar(lenHpBar, Vector4(0, 1, 0, 1));
|
hpBackgroundNode = createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||||
|
hpForegroundNode = createBar(Vector2::VEC_ZERO, size, Vector4(0, 1, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit::~Unit() {
|
Unit::~Unit() {
|
||||||
@@ -60,6 +61,15 @@ namespace battleship{
|
|||||||
lineOfSight = SOL_LUA_STATE["lineOfSight"][id + 1];
|
lineOfSight = SOL_LUA_STATE["lineOfSight"][id + 1];
|
||||||
unitClass = (UnitClass)SOL_LUA_STATE["unitClass"][id + 1];
|
unitClass = (UnitClass)SOL_LUA_STATE["unitClass"][id + 1];
|
||||||
type = (UnitType)SOL_LUA_STATE["unitType"][id + 1];
|
type = (UnitType)SOL_LUA_STATE["unitType"][id + 1];
|
||||||
|
int capacity = SOL_LUA_STATE["garrisonCapacity"][id + 1];
|
||||||
|
|
||||||
|
for(int i = 0; i < capacity; i++){
|
||||||
|
Vector2 size = 10 * Vector2::VEC_IJ;
|
||||||
|
Vector2 pos = Vector2(1.5 * size.x * i, 20);
|
||||||
|
Node *bg = createBar(pos, size, Vector4(0, 0, 0, 1));
|
||||||
|
Node *fg = createBar(pos, size, Vector4(0, 1, 0, 1));
|
||||||
|
garrisonSlots.push_back(GarrisonSlot(bg, fg, pos));
|
||||||
|
}
|
||||||
|
|
||||||
string cornerInd = "unitCornerPoints";
|
string cornerInd = "unitCornerPoints";
|
||||||
|
|
||||||
@@ -105,16 +115,16 @@ namespace battleship{
|
|||||||
orientAt(rot);
|
orientAt(rot);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* Unit::createBar(float initLen, Vector4 color){
|
Node* Unit::createBar(Vector2 pos, Vector2 size, Vector4 color){
|
||||||
Root *root = Root::getSingleton();
|
Root *root = Root::getSingleton();
|
||||||
Material *mat = new Material(root->getLibPath() + "gui");
|
Material *mat = new Material(root->getLibPath() + "gui");
|
||||||
mat->addBoolUniform("texturingEnabled", false);
|
mat->addBoolUniform("texturingEnabled", false);
|
||||||
mat->addVec4Uniform("diffuseColor", color);
|
mat->addVec4Uniform("diffuseColor", color);
|
||||||
|
|
||||||
Quad *quad = new Quad(Vector3(initLen, 10, 0), false);
|
Quad *quad = new Quad(Vector3(size.x, size.y, 0), false);
|
||||||
quad->setMaterial(mat);
|
quad->setMaterial(mat);
|
||||||
|
|
||||||
Node *node = new Node();
|
Node *node = new Node(Vector3(pos.x, pos.y, 0));
|
||||||
node->attachMesh(quad);
|
node->attachMesh(quad);
|
||||||
node->setVisible(false);
|
node->setVisible(false);
|
||||||
root->getGuiNode()->attachChild(node);
|
root->getGuiNode()->attachChild(node);
|
||||||
@@ -146,6 +156,9 @@ namespace battleship{
|
|||||||
screenPos = spaceToScreen(pos);
|
screenPos = spaceToScreen(pos);
|
||||||
displayUnitStats(hpForegroundNode, hpBackgroundNode, health, maxHealth);
|
displayUnitStats(hpForegroundNode, hpBackgroundNode, health, maxHealth);
|
||||||
|
|
||||||
|
for(GarrisonSlot &slot : garrisonSlots)
|
||||||
|
displayUnitStats(slot.foreground, slot.background, (int)(slot.vehicle ? 1 : 0), (int)1, slot.offset);
|
||||||
|
|
||||||
if (health <= 0)
|
if (health <= 0)
|
||||||
blowUp();
|
blowUp();
|
||||||
}
|
}
|
||||||
@@ -190,12 +203,13 @@ namespace battleship{
|
|||||||
|
|
||||||
if(selected){
|
if(selected){
|
||||||
Vector3 offset3d = Vector3(offset.x, offset.y, 0);
|
Vector3 offset3d = Vector3(offset.x, offset.y, 0);
|
||||||
float shiftedX = screenPos.x - 0.5 * lenHpBar;
|
|
||||||
background->setPosition(Vector3(shiftedX, screenPos.y, .1) + offset3d);
|
|
||||||
|
|
||||||
|
|
||||||
Quad *fgQuad = (Quad*)foreground->getMesh(0);
|
Quad *fgQuad = (Quad*)foreground->getMesh(0);
|
||||||
fgQuad->setSize(Vector3((float)currVal / maxVal * lenHpBar, 10, 0));
|
Vector3 size = fgQuad->getSize();
|
||||||
|
float shiftedX = screenPos.x - 0.5 * size.x;
|
||||||
|
background->setPosition(Vector3(shiftedX, screenPos.y, .1) + offset3d);
|
||||||
|
|
||||||
|
fgQuad->setSize(Vector3((float)currVal / maxVal * size.x, size.y, 0));
|
||||||
fgQuad->updateVerts(fgQuad->getMeshBase());
|
fgQuad->updateVerts(fgQuad->getMeshBase());
|
||||||
foreground->setPosition(Vector3(shiftedX, screenPos.y, 0) + offset3d);
|
foreground->setPosition(Vector3(shiftedX, screenPos.y, 0) + offset3d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ namespace vb01{
|
|||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
class Player;
|
class Player;
|
||||||
class Unit;
|
class Unit;
|
||||||
|
class Vehicle;
|
||||||
|
|
||||||
struct Order {
|
struct Order {
|
||||||
enum class TYPE {ATTACK, BUILD, MOVE, PATROL, LAUNCH};
|
enum class TYPE {ATTACK, BUILD, MOVE, PATROL, LAUNCH};
|
||||||
@@ -51,6 +52,14 @@ namespace battleship{
|
|||||||
|
|
||||||
class Unit : public GameObject{
|
class Unit : public GameObject{
|
||||||
public:
|
public:
|
||||||
|
struct GarrisonSlot{
|
||||||
|
Vehicle *vehicle = nullptr;
|
||||||
|
vb01::Node *background, *foreground;
|
||||||
|
vb01::Vector2 offset;
|
||||||
|
|
||||||
|
GarrisonSlot(vb01::Node *bg, vb01::Node *fg, vb01::Vector2 off, Vehicle *v = nullptr) : background(bg), foreground(fg), offset(off), vehicle(v){}
|
||||||
|
};
|
||||||
|
|
||||||
Unit(Player*, int, vb01::Vector3, vb01::Quaternion);
|
Unit(Player*, int, vb01::Vector3, vb01::Quaternion);
|
||||||
~Unit();
|
~Unit();
|
||||||
virtual void update();
|
virtual void update();
|
||||||
@@ -90,9 +99,9 @@ namespace battleship{
|
|||||||
int health, maxHealth, cost, id, playerId, lenHpBar = 200, rateOfFire;
|
int health, maxHealth, cost, id, playerId, lenHpBar = 200, rateOfFire;
|
||||||
s64 orderLineDispTime = 0, lastFireTime = 0;
|
s64 orderLineDispTime = 0, lastFireTime = 0;
|
||||||
float lineOfSight, range;
|
float lineOfSight, range;
|
||||||
|
std::vector<GarrisonSlot> garrisonSlots;
|
||||||
|
|
||||||
void removeOrder(int);
|
void removeOrder(int);
|
||||||
void displayUnitStats(vb01::Node*, vb01::Node*, int, int, vb01::Vector2 = vb01::Vector2::VEC_ZERO);
|
|
||||||
virtual void initProperties();
|
virtual void initProperties();
|
||||||
virtual void destroySound();
|
virtual void destroySound();
|
||||||
virtual void initSound();
|
virtual void initSound();
|
||||||
@@ -103,8 +112,9 @@ namespace battleship{
|
|||||||
virtual void move(Order){}
|
virtual void move(Order){}
|
||||||
virtual void patrol(Order){}
|
virtual void patrol(Order){}
|
||||||
virtual void launch(Order){}
|
virtual void launch(Order){}
|
||||||
vb01::Node* createBar(float, vb01::Vector4);
|
|
||||||
void removeBar(vb01::Node*);
|
void removeBar(vb01::Node*);
|
||||||
|
vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4);
|
||||||
|
void displayUnitStats(vb01::Node*, vb01::Node*, int, int, vb01::Vector2 offset = vb01::Vector2::VEC_ZERO);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,6 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Vehicle::initProperties(){
|
void Vehicle::initProperties(){
|
||||||
Unit::initProperties();
|
|
||||||
|
|
||||||
sol::state_view SOL_LUA_STATE = generateView();
|
sol::state_view SOL_LUA_STATE = generateView();
|
||||||
maxTurnAngle = SOL_LUA_STATE["maxTurnAngle"][id + 1];
|
maxTurnAngle = SOL_LUA_STATE["maxTurnAngle"][id + 1];
|
||||||
speed = SOL_LUA_STATE["speed"][id + 1];
|
speed = SOL_LUA_STATE["speed"][id + 1];
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ namespace battleship{
|
|||||||
void halt();
|
void halt();
|
||||||
void turn(float);
|
void turn(float);
|
||||||
void addOrder(Order);
|
void addOrder(Order);
|
||||||
void initProperties();
|
|
||||||
void advance(float, MoveDir = MoveDir::FORW);
|
void advance(float, MoveDir = MoveDir::FORW);
|
||||||
void preparePathpoints(Order);
|
void preparePathpoints(Order);
|
||||||
void removePathpoint(int = 0);
|
void removePathpoint(int = 0);
|
||||||
@@ -39,6 +38,7 @@ namespace battleship{
|
|||||||
void navigate(Order, float = 0.);
|
void navigate(Order, float = 0.);
|
||||||
void alignToSurface();
|
void alignToSurface();
|
||||||
void attack(Order);
|
void attack(Order);
|
||||||
|
virtual void initProperties();
|
||||||
virtual void fire();
|
virtual void fire();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user