forked from pro-whitehatjr/Trex_stage_0.5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
40 lines (30 loc) · 784 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
var trex, trex_running, edges;
var groundImage;
function preload(){
trex_running = loadAnimation("trex1.png","trex3.png","trex4.png");
groundImage = loadImage("ground2.png")
}
function setup(){
createCanvas(600,200);
// creating trex
trex = createSprite(50,160,20,50);
trex.addAnimation("running", trex_running);
edges = createEdgeSprites();
//adding scale and position to trex
trex.scale = 0.5;
trex.x = 50
}
function draw(){
//set background color
background("white");
//logging the y position of the trex
console.log(trex.y)
//jump when space key is pressed
if(keyDown("space")){
trex.velocityY = -10;
}
trex.velocityY = trex.velocityY + 0.5;
//stop trex from falling down
trex.collide(edges[3])
drawSprites();
}