xxxxxxxxxx
45
let mario;
let marioAni;
let floor;
function preload(){
marioAni = loadAnimation(
'assets/mario0001.png',
'assets/mario0002.png',
'assets/mario0003.png'
);
}
function setup() {
new Canvas(500, 300);
mario = new Sprite(width/2, height/2+60, 40,90);
mario.rotationLock = true
mario.addAni('run', marioAni);
world.gravity.y = 15;
floor = new Sprite(width/2,275,500, 5, "static");
floor.color = "brown";
}
function draw() {
clear();
if (kb.pressing("left") || kb.pressing("ArrowLeft")) {
mario.vel.x = -4;
mario.mirror.x = true;
mario.ani.play();
} else if (kb.pressing("right") || kb.pressing("ArrowRight")) {
mario.vel.x = 4;
mario.mirror.x = false;
mario.ani.play();
} else {
mario.vel.x = 0;
mario.ani.stop();
}
if (mario.x > width){
mario.x = 0;
} else if (mario.x < 0){
mario.x = width;
}else if (mario.y > height){
mario.y = 0;
}else if (mario.y < 0){
mario.y = height;
}
mario.debug = mouse.holding();
}