xxxxxxxxxx
49
let dinoImg;
let treeImg;
let dino;
function preload() {
dinoImg = loadImage('dino.png');
treeImg = loadImage('tree.png');
}
function setup() {
createCanvas(400, 400);
dino = new Dino(50,200, dinoImg);
}
function draw() {
background(0,200,230);
dino.update();
dino.show();
}
function keyPressed() {
dino.jump();
}
class Dino{
constructor(x,y,img) {
this.x = x;
this.y = y;
this.yv = 0;
this.img = img;
}
jump() {
this.yv = -8;
}
update() {
this.x = this.x + 1;
this.x = this.x % width;
if(this.y > 301)
this.yv++;
this.y = this.y + this.yv;
}
show() {
imageMode(CENTER);
image(this.img,this.x,this.y,100,100 );
}
}