/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the main character (Mario)
var Mario = Container.expand(function () {
var self = Container.call(this);
var marioGraphics = self.attachAsset('mario', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.isJumping = false;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.y > 2732 - marioGraphics.height / 2) {
self.y = 2732 - marioGraphics.height / 2;
self.isJumping = false;
}
};
self.jump = function () {
if (!self.isJumping) {
self.speedY = -20;
self.isJumping = true;
}
};
});
// Class for platforms
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Platforms are static, no update logic needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize Mario
var mario = new Mario();
mario.x = 2048 / 2;
mario.y = 2732 - 100;
game.addChild(mario);
// Initialize platforms
var platforms = [];
function createPlatform(x, y) {
var platform = new Platform();
platform.x = x;
platform.y = y;
platforms.push(platform);
game.addChild(platform);
}
// Create some platforms
createPlatform(2048 / 2, 2500);
createPlatform(2048 / 2 - 300, 2200);
createPlatform(2048 / 2 + 300, 1900);
// Handle game updates
game.update = function () {
mario.update();
platforms.forEach(function (platform) {
platform.update();
if (mario.intersects(platform) && mario.speedY > 0) {
mario.y = platform.y - mario.height / 2;
mario.speedY = 0;
mario.isJumping = false;
}
});
// Gravity effect
if (mario.isJumping) {
mario.speedY += 1;
}
};
// Handle touch events for jumping
game.down = function (x, y, obj) {
mario.jump();
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the main character (Mario)
var Mario = Container.expand(function () {
var self = Container.call(this);
var marioGraphics = self.attachAsset('mario', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.isJumping = false;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.y > 2732 - marioGraphics.height / 2) {
self.y = 2732 - marioGraphics.height / 2;
self.isJumping = false;
}
};
self.jump = function () {
if (!self.isJumping) {
self.speedY = -20;
self.isJumping = true;
}
};
});
// Class for platforms
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Platforms are static, no update logic needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize Mario
var mario = new Mario();
mario.x = 2048 / 2;
mario.y = 2732 - 100;
game.addChild(mario);
// Initialize platforms
var platforms = [];
function createPlatform(x, y) {
var platform = new Platform();
platform.x = x;
platform.y = y;
platforms.push(platform);
game.addChild(platform);
}
// Create some platforms
createPlatform(2048 / 2, 2500);
createPlatform(2048 / 2 - 300, 2200);
createPlatform(2048 / 2 + 300, 1900);
// Handle game updates
game.update = function () {
mario.update();
platforms.forEach(function (platform) {
platform.update();
if (mario.intersects(platform) && mario.speedY > 0) {
mario.y = platform.y - mario.height / 2;
mario.speedY = 0;
mario.isJumping = false;
}
});
// Gravity effect
if (mario.isJumping) {
mario.speedY += 1;
}
};
// Handle touch events for jumping
game.down = function (x, y, obj) {
mario.jump();
};