diff --git a/C++ProjectTemplate b/C++ProjectTemplate index aa8ddc0..05efab0 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/animations.c b/animations.c new file mode 100644 index 0000000..e69de29 diff --git a/animations.h b/animations.h new file mode 100644 index 0000000..d147840 --- /dev/null +++ b/animations.h @@ -0,0 +1,2 @@ +using namespace olc; + diff --git a/assets/maps/map0 b/assets/maps/map0 index 53cf79f..de87448 100644 --- a/assets/maps/map0 +++ b/assets/maps/map0 @@ -61,4 +61,5 @@ 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +OBJECT17;30; \ No newline at end of file diff --git a/assets/player.png b/assets/player.png new file mode 100644 index 0000000..5c1f355 Binary files /dev/null and b/assets/player.png differ diff --git a/main.cpp b/main.cpp index 9da9b25..341a089 100644 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ #define OLC_SOUNDWAVE #include "soundwaveEngine.h" #include "tiles.h" +#include "references.h" using namespace olc; @@ -33,9 +34,19 @@ class Object{ Animation*spr; vi2d pos; int frameIndex=0; - Object(vi2d pos,Animation*spr) { - this->spr; - this->pos; + 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; } }; @@ -58,6 +69,9 @@ public: Map*MAP_ONETT; std::vector> MAP; + std::map SPRITES; + std::map ANIMATIONS; + std::map OBJ_INFO; std::vector OBJECTS; bool OnUserCreate() override @@ -68,11 +82,19 @@ public: 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(); @@ -82,15 +104,50 @@ public: } 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>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]); } }; diff --git a/references.h b/references.h new file mode 100644 index 0000000..b606902 --- /dev/null +++ b/references.h @@ -0,0 +1,3 @@ +enum Reference{ + PLAYER, +}; \ No newline at end of file diff --git a/tiles.h b/tiles.h index 0cd86ee..07cf30b 100644 --- a/tiles.h +++ b/tiles.h @@ -1,6 +1,3 @@ -#define OLC_PGE_APPLICATION -#include "pixelGameEngine.h" - using namespace olc; class TILE{