User prompt
also make it if it crouching monstores wint spawn and make it go back up when stop crouching
User prompt
when it crouches dont let it go up just down
User prompt
when u crouch jumps and glitches fix it
User prompt
add chrouching aniamation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'window.addEventListener is not a function' in or related to this line: 'window.addEventListener('keydown', function (e) {' Line Number: 383
User prompt
with the joystick make crouching work with it or when u press s
User prompt
add joystick for movement
User prompt
there is no mobile button
User prompt
Please fix the bug: 'storage.has is not a function' in or related to this line: 'if (storage && storage.has('touchControlsEnabled')) {' Line Number: 114 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'storage is not defined' in or related to this line: 'if (storage && storage.has('touchControlsEnabled')) {' Line Number: 109 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
make it so u can enable touch controls from pause button even on pc
User prompt
make it mobile firendly
Remix started
Copy Mario vs Monsters
/**** * Plugins ****/ var storage = LK.import("@upit/storage.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 }); self.speed = 5; self.update = function () { // Track last position for collision detection self.lastX = self.x; self.lastY = self.y; self.lastWasIntersecting = false; self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for the mobile jump button var MobileButton = Container.expand(function () { var self = Container.call(this); // Create the button shape var button = new Container(); var buttonBg = LK.getAsset('button', { width: 200, height: 200, color: 0x3498db, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); button.addChild(buttonBg); // Add jump text var jumpText = new Text2("JUMP", { size: 50, fill: 0xFFFFFF, stroke: 0x000000, strokeThickness: 3 }); jumpText.anchor.set(0.5, 0.5); button.addChild(jumpText); self.addChild(button); // Handle touch events self.down = function () { buttonBg.alpha = 0.7; if (player && typeof player.jump === 'function') { player.jump(); } }; self.up = function () { buttonBg.alpha = 1; }; return self; }); // Define a class for pause menu items var PauseMenuItem = Container.expand(function () { var self = Container.call(this); self.createItem = function (text, y, callback) { var menuText = new Text2(text, { size: 70, fill: 0xFFFFFF, stroke: 0x000000, strokeThickness: 3 }); menuText.anchor.set(0.5, 0.5); menuText.y = y; self.addChild(menuText); self.down = function () { if (callback) { callback(); } }; return self; }; 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.update = function () { // Track last position for collision detection self.lastX = self.x; self.lastY = self.y; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Decreased gravity effect by 30% 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 ****/ // Make background fit the screen properly var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 })); background.x = 2048 / 2; background.y = 2732 / 2; // Game configuration var gameConfig = { touchControlsEnabled: true }; // Check if there's a stored preference for touch controls if (storage && storage.touchControlsEnabled !== undefined) { gameConfig.touchControlsEnabled = storage.touchControlsEnabled; } // 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 with better mobile visibility var scoreText = new Text2('Score: 0', { size: 120, fill: 0xFFFFFF, stroke: 0x000000, strokeThickness: 5 }); // Add the score text to the game GUI at the top center of the screen // Anchoring properly for responsive display scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); // 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); // Randomize the spawn interval for the next enemy enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Update enemies with better collision detection for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // More precise collision detection if (player.intersects(enemies[j])) { if (!enemies[j].lastWasIntersecting) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } enemies[j].lastWasIntersecting = true; } else { enemies[j].lastWasIntersecting = false; // Check if player passed the enemy if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); // Visual feedback when scoring var pointText = new Text2('+1', { size: 60, fill: 0xFFFFFF }); pointText.x = enemies[j].x; pointText.y = enemies[j].y - 100; game.addChild(pointText); // Animate and remove the +1 text LK.setTimeout(function () { pointText.destroy(); }, 1000); } } } }; // Custom pause handler LK.on('pause', function () { // Create touch controls toggle menu item var toggleItem = new PauseMenuItem().createItem(gameConfig.touchControlsEnabled ? "Disable Touch Controls" : "Enable Touch Controls", 200, function () { // Toggle touch controls setting gameConfig.touchControlsEnabled = !gameConfig.touchControlsEnabled; // Save setting in storage if (storage) { storage.touchControlsEnabled = gameConfig.touchControlsEnabled; } // Update button visibility when setting changes updateButtonVisibility(); // Resume game after changing setting LK.resumeGame(); }); // Position the menu item in the center of the screen toggleItem.x = 2048 / 2; toggleItem.y = 2732 / 2; // Add to pause menu LK.gui.center.addChild(toggleItem); }); // Create mobile jump button var mobileButton = new MobileButton(); mobileButton.x = 2048 - 200; // Position on bottom right mobileButton.y = 2732 - 200; game.addChild(mobileButton); // Function to update button visibility based on settings function updateButtonVisibility() { mobileButton.visible = gameConfig.touchControlsEnabled; } // Initial visibility updateButtonVisibility(); // Handle player jump with improved controls for mobile game.down = function (x, y, obj) { // Already handled by the button's down event when touch controls enabled // For anywhere else on screen: only jump when touch controls are enabled AND not pressing the button if (gameConfig.touchControlsEnabled && obj.event && obj.event.target !== mobileButton) { player.jump(); } }; // Add move handler for potential drag controls game.move = function (x, y, obj) { // Can be expanded for more mobile controls if needed }; // Initialize the score to zero scoreText.setText('0'); // Make score text more visible on mobile screens scoreText.size = 120;
===================================================================
--- original.js
+++ change.js
@@ -24,8 +24,44 @@
self.destroy();
}
};
});
+// Define a class for the mobile jump button
+var MobileButton = Container.expand(function () {
+ var self = Container.call(this);
+ // Create the button shape
+ var button = new Container();
+ var buttonBg = LK.getAsset('button', {
+ width: 200,
+ height: 200,
+ color: 0x3498db,
+ shape: 'ellipse',
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ button.addChild(buttonBg);
+ // Add jump text
+ var jumpText = new Text2("JUMP", {
+ size: 50,
+ fill: 0xFFFFFF,
+ stroke: 0x000000,
+ strokeThickness: 3
+ });
+ jumpText.anchor.set(0.5, 0.5);
+ button.addChild(jumpText);
+ self.addChild(button);
+ // Handle touch events
+ self.down = function () {
+ buttonBg.alpha = 0.7;
+ if (player && typeof player.jump === 'function') {
+ player.jump();
+ }
+ };
+ self.up = function () {
+ buttonBg.alpha = 1;
+ };
+ return self;
+});
// Define a class for pause menu items
var PauseMenuItem = Container.expand(function () {
var self = Container.call(this);
self.createItem = function (text, y, callback) {
@@ -183,8 +219,10 @@
// Save setting in storage
if (storage) {
storage.touchControlsEnabled = gameConfig.touchControlsEnabled;
}
+ // Update button visibility when setting changes
+ updateButtonVisibility();
// Resume game after changing setting
LK.resumeGame();
});
// Position the menu item in the center of the screen
@@ -192,12 +230,24 @@
toggleItem.y = 2732 / 2;
// Add to pause menu
LK.gui.center.addChild(toggleItem);
});
+// Create mobile jump button
+var mobileButton = new MobileButton();
+mobileButton.x = 2048 - 200; // Position on bottom right
+mobileButton.y = 2732 - 200;
+game.addChild(mobileButton);
+// Function to update button visibility based on settings
+function updateButtonVisibility() {
+ mobileButton.visible = gameConfig.touchControlsEnabled;
+}
+// Initial visibility
+updateButtonVisibility();
// Handle player jump with improved controls for mobile
game.down = function (x, y, obj) {
- // Only jump when touch controls are enabled
- if (gameConfig.touchControlsEnabled) {
+ // Already handled by the button's down event when touch controls enabled
+ // For anywhere else on screen: only jump when touch controls are enabled AND not pressing the button
+ if (gameConfig.touchControlsEnabled && obj.event && obj.event.target !== mobileButton) {
player.jump();
}
};
// Add move handler for potential drag controls