xxxxxxxxxx
72
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(600, 200);
//create a trex sprite
trex = createSprite(50,160,20,50);
trex.addAnimation("running", trex_running);
trex.scale = 0.5;
//create a ground sprite
ground = createSprite(200,180,400,20);
ground.addImage("ground",groundImage);
ground.x = ground.width /2;
ground.velocityX = -4;
invisibleGround = createSprite(200, 195, 400, 20);
}
function draw()
{
console.time();
background(220);
//jump when the space button is pressed
if (keyDown("space") && trex.y>=161.5)
{
trex.velocityY = -10;
}
trex.velocityY = trex.velocityY + 0.8
if (ground.x < 0)
{
ground.x = ground.width / 2;
}
console.info("this is where for loop begins");
for(var num = 0; num<20; num++)
{
console.log("running loop");
}
trex.collide(invisibleGround);
console.log(trex.y);
invisibleGround.visible = false;
console.error("this is how error appears");
console.timeEnd();
drawSprites();
}