Skip to content

Commit

Permalink
finished homework
Browse files Browse the repository at this point in the history
  • Loading branch information
Adria-F committed Mar 26, 2017
1 parent b6d3e2b commit 3a84ef1
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 19 deletions.
14 changes: 9 additions & 5 deletions SDL5_Handout/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ModuleAudio.h"
#include "ModuleWelcomeTitle.h"
#include "ModuleHighscores.h"
#include "ModuleSelection.h"

Application::Application()
{
Expand All @@ -19,11 +20,13 @@ Application::Application()
modules[3] = textures = new ModuleTextures();
modules[4] = scene_mine = new ModuleSceneMine();
modules[5] = scene_castle = new ModuleSceneCastle();
modules[6] = player = new ModulePlayer();
modules[7] = fade = new ModuleFadeToBlack();
modules[8] = audio = new ModuleAudio();
modules[9] = welcometitle = new ModuleWelcomeTitle();
modules[10] = highscores = new ModuleHighscores();
modules[6] = welcometitle = new ModuleWelcomeTitle();
modules[7] = highscores = new ModuleHighscores();
modules[8] = selection = new ModuleSelection();
modules[9] = player = new ModulePlayer();
modules[10] = fade = new ModuleFadeToBlack();
modules[11] = audio = new ModuleAudio();

}

Application::~Application()
Expand All @@ -42,6 +45,7 @@ bool Application::Init()
scene_castle->Disable();
highscores->Disable();
scene_mine->Disable();
selection->Disable();

for(int i = 0; i < NUM_MODULES && ret == true; ++i)
ret = modules[i]->Init();
Expand Down
4 changes: 3 additions & 1 deletion SDL5_Handout/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "Globals.h"

#define NUM_MODULES 11
#define NUM_MODULES 12

class ModuleWindow;
class ModuleInput;
Expand All @@ -17,6 +17,7 @@ class Module;
class ModuleAudio;
class ModuleWelcomeTitle;
class ModuleHighscores;
class ModuleSelection;

class Application
{
Expand All @@ -34,6 +35,7 @@ class Application
ModuleAudio* audio;
ModuleWelcomeTitle* welcometitle;
ModuleHighscores* highscores;
ModuleSelection* selection;

public:

Expand Down
Binary file added SDL5_Handout/Game/assets/maps/selection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added SDL5_Handout/Game/assets/music/insert_coin.ogg
Binary file not shown.
4 changes: 2 additions & 2 deletions SDL5_Handout/ModuleAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ bool ModuleAudio::Init()
return true;
}

void ModuleAudio::Play()
void ModuleAudio::Play(int loop)
{
Mix_PlayMusic(music, -1);
Mix_PlayMusic(music, loop);
}

void ModuleAudio::Stop()
Expand Down
4 changes: 3 additions & 1 deletion SDL5_Handout/ModuleAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

class ModuleAudio : public Module
{

public:
ModuleAudio();
virtual ~ModuleAudio();

bool Load(const char* path);
void Play();
void Play(int loop);
void Stop();

bool Init();
bool CleanUp();

public:
Mix_Music* music = nullptr;
};
Expand Down
5 changes: 2 additions & 3 deletions SDL5_Handout/ModuleHighscores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ bool ModuleHighscores::Start()
bool ret = true;
graphics = App->textures->Load("assets/maps/highscore_nameregist.png");

LOG("Loading music")
LOG("Loading music");
App->audio->Load("assets/music/highscore.ogg");
App->audio->Play();
App->audio->Play(-1);
// TODO 1: Enable (and properly disable) the player module
App->player->Enable(); //Player in highscores?
fading = false;

return true;
Expand Down
10 changes: 10 additions & 0 deletions SDL5_Handout/ModuleInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "Application.h"
#include "ModuleInput.h"
#include "SDL/include/SDL.h"
#include "ModuleAudio.h"
#include "ModuleFadeToBlack.h"

ModuleInput::ModuleInput() : Module()
{
Expand Down Expand Up @@ -36,6 +38,14 @@ update_status ModuleInput::PreUpdate()

if(keyboard[SDL_SCANCODE_ESCAPE])
return update_status::UPDATE_STOP;
if (keyboard[SDL_SCANCODE_SPACE])
{
if (App->fade->GetFadeState() == false)
{
App->audio->Load("assets/music/insert_coin.ogg");
App->audio->Play(1);
}
}

return update_status::UPDATE_CONTINUE;
}
Expand Down
1 change: 1 addition & 0 deletions SDL5_Handout/ModuleInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Module.h"
#include "Globals.h"
#include "ModuleAudio.h"
#include "SDL\include\SDL_scancode.h"

typedef unsigned char Uint8;
Expand Down
3 changes: 2 additions & 1 deletion SDL5_Handout/ModuleSceneCastle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ bool ModuleSceneCastle::Start()
LOG("Loading castle scene");

graphics = App->textures->Load("assets/maps/castle_background.png");

App->audio->Load("assets/music/castle-welcome_title.ogg");
App->audio->Play();
App->audio->Play(-1);
// TODO 1: Enable (and properly disable) the player module
App->player->Enable();
fading = false;
Expand Down
2 changes: 1 addition & 1 deletion SDL5_Handout/ModuleSceneMine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool ModuleSceneMine::Start()

