-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
116 lines (102 loc) · 2.48 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
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
var grid = 50;
var width = 1366;
var carGroup1,logGroup1;
var grassHeight = 100;
var gameState = "play";
var carAnimation, logAnimation, playerAnimation;
var school;
function preload()
{
cityAnimation=loadAnimation("images/city1.png");
carAnimation1=loadAnimation("images/car1.png");
carAnimation2=loadAnimation("images/car2.png");
playerAnimation=loadAnimation("images/Player-03.png");
logAnimation=loadAnimation("images/log2.png");
}
function setup() {
createCanvas(1366,2700);
carGroup1 = new Group();
logGroup1 = new Group();
for(var i=0;i<6;i++){
var bottomGrass1 = createSprite(683,height-50-(i*400),width,grassHeight);
if(i%2===0)
{
var road= createSprite(683,height-150-(i*400)-grassHeight,width,300,)
road.shapeColor="black";
}
bottomGrass1.shapeColor = "green";
}
for(var i = 0; i < 40; i++){
cars = new Car(2);
carGroup1.add(cars.spt);
}
for(var i = 0; i < 40; i++){
log = new Log(-3);
logGroup1.add(log.spt);
}
player = new Player(width/2,height-25)
city=createSprite(width/2,-1500);
city.addAnimation("city",cityAnimation);
}
function draw() {
background("skyblue");
translate(0,-player.spt.y+height-150)
for(i=1;i<carGroup1.length;i++) {
if(carGroup1[i].x>width)
{
carGroup1[i].x=0;
}
if(carGroup1[i].x<0)
{
carGroup1[i].x=width;
}
}
for(i=1;i<logGroup1.length;i++){
if(logGroup1[i].x<0)
{
logGroup1[i].x=width;
}
}
if(carGroup1.isTouching(player.spt)){
player.spt.x = width/2;
player.spt.y = height-75;
}
if(logGroup1.isTouching(player.spt)){
player.spt.x= player.spt.x-3;
}
else if((player.spt.y > height-1550 && player.spt.y < height-1300) ||
(player.spt.y < height-500 && player.spt.y > height-850)||
(player.spt.y>height)||
(player.spt.x<0)||
(player.spt.x>width)){
player.spt.x = width/2;
player.spt.y = height-75;
}
if(city.isTouching(player.spt)){
gameState = "Win";
}
if(gameState === "Win")
{
stroke("Green");
fill("Green");
textSize(40);
text("Congratulations! You Made It.",width/2-250,-1700);
carGroup1.destroyEach();
logGroup1.destroyEach();
}
drawSprites();
}
function keyPressed(){
if(keyCode == UP_ARROW){
player.move(0,-2)
}
if(keyCode == DOWN_ARROW){
player.move(0,2)
}
if(keyCode == LEFT_ARROW){
player.move(-2,0)
}
if(keyCode == RIGHT_ARROW){
player.move(2,0)
}
}