generated from sigonasr2/CPlusPlusProjectTemplate
Weirdness with tiles fixed
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
b34e4f6bcb
commit
538fd98146
@ -9,18 +9,20 @@ enum GAMESTATE{
|
||||
CUTSCENE_2,
|
||||
CUTSCENE_3,
|
||||
GAMEWORLD,
|
||||
WAITING_FOR_CUTSCENE_3
|
||||
WAITING_FOR_CUTSCENE_3,
|
||||
};
|
||||
|
||||
enum TILES{
|
||||
DIRT,
|
||||
GRASS,
|
||||
WATER
|
||||
WATER,
|
||||
PLANTS
|
||||
};
|
||||
|
||||
enum CUTSCENE{
|
||||
PAN_DOME,
|
||||
PAUSE_TO_CUTSCENE_3,
|
||||
CUTSCENE_4,
|
||||
};
|
||||
|
||||
#define WIDTH 256
|
||||
@ -28,7 +30,8 @@ enum CUTSCENE{
|
||||
#define ALPHA_SCREEN1 128
|
||||
#define ALPHA_SCREEN2 20
|
||||
#define FADE_SPD 6
|
||||
#define MOVE_SPD 0.4
|
||||
#define MOVE_SPD 0.2
|
||||
#define MESSAGE_SCROLL_WAIT_SPD 2 //Number of frames to wait.
|
||||
|
||||
class Object{
|
||||
public:
|
||||
@ -45,7 +48,7 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
GAMESTATE GAME_STATE=CUTSCENE_1;
|
||||
GAMESTATE GAME_STATE=GAMEWORLD;
|
||||
int textInd=0;
|
||||
int cursorX=0;
|
||||
int transitionTime=0;
|
||||
@ -66,12 +69,15 @@ public:
|
||||
int CUTSCENE_TIMER=0;
|
||||
bool CUTSCENE_FLAGS[8];
|
||||
bool messageBoxVisible;
|
||||
int messageBoxCursor;
|
||||
std::string messageBoxSpeaker;
|
||||
std::string messageBoxText;
|
||||
|
||||
olc::Decal*DOME_DECAL;
|
||||
std::map<std::string,olc::Decal*> BASE_OBJECTS;
|
||||
|
||||
void LoadMap(char*mapName) {
|
||||
std::ifstream f("assets/maps/map1");
|
||||
std::ifstream f(mapName);
|
||||
std::string data;
|
||||
MAP_WIDTH=MAP_HEIGHT=-1;
|
||||
if (MAP!=NULL) {
|
||||
@ -79,7 +85,9 @@ public:
|
||||
free(MAP[y]);
|
||||
}
|
||||
free(MAP);
|
||||
MAP=NULL;
|
||||
}
|
||||
OBJECTS.clear();
|
||||
|
||||
int y=0;
|
||||
if (f.is_open()) {
|
||||
@ -132,7 +140,7 @@ public:
|
||||
TILES=new olc::Decal(new olc::Sprite("assets/tiles.png"));
|
||||
DOME_DECAL=new olc::Decal(new olc::Sprite("assets/dome.png"));
|
||||
BASE_OBJECTS["DOME"]=DOME_DECAL;
|
||||
LoadMap("map1");
|
||||
LoadMap("assets/maps/map2");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -169,8 +177,8 @@ public:
|
||||
}break;
|
||||
case CUTSCENE_2:{
|
||||
fadeIn();
|
||||
PlayCutscene(PAUSE_TO_CUTSCENE_3);
|
||||
GAME_STATE=WAITING_FOR_CUTSCENE_3;
|
||||
PlayCutscene(CUTSCENE_4);
|
||||
GAME_STATE=GAMEWORLD;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
@ -189,6 +197,11 @@ public:
|
||||
CUTSCENE_CONSOLE_TEXT.clear();
|
||||
textInd=0;
|
||||
}break;
|
||||
case CUTSCENE_4:{
|
||||
LoadMap("assets/maps/map2");
|
||||
PLAYER_COORDS[0]=16;
|
||||
PLAYER_COORDS[1]=6;
|
||||
}break;
|
||||
}
|
||||
for (int i=0;i<8;i++) {
|
||||
CUTSCENE_FLAGS[i]=false;
|
||||
@ -218,7 +231,7 @@ public:
|
||||
if (GetKey(olc::F1).bPressed) {
|
||||
}
|
||||
|
||||
if (!CUTSCENE_ACTIVE) {
|
||||
if (!CUTSCENE_ACTIVE&&!messageBoxVisible) {
|
||||
if (GetKey(olc::D).bHeld||GetKey(olc::RIGHT).bHeld) {
|
||||
PLAYER_COORDS[0]=clamp(PLAYER_COORDS[0]+MOVE_SPD,0.0,(double)MAP_WIDTH);
|
||||
}
|
||||
@ -330,11 +343,9 @@ public:
|
||||
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]]);
|
||||
}
|
||||
float xOffset=PLAYER_COORDS[0]-(WIDTH/32/2);
|
||||
float yOffset=PLAYER_COORDS[1]-(HEIGHT/32/2);
|
||||
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[clamp((int)(yOffset+y),0,MAP_HEIGHT-1)][clamp((int)(xOffset+x),0,MAP_WIDTH-1)]]);
|
||||
}
|
||||
}
|
||||
for (auto&obj:OBJECTS) {
|
||||
@ -348,6 +359,12 @@ public:
|
||||
void fadeIn() {
|
||||
fade=false;
|
||||
}
|
||||
void DisplayMessageBox(int dialogNumber) {
|
||||
messageBoxVisible=true;
|
||||
messageBoxCursor=0;
|
||||
messageBoxSpeaker="";
|
||||
messageBoxText="";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Binary file not shown.
12
assets/maps/map2
Normal file
12
assets/maps/map2
Normal file
@ -0,0 +1,12 @@
|
||||
29
|
||||
10
|
||||
00000000000000000000000000000
|
||||
00000000000000000000000000000
|
||||
00000022333333333333300000000
|
||||
00000022333333333333300000000
|
||||
00000022333333333333300000000
|
||||
00000000333333333333300000000
|
||||
00000000333333333333300000000
|
||||
00000000000000000000000000000
|
||||
00000000000000000000000000000
|
||||
00000000000000000000000000000
|
3
data.h
3
data.h
@ -51,8 +51,9 @@ $PLAYER
|
||||
We'll head there.)",//10
|
||||
};
|
||||
|
||||
olc::Pixel TILE_COLORS[3]={
|
||||
olc::Pixel TILE_COLORS[4]={
|
||||
olc::Pixel(112, 88, 64),
|
||||
olc::Pixel(60, 97, 49),
|
||||
olc::Pixel(30, 84, 87),
|
||||
olc::Pixel(29, 122, 0),
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user