LOG("Loading music");
App->audio->Load("assets/music/mine.ogg");
App->audio->Play();
App->audio->Play(-1);
// TODO 1: Enable (and properly disable) the player module
App->player->Enable();
fading = false;
Expand Down
67 changes: 67 additions & 0 deletions SDL5_Handout/ModuleSelection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "Globals.h"
#include "Application.h"
#include "ModuleTextures.h"
#include "ModuleRender.h"
#include "ModuleWelcomeTitle.h"
#include "ModulePlayer.h"
#include "ModuleSceneMine.h"
#include "ModuleInput.h"
#include "ModuleFadeToBlack.h"
#include "ModuleAudio.h"
#include "ModuleSelection.h"

ModuleSelection::ModuleSelection()
{
// Background
background.w = SCREEN_WIDTH;
background.h = SCREEN_HEIGHT;
background_x = 0;
background_y = 0;
}

ModuleSelection::~ModuleSelection()
{}

// Load assets
bool ModuleSelection::Start()
{
LOG("Loading WelcomeTitle scene");
bool ret = true;
graphics = App->textures->Load("assets/maps/selection.png");

LOG("Loading music");
App->audio->Load("assets/music/castle-welcome_title.ogg");
App->audio->Play(-1);
// TODO 1: Enable (and properly disable) the player module
App->player->Enable(); //Player in welcome title?
fading = false;

return ret;
}

// UnLoad assets
bool ModuleSelection::CleanUp()
{
LOG("Unloading selection scene");
App->audio->Stop();
App->player->Disable();

return true;
}

// Update: draw background

update_status ModuleSelection::Update()
{
// Draw everything --------------------------------------

App->render->Blit(graphics, background_x, background_y, &background, 0.75f); // Selection Screen


if (App->input->keyboard[SDL_SCANCODE_SPACE] && fading == false && App->fade->GetFadeState() == false)
{
App->fade->FadeToBlack(this, App->scene_mine);
fading = true;
}
return UPDATE_CONTINUE;
}
29 changes: 29 additions & 0 deletions SDL5_Handout/ModuleSelection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef __MODULESELECTION_H__
#define __MODULESELECTION_H__

#include "Module.h"
#include "Animation.h"
#include "Globals.h"

struct SDL_Texture;

class ModuleSelection : public Module
{
public:
ModuleSelection();
~ModuleSelection();

bool Start();
update_status Update();
bool CleanUp();

public:

SDL_Texture* graphics = nullptr;
SDL_Rect background;
bool fading;
int background_x;
int background_y;
};

#endif // __MODULESELECTION_H__
9 changes: 4 additions & 5 deletions SDL5_Handout/ModuleWelcomeTitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ModuleRender.h"
#include "ModuleWelcomeTitle.h"
#include "ModulePlayer.h"
#include "ModuleSceneMine.h"
#include "ModuleSelection.h"
#include "ModuleInput.h"
#include "ModuleFadeToBlack.h"
#include "ModuleAudio.h"
Expand All @@ -30,11 +30,10 @@ bool ModuleWelcomeTitle::Start()
bool ret = true;
graphics = App->textures->Load("assets/maps/credit-insert_welcome-page.png");

LOG("Loading music")
LOG("Loading music");
App->audio->Load("assets/music/castle-welcome_title.ogg");
App->audio->Play();
App->audio->Play(-1);
// TODO 1: Enable (and properly disable) the player module
App->player->Enable(); //Player in welcome title?
fading = false;

return ret;
Expand All @@ -61,7 +60,7 @@ update_status ModuleWelcomeTitle::Update()
// TODO 3: make so pressing SPACE the HONDA stage is loaded
if (App->input->keyboard[SDL_SCANCODE_SPACE] && fading == false && App->fade->GetFadeState() == false)
{
App->fade->FadeToBlack(this, App->scene_mine);
App->fade->FadeToBlack(this, App->selection);
fading = true;
}
return UPDATE_CONTINUE;
Expand Down
2 changes: 2 additions & 0 deletions SDL5_Handout/SDL Game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<ClInclude Include="ModuleRender.h" />
<ClInclude Include="ModuleSceneMine.h" />
<ClInclude Include="ModuleSceneCastle.h" />
<ClInclude Include="ModuleSelection.h" />
<ClInclude Include="ModuleTextures.h" />
<ClInclude Include="ModuleWelcomeTitle.h" />
<ClInclude Include="ModuleWindow.h" />
Expand All @@ -99,6 +100,7 @@
<ClCompile Include="ModuleRender.cpp" />
<ClCompile Include="ModuleSceneMine.cpp" />
<ClCompile Include="ModuleSceneCastle.cpp" />
<ClCompile Include="ModuleSelection.cpp" />
<ClCompile Include="ModuleTextures.cpp" />
<ClCompile Include="ModuleWelcomeTitle.cpp" />
<ClCompile Include="ModuleWindow.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions SDL5_Handout/SDL Game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<ClInclude Include="ModuleHighscores.h">
<Filter>Modules</Filter>
</ClInclude>
<ClInclude Include="ModuleSelection.h">
<Filter>Modules</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
Expand Down Expand Up @@ -109,5 +112,8 @@
<ClCompile Include="ModuleHighscores.cpp">
<Filter>Modules</Filter>
</ClCompile>
<ClCompile Include="ModuleSelection.cpp">
<Filter>Modules</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit 3a84ef1

Please sign in to comment.