-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
61 lines (46 loc) · 1.38 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
var bgImg
var cat,catImg
var mouse,mouseImg
function preload() {
bgImg=loadImage("images/garden.png");
catImg2=loadImage("images/tomOne.png");
catImg=loadAnimation("images/tomTwo.png","images/tomThree.png");
mouseImg2=loadImage("Images/jerryOne.png");
mouseImg=loadAnimation("images/jerryTwo.png","images/jerryThree.png");
mouseImg3=loadImage("images/jerryFour.png");
catImg3=loadImage("images/tomFour.png");
}
function setup(){
createCanvas(1000,800);
cat=createSprite(750,450);
cat.addImage("tomWalking",catImg2);
cat.scale=0.1
mouse=createSprite(200,450);
mouse.addImage("jerryWalking",mouseImg2);
mouse.scale=0.1;
}
function draw() {
background(bgImg);
if(cat.isTouching(mouse)){
cat.velocityX=0;
cat.addImage("tomStop",catImg3)
cat.changeImage("tomStop")
mouse.addImage("jerryStop",mouseImg3)
mouse.changeImage("jerryStop")
}
cat.setCollider("rectangle",80,80,240,260)
// cat.debug=true;
mouse.setCollider("circle",0,0,400)
// mouse.debug=true;
keyPressed();
drawSprites();
}
function keyPressed(){
if(keyDown(LEFT_ARROW)) {
cat.velocityX=-5;
cat.addAnimation("tomwalk",catImg);
cat.changeAnimation("tomwalk")
mouse.addAnimation("jerry",mouseImg)
mouse.changeAnimation("jerry")
}
}