Firefighter better animations added

This commit is contained in:
2021-01-31 02:10:02 -05:00
parent 697ab6f8fc
commit 3481c20e4f
11 changed files with 75 additions and 44 deletions

View File

@ -11,6 +11,7 @@
#include <string>
#include "SDL2/SDL.h"
#include "Components.h"
#include "ECS.h"
#include "../assetmgr/TextureManager.h"
#include <iostream>
@ -72,19 +73,19 @@ public:
void update() override
{
// if(tag != "terrain")
// {
// collider.x = static_cast<int>(transform->position.x)+9;
// collider.y = static_cast<int>(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<int>(transform->position.x);
collider.y = static_cast<int>(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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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<ColliderComponent>().collider;
if(Collision::AABB(cCol, playerCol))
{
player.getComponent<TransformComponent>().position = playerPos;
// printf("Collision detected!\n");
// player.getComponent<TransformComponent>().position = playerPos;
gravityOnPlayer = false;
// player.getComponent<SpriteComponent>().Play("Idle");
}
// while(Collision::AABB(cCol, playerCol))
// {
// gravityOnPlayer = false;
// }
}
// Gravity
if (gravityOnPlayer){
player.getComponent<TransformComponent>().position.y += 5;
}
// for(auto& p: projectiles)
// {
// if(Collision::AABB(player.getComponent<ColliderComponent>().collider, p->getComponent<ColliderComponent>().collider))

View File

@ -37,6 +37,7 @@ public:
// static std::vector<ColliderComponent*> colliders;
static bool isRunning;
static bool debugCollisionBoxes;
static bool gravityOnPlayer;
static SDL_Rect camera;
static AssetManager* assets;
enum groupLabels : std::size_t