Code edit (1 edits merged)
Please save this source code
User prompt
can you add keyboard movement w=jump a=left d=right i mean if you press w player jump if press a player go to do left if you press d player go to do right
Code edit (1 edits merged)
Please save this source code
User prompt
Monster Escape: Survival Platform
Initial prompt
A thrilling and intense survival platformer where the player begins on a platform with a giant, menacing monster looming behind them. The monster takes up a large portion of the screen, with part of its body appearing behind the platform and part in front, creating a dramatic layered effect. The monster launches powerful attacks targeting specific areas on the platform. These attacks come randomly, and the player must react quickly to survive. Some are fast strikes on one side, others cover wide zones — and as time passes, they become more dangerous. Every 5 seconds, the monster’s attacks grow faster, more frequent, and cover larger zones. The player uses the keyboard arrow keys to control movement: ← (Left arrow): move left → (Right arrow): move right ↑ (Up arrow): jump Gravity pulls the player back down after jumping, and the platform has boundaries so they cannot fall off the sides. If the player is hit by one of the monster’s attacks, the game ends immediately. The score is based on how long the player survives, with higher points earned at higher difficulty stages. During the game, coins appear on the platform. The player can collect these coins. There is a main menu before the game starts. A skin system allows the player to change their appearance, with different colors or custom-designed skins. Skins can be purchased using coins, but no saving system is required — everything resets when the game restarts. Visual and audio cues warn players of incoming attacks, helping them react in time. The goal is simple: survive as long as possible by dodging the monster’s relentless attacks.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.bobOffset = Math.random() * Math.PI * 2;
self.update = function () {
if (self.collected) {
return;
}
// Bobbing animation
coinGraphics.y = Math.sin(LK.ticks * 0.1 + self.bobOffset) * 10;
coinGraphics.rotation += 0.05;
// Check collection
if (self.intersects(player)) {
self.collected = true;
coins++;
totalCoins++;
updateScore();
LK.getSound('coin').play();
// Collect animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
gameCoins.splice(gameCoins.indexOf(self), 1);
}
});
}
};
return self;
});
var MonsterAttack = Container.expand(function () {
var self = Container.call(this);
var warningGraphics = self.attachAsset('attackWarning', {
anchorX: 0.5,
anchorY: 0.5
});
self.warningTime = 1000;
self.attackTime = 300;
self.state = 'warning';
self.timer = 0;
self.active = true;
self.update = function () {
if (!self.active) {
return;
}
self.timer += 16.67;
if (self.state === 'warning') {
// Pulsing warning effect
var pulse = Math.sin(self.timer * 0.01) * 0.3 + 0.7;
warningGraphics.alpha = pulse;
if (self.timer >= self.warningTime) {
// Switch to attack
self.state = 'attack';
self.timer = 0;
warningGraphics.visible = false;
var attackGraphics = self.attachAsset('attack', {
anchorX: 0.5,
anchorY: 0.5
});
LK.getSound('hit').play();
// Check collision with player
if (self.intersects(player)) {
gameOver();
}
}
} else if (self.state === 'attack') {
if (self.timer >= self.attackTime) {
self.active = false;
self.destroy();
attacks.splice(attacks.indexOf(self), 1);
}
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityX = 0;
self.velocityY = 0;
self.onGround = false;
self.speed = 8;
self.jumpPower = -20;
self.gravity = 1.2;
self.maxFallSpeed = 15;
self.update = function () {
// Apply gravity
if (!self.onGround) {
self.velocityY += self.gravity;
if (self.velocityY > self.maxFallSpeed) {
self.velocityY = self.maxFallSpeed;
}
}
// Apply velocity
self.x += self.velocityX;
self.y += self.velocityY;
// Platform collision
var platformY = 2732 - 300;
if (self.y >= platformY && self.velocityY >= 0) {
self.y = platformY;
self.velocityY = 0;
self.onGround = true;
} else {
self.onGround = false;
}
// Platform boundaries
var platformLeft = 124;
var platformRight = 1924;
if (self.x < platformLeft) {
self.x = platformLeft;
self.velocityX = 0;
}
if (self.x > platformRight) {
self.x = platformRight;
self.velocityX = 0;
}
// Apply friction
self.velocityX *= 0.85;
};
self.moveLeft = function () {
self.velocityX = -self.speed;
};
self.moveRight = function () {
self.velocityX = self.speed;
};
self.jump = function () {
if (self.onGround) {
self.velocityY = self.jumpPower;
self.onGround = false;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
//backgroundColor: 0x87CEEB // Bunu kaldırdık çünkü arkaplan resmi kullanacağız
});
/****
* Game Code
****/
/****
* Add Background
****/
var background = game.addChild(LK.getAsset('Background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
// Game state variables
var gameState = 'menu'; // 'menu', 'playing', 'gameOver'
var player;
var monster;
var platform;
var attacks = [];
var gameCoins = [];
var coins = 0;
var totalCoins = storage.totalCoins || 0;
var survivalTime = 0;
var difficultyLevel = 1;
var lastDifficultyIncrease = 0;
var lastAttackTime = 0;
var lastCoinSpawn = 0;
var currentSkin = storage.currentSkin || 0;
var unlockedSkins = storage.unlockedSkins || [0];
// Input tracking
var leftPressed = false;
var rightPressed = false;
var upPressed = false;
var lastUpPressed = false;
// Keyboard event listeners
LK.on('keydown', function (event) {
if (gameState === 'playing') {
switch (event.key.toLowerCase()) {
case 'a':
leftPressed = true;
break;
case 'd':
rightPressed = true;
break;
case 'w':
upPressed = true;
break;
}
}
});
LK.on('keyup', function (event) {
if (gameState === 'playing') {
switch (event.key.toLowerCase()) {
case 'a':
leftPressed = false;
break;
case 'd':
rightPressed = false;
break;
case 'w':
upPressed = false;
break;
}
}
});
// UI elements
var scoreText;
var timeText;
var coinText;
var menuContainer;
var skinButtons = [];
// Skin colors
var skinColors = [0x4CAF50, 0xFF5722, 0x2196F3, 0xFF9800, 0x9C27B0, 0x00BCD4, 0xFFEB3B, 0xE91E63];
// Skin prices
var skinPrices = [0, 50, 100, 150, 200, 300, 400, 500];
function initializeGame() {
// Create monster (background)
monster = game.addChild(LK.getAsset('monster', {
anchorX: 0.5,
anchorY: 1.0
}));
monster.x = 1024;
monster.y = 2732;
monster.alpha = 0.7;
// Create platform
platform = game.addChild(LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
}));
platform.x = 1024;
platform.y = 2732 - 250;
// Create player
player = game.addChild(new Player());
player.x = 1024;
player.y = 2732 - 300;
// Update player skin
updatePlayerSkin();
// Initialize UI
scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -20;
scoreText.y = 120;
timeText = new Text2('Time: 0s', {
size: 60,
fill: 0xFFFFFF
});
timeText.anchor.set(0.5, 0);
LK.gui.top.addChild(timeText);
timeText.y = 120;
coinText = new Text2('Coins: 0', {
size: 60,
fill: 0xFFD700
});
coinText.anchor.set(0, 0);
LK.gui.topLeft.addChild(coinText);
coinText.x = 120;
coinText.y = 120;
// Reset game variables
coins = 0;
survivalTime = 0;
difficultyLevel = 1;
lastDifficultyIncrease = 0;
lastAttackTime = 0;
lastCoinSpawn = 0;
attacks = [];
gameCoins = [];
updateScore();
// Play background music
LK.playMusic('bgmusic');
}
function createMenu() {
menuContainer = game.addChild(new Container());
// Title
var title = new Text2('Monster Escape', {
size: 120,
fill: 0xFFFFFF
});
title.anchor.set(0.5, 0.5);
title.x = 1024;
title.y = 400;
menuContainer.addChild(title);
// Coins display
var coinDisplay = new Text2('Coins: ' + totalCoins, {
size: 80,
fill: 0xFFD700
});
coinDisplay.anchor.set(0.5, 0.5);
coinDisplay.x = 1024;
coinDisplay.y = 600;
menuContainer.addChild(coinDisplay);
// Skin selection
var skinTitle = new Text2('Select Skin:', {
size: 60,
fill: 0xFFFFFF
});
skinTitle.anchor.set(0.5, 0.5);
skinTitle.x = 1024;
skinTitle.y = 800;
menuContainer.addChild(skinTitle);
// Skin buttons
var startX = 1024 - skinColors.length * 80 / 2;
for (var i = 0; i < skinColors.length; i++) {
var skinButton = menuContainer.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
tint: skinColors[i],
scaleX: 0.8,
scaleY: 0.8
}));
skinButton.x = startX + i * 120;
skinButton.y = 1000;
skinButton.skinIndex = i;
skinButton.interactive = true;
skinButtons.push(skinButton);
// Add price text for locked skins
if (!unlockedSkins.includes(i) && i > 0) {
var priceText = new Text2(skinPrices[i].toString(), {
size: 30,
fill: 0xFFFFFF
});
priceText.anchor.set(0.5, 0.5);
priceText.x = skinButton.x;
priceText.y = skinButton.y + 60;
menuContainer.addChild(priceText);
skinButton.alpha = 0.5;
}
// Highlight current skin
if (i === currentSkin) {
skinButton.scaleX = 1.0;
skinButton.scaleY = 1.0;
}
}
// Start button
var startButton = new Text2('TAP TO START', {
size: 80,
fill: 0x00FF00
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 1024;
startButton.y = 1400;
menuContainer.addChild(startButton);
// Pulsing animation for start button
tween(startButton, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButton, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (gameState === 'menu') {
tween(startButton, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: arguments.callee
});
}
}
});
}
});
}
function updatePlayerSkin() {
if (player && player.children.length > 0) {
player.children[0].tint = skinColors[currentSkin];
}
}
function startGame() {
gameState = 'playing';
if (menuContainer) {
menuContainer.destroy();
menuContainer = null;
}
initializeGame();
}
function gameOver() {
gameState = 'gameOver';
// Save total coins
storage.totalCoins = totalCoins;
storage.currentSkin = currentSkin;
storage.unlockedSkins = unlockedSkins;
// Calculate final score
var finalScore = Math.floor(survivalTime / 100) + coins * 10 + (difficultyLevel - 1) * 50;
LK.setScore(finalScore);
LK.showGameOver();
}
function spawnAttack() {
var attack = game.addChild(new MonsterAttack());
attack.x = 124 + Math.random() * 1700;
attack.y = 2732 - 350;
attacks.push(attack);
// Scale attack size based on difficulty
var scale = Math.min(1 + (difficultyLevel - 1) * 0.2, 2.0);
attack.scaleX = scale;
attack.scaleY = scale;
LK.getSound('warning').play();
}
function spawnCoin() {
var coin = game.addChild(new Coin());
coin.x = 200 + Math.random() * 1600;
coin.y = 2732 - 400;
gameCoins.push(coin);
}
function updateScore() {
if (scoreText) {
var score = Math.floor(survivalTime / 100) + coins * 10;
scoreText.setText('Score: ' + score);
}
if (timeText) {
timeText.setText('Time: ' + Math.floor(survivalTime / 100) + 's');
}
if (coinText) {
coinText.setText('Coins: ' + coins);
}
}
function handleSkinSelection(skinIndex) {
if (unlockedSkins.includes(skinIndex)) {
currentSkin = skinIndex;
// Update button appearances
for (var i = 0; i < skinButtons.length; i++) {
if (i === currentSkin) {
skinButtons[i].scaleX = 1.0;
skinButtons[i].scaleY = 1.0;
} else {
skinButtons[i].scaleX = 0.8;
skinButtons[i].scaleY = 0.8;
}
}
} else if (totalCoins >= skinPrices[skinIndex]) {
// Purchase skin
totalCoins -= skinPrices[skinIndex];
unlockedSkins.push(skinIndex);
currentSkin = skinIndex;
// Recreate menu to update display
if (menuContainer) {
menuContainer.destroy();
skinButtons = [];
}
createMenu();
}
}
// Initialize menu
gameState = 'menu';
createMenu();
// Event handlers
game.down = function (x, y, obj) {
if (gameState === 'menu') {
// Check skin button clicks
for (var i = 0; i < skinButtons.length; i++) {
var button = skinButtons[i];
var bounds = button.getBounds();
if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
handleSkinSelection(button.skinIndex);
return;
}
}
// Start game if not clicking on skin buttons
startGame();
} else if (gameState === 'playing') {
// Touch controls for mobile
if (x < 1024 / 2) {
leftPressed = true;
} else if (x > 1024 + 1024 / 2) {
rightPressed = true;
} else {
upPressed = true;
}
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing') {
leftPressed = false;
rightPressed = false;
upPressed = false;
}
};
game.update = function () {
if (gameState !== 'playing') {
return;
}
// Handle input
if (leftPressed) {
player.moveLeft();
}
if (rightPressed) {
player.moveRight();
}
if (upPressed && !lastUpPressed) {
player.jump();
}
lastUpPressed = upPressed;
// Update survival time
survivalTime++;
// Increase difficulty every 5 seconds (300 ticks at 60fps)
if (survivalTime - lastDifficultyIncrease >= 300) {
difficultyLevel++;
lastDifficultyIncrease = survivalTime;
}
// Spawn attacks based on difficulty
var attackInterval = Math.max(60 - (difficultyLevel - 1) * 5, 20);
if (survivalTime - lastAttackTime >= attackInterval) {
spawnAttack();
lastAttackTime = survivalTime;
}
// Spawn coins occasionally
if (survivalTime - lastCoinSpawn >= 180 + Math.random() * 120) {
spawnCoin();
lastCoinSpawn = survivalTime;
}
// Update score display
if (survivalTime % 10 === 0) {
updateScore();
}
// Clean up inactive attacks
for (var i = attacks.length - 1; i >= 0; i--) {
if (!attacks[i].active) {
attacks.splice(i, 1);
}
}
// Update player and other game objects
if (player) {
player.update();
}
for (var i = 0; i < attacks.length; i++) {
attacks[i].update();
}
for (var i = gameCoins.length - 1; i >= 0; i--) {
gameCoins[i].update();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -15,9 +15,11 @@
});
self.collected = false;
self.bobOffset = Math.random() * Math.PI * 2;
self.update = function () {
- if (self.collected) return;
+ if (self.collected) {
+ return;
+ }
// Bobbing animation
coinGraphics.y = Math.sin(LK.ticks * 0.1 + self.bobOffset) * 10;
coinGraphics.rotation += 0.05;
// Check collection
@@ -54,9 +56,11 @@
self.state = 'warning';
self.timer = 0;
self.active = true;
self.update = function () {
- if (!self.active) return;
+ if (!self.active) {
+ return;
+ }
self.timer += 16.67;
if (self.state === 'warning') {
// Pulsing warning effect
var pulse = Math.sin(self.timer * 0.01) * 0.3 + 0.7;
@@ -151,14 +155,23 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB
+ //backgroundColor: 0x87CEEB // Bunu kaldırdık çünkü arkaplan resmi kullanacağız
});
/****
* Game Code
****/
+/****
+* Add Background
+****/
+var background = game.addChild(LK.getAsset('Background', {
+ anchorX: 0,
+ anchorY: 0
+}));
+background.x = 0;
+background.y = 0;
// Game state variables
var gameState = 'menu'; // 'menu', 'playing', 'gameOver'
var player;
var monster;
@@ -216,24 +229,9 @@
var coinText;
var menuContainer;
var skinButtons = [];
// Skin colors
-var skinColors = [0x4CAF50,
-// Green (default)
-0xFF5722,
-// Red
-0x2196F3,
-// Blue
-0xFF9800,
-// Orange
-0x9C27B0,
-// Purple
-0x00BCD4,
-// Cyan
-0xFFEB3B,
-// Yellow
-0xE91E63 // Pink
-];
+var skinColors = [0x4CAF50, 0xFF5722, 0x2196F3, 0xFF9800, 0x9C27B0, 0x00BCD4, 0xFFEB3B, 0xE91E63];
// Skin prices
var skinPrices = [0, 50, 100, 150, 200, 300, 400, 500];
function initializeGame() {
// Create monster (background)
@@ -509,9 +507,11 @@
upPressed = false;
}
};
game.update = function () {
- if (gameState !== 'playing') return;
+ if (gameState !== 'playing') {
+ return;
+ }
// Handle input
if (leftPressed) {
player.moveLeft();
}
@@ -549,5 +549,15 @@
if (!attacks[i].active) {
attacks.splice(i, 1);
}
}
+ // Update player and other game objects
+ if (player) {
+ player.update();
+ }
+ for (var i = 0; i < attacks.length; i++) {
+ attacks[i].update();
+ }
+ for (var i = gameCoins.length - 1; i >= 0; i--) {
+ gameCoins[i].update();
+ }
};
\ No newline at end of file
attack red black hell a round. In-Game asset. 2d. High contrast. No shadows
attack warning yellow have a dead logo. In-Game asset. 2d. High contrast. No shadows
hell coin. In-Game asset. 2d. High contrast. No shadows
hell monster piksel. In-Game asset. 2d. High contrast. No shadows
a hell platform. In-Game asset. 2d. High contrast. No shadows
a hell player 2d pixel. In-Game asset. 2d. High contrast. No shadows
a hell back ground. In-Game asset. 2d. High contrast. No shadows