xxxxxxxxxx
88
let marioIdle;
let marioRun;
let marioJumpImage;
let platforms;
let platformx = 10;
let platformy = 450;
let platformw = 100
let platformh = 25
let score = 0
let coins;
let touchingGround = false;
function preload() {
marioIdle = loadAnimation("Knight/_Idle.png", {
size: [120, 120],
frames: 10,
});
marioRun = loadAnimation("Knight/_Run.png", {
size: [120, 120],
frames: 8,
});
pickupSound = loadSound("Ding.wav");
}
function setup() {
new Canvas(500, 400);
world.gravity.y = 10;
print("Touching Ground is false");
mario = new Sprite(250, 100, 20, 60);
mario.rotationLock = true;
mario.addAni("idle", marioIdle);
mario.addAni("run", marioRun);
mario.anis.offset.y = -30
mario.anis.offset.x = 5
//create platform sprites
platforms = new Group();
for (let i = 0; i < 100; i++) {
new platforms.Sprite(platformx, platformy, platformw, platformh, "static");
platformw = random(10,200)
platformx = platformx+platformw + random(-50,50)
platformy = platformy-platformh+random(-45,45)
}
coins = new Group();
coins.color = 'yellow';
for (let i = 0; i < 10; i++) {
new coins.Sprite(random(50,1200), random(150,200), 25, "static");
}
mario.overlaps(coins, pickupCoins);
}
function pickupCoins(mario, coin) {
pickupSound.play()
coin.remove();
score++
}
function draw() {
clear();
camera.x = mario.x+100;
camera.y = mario.y;
if (kb.pressed(" ") && touchingGround==true) {
mario.vel.y = -8;
touchingGround = false;
print("Touching Ground is false");
} else if (kb.pressing("left")) {
mario.ani = "run";
mario.vel.x = -4;
mario.mirror.x = true;
} else if (kb.pressing("right")) {
mario.ani = "run";
mario.vel.x = 4;
mario.mirror.x = false;
} else {
mario.vel.x = 0;
mario.ani = "idle";
}
mario.collides(platforms, setTouching);
mario.debug = mouse.holding();
}
function setTouching() {
touchingGround = true;
print("Touching Ground is true");
}