a,d keys implemented and screen for 1080p

This commit is contained in:
Alan Youngblood 2021-12-30 13:42:55 -05:00
parent b9e9c04235
commit af393e8acb
7 changed files with 83 additions and 11 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
{ {
"GameName":"Beagle Rescue", "GameName":"Beagle Rescue",
"WindowName":"Beagle Rescue", "WindowName":"Beagle Rescue",
"WindowSize":{"w":320,"h":240}, "WindowSize":{"w":640,"h":360},
"WindowFullScreen": 0, "WindowFullScreen": 0,
"GlobalScale": 1 "GlobalScale": 3
} }

View File

@ -78,6 +78,24 @@ public:
sprite->spriteFlip = SDL_FLIP_HORIZONTAL; sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
} }
break; break;
case SDLK_a:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = -1;
if(Game::playerIsGrounded){
sprite->Play("Walk");
}
sprite->spriteFlip = SDL_FLIP_NONE;
}
break;
case SDLK_d:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = 1;
if(Game::playerIsGrounded){
sprite->Play("Walk");
}
sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
}
break;
case SDLK_k: case SDLK_k:
if (!Game::debugCollisionBoxes) if (!Game::debugCollisionBoxes)
{ Game::debugCollisionBoxes = true; } { Game::debugCollisionBoxes = true; }
@ -129,7 +147,26 @@ public:
} }
} }
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = 0;
sprite->Play("Idle");
if (!Game::gravityOnPlayer){
Game::gravityOnPlayer = true;
}
}
break;
case SDLK_a:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = 0;
sprite->Play("Idle");
if (!Game::gravityOnPlayer){
Game::gravityOnPlayer = true;
// sprite->Play("Fall");
}
}
break;
case SDLK_d:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){ if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
transform->velocity.x = 0; transform->velocity.x = 0;
sprite->Play("Idle"); sprite->Play("Idle");
@ -151,13 +188,13 @@ public:
break; break;
case SDLK_i: case SDLK_i:
break; break;
case SDLK_d: // case SDLK_d:
if (Game::debugMenu == false){ // if (Game::debugMenu == false){
Game::debugMenu = true;} // Game::debugMenu = true;}
else { // else {
Game::debugMenu = false; // Game::debugMenu = false;
} // }
break; // break;
case SDLK_ESCAPE: // exit the game when Escape pressed case SDLK_ESCAPE: // exit the game when Escape pressed
Game::isRunning = false; Game::isRunning = false;
break; break;

View File

@ -31,6 +31,7 @@ UINineSlice* scoreboard9Slice;
UINineSlice* debugBox; UINineSlice* debugBox;
UIText* debugStaticText; UIText* debugStaticText;
UIText* debugdynamicText; UIText* debugdynamicText;
UIText* debugJumpText;
GameStateManager* Game::gsm = new GameStateManager(); GameStateManager* Game::gsm = new GameStateManager();
@ -64,6 +65,16 @@ int last_time;
int current_time; int current_time;
int diff_time; int diff_time;
std::string Game::BoolToString(bool b) {
std::string myString;
if (b) {
myString = "true";
} else {
myString = "false";
}
return myString;
}
Game::Game() { Game::Game() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
@ -147,6 +158,8 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
UIText* debugStaticText5; UIText* debugStaticText5;
UIText* debugStaticText6; UIText* debugStaticText6;
UIText* debugStaticText7; UIText* debugStaticText7;
std::string debugStaticString = "Collision"; std::string debugStaticString = "Collision";
debugStaticText = new UIText(debugStaticString, "font", 0,0,8,12,1); debugStaticText = new UIText(debugStaticString, "font", 0,0,8,12,1);
debugStaticText->ParseString(debugStaticString,220*globalScale,14*gScale,1,"debug",Game::groupUI_Layer3); debugStaticText->ParseString(debugStaticString,220*globalScale,14*gScale,1,"debug",Game::groupUI_Layer3);
@ -169,6 +182,9 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
debugStaticText7 = new UIText(debugStaticString7, "font", 0,0,8,12,1); debugStaticText7 = new UIText(debugStaticString7, "font", 0,0,8,12,1);
debugStaticText7->ParseString(debugStaticString7,220*globalScale,74*gScale,1,"debug",Game::groupUI_Layer3); debugStaticText7->ParseString(debugStaticString7,220*globalScale,74*gScale,1,"debug",Game::groupUI_Layer3);
debugJumpText = new UIText(Game::BoolToString(playerIsJumping), "font", 0,0,8,12,1);
debugJumpText->ParseString(Game::BoolToString(playerIsJumping),260*globalScale,44*gScale,1,"debugJumpText",Game::groupUI_Layer3);
// debug UI box // debug UI box
SDL_Rect debugBoxRect = SDL_Rect(); SDL_Rect debugBoxRect = SDL_Rect();
debugBoxRect.x = 220*globalScale; debugBoxRect.x = 220*globalScale;
@ -259,6 +275,15 @@ void Game::update()
// Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0); // Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0);
// } // }
// for (auto& letter : debugText)
// {
// if(letter->tag=="debugJumpText"){
// std::cout<<letter->tag<<std::endl;
// }
// }
// debugJumpText->ParseString(Game::BoolToString(playerIsJumping),260*gScale,44*gScale,1,"debugJumpText",Game::groupUI_Layer3);
manager.refresh(); manager.refresh();
manager.update(); manager.update();
@ -407,3 +432,4 @@ void Game::drawLine(Vector2D srcpt, Vector2D destpt, int red, int green, int blu
SDL_SetRenderDrawColor(renderer, red, green, blue, 255); SDL_SetRenderDrawColor(renderer, red, green, blue, 255);
SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y); SDL_RenderDrawLine(renderer, srcpt.x, srcpt.y, destpt.x, destpt.y);
} }

View File

@ -45,6 +45,7 @@ public:
static SDL_Rect camera; static SDL_Rect camera;
static AssetManager* assets; static AssetManager* assets;
static GameStateManager* gsm; static GameStateManager* gsm;
std::string BoolToString(bool b);
enum groupLabels : std::size_t enum groupLabels : std::size_t
{ {
groupMap, groupMap,

View File

@ -65,3 +65,9 @@ void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrS
letter.setTag(tag); letter.setTag(tag);
letter.addGroup(groupLabel); letter.addGroup(groupLabel);
} }
void UIText::RemoveAllLetters()
{
manager.getEntitiesByTag("");
}

View File

@ -26,6 +26,8 @@ public:
void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale, Game::groupLabels groupLabel); void AddLetter(int xpos, int ypos, char crnt, std::string tag, int lttrScale, Game::groupLabels groupLabel);
void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag, Game::groupLabels group); void ParseString(std::string inputText, int x, int y, int letterScale, std::string tag, Game::groupLabels group);
void RemoveAllLetters();
void UpdateString(std::string newInputText);
int scale; int scale;
}; };