-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleLevelOne.cpp
More file actions
113 lines (89 loc) · 5.41 KB
/
ModuleLevelOne.cpp
File metadata and controls
113 lines (89 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "ModuleLevelOne.h"
#include "Game.h"
#include "ModuleAudio.h"
#include "ModuleTextures.h"
#include "ModuleParticles.h"
#include "ModuleCollisions.h"
#include "ModulePlayer.h"
#include "ModuleEnemies.h"
#include "ModuleFonts.h"
#include "ModuleRender.h"
#include "ModuleTileset.h"
#include "ModuleWinScreen.h"
#include <stdio.h>
ModuleLevelOne::ModuleLevelOne(bool startEnabled) : Module(startEnabled) {
// Background
backgroundAdapter = { 0, 0, 384, 208 };
}
ModuleLevelOne::~ModuleLevelOne() {}
// Load assets
bool ModuleLevelOne::Start() {
LOG("Loading background assets");
once = true;
hasStarted = false;
game->GetModuleWinScreen()->SetCurrentLevel(1);
game->GetModuleParticles()->Enable();
for (int i = 0; i < 9; i++) {
game->GetModuleParticles()->AddParticle(game->GetModuleParticles()->ready, (backgroundAdapter.w / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().w / 2), (backgroundAdapter.h / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().h / 2), Collider::TYPE::NONE, i * 5);
}
game->GetModuleParticles()->AddParticle(game->GetModuleParticles()->ready, (backgroundAdapter.w / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().w / 2), (backgroundAdapter.h / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().h / 2), Collider::TYPE::NONE, 50);
game->GetModuleParticles()->AddParticle(game->GetModuleParticles()->ready, (backgroundAdapter.w / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().w / 2), (backgroundAdapter.h / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().h / 2), Collider::TYPE::NONE, 60);
p = game->GetModuleParticles()->AddParticle(game->GetModuleParticles()->ready, (backgroundAdapter.w / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().w / 2), (backgroundAdapter.h / 2) - (game->GetModuleParticles()->ready.GetCurrentAnim().h / 2), Collider::TYPE::NONE, 70);
backgroundTexture = game->GetModuleTextures()->Load("Resources/Sprites/Backgrounds/Background1.png");
// Colliders ---
//game->GetModuleCollisions()->AddCollider({ 0, backgroundAdapter.h-TILE_SIZE, backgroundAdapter.w, TILE_SIZE }, Collider::TYPE::FLOOR); // {0,186,384,7} BOTTOM
//game->GetModuleCollisions()->AddCollider({0, 0, TILE_SIZE , backgroundAdapter.h }, Collider::TYPE::WALL); // {0,0,8,193} LEFT
game->GetModuleCollisions()->AddCollider({ 0, 0, backgroundAdapter.w, TILE_SIZE }, Collider::TYPE::FLOOR); // {0,0,384,7} TOP
//game->GetModuleCollisions()->AddCollider({ backgroundAdapter.w-TILE_SIZE, 0, TILE_SIZE, backgroundAdapter.h }, Collider::TYPE::WALL); // {376,0,8,193} RIGHT
game->GetModuleEnemies()->AddEnemy(ENEMY_TYPE::CHUNGUS_BALLOON, 32, 24, true);
game->GetModulePlayer()->Enable();
game->GetModuleEnemies()->Enable();
game->GetModuleCollisions()->Enable();
game->GetModuleTileset()->Enable();
return true;
}
UPDATE_STATUS ModuleLevelOne::Update() {
if (p->GetFrameCount() >= 5) { SetIfStarted(true); }
if (hasStarted) {
if (once) {
once = false;
game->GetModuleAudio()->PlayMusicOnce("Resources/BGM/introFuji.ogg");
}
if (game->GetModulePlayer()->GetPlayerLives() >= 0 && game->GetModulePlayer()->GetTimer() >= 50) { game->GetModuleAudio()->ChangeAtEnd("Resources/BGM/fuji.ogg"); }
}
return UPDATE_STATUS::UPDATE_CONTINUE;
}
// Update: draw background
UPDATE_STATUS ModuleLevelOne::PostUpdate() {
// Draw everything --------------------------------------
sprintf_s(levelTitle, 10, "mt.fuji");
game->GetModuleFonts()->BlitText(TILE_SIZE * 20, backgroundAdapter.h, game->GetModulePlayer()->GetFontIndex(), levelTitle);
sprintf_s(stageText, 10, "1-1 stage");
game->GetModuleFonts()->BlitText(TILE_SIZE * 20, backgroundAdapter.h + (TILE_SIZE * 2), game->GetModulePlayer()->GetFontIndex(), stageText);
sprintf_s(highScore, 15, "hi: 100000");
game->GetModuleFonts()->BlitText(TILE_SIZE * 19, backgroundAdapter.h + (TILE_SIZE * 3), game->GetModulePlayer()->GetFontIndex(), highScore);
game->GetModuleRender()->Blit(backgroundTexture, 0, 0, GetInvertValue(), NULL);
return UPDATE_STATUS::UPDATE_CONTINUE;
}
bool ModuleLevelOne::CleanUp() {
game->GetModuleTextures()->Unload(backgroundTexture);
game->GetModuleTextures()->Unload(game->GetModulePlayer()->GetTexture());
game->GetModuleTextures()->Unload(game->GetModulePlayer()->GetBlueTextTexture());
game->GetModuleTextures()->Unload(game->GetModulePlayer()->GetPowerIconTexture());
game->GetModuleFonts()->Unload(game->GetModulePlayer()->GetFontIndex());
game->GetModuleFonts()->Unload(game->GetModulePlayer()->GetTimerFontIndex());
game->GetModuleAudio()->UnloadFx(game->GetModulePlayer()->GetNormalShotSoundIndex());
game->GetModuleAudio()->UnloadFx(game->GetModulePlayer()->GetVulcanShotSoundIndex());
game->GetModuleAudio()->UnloadFx(game->GetModulePlayer()->GetDedSoundIndex());
game->GetModuleAudio()->PlayMusicOnce("Resources/BGM/noMusic.ogg");
game->GetModulePlayer()->Disable();
game->GetModuleEnemies()->Disable();
game->GetModuleParticles()->Disable();
game->GetModuleCollisions()->Disable();
game->GetModuleTileset()->Disable();
hasStarted = false;
return true;
}
bool ModuleLevelOne::CheckIfStarted() const { return hasStarted; }
void ModuleLevelOne::SetIfStarted(bool _hasStarted) { hasStarted = _hasStarted; }
SDL_Rect ModuleLevelOne::GetBackgroundAdapter() const { return backgroundAdapter; }