-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
55 lines (37 loc) · 980 Bytes
/
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
var path,boy, leftBoundary,rightBoundary;
var pathImg,boyImg;
var i;
function preload(){
pathImg = loadImage("path.png");
boyImg = loadAnimation("Runner-1.png","Runner-2.png");
}
function setup(){
createCanvas(400,400);
// Moving background
path=createSprite(200,200);
path.addImage(pathImg);
path.velocityY = 4;
path.scale=1.2;
//creating boy running
boy = createSprite(180,340,30,30);
boy.scale=0.08;
boy.addAnimation("JakeRunning",boyImg);
leftBoundary=createSprite(0,0,100,800);
leftBoundary.visible = false;
rightBoundary=createSprite(410,0,100,800);
rightBoundary.visible = false;
}
function draw() {
background(0);
path.velocityY = 4;
boy.x = World.mouseX;
edges= createEdgeSprites();
boy.collide(edges[3]);
boy.collide(leftBoundary);
boy.collide(rightBoundary);
//code to reset the background
if(path.y > 400 ){
path.y = height/2;
}
drawSprites();
}