-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mario_Kart_du_Bled.cs
193 lines (165 loc) · 4.7 KB
/
Mario_Kart_du_Bled.cs
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using Godot;
using System;
public class Mario_Kart_du_Bled : Node2D
{
public float time = 0F;
public float best_time = 999F;
public int nb_checkpoint_passed = 0;
public int nb_mur_cogne = 0;
public bool[] all_passed = {false, false, false, false};
public float ticZoneLente;
public float nbZoneLente = 0F;
// Called when the node enters the scene tree for the first time.
public override void _Ready(){}
public float getTime(){
return time;
}
public float getNbZoneLente(){
return nbZoneLente;
}
public void setNbZoneLente(float t){
nbZoneLente = t;
}
public void setTime(float t)
{
time = t;
}
public void setAll_Passed(bool[] tab){
all_passed = tab;
}
public int getNbCheckpoints(){
return nb_checkpoint_passed;
}
public void setNbCheckpoints(int c){
nb_checkpoint_passed = c;
}
public void setTextPopulation(int num){
var msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("population");
msg.Text = "Population : "+num;
msg.Show();
}
public void setTextIndividu(int num){
var msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("individu");
msg.Text = "Individu : "+num;
msg.Show();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
// Each checkpoint (Area2D objects) must be passed trought at least once before the finish line allow the best time to be displayed
public override void _Process(float delta)
{
time+=delta;
var msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("time");
msg.Text = "TIME : "+time;
msg.Show();
if(!all_passed[0] && !all_passed[1] && !all_passed[2] && !all_passed[3]){
var msg2 = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg2.Text = "CHECKPOINT PASSED : "+nb_checkpoint_passed;
msg2.Show();
}
}
public void _on_checkpoint1_body_entered(Node2D body)
{
if(body.Name == "player"){
if(all_passed[0] == false){
all_passed[0] = true;
nb_checkpoint_passed++;
var msg2 = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg2.Text = "CHECKPOINT PASSED :"+nb_checkpoint_passed;
msg2.Show();
}
}
}
public void _on_checkpoint2_body_entered(Node2D body)
{
if(body.Name == "player"){
if(all_passed[1] == false){
all_passed[1] = true;
nb_checkpoint_passed++;
var msg2 = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg2.Text = "CHECKPOINT PASSED :"+nb_checkpoint_passed;
msg2.Show();
}
}
}
public void _on_checkpoint3_body_entered(Node2D body)
{
if(body.Name == "player"){
if(all_passed[2] == false){
all_passed[2] = true;
nb_checkpoint_passed++;
var msg2 = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg2.Text = "CHECKPOINT PASSED :"+nb_checkpoint_passed;
msg2.Show();
}
}
}
public void _on_checkpoint4_body_entered(Node2D body)
{
if(body.Name == "player"){
if(all_passed[3] == false){
all_passed[3] = true;
nb_checkpoint_passed++;
var msg2 = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg2.Text = "CHECKPOINT PASSED :"+nb_checkpoint_passed;
msg2.Show();
}
}
}
// the finish line displays the best time on the car entering it's collider, ony if the lap was done "correctly".
// it also reinitialize the timer and allows to run another lap by reinitializing the all_passed array.
public void _on_finish_line_body_entered(Node2D body)
{
if(body.Name == "player"){
if((all_passed[0] && all_passed[1] && all_passed[2] && all_passed[3])){
if(time < best_time){
best_time = time;
}
time = 0F;
var msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("time");
msg.Text = "TIME :"+time;
msg.Show();
msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("best");
msg.Text = "BEST :"+best_time;
msg.Show();
nb_checkpoint_passed = 0;
msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg.Text = "CHECKPOINT PASSED :"+nb_checkpoint_passed;
msg.Show();
for(int i = 0; i<4; i++){
all_passed[i] = false;
}
}
}
}
// Changement vélocité Zone Lente
public void _on_ZoneLente_body_entered(player body)
{
if(body.Name == "player"){
ticZoneLente = time;
body.VelocityZL();
}
}
public void _on_ZoneLente_body_exited(player body)
{
if(body.Name == "player"){
nbZoneLente += time - ticZoneLente;
body.VelocityInit();
nbZoneLente++;
}
}
// Pour remettre "tout" à zéro avec un nouvel individu :
public void resetAll(){
time = 0F;
nbZoneLente = 0F;
var msg = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("time");
msg.Text = "TIME :"+time;
msg.Show();
for(int i = 0; i<all_passed.Length; i++){
all_passed[i] = false;
}
nb_checkpoint_passed = 0;
var msg2 = (GetNode<CanvasLayer>("HUD")).GetNode<Label>("nbcp");
msg2.Text = "CHECKPOINT PASSED :"+nb_checkpoint_passed;
msg2.Show();
}
}