-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
119 lines (89 loc) · 2.63 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
117
118
119
var monkey , monkey_running
var banana ,bananaImage, obstacle, obstacleImage
var FoodGroup, obstaclesGroup
var score
var blank, blankImage,white
function preload(){
monkey_running = loadAnimation("sprite_0.png","sprite_1.png","sprite_2.png","sprite_3.png","sprite_4.png","sprite_5.png","sprite_6.png","sprite_7.png","sprite_8.png")
bananaImage = loadImage("banana.png");
obstacleImage =
loadImage("rock-1.png");
blankImage = loadImage("AAAABfTWSe7ZdX58pYgd5ps2GbI93QUKTIesqgUb8wPJxGa6xOsJXZOBhLFkIhIwZYS0hXZllJCzIIMC1B_vrI7ydpFw9B1l0QV0cqcR.png")
}
function setup() {
//creating monkey
monkey=createSprite(80,315, 20,20);
monkey.addAnimation("moving", monkey_running);
monkey.scale=0.1
ground = createSprite(400,350,900,10);
ground.velocityx=-4;
ground.x=ground.width/2;
console.log(ground.x);
obstaclesGroup = new Group();
FoodGroup = new Group();
}
function draw() {
background(rgb(257,257,257));
if(ground.x<0){
ground.x=ground.width/2;
}
if(monkey.isTouching(FoodGroup)){
FoodGroup.destroyEach();
}
if(monkey.isTouching(obstaclesGroup)){
monkey.visible = false;
whiteImage();
blankImg();
}
if(keyDown( "space")){
monkey.velocityY = -17;
}
monkey.velocityY = monkey.velocityY + 0.8;
monkey.collide(ground);
console.log(monkey.y)
stroke("white");
textSize(20);
fill("white");
text("Score: "+ score, 500,50);
stroke("black");
textSize(20);
fill("black");
survivalTime=Math.ceil(frameCount/frameRate())
text("Survival Time: "+ survivalTime, 100,50);
spawnObstacles();
spawnFood();
drawSprites();
}
function whiteImage(){
white = createSprite(170,50,200,70);
white.shapeColour = "White";
}
function spawnObstacles(){
if (frameCount % 120 === 0){
obstacle = createSprite(600,280,10,10);
obstacle.velocityX = -6;
obstacle.addImage(obstacleImage);
obstacle.scale = 0.1;
obstacle.collide(ground);
obstacle.setCollider("circle", 0, 0, 180);
obstacle.scale = 0.5;
obstacle.lifetime = 300;
obstaclesGroup.add(obstacle);
}
}
function spawnFood(){
if (frameCount % 80 === 0){
banana = createSprite(420,180,10,20)
banana.velocityX = -6;
banana.addImage(bananaImage);
banana.scale = 0.1;
banana.y = Math.round(random(100,180 ))
banana.lifetime = 400
FoodGroup.add(banana);
}
}
function blankImg(){
blank = createSprite(150,50,100,50);
blank.addImage(blankImage);
blank.scale = 0.1;
}