|
|
|
@ -6,6 +6,7 @@ using namespace std; |
|
|
|
|
|
|
|
|
|
enum GAMESTATE{ |
|
|
|
|
CUTSCENE_1, |
|
|
|
|
CUTSCENE_2, |
|
|
|
|
GAMEWORLD |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -15,6 +16,10 @@ enum TILES{ |
|
|
|
|
WATER |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
enum CUTSCENE{ |
|
|
|
|
PAN_DOME, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#define WIDTH 256 |
|
|
|
|
#define HEIGHT 224 |
|
|
|
|
#define ALPHA_SCREEN1 128 |
|
|
|
@ -37,7 +42,7 @@ public: |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
GAMESTATE GAME_STATE=GAMEWORLD; |
|
|
|
|
GAMESTATE GAME_STATE=CUTSCENE_1; |
|
|
|
|
int textInd=0; |
|
|
|
|
int cursorX=0; |
|
|
|
|
int transitionTime=0; |
|
|
|
@ -53,6 +58,10 @@ public: |
|
|
|
|
olc::Decal*TILES; |
|
|
|
|
float PLAYER_COORDS[2] = {}; |
|
|
|
|
std::vector<Object> OBJECTS; |
|
|
|
|
bool CUTSCENE_ACTIVE=false; |
|
|
|
|
CUTSCENE CURRENT_CUTSCENE=PAN_DOME; |
|
|
|
|
int CUTSCENE_TIMER=0; |
|
|
|
|
bool CUTSCENE_FLAGS[8]; |
|
|
|
|
|
|
|
|
|
olc::Decal*DOME_DECAL; |
|
|
|
|
std::map<std::string,olc::Decal*> BASE_OBJECTS; |
|
|
|
@ -141,17 +150,19 @@ public: |
|
|
|
|
updateGame(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (GetKey(olc::D).bHeld||GetKey(olc::RIGHT).bHeld) { |
|
|
|
|
PLAYER_COORDS[0]=clamp(PLAYER_COORDS[0]+MOVE_SPD,0.0,(double)MAP_WIDTH); |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::A).bHeld||GetKey(olc::LEFT).bHeld) { |
|
|
|
|
PLAYER_COORDS[0]=clamp(PLAYER_COORDS[0]-MOVE_SPD,0.0,(double)MAP_WIDTH); |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::W).bHeld||GetKey(olc::UP).bHeld) { |
|
|
|
|
PLAYER_COORDS[1]=clamp(PLAYER_COORDS[1]-MOVE_SPD,0.0,(double)MAP_HEIGHT); |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::S).bHeld||GetKey(olc::DOWN).bHeld) { |
|
|
|
|
PLAYER_COORDS[1]=clamp(PLAYER_COORDS[1]+MOVE_SPD,0.0,(double)MAP_HEIGHT); |
|
|
|
|
if (!CUTSCENE_ACTIVE) { |
|
|
|
|
if (GetKey(olc::D).bHeld||GetKey(olc::RIGHT).bHeld) { |
|
|
|
|
PLAYER_COORDS[0]=clamp(PLAYER_COORDS[0]+MOVE_SPD,0.0,(double)MAP_WIDTH); |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::A).bHeld||GetKey(olc::LEFT).bHeld) { |
|
|
|
|
PLAYER_COORDS[0]=clamp(PLAYER_COORDS[0]-MOVE_SPD,0.0,(double)MAP_WIDTH); |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::W).bHeld||GetKey(olc::UP).bHeld) { |
|
|
|
|
PLAYER_COORDS[1]=clamp(PLAYER_COORDS[1]-MOVE_SPD,0.0,(double)MAP_HEIGHT); |
|
|
|
|
} |
|
|
|
|
if (GetKey(olc::S).bHeld||GetKey(olc::DOWN).bHeld) { |
|
|
|
|
PLAYER_COORDS[1]=clamp(PLAYER_COORDS[1]+MOVE_SPD,0.0,(double)MAP_HEIGHT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
drawGame(); |
|
|
|
@ -162,9 +173,8 @@ public: |
|
|
|
|
void fadeOutCompleted() { |
|
|
|
|
switch (GAME_STATE) { |
|
|
|
|
case CUTSCENE_1:{ |
|
|
|
|
GAME_STATE=GAMEWORLD; |
|
|
|
|
PLAYER_COORDS[0]=21; |
|
|
|
|
PLAYER_COORDS[1]=17; |
|
|
|
|
GAME_STATE=CUTSCENE_2; |
|
|
|
|
PlayCutscene(PAN_DOME); |
|
|
|
|
fadeIn(); |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
@ -174,8 +184,25 @@ public: |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PlayCutscene(CUTSCENE scene) { |
|
|
|
|
switch (scene) { |
|
|
|
|
case PAN_DOME:{ |
|
|
|
|
PLAYER_COORDS[0]=14; |
|
|
|
|
PLAYER_COORDS[1]=18+(64/2/32); |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
for (int i=0;i<8;i++) { |
|
|
|
|
CUTSCENE_FLAGS[i]=false; |
|
|
|
|
} |
|
|
|
|
CUTSCENE_ACTIVE=true; |
|
|
|
|
CUTSCENE_TIMER=0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void updateGame(){ |
|
|
|
|
frameCount++; |
|
|
|
|
if (CUTSCENE_ACTIVE) { |
|
|
|
|
CUTSCENE_TIMER++; |
|
|
|
|
} |
|
|
|
|
if (fade&&transparency<255) { |
|
|
|
|
transparency=clamp(transparency+FADE_SPD,0,255); |
|
|
|
|
if (transparency==255) { |
|
|
|
@ -214,6 +241,21 @@ public: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case CUTSCENE_2:{ |
|
|
|
|
//FLAG 0 - When flipped on, camera stops.
|
|
|
|
|
if (!CUTSCENE_FLAGS[0]) { |
|
|
|
|
PLAYER_COORDS[0]+=0.06; |
|
|
|
|
} else { |
|
|
|
|
if (CUTSCENE_TIMER>120) { |
|
|
|
|
fadeOut(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (PLAYER_COORDS[0]>38+(128/2/32)) { |
|
|
|
|
PLAYER_COORDS[0]=38+(128/2/32); |
|
|
|
|
CUTSCENE_FLAGS[0]=true; |
|
|
|
|
CUTSCENE_TIMER=0; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -231,24 +273,29 @@ public: |
|
|
|
|
GradientFillRectDecal({0,HEIGHT/2},{WIDTH/2,HEIGHT/2},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN2}); |
|
|
|
|
GradientFillRectDecal({WIDTH/2,HEIGHT/2},{WIDTH/2,HEIGHT/2},{20, 28, 22,ALPHA_SCREEN2},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN1}); |
|
|
|
|
}break; |
|
|
|
|
case CUTSCENE_2: |
|
|
|
|
case GAMEWORLD:{ |
|
|
|
|
for (int y=-1;y<=HEIGHT/32;y++) { |
|
|
|
|
for (int x=-1;x<=WIDTH/32;x++) { |
|
|
|
|
int xOffset=PLAYER_COORDS[0]-(WIDTH/64); |
|
|
|
|
int yOffset=PLAYER_COORDS[1]-(HEIGHT/64); |
|
|
|
|
if (xOffset+x>=0&&xOffset+x<MAP_WIDTH&&yOffset+y>=0&&yOffset+y<MAP_HEIGHT) { |
|
|
|
|
DrawPartialDecal({(x-(PLAYER_COORDS[0]-(int)PLAYER_COORDS[0]))*32,(y-(PLAYER_COORDS[1]-(int)PLAYER_COORDS[1]))*32},{32,32},TILES,{0,0},{32,32},TILE_COLORS[MAP[yOffset+y][xOffset+x]]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (auto&obj:OBJECTS) { |
|
|
|
|
DrawDecal({(obj.x-PLAYER_COORDS[0])*32+WIDTH/2,(obj.y-PLAYER_COORDS[1])*32+HEIGHT/2},obj.spr); |
|
|
|
|
} |
|
|
|
|
DrawGameWorld(); |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DrawGameWorld() { |
|
|
|
|
for (int y=-1;y<=HEIGHT/32;y++) { |
|
|
|
|
for (int x=-1;x<=WIDTH/32;x++) { |
|
|
|
|
int xOffset=PLAYER_COORDS[0]-(WIDTH/64); |
|
|
|
|
int yOffset=PLAYER_COORDS[1]-(HEIGHT/64); |
|
|
|
|
if (xOffset+x>=0&&xOffset+x<MAP_WIDTH&&yOffset+y>=0&&yOffset+y<MAP_HEIGHT) { |
|
|
|
|
DrawPartialDecal({(x-(PLAYER_COORDS[0]-(int)PLAYER_COORDS[0]))*32,(y-(PLAYER_COORDS[1]-(int)PLAYER_COORDS[1]))*32},{32,32},TILES,{0,0},{32,32},TILE_COLORS[MAP[yOffset+y][xOffset+x]]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (auto&obj:OBJECTS) { |
|
|
|
|
DrawDecal({(obj.x-PLAYER_COORDS[0])*32+WIDTH/2,(obj.y-PLAYER_COORDS[1])*32+HEIGHT/2},obj.spr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fadeOut() { |
|
|
|
|
fade=true; |
|
|
|
|
} |
|
|
|
|