User prompt
2 ci levelde ilk plakaya kare değip ikinci plakayada karakter deydiğinde kapı açılsın
User prompt
Oyuna her girildiğinde 1ci levelden başlanılsın
User prompt
Sağa gitme ve sola gitme butonlarını yan yana koy 2ci levelde haritada 2 plaka olsun karakter onların ikisinede değdiğinde kapı açılsın ve 3 levele geçsin
User prompt
Karakterin Sağa sola gitmesi ve zıplaması için tuşlar ekle
User prompt
Karakter karenin içinden geçemesin ve karakterin hareket etmesi için sağa sola ve zıplama tuşu ekle
Code edit (1 edits merged)
Please save this source code
User prompt
Block Pusher Portal
Initial prompt
ortada platgormun üzerinde bir ittirilebilir kare olsun ileride platformun üzerinde 1 tabela olsun kareyi ittirerek onun üzerine getirildiğinde haritanın sonunda bir kapı açılsın karakter kapıya deydiği zaman yeni sahneye atılsın yeni sahnede aynı platform olsun ve arka plan için bir varlık oluştur
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Block = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 1.0
});
self.canPush = function (direction, playerX) {
var newX = self.x + direction * 8;
var distance = Math.abs(self.x - playerX);
if (distance > 150) return false;
if (newX < 70 || newX > 1978) return false;
return true;
};
self.push = function (direction) {
if (self.canPush(direction, player.x)) {
var newX = self.x + direction * 8;
tween(self, {
x: newX
}, {
duration: 100
});
LK.getSound('blockMove').play();
}
};
return self;
});
var Door = Container.expand(function () {
var self = Container.call(this);
var doorGraphics = self.attachAsset('door', {
anchorX: 0.5,
anchorY: 1.0
});
self.isOpen = false;
self.alpha = 0.3;
self.open = function () {
self.isOpen = true;
tween(self, {
alpha: 1.0
}, {
duration: 500
});
};
self.close = function () {
self.isOpen = false;
tween(self, {
alpha: 0.3
}, {
duration: 500
});
};
self.down = function (x, y, obj) {
if (self.isOpen) {
nextLevel();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 8;
self.isMoving = false;
self.moveDirection = 0;
self.velocityY = 0;
self.isJumping = false;
self.jumpPower = -25;
self.gravity = 1.2;
self.groundY = self.y;
self.update = function () {
if (self.isMoving) {
var newX = self.x + self.moveDirection * self.speed;
// Check boundaries
if (newX >= 60 && newX <= 1988) {
// Check collision with block
var willCollide = false;
if (block) {
var blockLeft = block.x - 70;
var blockRight = block.x + 70;
var playerLeft = newX - 60;
var playerRight = newX + 60;
// Check if player and block are on same level and would overlap
if (Math.abs(self.y - block.y) < 100) {
if (playerRight > blockLeft && playerLeft < blockRight) {
willCollide = true;
}
}
}
if (!willCollide) {
self.x = newX;
}
}
}
// Handle jumping physics
if (self.isJumping || self.velocityY !== 0) {
self.velocityY += self.gravity;
self.y += self.velocityY;
// Check if landed
if (self.y >= self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
self.isJumping = false;
}
}
};
self.jump = function () {
if (!self.isJumping && self.velocityY === 0) {
self.velocityY = self.jumpPower;
self.isJumping = true;
}
};
return self;
});
var Signpost = Container.expand(function () {
var self = Container.call(this);
var signpostGraphics = self.attachAsset('signpost', {
anchorX: 0.5,
anchorY: 1.0
});
self.isActivated = false;
self.lastActivated = false;
self.checkActivation = function (block) {
var distance = Math.abs(self.x - block.x);
self.isActivated = distance < 80;
if (!self.lastActivated && self.isActivated) {
signpostGraphics.tint = 0x00ff00;
if (currentLevel >= 2) {
// Check if both signposts are activated for level 2+
var allActivated = signpost.isActivated && signpost2 && signpost2.isActivated;
if (allActivated) {
openDoor();
LK.getSound('doorOpen').play();
}
} else {
openDoor();
LK.getSound('doorOpen').play();
}
} else if (self.lastActivated && !self.isActivated) {
signpostGraphics.tint = 0xffd700;
closeDoor();
}
self.lastActivated = self.isActivated;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var currentLevel = storage.currentLevel || 1;
var player;
var block;
var signpost;
var signpost2;
var door;
var platform;
var background;
var isPlayerMoving = false;
var moveDirection = 0;
var levelText = new Text2('Level 1', {
size: 100,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
function setupLevel() {
if (background) background.destroy();
if (platform) platform.destroy();
if (player) player.destroy();
if (block) block.destroy();
if (signpost) signpost.destroy();
if (signpost2) signpost2.destroy();
if (door) door.destroy();
background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
platform = game.addChild(LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2000
}));
var levelOffset = (currentLevel - 1) * 200;
var baseY = 1920;
player = game.addChild(new Player());
player.x = 300 + currentLevel * 50;
player.y = baseY;
player.groundY = baseY;
block = game.addChild(new Block());
block.x = 600 + levelOffset;
block.y = baseY;
if (currentLevel >= 2) {
// Level 2 and beyond: create two signposts
signpost = game.addChild(new Signpost());
signpost.x = 1000;
signpost.y = baseY;
signpost2 = game.addChild(new Signpost());
signpost2.x = 1400;
signpost2.y = baseY;
} else {
// Level 1: single signpost
signpost = game.addChild(new Signpost());
signpost.x = 1200 + currentLevel * 100;
signpost.y = baseY;
}
door = game.addChild(new Door());
door.x = 1700;
door.y = baseY;
levelText.setText('Level ' + currentLevel);
}
function openDoor() {
if (currentLevel >= 2) {
// Level 2+: both signposts must be activated
if (signpost && signpost2 && signpost.isActivated && signpost2.isActivated) {
door.open();
}
} else {
// Level 1: single signpost
door.open();
}
}
function closeDoor() {
if (currentLevel >= 2) {
// Level 2+: close door if either signpost is deactivated
if (!signpost.isActivated || !signpost2.isActivated) {
door.close();
}
} else {
// Level 1: close door
door.close();
}
}
// Create control buttons
var leftButton = new Text2('◀', {
size: 120,
fill: 0xFFFFFF
});
leftButton.anchor.set(0.5, 0.5);
leftButton.alpha = 0.7;
var rightButton = new Text2('▶', {
size: 120,
fill: 0xFFFFFF
});
rightButton.anchor.set(0.5, 0.5);
rightButton.alpha = 0.7;
var jumpButton = new Text2('↑', {
size: 120,
fill: 0xFFFFFF
});
jumpButton.anchor.set(0.5, 0.5);
jumpButton.alpha = 0.7;
// Position buttons
LK.gui.bottomLeft.addChild(leftButton);
leftButton.x = 150;
leftButton.y = -150;
LK.gui.bottomLeft.addChild(rightButton);
rightButton.x = 270;
rightButton.y = -150;
LK.gui.bottomRight.addChild(jumpButton);
jumpButton.x = -150;
jumpButton.y = -150;
// Button event handlers
leftButton.down = function () {
moveDirection = -1;
isPlayerMoving = true;
player.isMoving = true;
player.moveDirection = moveDirection;
leftButton.alpha = 1.0;
};
leftButton.up = function () {
isPlayerMoving = false;
player.isMoving = false;
moveDirection = 0;
leftButton.alpha = 0.7;
};
rightButton.down = function () {
moveDirection = 1;
isPlayerMoving = true;
player.isMoving = true;
player.moveDirection = moveDirection;
rightButton.alpha = 1.0;
};
rightButton.up = function () {
isPlayerMoving = false;
player.isMoving = false;
moveDirection = 0;
rightButton.alpha = 0.7;
};
jumpButton.down = function () {
if (player) {
player.jump();
}
jumpButton.alpha = 1.0;
};
jumpButton.up = function () {
jumpButton.alpha = 0.7;
};
function nextLevel() {
currentLevel++;
storage.currentLevel = currentLevel;
LK.getSound('levelComplete').play();
LK.effects.flashScreen(0xffffff, 500);
LK.setTimeout(function () {
setupLevel();
}, 600);
}
game.down = function (x, y, obj) {
if (x < 1024) {
moveDirection = -1;
} else {
moveDirection = 1;
}
isPlayerMoving = true;
player.isMoving = true;
player.moveDirection = moveDirection;
};
game.up = function (x, y, obj) {
isPlayerMoving = false;
player.isMoving = false;
moveDirection = 0;
};
game.update = function () {
if (isPlayerMoving && moveDirection !== 0) {
var playerDistance = Math.abs(player.x - block.x);
if (playerDistance < 150) {
if (moveDirection > 0 && player.x < block.x) {
block.push(1);
} else if (moveDirection < 0 && player.x > block.x) {
block.push(-1);
}
}
}
if (signpost && block) {
signpost.checkActivation(block);
if (signpost2) {
signpost2.checkActivation(block);
}
}
};
setupLevel(); ===================================================================
--- original.js
+++ change.js
@@ -134,10 +134,19 @@
var distance = Math.abs(self.x - block.x);
self.isActivated = distance < 80;
if (!self.lastActivated && self.isActivated) {
signpostGraphics.tint = 0x00ff00;
- openDoor();
- LK.getSound('doorOpen').play();
+ if (currentLevel >= 2) {
+ // Check if both signposts are activated for level 2+
+ var allActivated = signpost.isActivated && signpost2 && signpost2.isActivated;
+ if (allActivated) {
+ openDoor();
+ LK.getSound('doorOpen').play();
+ }
+ } else {
+ openDoor();
+ LK.getSound('doorOpen').play();
+ }
} else if (self.lastActivated && !self.isActivated) {
signpostGraphics.tint = 0xffd700;
closeDoor();
}
@@ -159,8 +168,9 @@
var currentLevel = storage.currentLevel || 1;
var player;
var block;
var signpost;
+var signpost2;
var door;
var platform;
var background;
var isPlayerMoving = false;
@@ -176,8 +186,9 @@
if (platform) platform.destroy();
if (player) player.destroy();
if (block) block.destroy();
if (signpost) signpost.destroy();
+ if (signpost2) signpost2.destroy();
if (door) door.destroy();
background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
@@ -198,21 +209,48 @@
player.groundY = baseY;
block = game.addChild(new Block());
block.x = 600 + levelOffset;
block.y = baseY;
- signpost = game.addChild(new Signpost());
- signpost.x = 1200 + currentLevel * 100;
- signpost.y = baseY;
+ if (currentLevel >= 2) {
+ // Level 2 and beyond: create two signposts
+ signpost = game.addChild(new Signpost());
+ signpost.x = 1000;
+ signpost.y = baseY;
+ signpost2 = game.addChild(new Signpost());
+ signpost2.x = 1400;
+ signpost2.y = baseY;
+ } else {
+ // Level 1: single signpost
+ signpost = game.addChild(new Signpost());
+ signpost.x = 1200 + currentLevel * 100;
+ signpost.y = baseY;
+ }
door = game.addChild(new Door());
door.x = 1700;
door.y = baseY;
levelText.setText('Level ' + currentLevel);
}
function openDoor() {
- door.open();
+ if (currentLevel >= 2) {
+ // Level 2+: both signposts must be activated
+ if (signpost && signpost2 && signpost.isActivated && signpost2.isActivated) {
+ door.open();
+ }
+ } else {
+ // Level 1: single signpost
+ door.open();
+ }
}
function closeDoor() {
- door.close();
+ if (currentLevel >= 2) {
+ // Level 2+: close door if either signpost is deactivated
+ if (!signpost.isActivated || !signpost2.isActivated) {
+ door.close();
+ }
+ } else {
+ // Level 1: close door
+ door.close();
+ }
}
// Create control buttons
var leftButton = new Text2('◀', {
size: 120,
@@ -235,10 +273,10 @@
// Position buttons
LK.gui.bottomLeft.addChild(leftButton);
leftButton.x = 150;
leftButton.y = -150;
-LK.gui.bottom.addChild(rightButton);
-rightButton.x = 150;
+LK.gui.bottomLeft.addChild(rightButton);
+rightButton.x = 270;
rightButton.y = -150;
LK.gui.bottomRight.addChild(jumpButton);
jumpButton.x = -150;
jumpButton.y = -150;
@@ -314,7 +352,10 @@
}
}
if (signpost && block) {
signpost.checkActivation(block);
+ if (signpost2) {
+ signpost2.checkActivation(block);
+ }
}
};
setupLevel();
\ No newline at end of file