User prompt
why are the hearts a black box fix that
User prompt
make live to three hearts in the midle
User prompt
give the player three lives
User prompt
make the monsters faster
User prompt
make gravity to 0.9
User prompt
make the player falls slower
User prompt
make the hitboxes from the monsters smaller
User prompt
make that the monsters roll in the other direction
User prompt
other direction
User prompt
make that the monsters roll ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make that the monsters roll
User prompt
make that the monsters bounce every 2 seconds
User prompt
make that the monsters bounce up from the floor ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Remix started
Copy Mario vs Monsters
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); // Create a smaller hitbox for the enemy (reduce the collision area) self.hitArea = new Rectangle(-50, -50, 100, 100); self.speed = 8; self.update = function () { self.x -= self.speed; // Make the enemy roll by rotating it in the opposite direction self.rotation -= 0.1; if (self.x < -50) { self.destroy(); } }; }); // Define a class for heart display var Heart = Container.expand(function () { var self = Container.call(this); // Create a heart using the heart asset var heartShape = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); // Animate heart slightly self.animate = function () { tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 800, easing: tween.easeInOutQuad, onFinish: function onFinish() { tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 800, easing: tween.easeInOutQuad, onFinish: self.animate }); } }); }; return self; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.velocityY = 0; self.invulnerable = false; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.9; // Gravity effect if (self.y >= 2732 / 2) { // Ground level self.y = 2732 / 2; self.isJumping = false; self.velocityY = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; // Initialize enemies var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); // Add the score text to the game GUI at the top center of the screen LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 0; // Initialize lives counter var lives = 3; var hearts = []; var heartsContainer = new Container(); game.addChild(heartsContainer); // Position hearts container in the middle of the screen heartsContainer.x = 2048 / 2; heartsContainer.y = 150; // Create heart display function updateHeartDisplay() { // Clear existing hearts while (hearts.length > 0) { var heart = hearts.pop(); heart.destroy(); } // Create new hearts based on current lives for (var i = 0; i < lives; i++) { var heart = new Heart(); heart.x = (i - (lives - 1) / 2) * 100; // Distribute hearts evenly heart.y = 0; hearts.push(heart); heartsContainer.addChild(heart); heart.animate(); } } // Initial heart display updateHeartDisplay(); // Handle game updates game.update = function () { player.update(); // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2; enemies.push(enemy); game.addChild(enemy); // Apply rolling animation with tween in the opposite direction tween(enemy, { rotation: -Math.PI * 4 }, { duration: 2000, easing: tween.linear, onFinish: function onFinish() { // Continuously roll the enemy in the opposite direction tween(enemy, { rotation: enemy.rotation - Math.PI * 4 }, { duration: 2000, easing: tween.linear }); } }); // Randomize the spawn interval for the next enemy enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j]) && !player.invulnerable) { // Handle collision lives--; updateHeartDisplay(); // Make player invulnerable temporarily player.invulnerable = true; player.alpha = 0.5; // Flash the screen red LK.effects.flashScreen(0xff0000, 500); // Remove the enemy enemies[j].destroy(); enemies.splice(j, 1); // Check if player has run out of lives if (lives <= 0) { LK.showGameOver(); } else { // Make player vulnerable again after a short time LK.setTimeout(function () { player.invulnerable = false; player.alpha = 1; }, 1500); } } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); } } }; // Handle player jump game.down = function (x, y, obj) { player.jump(); }; // Import tween plugin for animations
===================================================================
--- original.js
+++ change.js
@@ -27,13 +27,13 @@
});
// Define a class for heart display
var Heart = Container.expand(function () {
var self = Container.call(this);
- // Create a red heart shape
- var heartShape = self.attachAsset({
+ // Create a heart using the heart asset
+ var heartShape = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
- }, {});
+ });
// Animate heart slightly
self.animate = function () {
tween(self, {
scaleX: 1.1,