-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinish.cpp
More file actions
57 lines (49 loc) · 1.87 KB
/
Finish.cpp
File metadata and controls
57 lines (49 loc) · 1.87 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
#include "Finish.h"
#include "LevelManager.h"
#include <iostream>
namespace Tmpl8
{
// Constructor //
Finish::Finish()
:flag(new Surface("assets/Objects/flag.png"), 9)
{}
// Draw function
void Finish::Draw(Surface* screen, const int tilex, const int tiley, const Location& drawOffset)
{
flag.Draw(screen, tilex * LevelManager::tileSize - static_cast<int>(drawOffset.x),
tiley * LevelManager::tileSize - static_cast<int>(drawOffset.y));
}
// Function that checks more precise collision & then calls level complete if there is collision.
void Finish::Trigger(MenuManager& menu, LevelManager& level, Player& player, const Location& tileLoc)
{
// Get/Set location of finish hitbox.
Location topLeft = { 0.0f, 0.0f };
Location bottomRight = { 0.0f, 0.0f };
bottomRight.x = tileLoc.x - 27 + static_cast<float>(level.tileSize) / 2;
bottomRight.y = tileLoc.y + static_cast<float>(level.tileSize) / 2;
topLeft.x = tileLoc.x + 9 - static_cast<float>(level.tileSize) / 2;
topLeft.y = tileLoc.y + 15 - static_cast<float>(level.tileSize) / 2;
// Check collision & call functions.
if (player.CheckCollision(topLeft, bottomRight))
{
level.SetLevelState(level.GetCurrentLevel(), LevelManager::LevelState::Completed);
level.SetLevelState(level.GetCurrentLevel() + 1, LevelManager::LevelState::Open);
menu.SetMenuState(MenuManager::MenuState::LevelComplete);
std::cout << "Finish triggered!" << std::endl;
}
}
// Function that updates the animation frame
void Finish::UpdateFrame(const float& deltaTime)
{
timer -= deltaTime;
if (timer < 0) {
timer += frameTime;
if (++frame > 8) { frame = 0; }
flag.SetFrame(frame);
}
/* ======================== DEBUG ======================== */
//std::cout << "Frame: " << frame << std::endl;
//std::cout << "FrameTimer: " << timer << std::endl;
/* ======================================================= */
}
};