Ability to place entities on the map.

linux_template
sigonasr2 2 years ago
parent 8e8b2586bb
commit d44fbb5033
  1. 49
      Faceball2030/Editor.cpp
  2. 19
      Faceball2030/Editor.h
  3. 1
      Faceball2030/Faceball2030.vcxproj
  4. BIN
      Faceball2030/assets/circle.png
  5. 21
      Faceball2030/main.cpp
  6. 16
      Faceball2030/main.h

@ -6,8 +6,25 @@ using namespace olc;
extern FaceBall* game; extern FaceBall* game;
void Editor::Update(float fElapsedTime){ void Editor::Update(float fElapsedTime){
LoadLevelHandling();
vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth()/2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight()/2 }; vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth()/2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight()/2 };
if (game->GetMouseWheel() != 0) {
if (game->GetMouseWheel() > 0) {
if (selectedEnemy < 63) {
selectedEnemy=EnemyID(selectedEnemy+1);
}
else {
selectedEnemy = EnemyID::NONE;
}
}
else {
if (selectedEnemy > 0) {
selectedEnemy = EnemyID(selectedEnemy - 1);
}
else {
selectedEnemy = AREA_MAP;
}
}
}
for (int y = 0; y < MAP_SIZE.y; y++) { for (int y = 0; y < MAP_SIZE.y; y++) {
for (int x = 0; x < MAP_SIZE.x; x++) { for (int x = 0; x < MAP_SIZE.x; x++) {
Tile&t = map[y][x]; Tile&t = map[y][x];
@ -42,15 +59,36 @@ void Editor::Update(float fElapsedTime){
neighbor.wallE = t.wallW; neighbor.wallE = t.wallW;
} }
} }
if (game->GetMouse(0).bPressed) {
t.enemyId = selectedEnemy;
}
if (game->GetMouse(1).bPressed) {
t.enemyId = EnemyID::NONE;
}
game->FillRectDecal(squarePos, GRID_SIZE, { 0,0,255,64 }); game->FillRectDecal(squarePos, GRID_SIZE, { 0,0,255,64 });
} }
//game->DrawRectDecal(squarePos,GRID_SIZE,{64,64,64}); //game->DrawRectDecal(squarePos,GRID_SIZE,{64,64,64});
game->DrawLineDecal(squarePos,{squarePos.x+GRID_SIZE.x,squarePos.y},t.wallN?WHITE:Pixel{64,64,64}); if (t.enemyId != EnemyID::NONE) {
game->DrawLineDecal({ squarePos.x + GRID_SIZE.x,squarePos.y }, { squarePos.x + GRID_SIZE.x,squarePos.y + GRID_SIZE.y }, t.wallE ? WHITE : Pixel{ 64,64,64 }); if (t.enemyId >= COIN) {
game->DrawLineDecal({ squarePos.x + GRID_SIZE.x,squarePos.y + GRID_SIZE.y }, { squarePos.x,squarePos.y + GRID_SIZE.y }, t.wallS ? WHITE : Pixel{ 64,64,64 }); game->DrawPolygonDecal(nullptr, {
game->DrawLineDecal({ squarePos.x,squarePos.y + GRID_SIZE.y }, squarePos, t.wallW ? WHITE : Pixel{ 64,64,64 }); vf2d{0,(float) GRID_SIZE.y / 2} + squarePos ,
vf2d{(float)GRID_SIZE.x / 2,0} + squarePos ,
vf2d{(float)GRID_SIZE.x,(float)GRID_SIZE.y / 2} + squarePos ,
vf2d{(float)GRID_SIZE.x / 2,(float)GRID_SIZE.y} + squarePos ,
}, { {0,0},{0,0} ,{0,0} ,{0,0} }, game->GetData(t.enemyId).col);
} }
else {
game->DrawDecal(squarePos, game->circle, { 1,1 }, game->GetData(t.enemyId).col);
} }
}
game->DrawLineDecal(squarePos,{squarePos.x+ (float)GRID_SIZE.x,squarePos.y},t.wallN?WHITE:Pixel{64,64,64});
game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y }, { squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, t.wallE ? WHITE : Pixel{ 64,64,64 });
game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, { squarePos.x,squarePos.y + (float)GRID_SIZE.y }, t.wallS ? WHITE : Pixel{ 64,64,64 });
game->DrawLineDecal({ squarePos.x,squarePos.y + (float)GRID_SIZE.y }, squarePos, t.wallW ? WHITE : Pixel{ 64,64,64 });
}
}
game->DrawStringDecal({ 2,16 }, "Selected Enemy ("+std::to_string(selectedEnemy) + "): " + game->GetData(selectedEnemy).name, WHITE, {3,3});
LoadLevelHandling();
} }
void Editor::LoadLevelHandling() { void Editor::LoadLevelHandling() {
@ -61,6 +99,7 @@ void Editor::LoadLevelHandling() {
} }
} }
else { else {
game->FillRectDecal({ 0,0 }, { (float)game->ScreenWidth(),32 }, BLACK);
game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 }); game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 });
} }
} }

