generated from sigonasr2/CPlusPlusProjectTemplate
Setup animation structures and framework
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
ff6931f772
commit
1cb932c151
Binary file not shown.
0
animations.c
Normal file
0
animations.c
Normal file
2
animations.h
Normal file
2
animations.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
using namespace olc;
|
||||||
|
|
@ -61,4 +61,5 @@
|
|||||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
OBJECT17;30;
|
BIN
assets/player.png
Normal file
BIN
assets/player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
67
main.cpp
67
main.cpp
@ -5,6 +5,7 @@
|
|||||||
#define OLC_SOUNDWAVE
|
#define OLC_SOUNDWAVE
|
||||||
#include "soundwaveEngine.h"
|
#include "soundwaveEngine.h"
|
||||||
#include "tiles.h"
|
#include "tiles.h"
|
||||||
|
#include "references.h"
|
||||||
|
|
||||||
using namespace olc;
|
using namespace olc;
|
||||||
|
|
||||||
@ -33,9 +34,19 @@ class Object{
|
|||||||
Animation*spr;
|
Animation*spr;
|
||||||
vi2d pos;
|
vi2d pos;
|
||||||
int frameIndex=0;
|
int frameIndex=0;
|
||||||
Object(vi2d pos,Animation*spr) {
|
int frameCount=0;
|
||||||
this->spr;
|
int animationSpd=12; //How many frames to wait between each frame.
|
||||||
this->pos;
|
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;
|
Map*MAP_ONETT;
|
||||||
|
|
||||||
std::vector<std::vector<TILE*>> MAP;
|
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;
|
std::vector<Object*> OBJECTS;
|
||||||
|
|
||||||
bool OnUserCreate() override
|
bool OnUserCreate() override
|
||||||
@ -68,11 +82,19 @@ public:
|
|||||||
|
|
||||||
MAP_ONETT=new Map("map0");
|
MAP_ONETT=new Map("map0");
|
||||||
|
|
||||||
|
SetupAnimations();
|
||||||
|
SetupObjectInfo();
|
||||||
|
|
||||||
|
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
|
||||||
|
|
||||||
|
//LoadMap(MAP_ONETT);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
bool OnUserUpdate(float fElapsedTime) override
|
||||||
{
|
{
|
||||||
|
elapsedTime+=fElapsedTime;
|
||||||
while (elapsedTime>TARGET_RATE) {
|
while (elapsedTime>TARGET_RATE) {
|
||||||
elapsedTime-=TARGET_RATE;
|
elapsedTime-=TARGET_RATE;
|
||||||
updateGame();
|
updateGame();
|
||||||
@ -82,15 +104,50 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateGame(){
|
void updateGame(){
|
||||||
|
frameCount++;
|
||||||
|
for (auto&obj:OBJECTS) {
|
||||||
|
if (obj->frameCount++>obj->animationSpd) {
|
||||||
|
obj->frameCount=0;
|
||||||
|
obj->frameIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
void drawGame(){
|
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) {
|
void LoadMap(Map*map) {
|
||||||
std::ifstream f("assets/maps/"+map->filename);
|
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]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
3
references.h
Normal file
3
references.h
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
enum Reference{
|
||||||
|
PLAYER,
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user