-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModuleSceneLevel.cpp
132 lines (120 loc) · 2.87 KB
/
ModuleSceneLevel.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "Application.h"
#include "ModuleSceneLevel.h"
#include "ModulePlayer.h"
#include "ModuleUI.h"
#include "ModuleFadeToBlack.h"
#include "ModuleSceneHighscore.h"
#include "ModuleAudio.h"
#include "Road.h"
using namespace std;
ModuleSceneLevel::ModuleSceneLevel(bool active) : Module(active)
{
}
ModuleSceneLevel::~ModuleSceneLevel()
{}
// Load assets
bool ModuleSceneLevel::Start()
{
road = new Road();
actualState = COUNTDOWN;
countdownTimer = 5.f;
gameoverTimer = 5.f;
semaphorOne = semaphorTwo = semaphorThree = false;
tick_timer = clock();
App->player->Enable();
App->ui->Enable();
road->Start();
road->InitRoad();
if (App->musicLevel != "")
App->audio->PlayMusic(App->musicLevel, 0.f);
semaphorSignal1 = App->audio->LoadFx("Audio/semaphorOne.wav");
semaphorSignal2 = App->audio->LoadFx("Audio/semaphorTwo.wav");
return true;
}
// UnLoad assets
bool ModuleSceneLevel::CleanUp()
{
App->player->Disable();
App->ui->Disable();
road->CleanUp();
RELEASE(road);
return true;
}
// Update: draw background
update_status ModuleSceneLevel::Update()
{
time = (float)((clock() - tick_timer) / (double)CLOCKS_PER_SEC);
tick_timer = clock();
switch (actualState)
{
case COUNTDOWN:
if (countdownTimer < 4.0f)
App->player->preparingAnim.speed = 0.1f;
if (countdownTimer < 2.0f)
road->ActivateAnims();
if (countdownTimer < 2.f && semaphorOne == false)
{
semaphorOne = true;
App->audio->PlayFx(semaphorSignal1);
}
if (countdownTimer < 1.f && semaphorTwo == false)
{
semaphorTwo = true;
App->audio->PlayFx(semaphorSignal1);
}
if (countdownTimer < 0.1f && semaphorThree == false)
{
semaphorThree = true;
App->audio->PlayFx(semaphorSignal2);
}
countdownTimer -= time;
if (countdownTimer < 0)
{
actualState = RUNNING;
App->player->playerState = ONROAD;
App->ui->uiState = UIPlay;
}
road->DrawRoad();
break;
case RUNNING:
road->UpdateRoad(time);
road->DrawRoad();
if (road->ending)
{
actualState = FINISH;
App->ui->uiState = UIFinish;
}
if (App->ui->timeLeft < 0.f)
{
App->audio->StopFx();
actualState = GAMEOVER;
App->ui->uiState = UIGameOver;
App->player->playerState = PlayerGAMEOVER;
}
break;
case GAMEOVER:
road->DrawRoad();
gameoverTimer -= time;
if (gameoverTimer < 0.f && App->fade->isFading() == false)
{
App->audio->StopMusic(0.f);
App->score = App->player->score;
App->totalTime = App->ui->totalTime + App->ui->lapTime;
App->fade->FadeToBlack(App->highscore, this, 0.f);
}
break;
case FINISH:
road->UpdateRoadEnding(time);
road->DrawRoad();
if (App->player->endSequence.Finished() && App->fade->isFading() == false)
{
App->audio->StopFx();
App->audio->StopMusic(0.f);
App->score = App->player->score;
App->totalTime = App->ui->totalTime + App->ui->lapTime;
App->fade->FadeToBlack(App->highscore, this, 0.f);
}
break;
}
return UPDATE_CONTINUE;
}