Layers in Editor now work.
This commit is contained in:
parent
646485cfac
commit
a081174ad1
@ -6,103 +6,11 @@ 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 };
|
||||
if (game->GetMouseWheel() != 0) {
|
||||
if (game->GetMouseWheel() > 0) {
|
||||
if (selectedEnemy < 63) {
|
||||
selectedEnemy=EnemyID(selectedEnemy+1);
|
||||
}
|
||||
else {
|
||||
selectedEnemy = EnemyID::NONE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedEnemy > 0) {
|
||||
selectedEnemy = EnemyID(selectedEnemy - 1);
|
||||
}
|
||||
else {
|
||||
selectedEnemy = AREA_MAP;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < MAP_SIZE.y; y++) {
|
||||
for (int x = 0; x < MAP_SIZE.x; x++) {
|
||||
Tile&t = map[y][x];
|
||||
vf2d squarePos = vf2d{ (float)x,(float)y }*GRID_SIZE + center;
|
||||
if (game->GetMouseX() >= squarePos.x && game->GetMouseX() <= squarePos.x + GRID_SIZE.x &&
|
||||
game->GetMouseY() >= squarePos.y && game->GetMouseY() <= squarePos.y + GRID_SIZE.y) {
|
||||
if (game->GetKey(W).bPressed) {
|
||||
t.wallN = !t.wallN;
|
||||
if (y > 0) {
|
||||
Tile& neighbor = map[y - 1][x];
|
||||
neighbor.wallS = t.wallN;
|
||||
}
|
||||
}
|
||||
if (game->GetKey(D).bPressed) {
|
||||
t.wallE = !t.wallE;
|
||||
if (x < MAP_SIZE.x-1) {
|
||||
Tile& neighbor = map[y][x+1];
|
||||
neighbor.wallW = t.wallE;
|
||||
}
|
||||
}
|
||||
if (game->GetKey(S).bPressed) {
|
||||
t.wallS = !t.wallS;
|
||||
if (y < MAP_SIZE.y - 1) {
|
||||
Tile& neighbor = map[y+1][x];
|
||||
neighbor.wallN = t.wallS;
|
||||
}
|
||||
}
|
||||
if (game->GetKey(A).bPressed) {
|
||||
t.wallW = !t.wallW;
|
||||
if (x > 0) {
|
||||
Tile& neighbor = map[y][x-1];
|
||||
neighbor.wallE = t.wallW;
|
||||
}
|
||||
}
|
||||
if (game->GetMouse(0).bPressed) {
|
||||
t.enemyId = selectedEnemy;
|
||||
}
|
||||
if (game->GetMouse(1).bPressed) {
|
||||
t.enemyId = EnemyID::NONE;
|
||||
}
|
||||
if (game->GetKey(DOWN).bHeld) {
|
||||
t.facingDir = FacingDirection::SOUTH;
|
||||
}
|
||||
if (game->GetKey(RIGHT).bHeld) {
|
||||
t.facingDir = FacingDirection::EAST;
|
||||
}
|
||||
if (game->GetKey(UP).bHeld) {
|
||||
t.facingDir = FacingDirection::NORTH;
|
||||
}
|
||||
if (game->GetKey(LEFT).bHeld) {
|
||||
t.facingDir = FacingDirection::WEST;
|
||||
}
|
||||
game->FillRectDecal(squarePos, GRID_SIZE, { 0,0,255,64 });
|
||||
}
|
||||
//game->DrawRectDecal(squarePos,GRID_SIZE,{64,64,64});
|
||||
if (t.enemyId != EnemyID::NONE) {
|
||||
if (t.enemyId >= COIN) {
|
||||
game->DrawPolygonDecal(nullptr, {
|
||||
vf2d{0,(float) GRID_SIZE.y / 2} + squarePos ,
|
||||
vf2d{(float)GRID_SIZE.x / 2,0} + squarePos ,
|
||||
vf2d{(float)GRID_SIZE.x,(float)GRID_SIZE.y / 2} + squarePos ,
|
||||
vf2d{(float)GRID_SIZE.x / 2,(float)GRID_SIZE.y} + squarePos ,
|
||||
}, { {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);
|
||||
if (t.enemyId >= START) {
|
||||
game->DrawRotatedDecal(squarePos + vf2d{16, 16}, game->arrow, PI / 2 * (int)t.facingDir, { 16,16 }, { 1,1 }, WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
game->DrawLineDecal(squarePos,{squarePos.x+ (float)GRID_SIZE.x,squarePos.y},t.wallN?WHITE:Pixel{64,64,64});
|
||||
game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y }, { squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, t.wallE ? WHITE : Pixel{ 64,64,64 });
|
||||
game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, { squarePos.x,squarePos.y + (float)GRID_SIZE.y }, t.wallS ? WHITE : Pixel{ 64,64,64 });
|
||||
game->DrawLineDecal({ squarePos.x,squarePos.y + (float)GRID_SIZE.y }, squarePos, t.wallW ? WHITE : Pixel{ 64,64,64 });
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@ -149,6 +57,161 @@ void Editor::LoadLevelHandling() {
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::MouseWheelEnemySelection()
|
||||
{
|
||||
if (game->GetMouseWheel() != 0) {
|
||||
if (game->GetMouseWheel() > 0) {
|
||||
if (selectedEnemy < 63) {
|
||||
selectedEnemy = EnemyID(selectedEnemy + 1);
|
||||
}
|
||||
else {
|
||||
selectedEnemy = EnemyID::NONE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (selectedEnemy > 0) {
|
||||
selectedEnemy = EnemyID(selectedEnemy - 1);
|
||||
}
|
||||
else {
|
||||
selectedEnemy = AREA_MAP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
vf2d squarePos = vf2d{ (float)x,(float)y }*GRID_SIZE + center;
|
||||
if (game->GetMouseX() >= squarePos.x && game->GetMouseX() <= squarePos.x + GRID_SIZE.x &&
|
||||
game->GetMouseY() >= squarePos.y && game->GetMouseY() <= squarePos.y + GRID_SIZE.y) {
|
||||
if (game->GetKey(W).bPressed) {
|
||||
t.wallN = !t.wallN;
|
||||
if (y > 0) {
|
||||
Tile& neighbor = map[y - 1][x];
|
||||
neighbor.wallS = t.wallN;
|
||||
}
|
||||
}
|
||||
if (game->GetKey(D).bPressed) {
|
||||
t.wallE = !t.wallE;
|
||||
if (x < MAP_SIZE.x - 1) {
|
||||
Tile& neighbor = map[y][x + 1];
|
||||
neighbor.wallW = t.wallE;
|
||||
}
|
||||
}
|
||||
if (game->GetKey(S).bPressed) {
|
||||
t.wallS = !t.wallS;
|
||||
if (y < MAP_SIZE.y - 1) {
|
||||
Tile& neighbor = map[y + 1][x];
|
||||
neighbor.wallN = t.wallS;
|
||||
}
|
||||
}
|
||||
if (game->GetKey(A).bPressed) {
|
||||
t.wallW = !t.wallW;
|
||||
if (x > 0) {
|
||||
Tile& neighbor = map[y][x - 1];
|
||||
neighbor.wallE = t.wallW;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (game->GetKey(RIGHT).bHeld) {
|
||||
t.facingDir = FacingDirection::EAST;
|
||||
}
|
||||
if (game->GetKey(UP).bHeld) {
|
||||
t.facingDir = FacingDirection::NORTH;
|
||||
}
|
||||
if (game->GetKey(LEFT).bHeld) {
|
||||
t.facingDir = FacingDirection::WEST;
|
||||
}
|
||||
game->FillRectDecal(squarePos, GRID_SIZE, { 0,0,255,64 });
|
||||
}
|
||||
//game->DrawRectDecal(squarePos,GRID_SIZE,{64,64,64});
|
||||
if (t.enemyId != EnemyID::NONE) {
|
||||
if (t.enemyId >= COIN) {
|
||||
game->DrawPolygonDecal(nullptr, {
|
||||
vf2d{0,(float)GRID_SIZE.y / 2} + squarePos ,
|
||||
vf2d{(float)GRID_SIZE.x / 2,0} + squarePos ,
|
||||
vf2d{(float)GRID_SIZE.x,(float)GRID_SIZE.y / 2} + squarePos ,
|
||||
vf2d{(float)GRID_SIZE.x / 2,(float)GRID_SIZE.y} + squarePos ,
|
||||
}, { {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.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.r,
|
||||
WHITE.g,
|
||||
WHITE.b,
|
||||
(uint8_t)(waveLayer == 0 && t.wave1 || waveLayer == 1 && t.wave2 || waveLayer == 2 && t.wave3 ? 255 : 64)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
game->DrawLineDecal(squarePos, { squarePos.x + (float)GRID_SIZE.x,squarePos.y }, t.wallN ? WHITE : Pixel{ 64,64,64 });
|
||||
game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y }, { squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, t.wallE ? WHITE : Pixel{ 64,64,64 });
|
||||
game->DrawLineDecal({ squarePos.x + (float)GRID_SIZE.x,squarePos.y + (float)GRID_SIZE.y }, { squarePos.x,squarePos.y + (float)GRID_SIZE.y }, t.wallS ? WHITE : Pixel{ 64,64,64 });
|
||||
game->DrawLineDecal({ squarePos.x,squarePos.y + (float)GRID_SIZE.y }, squarePos, t.wallW ? WHITE : Pixel{ 64,64,64 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::WaveLayerSelection()
|
||||
{
|
||||
if (game->GetKey(K1).bPressed) {
|
||||
waveLayer = 0;
|
||||
}
|
||||
if (game->GetKey(K2).bPressed) {
|
||||
waveLayer = 1;
|
||||
}
|
||||
if (game->GetKey(K3).bPressed) {
|
||||
waveLayer = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::OnTextEntryComplete(const std::string& sText) {
|
||||
std::stringstream ss(game->TextEntryGetString());
|
||||
int input;
|
||||
|
@ -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…
x
Reference in New Issue
Block a user