TileMaps and camera tuning

This commit is contained in:
2022-04-29 21:31:34 -04:00
parent bc4262d552
commit 9f4007bb79
6 changed files with 51 additions and 49 deletions

View File

@ -36,7 +36,7 @@ SDL_Renderer* Game::renderer = nullptr;
SDL_Event Game::event;
SDL_Rect Game::camera;
SDL_Rect levelMap;
SDL_Rect Game::levelMap;
AssetManager* Game::assets = new AssetManager(&manager);
@ -161,9 +161,6 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
assets->AddSoundClip("bark2","assets/audio/sfx/Bark2.wav");
// map = new Map("terrain",globalScale,16);
gameScene.addComponent<TileMapComponent>(map,gScale);
gameScene.addGroup(groupMap);
// std::string myText = "Find lost puppies!\nThey need your help!";
std::string myText = "Press U to Start";
@ -179,24 +176,24 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
my9Slice = new UINineSlice("textBox");
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale,Game::groupUI_Layer0);
uiInfo.addComponent<TransformComponent>(camera.w-94,10,72,96,gScale);
uiInfo.addComponent<TransformComponent>((camera.w-94)*gScale,10*gScale,72,96,gScale);
// uiInfo.addComponent<UITextComponent>("font", "CollisionHori: Vert: Jump: P.y : P.dy: YVec: ", 8, 12, 1);
uiInfo.addComponent<UITextComponent>("font", "Camera CamX: CamY: P.x: P.y : P.dy: YVec: ", 8, 12, gScale);
uiInfo.addGroup(groupUI_Layer3);
uiCamXInfo.addComponent<TransformComponent>(camera.w-48,24,40,12,gScale);
uiCamXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
uiCamXInfo.addComponent<TransformComponent>((camera.w-48)*gScale,24*gScale,40,12,gScale);
uiCamXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, gScale);
uiCamXInfo.addGroup(groupUI_Layer3);
uiCamYInfo.addComponent<TransformComponent>(camera.w-48,36,40,12,gScale);
uiCamYInfo.addComponent<TransformComponent>((camera.w-48)*gScale,36*gScale,40,12,gScale);
uiCamYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
uiCamYInfo.addGroup(groupUI_Layer3);
uiPlayerXInfo.addComponent<TransformComponent>(camera.w-48,48,40,12,gScale);
uiPlayerXInfo.addComponent<TransformComponent>((camera.w-48)*gScale,48*gScale,40,12,gScale);
uiPlayerXInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
uiPlayerXInfo.addGroup(groupUI_Layer3);
uiPlayerYInfo.addComponent<TransformComponent>(camera.w-48,60,40,12,gScale);
uiPlayerYInfo.addComponent<TransformComponent>((camera.w-48)*gScale,60*gScale,40,12,gScale);
uiPlayerYInfo.addComponent<UITextComponent>("font", "nan", 8, 12, 1);
uiPlayerYInfo.addGroup(groupUI_Layer3);
@ -216,7 +213,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
//ecs implementation
// player.addComponent<TransformComponent>(860*globalScale,640*globalScale,22,42,globalScale);
player.addComponent<TransformComponent>(150*globalScale,100*globalScale,22,42,globalScale); // 180,120
player.addComponent<TransformComponent>(150,100,22,42,globalScale); // 180,120
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
// player.addComponent<PlayerController>(0.0,0.0,false,false,Vector2D().Zero());
@ -224,6 +221,9 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
player.addComponent<KeyboardController>();
player.addGroup(groupPlayers);
gameScene.addComponent<TileMapComponent>(map,gScale,player.getComponent<TransformComponent>().position.x+player.getComponent<TransformComponent>().width/2,player.getComponent<TransformComponent>().position.y+player.getComponent<TransformComponent>().height/2); //150,100
gameScene.addGroup(groupMap);
playerPosition = Vector2D().Zero();
pVel = Vector2D().Zero();
@ -330,23 +330,25 @@ void Game::update()
uiCamYInfo.getComponent<UITextComponent>().updateString(std::to_string(camera.y));
int playerX = player.getComponent<TransformComponent>().position.x;
int playerY = player.getComponent<TransformComponent>().position.y;
uiPlayerXInfo.getComponent<UITextComponent>().updateString(std::to_string(playerX));
uiPlayerYInfo.getComponent<UITextComponent>().updateString(std::to_string(playerY));
playerPosition.x = playerX;
playerPosition.y = playerY;
pVel.x = player.getComponent<TransformComponent>().velocity.x;
pVel.y = player.getComponent<TransformComponent>().velocity.y;
if(camera.x < 0)
camera.x = 0;
if (camera.y < 0)
camera.y = 0;
if (camera.x > levelMap.w-camera.w)
camera.x = levelMap.w-camera.w;
if (camera.y > levelMap.h-camera.h)
camera.y = levelMap.h-camera.h;
// if(camera.x < 0)
// camera.x = 0;
// if (camera.y < 0)
// camera.y = 0;
// if (camera.x > levelMap.w-camera.w*1.5-player.getComponent<TransformComponent>().width)
// camera.x = levelMap.w-camera.w*1.5-player.getComponent<TransformComponent>().width;
// if (camera.y > levelMap.h-camera.h*1.5-player.getComponent<TransformComponent>().height)
// camera.y = levelMap.h-camera.h*1.5-player.getComponent<TransformComponent>().height;
if (Game::debugCollisionBoxes)
{
for (auto& c: colliders)

View File

@ -45,6 +45,7 @@ public:
static Vector2D playerPosition;
static Vector2D pVel;
static SDL_Rect camera;
static SDL_Rect levelMap;
static AssetManager* assets;
static GameStateManager* gsm;
std::string BoolToString(bool b);