changed team structure
This commit is contained in:
@@ -1,21 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Towers.h"
|
#include "Towers.h"
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace game {
|
namespace game {
|
||||||
|
|
||||||
enum class Direction : std::uint8_t{
|
|
||||||
PositiveX = 1 << 0,
|
|
||||||
NegativeX = 1 << 1,
|
|
||||||
PositiveY = 1 << 2,
|
|
||||||
NegativeY = 1 << 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class EffectType : std::uint8_t{
|
enum class EffectType : std::uint8_t{
|
||||||
Slowness = 0,
|
Slowness = 0,
|
||||||
Stun,
|
Stun,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -15,10 +17,22 @@ enum class TeamColor : std::int8_t{
|
|||||||
Blue
|
Blue
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Spawn{
|
||||||
|
Direction direction;
|
||||||
|
std::int32_t x, y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TeamCastle{
|
||||||
|
std::int32_t x, y;
|
||||||
|
std::uint16_t life = 1000;
|
||||||
|
};
|
||||||
|
|
||||||
class Team{
|
class Team{
|
||||||
private:
|
private:
|
||||||
std::vector<Player*> m_Players;
|
std::vector<Player*> m_Players;
|
||||||
TeamColor m_Color;
|
TeamColor m_Color;
|
||||||
|
Spawn m_Spawn;
|
||||||
|
TeamCastle m_TeamCastle;
|
||||||
public:
|
public:
|
||||||
Team(TeamColor color);
|
Team(TeamColor color);
|
||||||
|
|
||||||
@@ -27,6 +41,12 @@ public:
|
|||||||
|
|
||||||
TeamColor getColor() const;
|
TeamColor getColor() const;
|
||||||
|
|
||||||
|
const Spawn& getSpawn() const {return m_Spawn;}
|
||||||
|
Spawn& getSpawn() {return m_Spawn;}
|
||||||
|
|
||||||
|
const TeamCastle& getCastle() const {return m_TeamCastle;}
|
||||||
|
TeamCastle& getCastle() {return m_TeamCastle;}
|
||||||
|
|
||||||
std::uint8_t getPlayerCount() const;
|
std::uint8_t getPlayerCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
16
include/game/Types.h
Normal file
16
include/game/Types.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace td {
|
||||||
|
namespace game {
|
||||||
|
|
||||||
|
enum class Direction : std::uint8_t{
|
||||||
|
PositiveX = 1 << 0,
|
||||||
|
NegativeX = 1 << 1,
|
||||||
|
PositiveY = 1 << 2,
|
||||||
|
NegativeY = 1 << 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace game
|
||||||
|
} // namespace td
|
||||||
@@ -76,16 +76,6 @@ struct DecorationTile : Tile{
|
|||||||
virtual TileType getType() const{ return TileType::Decoration; }
|
virtual TileType getType() const{ return TileType::Decoration; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Spawn{
|
|
||||||
Direction direction;
|
|
||||||
std::int32_t x, y;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TeamCastle{
|
|
||||||
std::int32_t x, y;
|
|
||||||
std::uint16_t life = 1000;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::shared_ptr<Tile> TilePtr;
|
typedef std::shared_ptr<Tile> TilePtr;
|
||||||
typedef std::vector<std::uint16_t> ChunkPalette;
|
typedef std::vector<std::uint16_t> ChunkPalette;
|
||||||
|
|
||||||
@@ -130,9 +120,6 @@ protected:
|
|||||||
|
|
||||||
SpawnColorPalette m_SpawnColorPalette;
|
SpawnColorPalette m_SpawnColorPalette;
|
||||||
|
|
||||||
Spawn m_Spawns[2];
|
|
||||||
TeamCastle m_Castles[2];
|
|
||||||
|
|
||||||
TilePalette m_TilePalette;
|
TilePalette m_TilePalette;
|
||||||
|
|
||||||
MobList m_Mobs;
|
MobList m_Mobs;
|
||||||
@@ -167,21 +154,22 @@ public:
|
|||||||
|
|
||||||
const std::unordered_map<ChunkCoord, ChunkPtr>& getChunks() const{ return m_Chunks; }
|
const std::unordered_map<ChunkCoord, ChunkPtr>& getChunks() const{ return m_Chunks; }
|
||||||
|
|
||||||
const Spawn& getRedSpawn() const{ return m_Spawns[(std::size_t) TeamColor::Red]; }
|
|
||||||
const Spawn& getBlueSpawn() const{ return m_Spawns[(std::size_t) TeamColor::Blue]; }
|
|
||||||
|
|
||||||
const Spawn& getSpawn(TeamColor color) const{ return m_Spawns[(std::size_t) color]; }
|
|
||||||
|
|
||||||
const Color& getSpawnColor(TeamColor color) const{ return m_SpawnColorPalette[(std::size_t) color]; }
|
const Color& getSpawnColor(TeamColor color) const{ return m_SpawnColorPalette[(std::size_t) color]; }
|
||||||
const SpawnColorPalette& getSpawnColors() const{ return m_SpawnColorPalette; }
|
const SpawnColorPalette& getSpawnColors() const{ return m_SpawnColorPalette; }
|
||||||
|
|
||||||
const TeamCastle& getRedCastle() const{ return m_Castles[(std::size_t) TeamColor::Red]; }
|
|
||||||
const TeamCastle& getBlueCastle() const{ return m_Castles[(std::size_t) TeamColor::Blue]; }
|
|
||||||
|
|
||||||
const MobList& getMobList() const{ return m_Mobs; }
|
const MobList& getMobList() const{ return m_Mobs; }
|
||||||
MobList& getMobList(){ return m_Mobs; }
|
MobList& getMobList(){ return m_Mobs; }
|
||||||
|
|
||||||
const Color& getTileColor(TilePtr tile) const;
|
const Color& getTileColor(TilePtr tile) const;
|
||||||
|
|
||||||
|
Team& getRedTeam();
|
||||||
|
const Team& getRedTeam() const;
|
||||||
|
|
||||||
|
Team& getBlueTeam();
|
||||||
|
const Team& getBlueTeam() const;
|
||||||
|
|
||||||
|
Team& getTeam(TeamColor team);
|
||||||
|
const Team& getTeam(TeamColor team) const;
|
||||||
private:
|
private:
|
||||||
void moveMobs(std::uint64_t delta);
|
void moveMobs(std::uint64_t delta);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ bool World::loadMap(const protocol::WorldBeginDataPacket* worldHeader){
|
|||||||
m_WalkablePalette = worldHeader->getWalkableTileColor();
|
m_WalkablePalette = worldHeader->getWalkableTileColor();
|
||||||
m_DecorationPalette = worldHeader->getDecorationPalette();
|
m_DecorationPalette = worldHeader->getDecorationPalette();
|
||||||
|
|
||||||
m_Spawns[(std::size_t) TeamColor::Red] = worldHeader->getRedSpawn();
|
getRedTeam().getSpawn() = worldHeader->getRedSpawn();
|
||||||
m_Spawns[(std::size_t) TeamColor::Blue] = worldHeader->getBlueSpawn();
|
getBlueTeam().getSpawn() = worldHeader->getBlueSpawn();
|
||||||
|
|
||||||
m_SpawnColorPalette = worldHeader->getSpawnPalette();
|
m_SpawnColorPalette = worldHeader->getSpawnPalette();
|
||||||
|
|
||||||
m_Castles[(std::size_t) TeamColor::Red] = worldHeader->getRedCastle();
|
getRedTeam().getCastle() = worldHeader->getRedCastle();
|
||||||
m_Castles[(std::size_t) TeamColor::Blue] = worldHeader->getBlueCastle();
|
getBlueTeam().getCastle() = worldHeader->getBlueCastle();
|
||||||
|
|
||||||
m_TilePalette = worldHeader->getTilePalette();
|
m_TilePalette = worldHeader->getTilePalette();
|
||||||
}
|
}
|
||||||
@@ -382,5 +382,29 @@ const Color& World::getTileColor(TilePtr tile) const{
|
|||||||
return m_DecorationPalette[0];
|
return m_DecorationPalette[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Team& World::getRedTeam(){
|
||||||
|
return m_Game->getRedTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Team& World::getRedTeam() const{
|
||||||
|
return m_Game->getRedTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
Team& World::getBlueTeam(){
|
||||||
|
return m_Game->getBlueTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Team& World::getBlueTeam() const{
|
||||||
|
return m_Game->getBlueTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
Team& World::getTeam(TeamColor team){
|
||||||
|
return m_Game->getTeam(team);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Team& World::getTeam(TeamColor team) const{
|
||||||
|
return m_Game->getTeam(team);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace game
|
} // namespace game
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ void ServerWorld::spawnMobs(game::MobType type, std::uint8_t level, game::Player
|
|||||||
game::Spawn* enemyMobSpawn;
|
game::Spawn* enemyMobSpawn;
|
||||||
|
|
||||||
if(senderTeam == game::TeamColor::Red){
|
if(senderTeam == game::TeamColor::Red){
|
||||||
enemyMobSpawn = &m_Spawns[(std::size_t) game::TeamColor::Blue];
|
enemyMobSpawn = &getTeam(game::TeamColor::Blue).getSpawn();
|
||||||
}else{
|
}else{
|
||||||
enemyMobSpawn = &m_Spawns[(std::size_t) game::TeamColor::Red];
|
enemyMobSpawn = &getTeam(game::TeamColor::Red).getSpawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t spawnCenterX = enemyMobSpawn->x;
|
std::int32_t spawnCenterX = enemyMobSpawn->x;
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ DataBuffer WorldBeginDataPacket::Serialize() const{
|
|||||||
|
|
||||||
memcpy((void*)data.data() + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
memcpy((void*)data.data() + bufferSize, decoTilePalette.data(), decoTilePalette.size() * sizeof(game::Color));
|
||||||
|
|
||||||
const game::Spawn& redSpawn = m_World->getRedSpawn(), blueSpawn = m_World->getBlueSpawn();
|
const game::Spawn& redSpawn = m_World->getRedTeam().getSpawn(), blueSpawn = m_World->getBlueTeam().getSpawn();
|
||||||
const game::TeamCastle& redCastle = m_World->getRedCastle(), blueCastle = m_World->getBlueCastle();
|
const game::TeamCastle& redCastle = m_World->getRedTeam().getCastle(), blueCastle = m_World->getBlueTeam().getCastle();
|
||||||
|
|
||||||
data << redSpawn << redCastle;
|
data << redSpawn << redCastle;
|
||||||
data << blueSpawn << blueCastle;
|
data << blueSpawn << blueCastle;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "game/BaseGame.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
@@ -114,7 +116,7 @@ GL::VAO loadWorldModel(const td::game::World* world){
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int spawnColor = 0; spawnColor < 2; spawnColor++){
|
for (int spawnColor = 0; spawnColor < 2; spawnColor++){
|
||||||
const game::Spawn& spawn = world->getSpawn(game::TeamColor(spawnColor));
|
const game::Spawn& spawn = world->getTeam(game::TeamColor(spawnColor)).getSpawn();
|
||||||
float fromX = spawn.x - 2, toX = spawn.x + 3;
|
float fromX = spawn.x - 2, toX = spawn.x + 3;
|
||||||
float fromY = spawn.y - 2, toY = spawn.y + 3;
|
float fromY = spawn.y - 2, toY = spawn.y + 3;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user