-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameplay.cpp
More file actions
155 lines (121 loc) · 2.71 KB
/
Gameplay.cpp
File metadata and controls
155 lines (121 loc) · 2.71 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include "Gameplay.h"
Gameplay::Gameplay() : Scene(Jeu), player(std::make_shared<Player>()), _cam(), _background(stg::StarAmount, 20, 100)
{
_delay = 3.0f;
_gamePaused = false;
_nbBullets = 0;
_cam.SetTarget({ 0, 0 });
_cam.SetOffset({ stg::screenWidth / 2.0f , stg::screenHeight / 2.0f });
}
void Gameplay::InitObjects()
{
_listSprite.clear();
// Positionnement du joueur
player->Init(stg::screenWidth / 2.0f, stg::screenHeight / 2.0f);
// Ajout des sprites
_listSprite.push_back(player);
}
void Gameplay::Init()
{
// Background
_background.Init();
InitObjects();
}
void Gameplay::Controls()
{
Vec2<float> mousePos;
mousePos = raywrp::GetScreenToWorld2DPoint(raywrp::GetMousePositionV(), _cam);
float rotation = raywrp::Vec2AngleDeg(player->GetPosition(), mousePos);
player->SetRotation(rotation);
if (IsKeyDown(KEY_SPACE))
{
player->Reactor();
}
if (IsMouseButtonDown(0))
{
// Bullet tir = player.Shoot(1);
// _listBullets.push_back(tir);
_nbBullets++;
_listSprite.push_back(player->Shoot(1));
}
else if (IsMouseButtonDown(1))
{
// Bullet tir = player.Shoot(2);
// _listBullets.push_back(tir);
_nbBullets++;
_listSprite.push_back(player->Shoot(2));
}
}
void Gameplay::Collision()
{
}
void Gameplay::ScoringSystem()
{
}
void Gameplay::BulletUpdate()
{
// Bullet update
for (auto it = _listSprite.begin(); it != _listSprite.end();) {
auto sprite = *it;
// Essayez de convertir le pointeur de base en un pointeur de Bullet
if (auto bullet = std::dynamic_pointer_cast<Bullet>(sprite)) {
if (bullet->isEnabled()) {
bullet->Update();
++it;
}
else {
it = _listSprite.erase(it);
_nbBullets--;
}
}
else {
// C'est un sprite qui n'est pas un Bullet, effectuez une mise à jour générique ici si nécessaire
sprite->Update();
++it;
}
}
}
void Gameplay::Update()
{
Controls();
_background.Update(player->GetPosition());
BulletUpdate();
for (auto& sprite : _listSprite)
{
sprite->Update();
}
_cam.SetTarget(player->GetPosition());
Collision();
ScoringSystem();
}
int Gameplay::playerDeath()
{
int death = 0;
return death;
}
Cam2D Gameplay::GetCamera()
{
return _cam;
}
void Gameplay::Draw()
{
DrawFPS(0, 0);
raywrp::BeginDraw2D(_cam);
_background.Draw();
for (auto& sprite : _listSprite)
{
if (sprite->isEnabled() && !sprite->isItThatObject(Joueur))
{
sprite->Draw();
}
}
player->Draw();
std::string text{ "Nombre d'etoiles : " };
text += std::to_string(_background.GetStarAmount());
raywrp::DrawTextV(text, { 100,500 }, 20, VIOLETFONCE);
text = "Nombre de tirs : ";
text += std::to_string(_nbBullets);
raywrp::DrawTextV(text, { 500,500 }, 20, VIOLETFONCE);
raywrp::EndDraw2D();
}