Added music and sfx

This commit is contained in:
Alan Youngblood 2021-01-31 16:29:42 -05:00
parent 5d76cfe49c
commit a3c829f7c8
18 changed files with 53 additions and 39 deletions

Binary file not shown.

Binary file not shown.

BIN
assets/audio/sfx/Bark1.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark2.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark3.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark4.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Bark5.wav Normal file

Binary file not shown.

BIN
assets/audio/sfx/Fire.wav Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,39 +34,21 @@ public:
switch (Game::event.key.keysym.sym)
{
case SDLK_UP:
// transform->velocity.y = -1;
// sprite->Play("WalkNorth");
// if (transform->velocity.x < 0)
// {
// sprite->Play("WalkNW");
// }
// if (transform->velocity.x > 0)
// {
// sprite->Play("WalkNW");
// sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
// }
break;
case SDLK_DOWN:
// transform->velocity.y = 1;
// sprite->Play("WalkSouth");
// if (transform->velocity.x < 0)
// {
// sprite->Play("WalkSW");
// }
// if (transform->velocity.x > 0)
// {
// sprite->Play("WalkSW");
// sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
// }
break;
case SDLK_LEFT:
transform->velocity.x = -1;
if(Game::playerIsGrounded){
sprite->Play("Walk");
}
sprite->spriteFlip = SDL_FLIP_NONE;
break;
case SDLK_RIGHT:
transform->velocity.x = 1;
if(Game::playerIsGrounded){
sprite->Play("Walk");
}
sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
break;
case SDLK_k:
@ -103,10 +85,17 @@ public:
case SDLK_LEFT:
transform->velocity.x = 0;
sprite->Play("Idle");
if (!Game::gravityOnPlayer){
Game::gravityOnPlayer = true;
sprite->Play("Fall");
}
break;
case SDLK_RIGHT:
transform->velocity.x = 0;
sprite->Play("Idle");
if (!Game::gravityOnPlayer){
Game::gravityOnPlayer = true;
}
break;
case SDLK_k:
if (Game::debugCollisionBoxes)

View File

@ -41,6 +41,7 @@ bool Game::isRunning = false;
auto& player(manager.addEntity());
// auto& enemy(manager.addEntity());
auto& puppy(manager.addEntity());
// auto& scoreboard(manager.addEntity());
auto& uiInfo(manager.addEntity());
@ -49,8 +50,14 @@ bool Game::debugCollisionBoxes = false;
bool Game::gravityOnPlayer = true;
bool Game::playerIsGrounded = false;
int gScale = 0;
int last_time;
int current_time;
int diff_time;
Game::Game() {
// TODO Auto-generated constructor stub
@ -94,38 +101,49 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError());
}
// current_time = SDL_GetTicks();
assets->AddTexture("terrain", "assets/textures/tiles/br-tiles.png");
assets->AddTexture("player", "assets/textures/actors/firefighter.png");
// assets->AddTexture("player", "assets/textures/actors/owl_anim.png");
assets->AddTexture("font", "assets/textures/ui/ui-font-cloud-sans.png");
assets->AddTexture("textBox", "assets/textures/ui/ui-element-cloud.png");
assets->AddTexture("puppy","assets/textures/actors/beaglepuppy.png");
assets->AddMusicTrack("simonZ","assets/audio/music/sillypuppy.ogg");
assets->AddMusicTrack("simonZ","assets/audio/music/victory.ogg");
assets->AddSoundClip("bwoop","assets/audio/sfx/bwoop.wav");
assets->AddSoundClip("bark1","assets/audio/sfx/Bark1.wav");
assets->AddSoundClip("bark2","assets/audio/sfx/Bark2.wav");
map = new Map("terrain",globalScale,16);
const char* myText = "Beagle Rescue";
const char* myText = "Find lost puppies!";
text = new UIText(myText, "font", 0, 0, 8, 12, globalScale);
text->ParseString(myText, 12, 22, globalScale);
SDL_Rect myDestRect = SDL_Rect();
myDestRect.x = 12;
myDestRect.y = 8;
myDestRect.w = 120;
myDestRect.w = 160;
myDestRect.h = 40;
my9Slice = new UINineSlice("textBox");
my9Slice->MakeSlices("textBox",32,32,14,17,14,17,myDestRect,globalScale);
my9Slice->MakeSlices("textBox",32,32,14,16,14,16,myDestRect,globalScale);
//ecs implementation
map->LoadMap("assets/maps/br-map-color.txt",70,45, globalScale);
player.addComponent<TransformComponent>(150*globalScale,80*globalScale,22,42,globalScale);
player.addComponent<TransformComponent>(860*globalScale,630*globalScale,22,42,globalScale);
// player.addComponent<TransformComponent>(150*globalScale,80*globalScale,40,40,globalScale);
player.addComponent<SpriteComponent>("player", SpriteComponent::spriteAnimation, "assets/textures/actors/firefighter.json");
player.addComponent<KeyboardController>();
player.addComponent<ColliderComponent>("player");
player.addGroup(groupPlayers);
puppy.addComponent<TransformComponent>(1024*globalScale,210*globalScale,36,30,globalScale);
puppy.addComponent<SpriteComponent>("puppy", SpriteComponent::spriteObject);
puppy.addGroup(groupObjects);
// enemy.addComponent<TransformComponent>(180*globalScale,180*globalScale,32,32,globalScale);
// enemy.addComponent<SpriteComponent>("robber", SpriteComponent::spriteAnimation, "assets/textures/actors/robberrodent.json");
// enemy.addGroup(groupEnemies);
@ -141,7 +159,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
auto& tiles(manager.getGroup(Game::groupMap));
auto& players(manager.getGroup(Game::groupPlayers));
auto& colliders(manager.getGroup(Game::groupColliders));
// auto& objects(manager.getGroup(Game::groupObjects));
auto& objects(manager.getGroup(Game::groupObjects));
// auto& enemies(manager.getGroup(Game::groupEnemies));
// auto& projectiles(manager.getGroup(Game::groupProjectiles));
auto& gui(manager.getGroup(Game::groupUI_Layer0));
@ -173,6 +191,11 @@ void Game::update()
Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
}
if (Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0) == 0)
{
Mix_PlayChannel(-1, Game::assets->GetSoundClip("bark1"),0);
}
manager.refresh();
manager.update();
@ -181,15 +204,16 @@ void Game::update()
SDL_Rect cCol = c->getComponent<ColliderComponent>().collider;
if(Collision::AABB(cCol, playerCol))
{
// printf("Collision detected!\n");
// player.getComponent<TransformComponent>().position = playerPos;
gravityOnPlayer = false;
// player.getComponent<SpriteComponent>().Play("Idle");
// printf("Collision detected!\nplayerIsGrounded:%d if 0: idle plays\n",playerIsGrounded);
if(!playerIsGrounded){
player.getComponent<SpriteComponent>().Play("Idle");
}
// while(Collision::AABB(cCol, playerCol))
// {
// gravityOnPlayer = false;
// }
gravityOnPlayer = false;
playerIsGrounded = true;
}
}
// Gravity
@ -235,10 +259,10 @@ void Game::render()
}
}
// for (auto& o : objects)
// {
// o->draw();
// }
for (auto& o : objects)
{
o->draw();
}
//
// for (auto& e : enemies)
// {

View File

@ -38,6 +38,7 @@ public:
static bool isRunning;
static bool debugCollisionBoxes;
static bool gravityOnPlayer;
static bool playerIsGrounded;
static SDL_Rect camera;
static AssetManager* assets;
enum groupLabels : std::size_t