forked from shubhamwhj/Demo-racing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
89 lines (77 loc) · 1.91 KB
/
sketch.js
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
var canvas, backgroundImage;
var gameState = 0,finishedPlayers;
var playerCount;
var allPlayers;
var distance = 0;
var database;
var passedFinish;
var obstacles;
var s,i;
var form, player, game;
var cars, car1, car2, car3, car4;
var track, car1_img, car2_img, car3_img, car4_img;
function preload(){
s=loadSound("sound/sliding.mp3")
f2 = loadImage("images/f1.png");
track = loadImage("images/track.jpg");
car1_img = loadImage("images/car1.png");
car2_img = loadImage("images/car2.png");
car3_img = loadImage("images/car3.png");
car4_img = loadImage("images/car4.png");
ground = loadImage("images/ground.png");
bronze_img = loadImage("images/bronze.png");
silver_img = loadImage("images/silver.png");
gold_img = loadImage("images/gold.png");
}
function setup(){
canvas = createCanvas(displayWidth , displayHeight);
database = firebase.database();
gameState = 0;
distance = 0;
finishedPlayers = 0;
yVel = 0;
xVel = 0;
obstacles=createGroup();
xSet = false;
game = new Game();
game.getState();
game.start();
for(i=0;i<5;i++)
{
w=random(200,950);
h=random(-height*4,height-300);
f1 = createSprite(w,h);
//car1.debug="true";
f1.addImage("f1",f2);
obstacles.add(f1);
}
}
function draw(){
//start the game
background(200, 200, 255);
//start the game
//start the game
if (playerCount === 4 && finishedPlayers === 0) {
game.update(1);
}
//start the game for real
if (gameState === 1) {
game.play();
}
//end the game
if (finishedPlayers === 4) {
game.update(2);
//gameState = 2;
}
//display ranking
if (gameState === 2 && finishedPlayers === 4) {
game.displayRanks();
}
}
function keyPressed() {
if (keyCode === 13 && gameState !== 1 && passedFinish === false) {
form.enter();
console.log("hai");
passedFinish = true;
}
}