Load default map

linux_template
sigonasr2 2 years ago
parent b0d0f1e564
commit 6c16121c11
  1. 67
      Faceball2030/Editor.cpp
  2. 46
      Faceball2030/Editor.h
  3. 10
      Faceball2030/main.cpp
  4. 1
      Faceball2030/main.h

@ -1,11 +1,74 @@
#include "pixelGameEngine.h" #include "pixelGameEngine.h"
#include "main.h" #include "main.h"
#include "Editor.h"
using namespace olc; using namespace olc;
extern FaceBall* game; extern FaceBall* game;
void Editor::Update(float fElapsedTime){ void Editor::Update(float fElapsedTime){
game->DrawStringDecal({ 0,0 }, "HEllo World!", WHITE, { 4,4 }); if (!game->IsTextEntryEnabled()){
if (game->GetKey(F1).bPressed || reEnableTextEntry) {
game->TextEntryEnable(true);
reEnableTextEntry = false;
}
}
else {
game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): "+game->TextEntryGetString(), WHITE, {4,4});
}
}
void Editor::OnTextEntryComplete(const std::string& sText) {
std::stringstream ss(game->TextEntryGetString());
int level;
ss >> level;
if (level >= 1 && level <= 30) {
game->TextEntryEnable(false);
this->level = level;
LoadLevel();
}
else {
reEnableTextEntry = true;
}
}
void Editor::LoadLevel() {
std::ifstream file("assets/map/map"+std::to_string(level)+".map");
if (file.good()) {
while (file.good()) {
std::string line;
std::getline(file, line);
int width = std::atoi(line.c_str());
std::getline(file, line);
int height = std::atoi(line.c_str());
MAP_SIZE = { width,height };
map.clear();
for (int y = 0; y < MAP_SIZE.y; y++) {
std::vector<Tile>row;
for (int x = 0; x < MAP_SIZE.x; x++) {
std::getline(file, line);
int map_data = std::atoi(line.c_str());
Tile newTile;
newTile.blink = (map_data & 0b1000000000000000) >> 15;
newTile.facingDir = FacingDirection((map_data & 0b0110000000000000) >> 13);
newTile.enemyId = EnemyID((map_data & 0b0001111110000000) >> 7);
newTile.spawnWave = (map_data & 0b1110000) >> 4;
newTile.walls = map_data & 0b1111;
row.push_back(newTile);
}
map.push_back(row);
}
}
}
else {
std::cout << "Map Level " << level << " does not exist. Creating default map."<<std::endl;
MAP_SIZE = { 5,5 };
map.clear();
for (int y = 0; y < MAP_SIZE.y; y++) {
std::vector<Tile>row;
for (int x = 0; x < MAP_SIZE.x; x++) {
row.push_back({});
}
map.push_back(row);
}
}
} }

@ -2,10 +2,54 @@
#include "pixelGameEngine.h" #include "pixelGameEngine.h"
using namespace olc; using namespace olc;
enum class FacingDirection {
NORTH, EAST, SOUTH, WEST
};
enum EnemyID {
EXIT,
SHOOTME,
POWERUP_ARMOR=57,
POWERUP_SPEED=58,
POWERUP_SHOT=59,
SPECIAL_CAMO=60,
SPECIAL_STOP=61,
SPECIAL_SHIELD=62,
AREA_MAP=63,
};
/*
enum Wave {
WAVE0=0,
WAVE1=1,
WAVE2=2,
WAVE3=4
};
enum WallDirection {
NONE = 0,
NORTH = 1,
EAST = 2,
SOUTH = 4,
WEST = 8
};*/
struct Tile {
EnemyID enemyId=SHOOTME;
FacingDirection facingDir=FacingDirection::EAST;
byte spawnWave=0;
byte walls=0;
bool blink=false;
};
class Editor { class Editor {
std::string filename; int level;
vi2d MAP_SIZE; vi2d MAP_SIZE;
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;
public: public:
Editor() {} Editor() {}
void Update(float fElapsedTime); void Update(float fElapsedTime);
void OnTextEntryComplete(const std::string& sText);
void LoadLevel();
}; };

@ -715,7 +715,15 @@ bool FaceBall::OnUserUpdate(float fElapsedTime)
return true; return true;
} }
void FaceBall::OnTextEntryComplete(const std::string& sText) {
switch (mode) {
case GAME: {
}break;
case EDITOR: {
editor.OnTextEntryComplete(sText);
}break;
}
}
int main() int main()

@ -182,4 +182,5 @@ class FaceBall : public PixelGameEngine
void AddWall(Direction dir, vi2d gridSquare); void AddWall(Direction dir, vi2d gridSquare);
bool OnUserCreate() override; bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override; bool OnUserUpdate(float fElapsedTime) override;
void OnTextEntryComplete(const std::string& sText) override;
}; };
Loading…
Cancel
Save