-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
75 lines (46 loc) · 1.58 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
var background;
var tom,tomMovingImage,tomCollide,tomStableImage
var jerry,jerryMovingImage,jerryCollide,jerryStableImage
function preload() {
//load the images here
backgroundImage=loadImage("garden.png");
jerryStableImage=loadImage("jerryOne.png");
tomStableImage=loadImage("tomOne.png");
jerryImage=loadAnimation("jerryTwo.png","jerryFour.png");
tomMovingImage=loadAnimation("tomTwo.png","tomThree.png");
jerryCollide=loadImage("jerryThree.png");
tomCollide=loadImage("tomFour.png");
}
function setup(){
createCanvas(1000,800);
// create tom and jerry sprites here
tom=createSprite(800,600)
tom.addImage("tom",tomStableImage);
tom.scale=0.2;
tom.addImage("tomcollide",tomCollide);
jerry=createSprite(100,560);
jerry.addImage("jerry",jerryStableImage);
jerry.scale=0.2;
jerry.addImage("jerrycollide",jerryCollide);
}
function draw() {
background(backgroundImage)
keyPressed();
if(jerry.isTouching(tom)){
tom.velocityX=0
jerry.changeImage("jerrycollide");
tom.changeImage("tomcollide");
}
//Write condition here to evalute if tom and jerry collide
jerry.setCollider("circle",20,20,500)
drawSprites();
}
function keyPressed(){
if(keyCode === LEFT_ARROW){
tom.velocityX=-5;
tom.addAnimation("tomMoving",tomMovingImage)
tom.changeAnimation("tomMoving");
jerry.addAnimation("jerryMoving",jerryImage);
jerry.changeAnimation("jerryMoving")
}
}