-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
42 lines (31 loc) · 901 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
var trex, trex_running, trex_collided;
var ground, invisibleGround, groundImage;
function preload(){
trex_running = loadAnimation("trex1.png","trex3.png","trex4.png");
trex_collided = loadImage("trex_collided.png");
groundImage = loadImage("ground2.png")
}
function setup() {
createCanvas(400, 400);
trex = createSprite(50,380,20,50);
trex.addAnimation("running", trex_running);
trex.scale = 0.5;
ground = createSprite(200,380,400,20);
ground.addImage("ground",groundImage);
ground.x = ground.width /2;
ground.velocityX = -2;
invisibleGround = createSprite(200,390,400,10);
invisibleGround.visible = false;
}
function draw() {
background(220);
if(keyDown("space")) {
trex.velocityY = -10;
}
trex.velocityY = trex.velocityY + 0.8
if (ground.x < 0){
ground.x = ground.width/2;
}
trex.collide(invisibleGround);
drawSprites();
}