|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#include "data.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
enum GAMESTATE{
|
|
|
|
CUTSCENE_1,
|
|
|
|
GAMEWORLD
|
|
|
|
};
|
|
|
|
|
|
|
|
#define WIDTH 256
|
|
|
|
#define HEIGHT 224
|
|
|
|
#define ALPHA_SCREEN1 128
|
|
|
|
#define ALPHA_SCREEN2 20
|
|
|
|
#define FADE_SPD 6
|
|
|
|
|
|
|
|
class SeasonsOfLoneliness : public olc::PixelGameEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SeasonsOfLoneliness()
|
|
|
|
{
|
|
|
|
sAppName = "Seasons of Loneliness";
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
GAMESTATE GAME_STATE=CUTSCENE_1;
|
|
|
|
int textInd=0;
|
|
|
|
int cursorX=0;
|
|
|
|
int transitionTime=0;
|
|
|
|
bool fade=false;
|
|
|
|
int transparency=0;
|
|
|
|
int frameCount=0;
|
|
|
|
float elapsedTime=0;
|
|
|
|
const float TARGET_RATE = 1/60.0;
|
|
|
|
std::string CUTSCENE_CONSOLE_TEXT = "";
|
|
|
|
int**MAP=NULL;
|
|
|
|
int MAP_WIDTH=-1;
|
|
|
|
int MAP_HEIGHT=-1;
|
|
|
|
|
|
|
|
void LoadMap(char*mapName) {
|
|
|
|
std::ifstream f("assets/maps/map1");
|
|
|
|
std::string data;
|
|
|
|
MAP_WIDTH=MAP_HEIGHT=-1;
|
|
|
|
if (MAP!=NULL) {
|
|
|
|
for (int y=0;y<MAP_HEIGHT;y++) {
|
|
|
|
free(MAP[y]);
|
|
|
|
}
|
|
|
|
free(MAP);
|
|
|
|
}
|
|
|
|
int y=0;
|
|
|
|
if (f.is_open()) {
|
|
|
|
while (f.good()) {
|
|
|
|
f>>data;
|
|
|
|
if (MAP_WIDTH==-1) {
|
|
|
|
std::stringstream stream(data);
|
|
|
|
stream>>MAP_WIDTH;
|
|
|
|
} else
|
|
|
|
if (MAP_HEIGHT==-1) {
|
|
|
|
std::stringstream stream(data);
|
|
|
|
stream>>MAP_HEIGHT;
|
|
|
|
} else {
|
|
|
|
if (MAP==NULL) {
|
|
|
|
MAP=(int**)malloc(sizeof(int**)*MAP_HEIGHT);
|
|
|
|
}
|
|
|
|
MAP[y]=(int*)malloc(sizeof(int*)*MAP_WIDTH);
|
|
|
|
for (int i=0;i<data.length();i++) {
|
|
|
|
MAP[y][i]=data[i]-'0';
|
|
|
|
}
|
|
|
|
y++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int y=0;y<MAP_HEIGHT;y++) {
|
|
|
|
for (int x=0;x<MAP_WIDTH;x++) {
|
|
|
|
printf("%d",MAP[y][x]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnUserCreate() override
|
|
|
|
{
|
|
|
|
SetPixelMode(olc::Pixel::ALPHA);
|
|
|
|
//ConsoleCaptureStdOut(true);
|
|
|
|
// Called once at the start, so create things here
|
|
|
|
LoadMap("map1");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetAnyKey() {
|
|
|
|
switch (GAME_STATE) {
|
|
|
|
case CUTSCENE_1:{
|
|
|
|
if (textInd>=STORY_TEXT1.length()) {
|
|
|
|
fadeOut();
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override
|
|
|
|
{
|
|
|
|
elapsedTime+=fElapsedTime;
|
|
|
|
while (elapsedTime>TARGET_RATE) {
|
|
|
|
elapsedTime-=TARGET_RATE;
|
|
|
|
updateGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
drawGame();
|
|
|
|
// called once per frame
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fadeOutCompleted() {
|
|
|
|
switch (GAME_STATE) {
|
|
|
|
case CUTSCENE_1:{
|
|
|
|
GAME_STATE=GAMEWORLD;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fadeInCompleted() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateGame(){
|
|
|
|
frameCount++;
|
|
|
|
if (fade&&transparency<255) {
|
|
|
|
transparency=clamp(transparency+FADE_SPD,0,255);
|
|
|
|
if (transparency==255) {
|
|
|
|
fadeOutCompleted();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (!fade&&transparency>0) {
|
|
|
|
transparency=clamp(transparency-FADE_SPD,0,255);
|
|
|
|
if (transparency==0) {
|
|
|
|
fadeInCompleted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (GAME_STATE) {
|
|
|
|
case CUTSCENE_1:{
|
|
|
|
if (textInd<STORY_TEXT1.length()) {
|
|
|
|
char c = STORY_TEXT1[textInd++];
|
|
|
|
CUTSCENE_CONSOLE_TEXT+=c;
|
|
|
|
if (c!='\n') {
|
|
|
|
cursorX++;
|
|
|
|
} else {
|
|
|
|
cursorX=0;
|
|
|
|
}
|
|
|
|
if (GetTextSize(CUTSCENE_CONSOLE_TEXT).x>WIDTH-32) {
|
|
|
|
int tempIndex=textInd;
|
|
|
|
while (CUTSCENE_CONSOLE_TEXT[--tempIndex]!=' ') {
|
|
|
|
CUTSCENE_CONSOLE_TEXT.erase(tempIndex);
|
|
|
|
cursorX--;
|
|
|
|
}
|
|
|
|
CUTSCENE_CONSOLE_TEXT.erase(tempIndex++);
|
|
|
|
CUTSCENE_CONSOLE_TEXT+='\n';
|
|
|
|
cursorX=0;
|
|
|
|
while (tempIndex<textInd) {
|
|
|
|
CUTSCENE_CONSOLE_TEXT+=STORY_TEXT1[tempIndex++];
|
|
|
|
cursorX++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGame(){
|
|
|
|
switch (GAME_STATE) {
|
|
|
|
case CUTSCENE_1:{
|
|
|
|
DrawStringDecal({16,16},CUTSCENE_CONSOLE_TEXT,olc::GREEN,{1,1});
|
|
|
|
if (textInd<STORY_TEXT1.length()) {
|
|
|
|
FillRectDecal({16+(cursorX)*8%(WIDTH-32),8+GetTextSize(CUTSCENE_CONSOLE_TEXT).y+((cursorX==28)?8:0)},{4,8},olc::GREEN);
|
|
|
|
} else {
|
|
|
|
FillRectDecal({16+(cursorX)*8%(WIDTH-32),8+GetTextSize(CUTSCENE_CONSOLE_TEXT).y+((cursorX==28)?8:0)},{4,8},olc::Pixel(0,255,0,(0.5*sin(frameCount*4/60.0)+0.5)*256));
|
|
|
|
}
|
|
|
|
GradientFillRectDecal({0,0},{WIDTH/2,HEIGHT/2},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN2},{20, 28, 22,ALPHA_SCREEN1});
|
|
|
|
GradientFillRectDecal({WIDTH/2,0},{WIDTH/2,HEIGHT/2},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN2},{20, 28, 22,ALPHA_SCREEN1},{20, 28, 22,ALPHA_SCREEN1});
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency));
|
|
|
|
}
|
|
|
|
|
|
|
|
void fadeOut() {
|
|
|
|
fade=true;
|
|
|
|
}
|
|
|
|
void fadeIn() {
|
|
|
|
fade=false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
SeasonsOfLoneliness demo;
|
|
|
|
if (demo.Construct(256, 224, 4, 4))
|
|
|
|
demo.Start();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|