Layers in Editor now work.

linux_template
sigonasr2 2 years ago
parent 646485cfac
commit a081174ad1
  1. 149
      Faceball2030/Editor.cpp
  2. 4
      Faceball2030/Editor.h

@ -6,7 +6,59 @@ using namespace olc;
extern FaceBall* game;
void Editor::Update(float fElapsedTime){
vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth()/2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight()/2 };
MouseWheelEnemySelection();
RenderLevel();
WaveLayerSelection();
game->DrawStringDecal({ 2,16 }, "Selected Enemy ("+std::to_string(selectedEnemy) + "): " + game->GetData(selectedEnemy).name, WHITE, {3,3});
game->DrawStringDecal({ 2,(float)game->ScreenHeight() - 50 }, "Layer " + std::to_string(waveLayer), WHITE, { 5,5 });
LoadLevelHandling();
}
void Editor::LoadLevelHandling() {
if (!game->IsTextEntryEnabled()) {
if (promptState == PromptState::NONE) {
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;
}
}
else {
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 });
}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::MouseWheelEnemySelection()
{
if (game->GetMouseWheel() != 0) {
if (game->GetMouseWheel() > 0) {
if (selectedEnemy < 63) {
@ -25,6 +77,11 @@ void Editor::Update(float fElapsedTime){
}
}
}
}
void Editor::RenderLevel()
{
vf2d center = { -(float)MAP_SIZE.x / 2 * GRID_SIZE.x + game->ScreenWidth() / 2 , -(float)MAP_SIZE.y / 2 * GRID_SIZE.y + game->ScreenHeight() / 2 };
for (int y = 0; y < MAP_SIZE.y; y++) {
for (int x = 0; x < MAP_SIZE.x; x++) {
Tile& t = map[y][x];
@ -61,10 +118,37 @@ void Editor::Update(float fElapsedTime){
}
if (game->GetMouse(0).bPressed) {
t.enemyId = selectedEnemy;
switch (waveLayer) {
case 0: {
t.wave1 = true;
}break;
case 1: {
t.wave2 = true;
}break;
case 2: {
t.wave3 = true;
}break;
}
if (t.enemyId == EnemyID::NONE) {
t.wave1 = t.wave2 = t.wave3 = false;
}
}
if (game->GetMouse(1).bPressed) {
switch (waveLayer) {
case 0: {
t.wave1 = false;
}break;
case 1: {
t.wave2 = false;
}break;
case 2: {
t.wave3 = false;
}break;
}
if (!(t.wave1 || t.wave2 || t.wave3)) {
t.enemyId = EnemyID::NONE;
}
}
if (game->GetKey(DOWN).bHeld) {
t.facingDir = FacingDirection::SOUTH;
}
@ -90,9 +174,20 @@ void Editor::Update(float fElapsedTime){
}, { {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->DrawDecal(squarePos, game->circle, { 1,1 }, {
game->GetData(t.enemyId).col.r,
game->GetData(t.enemyId).col.g,
game->GetData(t.enemyId).col.b,
(uint8_t)(waveLayer == 0 && t.wave1||waveLayer==1&&t.wave2||waveLayer==2&&t.wave3 ? 255 : 64)
});
if (t.enemyId >= START) {
game->DrawRotatedDecal(squarePos + vf2d{16, 16}, game->arrow, PI / 2 * (int)t.facingDir, { 16,16 }, { 1,1 }, WHITE);
game->DrawRotatedDecal(squarePos + vf2d{ 16, 16 }, game->arrow, PI / 2 * (int)t.facingDir, { 16,16 }, { 1,1 }, {
WHITE.r,
WHITE.g,
WHITE.b,
(uint8_t)(waveLayer == 0 && t.wave1 || waveLayer == 1 && t.wave2 || waveLayer == 2 && t.wave3 ? 255 : 64)
}
);
}
}
}
@ -102,50 +197,18 @@ void Editor::Update(float fElapsedTime){
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() {
if (!game->IsTextEntryEnabled()) {
if (promptState == PromptState::NONE) {
if (game->GetKey(F1).bPressed) {
promptState = PromptState::ENTER_LEVEL;
game->TextEntryEnable(true);
void Editor::WaveLayerSelection()
{
if (game->GetKey(K1).bPressed) {
waveLayer = 0;
}
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;
}
}
else {
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 });
}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;
if (game->GetKey(K2).bPressed) {
waveLayer = 1;
}
if (game->GetKey(K3).bPressed) {
waveLayer = 2;
}
}

@ -65,10 +65,14 @@ class Editor {
const vi2d GRID_SIZE = { 32,32 };
EnemyID selectedEnemy=SHOOTME;
PromptState promptState = PromptState::NONE;
int waveLayer = 0;
public:
Editor() {}
void Update(float fElapsedTime);
void OnTextEntryComplete(const std::string& sText);
void LoadLevel();
void LoadLevelHandling();
void MouseWheelEnemySelection();
void RenderLevel();
void WaveLayerSelection();
};
Loading…
Cancel
Save