|
|
|
@ -6,10 +6,15 @@ |
|
|
|
|
#include "soundwaveEngine.h" |
|
|
|
|
#include "tiles.h" |
|
|
|
|
#include "references.h" |
|
|
|
|
#include "states.h" |
|
|
|
|
|
|
|
|
|
#define WIDTH 256 |
|
|
|
|
#define HEIGHT 224 |
|
|
|
|
#define CAMERA_MOVESPD 0.5 |
|
|
|
|
#define CAMERA_MOVESPD 5 |
|
|
|
|
#define TILEMAP_SIZE_X 512 |
|
|
|
|
#define TILEMAP_SIZE_Y 512 |
|
|
|
|
#define TILEMAP_EDITOR_DRAW_MULT 0.4375 |
|
|
|
|
#define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT) |
|
|
|
|
|
|
|
|
|
using namespace olc; |
|
|
|
|
|
|
|
|
@ -74,6 +79,9 @@ public: |
|
|
|
|
Map*CURRENT_MAP; |
|
|
|
|
Map*MAP_ONETT; |
|
|
|
|
vd2d cameraPos = {0,0}; |
|
|
|
|
state::GameState GAME_STATE = state::EDITOR; |
|
|
|
|
vi2d SELECTED_TILE={0,0}; |
|
|
|
|
vi2d HIGHLIGHTED_TILE={0,0}; |
|
|
|
|
|
|
|
|
|
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
|
|
|
|
|
|
|
|
@ -108,6 +116,7 @@ public: |
|
|
|
|
elapsedTime-=TARGET_RATE; |
|
|
|
|
updateGame(); |
|
|
|
|
} |
|
|
|
|
keyUpdates(); |
|
|
|
|
drawGame(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -121,32 +130,96 @@ public: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (UpHeld()) { |
|
|
|
|
cameraPos.y-=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
if (RightHeld()) { |
|
|
|
|
cameraPos.x+=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
if (LeftHeld()) { |
|
|
|
|
cameraPos.x-=CAMERA_MOVESPD; |
|
|
|
|
switch (GAME_STATE) { |
|
|
|
|
case state::TILE_SELECT:{ |
|
|
|
|
if (!TabHeld()) { |
|
|
|
|
GAME_STATE=state::EDITOR; |
|
|
|
|
} |
|
|
|
|
if (GetMouse(0).bHeld) { |
|
|
|
|
int selectedTileX=GetMouseX()/TILEMAP_EDITOR_TILESIZE; |
|
|
|
|
int selectedTileY=GetMouseY()/TILEMAP_EDITOR_TILESIZE; |
|
|
|
|
if (selectedTileX*TILEMAP_EDITOR_DRAW_MULT>=0&&selectedTileX*TILEMAP_EDITOR_DRAW_MULT<TILEMAP_SIZE_X&&selectedTileY*TILEMAP_EDITOR_DRAW_MULT<TILEMAP_SIZE_Y&&selectedTileY*TILEMAP_EDITOR_DRAW_MULT>=0) { |
|
|
|
|
SELECTED_TILE={selectedTileX,selectedTileY}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case state::EDITOR:{ |
|
|
|
|
if (TabHeld()) { |
|
|
|
|
GAME_STATE=state::TILE_SELECT; |
|
|
|
|
} |
|
|
|
|
if (UpHeld()) { |
|
|
|
|
cameraPos.y-=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
if (RightHeld()) { |
|
|
|
|
cameraPos.x+=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
if (LeftHeld()) { |
|
|
|
|
cameraPos.x-=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
if (DownHeld()) { |
|
|
|
|
cameraPos.y+=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
int selectedTileX=(GetMouseX()+cameraPos.x)/32; |
|
|
|
|
int selectedTileY=(GetMouseY()+cameraPos.y)/32; |
|
|
|
|
if (selectedTileX<MAP_WIDTH&&selectedTileY<MAP_HEIGHT&&selectedTileX>=0&&selectedTileY>=0) { |
|
|
|
|
HIGHLIGHTED_TILE={selectedTileX,selectedTileY}; |
|
|
|
|
} |
|
|
|
|
if (GetMouse(0).bHeld) { |
|
|
|
|
TILE*tile=MAP[HIGHLIGHTED_TILE.y][HIGHLIGHTED_TILE.x]; |
|
|
|
|
tile->tileX=SELECTED_TILE.x; |
|
|
|
|
tile->tileY=SELECTED_TILE.y; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
if (DownHeld()) { |
|
|
|
|
cameraPos.y+=CAMERA_MOVESPD; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void keyUpdates() { |
|
|
|
|
switch (GAME_STATE) { |
|
|
|
|
case state::TILE_SELECT:{ |
|
|
|
|
if (UpPressed()) { |
|
|
|
|
SELECTED_TILE.y=SELECTED_TILE.y-1; |
|
|
|
|
if (SELECTED_TILE.y<0) { |
|
|
|
|
SELECTED_TILE.y=TILEMAP_SIZE_Y/32-1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (RightPressed()) { |
|
|
|
|
SELECTED_TILE.x=(SELECTED_TILE.x+1)%(TILEMAP_SIZE_X/32); |
|
|
|
|
} |
|
|
|
|
if (LeftPressed()) { |
|
|
|
|
SELECTED_TILE.x=SELECTED_TILE.x-1; |
|
|
|
|
if (SELECTED_TILE.x<0) { |
|
|
|
|
SELECTED_TILE.x=TILEMAP_SIZE_X/32-1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (DownPressed()) { |
|
|
|
|
SELECTED_TILE.y=(SELECTED_TILE.y+1)%(TILEMAP_SIZE_Y/32); |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void drawGame(){ |
|
|
|
|
for (auto&obj:OBJECTS) { |
|
|
|
|
DrawPartialDecal(obj->pos,obj->spr->spr,{(obj->frameIndex%obj->spr->frames)*obj->spr->width,0},{obj->spr->width,obj->spr->spr->sprite->height},obj->scale,obj->color); |
|
|
|
|
} |
|
|
|
|
for (int y=-1;y<HEIGHT/32+2;y++) { |
|
|
|
|
for (int x=-1;x<WIDTH/32+2;x++) { |
|
|
|
|
int yTileOffset = cameraPos.y/32; |
|
|
|
|
int xTileOffset = cameraPos.x/32; |
|
|
|
|
if (x+xTileOffset>=0&&x+xTileOffset<MAP_WIDTH&&y+yTileOffset>=0&&y+yTileOffset<MAP_HEIGHT) { |
|
|
|
|
DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES[TILESET1],{MAP[y+yTileOffset][x+xTileOffset]->tileX*32,MAP[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); |
|
|
|
|
switch (GAME_STATE) { |
|
|
|
|
case state::EDITOR:{ |
|
|
|
|
for (auto&obj:OBJECTS) { |
|
|
|
|
DrawPartialDecal(obj->pos,obj->spr->spr,{(obj->frameIndex%obj->spr->frames)*obj->spr->width,0},{obj->spr->width,obj->spr->spr->sprite->height},obj->scale,obj->color); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (int y=-1;y<HEIGHT/32+2;y++) { |
|
|
|
|
for (int x=-1;x<WIDTH/32+2;x++) { |
|
|
|
|
int yTileOffset = cameraPos.y/32; |
|
|
|
|
int xTileOffset = cameraPos.x/32; |
|
|
|
|
if (x+xTileOffset>=0&&x+xTileOffset<MAP_WIDTH&&y+yTileOffset>=0&&y+yTileOffset<MAP_HEIGHT) { |
|
|
|
|
DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES[TILESET1],{MAP[y+yTileOffset][x+xTileOffset]->tileX*32,MAP[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
DrawRectDecal((HIGHLIGHTED_TILE)*32-cameraPos,{32,32},YELLOW); |
|
|
|
|
}break; |
|
|
|
|
case state::TILE_SELECT:{ |
|
|
|
|
//14x14 pixels per tile.
|
|
|
|
|
DrawDecal({0,0},SPRITES[TILESET1],{TILEMAP_EDITOR_DRAW_MULT,TILEMAP_EDITOR_DRAW_MULT}); |
|
|
|
|
DrawRectDecal(SELECTED_TILE*(TILEMAP_EDITOR_TILESIZE),{TILEMAP_EDITOR_TILESIZE,TILEMAP_EDITOR_TILESIZE},RED); |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -221,6 +294,9 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TabHeld(){ |
|
|
|
|
return GetKey(TAB).bHeld; |
|
|
|
|
} |
|
|
|
|
bool UpPressed(){ |
|
|
|
|
return GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128; |
|
|
|
|
} |
|
|
|
|