Dynamic adjustment of level size.

linux_template
sigonasr2 2 years ago
parent 926b43878e
commit 646485cfac
  1. 108
      Faceball2030/Editor.cpp
  2. 8
      Faceball2030/Editor.h

@ -108,29 +108,127 @@ void Editor::Update(float fElapsedTime){
void Editor::LoadLevelHandling() { void Editor::LoadLevelHandling() {
if (!game->IsTextEntryEnabled()) { if (!game->IsTextEntryEnabled()) {
if (game->GetKey(F1).bPressed || reEnableTextEntry) { if (promptState == PromptState::NONE) {
if (game->GetKey(F1).bPressed) {
promptState = PromptState::ENTER_LEVEL;
game->TextEntryEnable(true); game->TextEntryEnable(true);
}
if (game->GetKey(F2).bPressed) {
promptState = PromptState::ENTER_WIDTH;
game->TextEntryEnable(true,std::to_string(MAP_SIZE.x));
}
}
if (reEnableTextEntry) {
switch (promptState) {
case PromptState::ENTER_LEVEL: {
game->TextEntryEnable(true);
}break;
case PromptState::ENTER_WIDTH: {
game->TextEntryEnable(true, std::to_string(MAP_SIZE.y));
}break;
case PromptState::ENTER_HEIGHT: {
game->TextEntryEnable(true,std::to_string(MAP_SIZE.y));
}break;
}
reEnableTextEntry = false; reEnableTextEntry = false;
} }
} }
else { else {
game->FillRectDecal({ 0,0 }, { (float)game->ScreenWidth(),32 }, BLACK); game->FillRectDecal({ 0,0 }, { (float)game->ScreenWidth(),32 }, BLACK);
switch (promptState) {
case PromptState::ENTER_LEVEL: {
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 });
}break;
case PromptState::ENTER_WIDTH: {
game->DrawStringDecal({ 0,0 }, "Enter Level Width: " + game->TextEntryGetString(), WHITE, { 4,4 });
}break;
case PromptState::ENTER_HEIGHT: {
game->DrawStringDecal({ 0,0 }, "Enter Level Height: " + game->TextEntryGetString(), WHITE, { 4,4 });
}break;
}
} }
} }
void Editor::OnTextEntryComplete(const std::string& sText) { void Editor::OnTextEntryComplete(const std::string& sText) {
std::stringstream ss(game->TextEntryGetString()); std::stringstream ss(game->TextEntryGetString());
int level; int input;
ss >> level; ss >> input;
if (level >= 1 && level <= 30) { switch (promptState) {
case PromptState::ENTER_LEVEL: {
if (input >= 1 && input <= 30) {
game->TextEntryEnable(false); game->TextEntryEnable(false);
this->level = level; promptState = PromptState::NONE;
this->level = input;
LoadLevel(); LoadLevel();
} }
else { else {
reEnableTextEntry = true; reEnableTextEntry = true;
} }
}break;
case PromptState::ENTER_WIDTH: {
if (input >= 1 && input <= 50) {
promptState = PromptState::ENTER_HEIGHT;
reEnableTextEntry = true;
this->MAP_SIZE.x = input;
if (MAP_SIZE.x == map[0].size()) {
break; //We don't care to resize the vecetor at this point.
}
if (MAP_SIZE.x < map[0].size()) {
for (int y = 0; y < map.size(); y++) {
std::vector<Tile>& row = map[y];
row.erase(row.begin() + MAP_SIZE.x, row.end());
}
}
else {
for (int y = 0; y < map.size(); y++) {
std::vector<Tile>& row = map[y];
for (int x = map[y].size(); x < MAP_SIZE.x; x++) {
Tile t = {};
if (x > 0) {
Tile& neighborW = map[y][x-1];
t.wallW = neighborW.wallE;
}
row.push_back(t);
}
}
}
}
else {
reEnableTextEntry = true;
}
}break;
case PromptState::ENTER_HEIGHT: {
if (input >= 1 && input <= 50) {
game->TextEntryEnable(false);
promptState = PromptState::NONE;
this->MAP_SIZE.y = input;
if (MAP_SIZE.y == map.size()) {
break; //We don't care to resize the vecetor at this point.
}
if (MAP_SIZE.y < map.size()) {
map.erase(map.begin() + MAP_SIZE.y, map.end());
}
else {
for (int y = map.size(); y < MAP_SIZE.y; y++) {
std::vector<Tile> row;
for (int x = 0; x < MAP_SIZE.x; x++) {
Tile t = {};
if (y > 0) {
Tile& neighborN = map[y - 1][x];
t.wallN = neighborN.wallS;
}
row.push_back(t);
}
map.push_back(row);
}
}
}
else {
reEnableTextEntry = true;
}
}break;
}
} }
void Editor::LoadLevel() { void Editor::LoadLevel() {

@ -37,6 +37,13 @@ enum WallDirection {
WEST = 8 WEST = 8
};*/ };*/
enum class PromptState {
NONE,
ENTER_LEVEL,
ENTER_WIDTH,
ENTER_HEIGHT,
};
struct Tile { struct Tile {
EnemyID enemyId=EnemyID::NONE; EnemyID enemyId=EnemyID::NONE;
FacingDirection facingDir=FacingDirection::EAST; FacingDirection facingDir=FacingDirection::EAST;
@ -57,6 +64,7 @@ class Editor {
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; EnemyID selectedEnemy=SHOOTME;
PromptState promptState = PromptState::NONE;
public: public:
Editor() {} Editor() {}
void Update(float fElapsedTime); void Update(float fElapsedTime);

Loading…
Cancel
Save