|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#define OLC_PGEX_SPLASHSCREEN
|
|
|
|
#include "splash.h"
|
|
|
|
#define OLC_SOUNDWAVE
|
|
|
|
#include "soundwaveEngine.h"
|
|
|
|
#include "tiles.h"
|
|
|
|
#include "references.h"
|
|
|
|
|
|
|
|
using namespace olc;
|
|
|
|
|
|
|
|
class Map{
|
|
|
|
public:
|
|
|
|
std::string filename;
|
|
|
|
Map(std::string fname) {
|
|
|
|
this->filename=fname;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Animation{
|
|
|
|
public:
|
|
|
|
Decal*spr;
|
|
|
|
int frames=1;
|
|
|
|
int width=0;
|
|
|
|
Animation(Decal*spr,int width){
|
|
|
|
this->frames=spr->sprite->width/width;
|
|
|
|
this->width=width;
|
|
|
|
this->spr=spr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Object{
|
|
|
|
public:
|
|
|
|
Animation*spr;
|
|
|
|
vi2d pos;
|
|
|
|
int frameIndex=0;
|
|
|
|
int frameCount=0;
|
|
|
|
int animationSpd=12; //How many frames to wait between each frame.
|
|
|
|
std::string name;
|
|
|
|
vi2d scale={1,1};
|
|
|
|
Pixel color=WHITE;
|
|
|
|
//animationSpd is how long to wait before switching frames.
|
|
|
|
Object(std::string name,vi2d pos,Animation*spr,vi2d scale={1,1},Pixel color=WHITE,int animationSpd=1) {
|
|
|
|
this->spr=spr;
|
|
|
|
this->pos=pos;
|
|
|
|
this->name=name;
|
|
|
|
this->scale=scale;
|
|
|
|
this->color=color;
|
|
|
|
this->animationSpd=animationSpd;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SeasonI : public PixelGameEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SeasonI()
|
|
|
|
{
|
|
|
|
sAppName = "Season I: Winters of Loneliness";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
int frameCount=0;
|
|
|
|
float elapsedTime=0;
|
|
|
|
const float TARGET_RATE = 1/60.0;
|
|
|
|
int MAP_WIDTH;
|
|
|
|
int MAP_HEIGHT;
|
|
|
|
Map*CURRENT_MAP;
|
|
|
|
Map*MAP_ONETT;
|
|
|
|
|
|
|
|
std::vector<std::vector<TILE*>> MAP;
|
|
|
|
std::map<Reference,Decal*> SPRITES;
|
|
|
|
std::map<Reference,Animation*> ANIMATIONS;
|
|
|
|
std::map<Reference,Object*> OBJ_INFO;
|
|
|
|
std::vector<Object*> OBJECTS;
|
|
|
|
|
|
|
|
bool OnUserCreate() override
|
|
|
|
{
|
|
|
|
SetPixelMode(Pixel::ALPHA);
|
|
|
|
ConsoleCaptureStdOut(true);
|
|
|
|
// Called once at the start, so create things here
|
|
|
|
|
|
|
|
MAP_ONETT=new Map("map0");
|
|
|
|
|
|
|
|
SetupAnimations();
|
|
|
|
SetupObjectInfo();
|
|
|
|
|
|
|
|
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
|
|
|
|
|
|
|
|
//LoadMap(MAP_ONETT);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override
|
|
|
|
{
|
|
|
|
elapsedTime+=fElapsedTime;
|
|
|
|
while (elapsedTime>TARGET_RATE) {
|
|
|
|
elapsedTime-=TARGET_RATE;
|
|
|
|
updateGame();
|
|
|
|
}
|
|
|
|
drawGame();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateGame(){
|
|
|
|
frameCount++;
|
|
|
|
for (auto&obj:OBJECTS) {
|
|
|
|
if (obj->frameCount++>obj->animationSpd) {
|
|
|
|
obj->frameCount=0;
|
|
|
|
obj->frameIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void LoadMap(Map*map) {
|
|
|
|
std::ifstream f("assets/maps/"+map->filename);
|
|
|
|
for (int i=0;i<MAP.size();i++) {
|
|
|
|
for (int j=0;j<MAP[i].size();j++) {
|
|
|
|
delete MAP[i][j];
|
|
|
|
}
|
|
|
|
MAP[i].clear();
|
|
|
|
}
|
|
|
|
MAP_WIDTH=-1;
|
|
|
|
MAP_HEIGHT=-1;
|
|
|
|
MAP.clear();
|
|
|
|
std::string data;
|
|
|
|
while (f.good()) {
|
|
|
|
f>>data;
|
|
|
|
if (MAP_WIDTH==-1) {
|
|
|
|
MAP_WIDTH=data.length();
|
|
|
|
printf("Map Width: %d\n",MAP_WIDTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
MAP_HEIGHT++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupAnimations() {
|
|
|
|
SPRITES[PLAYER] = new Decal(new Sprite("assets/player.png"));
|
|
|
|
ANIMATIONS[PLAYER] = new Animation(SPRITES[PLAYER],32);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupObjectInfo() {
|
|
|
|
OBJ_INFO[PLAYER]=new Object("player",{0,0},ANIMATIONS[PLAYER]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
SeasonI demo;
|
|
|
|
if (demo.Construct(256, 224, 4, 4))
|
|
|
|
demo.Start();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|