Bonjour � tous, je suis en train de d�velopper un jeu pour mon projet tuteur�, mon probl�me est que je d�fini des variables globales, je les modifies dans une des fonctions et apr�s quand j�essaie d'acc�der depuis une autre fonction je ne peut pas car �a me dit que la variable est ind�finie. Si quelqu'un pourrai m'aider �a serrait g�nial, merci d'avance.

Voici le code:

Code : S�lectionner tout - Visualiser dans une fen�tre � part
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
 
$(document).ready(function(){
//Declarations
var canvas, context, width, height, frames = 0, floor, floor_position, actual_status = "play", character, character_position, game_velocity = 6, jump_force = 20,
maxJump = 1, background, players;
var actionLeft = actionRight = actionJump = action = actionHold = actionBomb = actionEsc = startAction = false;
 
 
//Class floor
class Floor{
	constructor(position_floor, width_floor, height_floor){
		this.position = position_floor;
		this.height = height_floor;
		this.width = width_floor;
		this.color = "#ffdf70";
	}
 
	//Drawing the floor
	draw_floor(){
		context.fillStyle = this.color;
		context.fillRect(this.position.x, this.position.y, this.width, this.height);
	}
 
}
 
//Class position
class Position{
	constructor(x_const, y_const){
		this.x = x_const;
		this.y = y_const;
	}
 
		right(){
			if(this.x < width-50 ){
				this.x += game_velocity;
			} else if (this.x >= width-50 ){
				this.x = width-50;
			}
 
		}
 
		left(){
			if(this.x > 0 ){
				this.x -= game_velocity;
			} else if (this.x <= 0 ){
				this.x = 0;
			}
		}
 
		jump(object){
			if(object.number_of_jump < maxJump){
				object.velocity = -jump_force;
			}
		}
 
	}
 
//Class Player
class Player{
	constructor(id, name, color){
		this.id = id
		this.name = name;
		this.velocity = 0;
		this.width = 50;
		this.height = 50;
		this.gravity = 1;
		this.color = color;
		this.position = new Position(Math.floor(width * Math.random()), Math.floor(height * Math.random()));
		this.number_of_jump = 0;
	}
 
 
	draw_character(){
		// var character_icon = new Image();
		// character_icon.src = "./images/character.png";
		// context.drawImage(character_icon, -this.width/2, -this.height/2);
 
		context.fillStyle = this.color;
		context.fillRect(this.position.x, this.position.y, this.width, this.height);
	};
 
	refresh_character(){
		this.velocity += this.gravity;
		this.position.y += this.velocity;
 
 
		if (this.position.y > (floor.position.y - this.height) && actual_status != "lost"){
			this.position.y = floor.position.y - this.height;
			this.velocity = 0;
			this.number_of_jump = 0;
		}
 
	};
 
}
 
 
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////Starting the Script//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function main(){
	actual_status = "play";
 
	//Getting window information(height and width)
			height = window.innerHeight;
			width = window.innerWidth;
 
	//Creating the canvas
	canvas = document.createElement("canvas");
	canvas.height = height;
	canvas.width = width;
 
	canvas.style.border = "1px solid red";
 
	context = canvas.getContext("2d");
 
	//Adding canvas to html
	document.body.appendChild(canvas);
 
	menu();
 
	floor_position = new Position(0, 550);
	floor = new Floor(floor_position, width, 50);
 
}
 
function menu(){
	console.log(floor);
		drawSun();
 
		start();
}
 
 
main();
 
 
 
function refresh(){
}
 
//Function play is the function wich permit to the game to have an infinite loop
function start(){
	//Permit to request for commands
//	sendAjax();
 
	refresh();
	draw();
 
	window.requestAnimationFrame(start);
}
 
function draw(){
     floor.draw_floor(); //LE BUG EST ICI QUAND J'essaie d'accéder à la fonction draw_floor de mon objet floor ça dit que flor est indéfini
}