-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncoes.js
135 lines (121 loc) · 3.13 KB
/
funcoes.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
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
//anythings cars's variables
let speedCar = [7,5,6,4,8,5];
let lengthCars = 50;
let heightCars = 40;
let level3 = false;
//posiction actors
let xCar = [600,400,150,0,227,500];
let yCar = [40,95,150,210,260,320];
let yCow = 368;
let xCow = 100;
let widthCow = 30;
let heightCow = widthCow;
let initialPositionCow = 368;
let cowOnScreen = true;
let speedCow = 3;
function showCow(){
image(cow, xCow, yCow, heightCow, widthCow);
}
function showCars(){
for(let i = 0; i < cars.length ; i++){
image(car1, xCar[0], yCar[0], lengthCars, heightCars);
image(car2, xCar[1], yCar[1], lengthCars, heightCars);
image(car3, xCar[2], yCar[2], lengthCars, heightCars);
image(car4, xCar[3], yCar[3], lengthCars, heightCars);
image(car5, xCar[4], yCar[4], lengthCars, heightCars);
image(car6, xCar[5], yCar[5], lengthCars, heightCars);
}
}
function moveCars(){
for(let i = 0; i < cars.length ; i++){ //movement of cars
xCar[i] -= speedCar[i];
}
if(level3 == true){
for(let i = -1; i < cars.length; i = i + 2){
xCar[i] += (speedCar[i]*2)// if it was *1 the movement would be canceled
}
}
}
function repositionCars(){
for(let i = 0; i < cars.length ; i++){//movement of cars in loop
if(xCar[i] < -lengthCars){
xCar[i] = width;
}
}
if(level3 == true){
for(let i = -1; i < cars.length; i = i + 2){
if(xCar[i] > width + lengthCars){ // the contrary repositioning of the cars
xCar[i] = -lengthCars;//so the car doesn't come out of nowhere
}
}
}
}
function moveCow(){
if (keyIsDown(UP_ARROW)){
yCow -= speedCow;
}
if (keyIsDown(DOWN_ARROW)){
if(yCow > 360){
yCow = 368//The use this function is only for down because if the cow will go for up, the player win one point
}
yCow += speedCow;
}
if(level3 == true){
if (keyIsDown(RIGHT_ARROW)){
xCow += speedCow;
if(xCow + widthCow > 600){
xCow = 570
}
}
if (keyIsDown(LEFT_ARROW)){
xCow -= speedCow;
if(xCow < 0){
xCow = 0;
}
}
}
}
function punctuation(){
text(score, 50, 26);
textSize(25);
fill(255);
if(yCow < 0){
score += 1;
yCow = initialPositionCow;
dotSound.play();
}
if(score < 0){//so there is no negative score
score = 0;
}
}
function carCollision() {//when the car collide with cow, it returns at initial position
for (let i = 0; i < cars.length; i += 1) {
if (yCow < yCar[i] + heightCars &&
xCow + widthCow > xCar[i] &&
xCow < xCar[i] + heightCars &&
yCow + heightCow > yCar[i]) {
yCow = initialPositionCow;
score -= 1;
collisionSound.play();
}
}
}
function nivel1(){
speedCar = [3,5,2,5,4,3];
score = 0;
level3 = false;
xCow = 100;
}
function nivel2(){
speedCar = [7,5,6,7,8,5];
score = 0;
level3 = false;
xCow = 100;
}
function nivel3(){
speedCar = [7,5,6,7,8,5];
speedCow = 2;
score = 0;
level3 = true;
xCow = 280;
}