diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 67cce0d..ff012ac 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/assets/maps/map0 b/assets/maps/map0 index 45d565c..a874bc9 100644 --- a/assets/maps/map0 +++ b/assets/maps/map0 @@ -1,3 +1,4 @@ +0000R00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 @@ -60,7 +61,4 @@ 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -OBJECT17;30;0 -OBJECT7;4;0 \ No newline at end of file +0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file diff --git a/main.cpp b/main.cpp index 365cc0c..99459ad 100644 --- a/main.cpp +++ b/main.cpp @@ -7,13 +7,19 @@ #include "tiles.h" #include "references.h" +#define WIDTH 256 +#define HEIGHT 224 +#define CAMERA_MOVESPD 0.5 + using namespace olc; class Map{ public: std::string filename; - Map(std::string fname) { + Decal*tileset; + Map(std::string fname,Decal*tileset) { this->filename=fname; + this->tileset=tileset; } }; @@ -32,12 +38,12 @@ class Animation{ class Object{ public: Animation*spr; - vi2d pos; + vd2d 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}; + vd2d 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) { @@ -67,6 +73,9 @@ public: int MAP_HEIGHT; Map*CURRENT_MAP; Map*MAP_ONETT; + vd2d cameraPos = {0,0}; + + bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. std::vector> MAP; std::map SPRITES; @@ -80,11 +89,11 @@ public: ConsoleCaptureStdOut(true); // Called once at the start, so create things here - MAP_ONETT=new Map("map0"); - SetupAnimations(); SetupObjectInfo(); + MAP_ONETT=new Map("map0",SPRITES[TILESET1]); + //OBJ_INFO["PLAYER"]=PLAYER_ANIMATION; LoadMap(MAP_ONETT); @@ -111,11 +120,34 @@ public: obj->frameIndex++; } } - }; + + if (UpHeld()) { + cameraPos.y-=CAMERA_MOVESPD; + } + if (RightHeld()) { + cameraPos.x+=CAMERA_MOVESPD; + } + if (LeftHeld()) { + cameraPos.x-=CAMERA_MOVESPD; + } + if (DownHeld()) { + cameraPos.y+=CAMERA_MOVESPD; + } + } + 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); } + for (int y=-1;y=0&&x+xTileOffset=0&&y+yTileOffsettileX*32,MAP[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32}); + } + } + } }; void LoadMap(Map*map) { @@ -159,27 +191,79 @@ public: OBJECTS.push_back(newObj); //printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str()); } else { + std::vector tiles; + for (int i=0;i>4; + tiles.push_back(new TILE(tileX,tileY)); + } + MAP.push_back(tiles); MAP_HEIGHT++; } } printf("Loaded map %s.\n",map->filename.c_str()); } + Decal*CreateSprite(std::string spriteName) { + return new Decal(new Sprite("assets/"+spriteName)); + } + void SetupAnimations() { - SPRITES[PLAYER] = new Decal(new Sprite("assets/player.png")); + SPRITES[PLAYER] = CreateSprite("player.png"); ANIMATIONS[PLAYER] = new Animation(SPRITES[PLAYER],32); + SPRITES[TILESET1] = CreateSprite("terrainmap.png"); } void SetupObjectInfo() { OBJ_INFO[PLAYER]=new Object("player",{0,0},ANIMATIONS[PLAYER]); } + + + + bool UpPressed(){ + return GetKey(W).bPressed||GetKey(UP).bPressed||GetKey(NP8).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128; + } + bool DownPressed(){ + return GetKey(S).bPressed||GetKey(DOWN).bPressed||GetKey(NP5).bPressed||GetKey(NP2).bPressed||MOUSE_PRESSED_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32&&GetMouseX()<=HEIGHT-128; + } + bool LeftPressed(){ + return GetKey(A).bPressed||GetKey(LEFT).bPressed||GetKey(NP4).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=32&&GetMouseX()>=0&&GetMouseY()>=HEIGHT-128; + } + bool RightPressed(){ + return GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed||MOUSE_PRESSED_DOWN&&GetMouseX()<=128&&GetMouseX()>=96&&GetMouseY()>=HEIGHT-128; + } + bool UpHeld(){ + return GetKey(W).bHeld||GetKey(UP).bHeld||GetKey(NP8).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128; + } + bool DownHeld(){ + return GetKey(S).bHeld||GetKey(DOWN).bHeld||GetKey(NP5).bHeld||GetKey(NP2).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32&&GetMouseX()<=HEIGHT-128; + } + bool LeftHeld(){ + return GetKey(A).bHeld||GetKey(LEFT).bHeld||GetKey(NP4).bHeld||MOUSE_DOWN&&GetMouseX()<=32&&GetMouseX()>=0&&GetMouseY()>=HEIGHT-128; + } + bool RightHeld(){ + return GetKey(D).bHeld||GetKey(RIGHT).bHeld||GetKey(NP6).bHeld||MOUSE_DOWN&&GetMouseX()<=128&&GetMouseX()>=96&&GetMouseY()>=HEIGHT-128; + } + bool UpReleased(){ + return GetKey(W).bReleased||GetKey(UP).bReleased||GetKey(NP8).bReleased||MOUSE_RELEASED&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128; + } + bool DownReleased(){ + return GetKey(S).bReleased||GetKey(DOWN).bReleased||GetKey(NP5).bReleased||GetKey(NP2).bReleased||MOUSE_RELEASED&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32&&GetMouseX()<=HEIGHT-128; + } + bool LeftReleased(){ + return GetKey(A).bReleased||GetKey(LEFT).bReleased||GetKey(NP4).bReleased||MOUSE_RELEASED&&GetMouseX()<=32&&GetMouseX()>=0&&GetMouseY()>=HEIGHT-128; + } + bool RightReleased(){ + return GetKey(D).bReleased||GetKey(RIGHT).bReleased||GetKey(NP6).bReleased||MOUSE_RELEASED&&GetMouseX()<=128&&GetMouseX()>=96&&GetMouseY()>=HEIGHT-128; + } }; int main() { SeasonI demo; - if (demo.Construct(256, 224, 4, 4)) + if (demo.Construct(WIDTH, HEIGHT, 4, 4)) demo.Start(); return 0; diff --git a/references.h b/references.h index b606902..938b3e3 100644 --- a/references.h +++ b/references.h @@ -1,3 +1,4 @@ enum Reference{ PLAYER, + TILESET1, }; \ No newline at end of file