Scroll tile view

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent c1c7cd50b1
commit cd8c77def2
  1. 40
      SeasonsOfLoneliness.cpp
  2. BIN
      Seasons_of_Loneliness
  3. 2
      assets/maps/map1

@ -9,11 +9,18 @@ enum GAMESTATE{
GAMEWORLD GAMEWORLD
}; };
enum TILES{
DIRT,
GRASS,
WATER
};
#define WIDTH 256 #define WIDTH 256
#define HEIGHT 224 #define HEIGHT 224
#define ALPHA_SCREEN1 128 #define ALPHA_SCREEN1 128
#define ALPHA_SCREEN2 20 #define ALPHA_SCREEN2 20
#define FADE_SPD 6 #define FADE_SPD 6
#define MOVE_SPD 0.01
class SeasonsOfLoneliness : public olc::PixelGameEngine class SeasonsOfLoneliness : public olc::PixelGameEngine
{ {
@ -24,7 +31,7 @@ public:
} }
public: public:
GAMESTATE GAME_STATE=CUTSCENE_1; GAMESTATE GAME_STATE=GAMEWORLD;
int textInd=0; int textInd=0;
int cursorX=0; int cursorX=0;
int transitionTime=0; int transitionTime=0;
@ -37,6 +44,8 @@ public:
int**MAP=NULL; int**MAP=NULL;
int MAP_WIDTH=-1; int MAP_WIDTH=-1;
int MAP_HEIGHT=-1; int MAP_HEIGHT=-1;
olc::Decal*TILES;
float PLAYER_COORDS[2] = {};
void LoadMap(char*mapName) { void LoadMap(char*mapName) {
std::ifstream f("assets/maps/map1"); std::ifstream f("assets/maps/map1");
@ -71,6 +80,7 @@ public:
} }
} }
} }
printf("Loaded %dx%d map:\n",MAP_WIDTH,MAP_HEIGHT);
for (int y=0;y<MAP_HEIGHT;y++) { for (int y=0;y<MAP_HEIGHT;y++) {
for (int x=0;x<MAP_WIDTH;x++) { for (int x=0;x<MAP_WIDTH;x++) {
printf("%d",MAP[y][x]); printf("%d",MAP[y][x]);
@ -84,6 +94,7 @@ public:
SetPixelMode(olc::Pixel::ALPHA); SetPixelMode(olc::Pixel::ALPHA);
//ConsoleCaptureStdOut(true); //ConsoleCaptureStdOut(true);
// Called once at the start, so create things here // Called once at the start, so create things here
TILES=new olc::Decal(new olc::Sprite("assets/tiles.png"));
LoadMap("map1"); LoadMap("map1");
return true; return true;
} }
@ -106,6 +117,19 @@ public:
updateGame(); 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);
}
drawGame(); drawGame();
// called once per frame // called once per frame
return true; return true;
@ -115,6 +139,9 @@ public:
switch (GAME_STATE) { switch (GAME_STATE) {
case CUTSCENE_1:{ case CUTSCENE_1:{
GAME_STATE=GAMEWORLD; GAME_STATE=GAMEWORLD;
PLAYER_COORDS[0]=21;
PLAYER_COORDS[1]=17;
fadeIn();
}break; }break;
} }
} }
@ -180,6 +207,17 @@ 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({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}); 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; }break;
case GAMEWORLD:{
for (int y=-1;y<=HEIGHT/32;y++) {
for (int x=-1;x<=WIDTH/32;x++) {
float xOffset=PLAYER_COORDS[0]-(WIDTH/64);
float 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});
}
}
}
}break;
} }
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency)); FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency));
} }

Binary file not shown.

@ -1,4 +1,4 @@
103 102
39 39
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Loading…
Cancel
Save