@ -7,15 +7,17 @@ enum class FacingDirection {
}; };
enum EnemyID { enum EnemyID {
NONE,
EXIT, EXIT,
SHOOTME, SHOOTME,
POWERUP_ARMOR=57, COIN = 56,
POWERUP_SPEED=58, POWERUP_ARMOR = 57,
POWERUP_SHOT=59, POWERUP_SPEED = 58,
SPECIAL_CAMO=60, POWERUP_SHOT = 59,
SPECIAL_STOP=61, SPECIAL_CAMO = 60,
SPECIAL_SHIELD=62, SPECIAL_STOP = 61,
AREA_MAP=63, SPECIAL_SHIELD = 62,
AREA_MAP = 63,
}; };
/* /*
@ -35,7 +37,7 @@ enum WallDirection {
};*/ };*/
struct Tile { struct Tile {
EnemyID enemyId=SHOOTME; EnemyID enemyId=EnemyID::NONE;
FacingDirection facingDir=FacingDirection::EAST; FacingDirection facingDir=FacingDirection::EAST;
bool wave1 = false; bool wave1 = false;
bool wave2 = false; bool wave2 = false;
@ -53,6 +55,7 @@ class Editor {
bool reEnableTextEntry; //We must set this to true to cause Text Entry to reappear due to how the callback works. bool reEnableTextEntry; //We must set this to true to cause Text Entry to reappear due to how the callback works.
std::vector<std::vector<Tile>> map; std::vector<std::vector<Tile>> map;
const vi2d GRID_SIZE = { 32,32 }; const vi2d GRID_SIZE = { 32,32 };
EnemyID selectedEnemy=SHOOTME;
public: public:
Editor() {} Editor() {}
void Update(float fElapsedTime); void Update(float fElapsedTime);

@ -104,6 +104,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

@ -8,6 +8,24 @@ using namespace olc;
FaceBall* game; FaceBall* game;
void FaceBall::InitializeEnemyData() {
enemyData[EXIT] = { "EXIT",GREEN };
enemyData[SHOOTME] = { "SHOOTME",YELLOW,1,1,PI / 8,2,1,3 };
enemyData[COIN] = { "Coin",BLUE };
enemyData[POWERUP_ARMOR] = { "Armor",{96,0,96} };
enemyData[POWERUP_SPEED] = { "Speed",{96,0,96} };
enemyData[POWERUP_SHOT] = { "Shot",{96,0,96} };
enemyData[SPECIAL_CAMO] = { "Camouflage",DARK_RED };
enemyData[SPECIAL_STOP] = { "Stop",DARK_RED };
enemyData[SPECIAL_SHIELD] = { "Shield",DARK_RED };
enemyData[AREA_MAP] = { "Map",GREEN };
}
EnemyData FaceBall::GetData(EnemyID id)
{
return enemyData[id];
}
vec3d vec3d
FaceBall::Matrix_MultiplyVector(mat4x4& m, vec3d& i) FaceBall::Matrix_MultiplyVector(mat4x4& m, vec3d& i)
{ {
@ -587,8 +605,11 @@ bool FaceBall::OnUserCreate()
sAppName = "Faceball 2030"; sAppName = "Faceball 2030";
matProj = Matrix_MakeProjection(90.0f, (float)ScreenHeight() / (float)ScreenWidth(), 0.1f, 1000.0f); matProj = Matrix_MakeProjection(90.0f, (float)ScreenHeight() / (float)ScreenWidth(), 0.1f, 1000.0f);
dot = new Decal(new Sprite("assets/dot.png")); dot = new Decal(new Sprite("assets/dot.png"));
circle = new Decal(new Sprite("assets/circle.png"));
enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.png")); enemy_ShootMe_tex = new Decal(new Sprite("assets/enemies/ShootMe.png"));
InitializeEnemyData();
Mesh testEnemy("assets/enemies/ShootMe.obj", enemy_ShootMe_tex); Mesh testEnemy("assets/enemies/ShootMe.obj", enemy_ShootMe_tex);
mapMesh.texture = dot; mapMesh.texture = dot;
for (int i = 0; i < 75; i++) { for (int i = 0; i < 75; i++) {

@ -123,6 +123,17 @@ struct Object {
float rot = 0; float rot = 0;
}; };
struct EnemyData {
std::string name;
Pixel col=YELLOW;
int health = 1;
float movSpd = 1;
float rotSpd = PI / 8;
int ammo = 2;
float fireDelay = 1;
float reloadTime = 3;
};
struct mat4x4 struct mat4x4
{ {
float m[4][4] = { 0 }; float m[4][4] = { 0 };
@ -136,12 +147,16 @@ class FaceBall : public PixelGameEngine
{ {
sAppName = "3D Demo"; sAppName = "3D Demo";
} }
EnemyData GetData(EnemyID id);
Decal* circle;
private: private:
Mesh mapMesh; Mesh mapMesh;
Decal* dot, * enemy_ShootMe_tex; Decal* dot, * enemy_ShootMe_tex;
vi2d MAP_SIZE = { 10,10 }; vi2d MAP_SIZE = { 10,10 };
std::vector<std::vector<MapSquare>>map; std::vector<std::vector<MapSquare>>map;
std::map<EnemyID, EnemyData>enemyData;
std::vector<Object>objects; std::vector<Object>objects;
GAMEMODE mode=GAMEMODE::GAME; GAMEMODE mode=GAMEMODE::GAME;
Editor editor; Editor editor;
@ -183,4 +198,5 @@ class FaceBall : public PixelGameEngine
bool OnUserCreate() override; bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override; bool OnUserUpdate(float fElapsedTime) override;
void OnTextEntryComplete(const std::string& sText) override; void OnTextEntryComplete(const std::string& sText) override;
void InitializeEnemyData();
}; };
Loading…
Cancel
Save