Dynamic adjustment of level size.
This commit is contained in:
parent
926b43878e
commit
646485cfac
@ -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) {
|
||||||
game->TextEntryEnable(true);
|
if (game->GetKey(F1).bPressed) {
|
||||||
|
promptState = PromptState::ENTER_LEVEL;
|
||||||
|
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);
|
||||||
game->DrawStringDecal({ 0,0 }, "Enter Level (1-30): " + game->TextEntryGetString(), WHITE, { 4,4 });
|
switch (promptState) {
|
||||||
|
case PromptState::ENTER_LEVEL: {
|
||||||
|
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) {
|
||||||
game->TextEntryEnable(false);
|
case PromptState::ENTER_LEVEL: {
|
||||||
this->level = level;
|
if (input >= 1 && input <= 30) {
|
||||||
LoadLevel();
|
game->TextEntryEnable(false);
|
||||||
}
|
promptState = PromptState::NONE;
|
||||||
else {
|
this->level = input;
|
||||||
reEnableTextEntry = true;
|
LoadLevel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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…
x
Reference in New Issue
Block a user