diff --git a/assets/textures/actors/firefighter-idle.gif b/assets/textures/actors/firefighter-idle.gif new file mode 100644 index 0000000..e8f1b32 Binary files /dev/null and b/assets/textures/actors/firefighter-idle.gif differ diff --git a/assets/textures/actors/firefighter-walk.gif b/assets/textures/actors/firefighter-walk.gif new file mode 100644 index 0000000..9bb5dcb Binary files /dev/null and b/assets/textures/actors/firefighter-walk.gif differ diff --git a/assets/textures/actors/firefighter.aseprite b/assets/textures/actors/firefighter.aseprite index 2e08500..9a59f76 100644 Binary files a/assets/textures/actors/firefighter.aseprite and b/assets/textures/actors/firefighter.aseprite differ diff --git a/assets/textures/actors/firefighter.json b/assets/textures/actors/firefighter.json index dc8df61..b63edcd 100644 --- a/assets/textures/actors/firefighter.json +++ b/assets/textures/actors/firefighter.json @@ -28,7 +28,7 @@ }, { "filename": "3", - "frame": { "x": 66, "y": 0, "w": 22, "h": 42 }, + "frame": { "x": 0, "y": 42, "w": 22, "h": 42 }, "rotated": false, "trimmed": false, "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 42 }, @@ -37,7 +37,7 @@ }, { "filename": "4", - "frame": { "x": 88, "y": 0, "w": 22, "h": 42 }, + "frame": { "x": 22, "y": 42, "w": 22, "h": 42 }, "rotated": false, "trimmed": false, "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 42 }, @@ -46,7 +46,7 @@ }, { "filename": "5", - "frame": { "x": 110, "y": 0, "w": 22, "h": 42 }, + "frame": { "x": 44, "y": 42, "w": 22, "h": 42 }, "rotated": false, "trimmed": false, "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 42 }, @@ -55,7 +55,7 @@ }, { "filename": "6", - "frame": { "x": 132, "y": 0, "w": 22, "h": 42 }, + "frame": { "x": 0, "y": 84, "w": 22, "h": 42 }, "rotated": false, "trimmed": false, "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 42 }, @@ -64,7 +64,7 @@ }, { "filename": "7", - "frame": { "x": 154, "y": 0, "w": 22, "h": 42 }, + "frame": { "x": 22, "y": 84, "w": 22, "h": 42 }, "rotated": false, "trimmed": false, "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 42 }, @@ -73,7 +73,7 @@ }, { "filename": "8", - "frame": { "x": 176, "y": 0, "w": 22, "h": 42 }, + "frame": { "x": 44, "y": 84, "w": 22, "h": 42 }, "rotated": false, "trimmed": false, "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 42 }, @@ -86,11 +86,13 @@ "version": "1.2.25-x64", "image": "firefighter.png", "format": "RGBA8888", - "size": { "w": 198, "h": 42 }, + "size": { "w": 66, "h": 126 }, "scale": "1", "frameTags": [ { "name": "idle", "from": 0, "to": 2, "direction": "forward" }, - { "name": "walk", "from": 3, "to": 8, "direction": "forward" } + { "name": "walk", "from": 3, "to": 5, "direction": "forward" }, + { "name": "jump", "from": 6, "to": 6, "direction": "forward" }, + { "name": "fall", "from": 7, "to": 7, "direction": "forward" } ] } } diff --git a/assets/textures/actors/firefighter.png b/assets/textures/actors/firefighter.png index e27bac3..0b3c403 100644 Binary files a/assets/textures/actors/firefighter.png and b/assets/textures/actors/firefighter.png differ diff --git a/build/BeagleRescue b/build/BeagleRescue index 83f6a83..b2d8db7 100755 Binary files a/build/BeagleRescue and b/build/BeagleRescue differ diff --git a/src/ecs/ColliderComponent.h b/src/ecs/ColliderComponent.h index d0cc225..6582ca4 100644 --- a/src/ecs/ColliderComponent.h +++ b/src/ecs/ColliderComponent.h @@ -11,6 +11,7 @@ #include #include "SDL2/SDL.h" #include "Components.h" +#include "ECS.h" #include "../assetmgr/TextureManager.h" #include @@ -72,19 +73,19 @@ public: void update() override { -// if(tag != "terrain") -// { -// collider.x = static_cast(transform->position.x)+9; -// collider.y = static_cast(transform->position.y)+28; -//// collider.w = transform->width * transform->scale; -//// collider.h = transform->height * transform->scale; -// collider.w = 12 * transform->scale; -// collider.h = 12 * transform->scale; + if(tag != "terrain") + { + collider.x = static_cast(transform->position.x); + collider.y = static_cast(transform->position.y); + collider.w = transform->width * transform->scale; + collider.h = transform->height * transform->scale; +// collider.w = 12 * transform->scale; +// collider.h = 12 * transform->scale; // -//// std::cout << "collider.w: " << collider.w << std::endl; -//// std::cout << "collider.h: " << collider.h << std::endl; -//// std::cout << "tag: " << tag << std::endl; -// } +// std::cout << "collider.w: " << collider.w << std::endl; +// std::cout << "collider.h: " << collider.h << std::endl; +// std::cout << "tag: " << tag << std::endl; + } destR.x = collider.x - Game::camera.x; destR.y = collider.y - Game::camera.y; // std::cout << "tag: " << tag << std::endl; diff --git a/src/ecs/KeyboardController.h b/src/ecs/KeyboardController.h index 2a4e0d7..82cedf5 100644 --- a/src/ecs/KeyboardController.h +++ b/src/ecs/KeyboardController.h @@ -34,39 +34,39 @@ public: switch (Game::event.key.keysym.sym) { case SDLK_UP: - transform->velocity.y = -1; +// transform->velocity.y = -1; // sprite->Play("WalkNorth"); - if (transform->velocity.x < 0) - { +// if (transform->velocity.x < 0) +// { // sprite->Play("WalkNW"); - } - if (transform->velocity.x > 0) - { +// } +// if (transform->velocity.x > 0) +// { // sprite->Play("WalkNW"); // sprite->spriteFlip = SDL_FLIP_HORIZONTAL; - } +// } break; case SDLK_DOWN: - transform->velocity.y = 1; +// transform->velocity.y = 1; // sprite->Play("WalkSouth"); - if (transform->velocity.x < 0) - { +// if (transform->velocity.x < 0) +// { // sprite->Play("WalkSW"); - } - if (transform->velocity.x > 0) - { +// } +// if (transform->velocity.x > 0) +// { // sprite->Play("WalkSW"); // sprite->spriteFlip = SDL_FLIP_HORIZONTAL; - } +// } break; case SDLK_LEFT: transform->velocity.x = -1; -// sprite->Play("Walk"); + sprite->Play("Walk"); sprite->spriteFlip = SDL_FLIP_NONE; break; case SDLK_RIGHT: transform->velocity.x = 1; -// sprite->Play("Walk"); + sprite->Play("Walk"); sprite->spriteFlip = SDL_FLIP_HORIZONTAL; break; case SDLK_k: @@ -77,6 +77,9 @@ public: { Mix_PlayChannel(-1, Game::assets->GetSoundClip("bwoop"),0); } + Game::gravityOnPlayer = true; + sprite->Play("Jump"); + transform->velocity.y = -1; break; default: break; @@ -99,11 +102,11 @@ public: break; case SDLK_LEFT: transform->velocity.x = 0; -// sprite->Play("idle"); + sprite->Play("Idle"); break; case SDLK_RIGHT: transform->velocity.x = 0; -// sprite->Play("idle"); + sprite->Play("Idle"); break; case SDLK_k: if (Game::debugCollisionBoxes) @@ -111,6 +114,11 @@ public: else {Game::debugCollisionBoxes = true; } break; + case SDLK_j: + transform->velocity.y = 0; + sprite->Play("Fall"); + Game::gravityOnPlayer = true; + break; case SDLK_ESCAPE: // exit the game when Escape pressed Game::isRunning = false; break; diff --git a/src/ecs/SpriteComponent.h b/src/ecs/SpriteComponent.h index d468dae..03598ab 100644 --- a/src/ecs/SpriteComponent.h +++ b/src/ecs/SpriteComponent.h @@ -106,10 +106,16 @@ public: // printf("No animations\n"); // } // Play("idle"); - } - Animation Idle = Animation(0,2,100); - animations.emplace("Idle", Idle); + Animation idle = Animation(0,3,100); + animations.emplace("Idle", idle); + Animation walk = Animation(1,3,100); + animations.emplace("Walk", walk); + Animation jump = Animation(2,1,100); + animations.emplace("Jump", jump); + Animation fall = Animation(2,2,100); + animations.emplace("Fall",fall); Play("Idle"); + } setTex(id); } diff --git a/src/game/Game.cpp b/src/game/Game.cpp index 7c7b770..9ffcba9 100644 --- a/src/game/Game.cpp +++ b/src/game/Game.cpp @@ -47,6 +47,8 @@ auto& uiInfo(manager.addEntity()); bool Game::debugCollisionBoxes = false; +bool Game::gravityOnPlayer = true; + int gScale = 0; Game::Game() { @@ -108,7 +110,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g SDL_Rect myDestRect = SDL_Rect(); myDestRect.x = 12; myDestRect.y = 8; - myDestRect.w = 140; + myDestRect.w = 120; myDestRect.h = 40; my9Slice = new UINineSlice("textBox"); my9Slice->MakeSlices("textBox",32,32,14,17,14,17,myDestRect,globalScale); @@ -179,10 +181,21 @@ void Game::update() SDL_Rect cCol = c->getComponent().collider; if(Collision::AABB(cCol, playerCol)) { - player.getComponent().position = playerPos; +// printf("Collision detected!\n"); +// player.getComponent().position = playerPos; + gravityOnPlayer = false; +// player.getComponent().Play("Idle"); } +// while(Collision::AABB(cCol, playerCol)) +// { +// gravityOnPlayer = false; +// } } - + +// Gravity + if (gravityOnPlayer){ + player.getComponent().position.y += 5; + } // for(auto& p: projectiles) // { // if(Collision::AABB(player.getComponent().collider, p->getComponent().collider)) diff --git a/src/game/Game.hpp b/src/game/Game.hpp index 8f3088e..d163bcf 100644 --- a/src/game/Game.hpp +++ b/src/game/Game.hpp @@ -37,6 +37,7 @@ public: // static std::vector colliders; static bool isRunning; static bool debugCollisionBoxes; + static bool gravityOnPlayer; static SDL_Rect camera; static AssetManager* assets; enum groupLabels : std::size_t