parent
b0d0f1e564
commit
6c16121c11
@ -1,11 +1,74 @@ |
||||
|
||||
#include "pixelGameEngine.h" |
||||
#include "main.h" |
||||
#include "Editor.h" |
||||
using namespace olc; |
||||
|
||||
extern FaceBall* game; |
||||
|
||||
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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue