/****
* Classes
****/
var ControlButton = Container.expand(function (type) {
var self = Container.call(this);
self.buttonType = type;
self.isPressed = false;
var buttonGraphics;
if (type === 'jump') {
buttonGraphics = self.attachAsset('jumpButton', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
buttonGraphics = self.attachAsset(type === 'left' ? 'leftButton' : 'rightButton', {
anchorX: 0.5,
anchorY: 0.5
});
}
self.down = function (x, y, obj) {
self.isPressed = true;
buttonGraphics.alpha = 0.7;
};
self.up = function (x, y, obj) {
self.isPressed = false;
buttonGraphics.alpha = 1.0;
};
return self;
});
var Platform = Container.expand(function (width, height) {
var self = Container.call(this);
self.platformWidth = width || 300;
self.platformHeight = height || 40;
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: self.platformWidth / 300,
scaleY: self.platformHeight / 40
});
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.speed = 8;
self.jumpPower = 20;
self.gravity = 0.8;
self.onGround = false;
self.maxFallSpeed = 15;
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;
}
};
self.stopHorizontalMovement = function () {
self.velocityX = 0;
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
// Limit fall speed
if (self.velocityY > self.maxFallSpeed) {
self.velocityY = self.maxFallSpeed;
}
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Keep player within screen bounds horizontally
if (self.x < 40) {
self.x = 40;
}
if (self.x > 2008) {
self.x = 2008;
}
// Reset onGround flag
self.onGround = false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var player = game.addChild(new Player());
player.x = 1024;
player.y = 2500;
var platforms = [];
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 1.0
}));
ground.x = 1024;
ground.y = 2732;
// Create platforms
var platformData = [{
x: 400,
y: 2400,
width: 200
}, {
x: 800,
y: 2200,
width: 250
}, {
x: 1200,
y: 2000,
width: 200
}, {
x: 600,
y: 1800,
width: 300
}, {
x: 1400,
y: 1600,
width: 200
}, {
x: 300,
y: 1400,
width: 250
}, {
x: 1000,
y: 1200,
width: 300
}, {
x: 1600,
y: 1000,
width: 200
}];
for (var i = 0; i < platformData.length; i++) {
var platformInfo = platformData[i];
var platform = game.addChild(new Platform(platformInfo.width));
platform.x = platformInfo.x;
platform.y = platformInfo.y;
platforms.push(platform);
}
// Control buttons
var leftButton = LK.gui.bottomLeft.addChild(new ControlButton('left'));
leftButton.x = 80;
leftButton.y = -80;
var rightButton = LK.gui.bottomLeft.addChild(new ControlButton('right'));
rightButton.x = 220;
rightButton.y = -80;
var jumpButton = LK.gui.bottomRight.addChild(new ControlButton('jump'));
jumpButton.x = -80;
jumpButton.y = -80;
// Control button labels
var leftLabel = new Text2('←', {
size: 60,
fill: 0xFFFFFF
});
leftLabel.anchor.set(0.5, 0.5);
leftButton.addChild(leftLabel);
var rightLabel = new Text2('→', {
size: 60,
fill: 0xFFFFFF
});
rightLabel.anchor.set(0.5, 0.5);
rightButton.addChild(rightLabel);
var jumpLabel = new Text2('↑', {
size: 60,
fill: 0xFFFFFF
});
jumpLabel.anchor.set(0.5, 0.5);
jumpButton.addChild(jumpLabel);
function checkCollisions() {
var playerBottom = player.y;
var playerTop = player.y - 80;
var playerLeft = player.x - 40;
var playerRight = player.x + 40;
// Check ground collision
if (playerBottom >= ground.y - 50) {
if (player.velocityY > 0) {
player.y = ground.y - 50;
player.velocityY = 0;
player.onGround = true;
}
}
// Check platform collisions
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
var platformLeft = platform.x - platform.platformWidth / 2;
var platformRight = platform.x + platform.platformWidth / 2;
var platformTop = platform.y - platform.platformHeight / 2;
var platformBottom = platform.y + platform.platformHeight / 2;
// Check if player is horizontally aligned with platform
if (playerRight > platformLeft && playerLeft < platformRight) {
// Check if player is falling onto platform from above
if (player.velocityY > 0 && playerBottom >= platformTop && playerTop < platformTop) {
player.y = platformTop;
player.velocityY = 0;
player.onGround = true;
}
}
}
}
game.update = function () {
// Handle input
if (leftButton.isPressed) {
player.moveLeft();
} else if (rightButton.isPressed) {
player.moveRight();
} else {
player.stopHorizontalMovement();
}
if (jumpButton.isPressed) {
player.jump();
}
// Check collisions
checkCollisions();
// Check if player fell off screen
if (player.y > 2800) {
// Reset player position
player.x = 1024;
player.y = 2500;
player.velocityX = 0;
player.velocityY = 0;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,236 @@
-/****
+/****
+* Classes
+****/
+var ControlButton = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.buttonType = type;
+ self.isPressed = false;
+ var buttonGraphics;
+ if (type === 'jump') {
+ buttonGraphics = self.attachAsset('jumpButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else {
+ buttonGraphics = self.attachAsset(type === 'left' ? 'leftButton' : 'rightButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ self.down = function (x, y, obj) {
+ self.isPressed = true;
+ buttonGraphics.alpha = 0.7;
+ };
+ self.up = function (x, y, obj) {
+ self.isPressed = false;
+ buttonGraphics.alpha = 1.0;
+ };
+ return self;
+});
+var Platform = Container.expand(function (width, height) {
+ var self = Container.call(this);
+ self.platformWidth = width || 300;
+ self.platformHeight = height || 40;
+ var platformGraphics = self.attachAsset('platform', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: self.platformWidth / 300,
+ scaleY: self.platformHeight / 40
+ });
+ 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.speed = 8;
+ self.jumpPower = 20;
+ self.gravity = 0.8;
+ self.onGround = false;
+ self.maxFallSpeed = 15;
+ 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;
+ }
+ };
+ self.stopHorizontalMovement = function () {
+ self.velocityX = 0;
+ };
+ self.update = function () {
+ // Apply gravity
+ self.velocityY += self.gravity;
+ // Limit fall speed
+ if (self.velocityY > self.maxFallSpeed) {
+ self.velocityY = self.maxFallSpeed;
+ }
+ // Update position
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ // Keep player within screen bounds horizontally
+ if (self.x < 40) {
+ self.x = 40;
+ }
+ if (self.x > 2008) {
+ self.x = 2008;
+ }
+ // Reset onGround flag
+ self.onGround = false;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+var player = game.addChild(new Player());
+player.x = 1024;
+player.y = 2500;
+var platforms = [];
+var ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 1.0
+}));
+ground.x = 1024;
+ground.y = 2732;
+// Create platforms
+var platformData = [{
+ x: 400,
+ y: 2400,
+ width: 200
+}, {
+ x: 800,
+ y: 2200,
+ width: 250
+}, {
+ x: 1200,
+ y: 2000,
+ width: 200
+}, {
+ x: 600,
+ y: 1800,
+ width: 300
+}, {
+ x: 1400,
+ y: 1600,
+ width: 200
+}, {
+ x: 300,
+ y: 1400,
+ width: 250
+}, {
+ x: 1000,
+ y: 1200,
+ width: 300
+}, {
+ x: 1600,
+ y: 1000,
+ width: 200
+}];
+for (var i = 0; i < platformData.length; i++) {
+ var platformInfo = platformData[i];
+ var platform = game.addChild(new Platform(platformInfo.width));
+ platform.x = platformInfo.x;
+ platform.y = platformInfo.y;
+ platforms.push(platform);
+}
+// Control buttons
+var leftButton = LK.gui.bottomLeft.addChild(new ControlButton('left'));
+leftButton.x = 80;
+leftButton.y = -80;
+var rightButton = LK.gui.bottomLeft.addChild(new ControlButton('right'));
+rightButton.x = 220;
+rightButton.y = -80;
+var jumpButton = LK.gui.bottomRight.addChild(new ControlButton('jump'));
+jumpButton.x = -80;
+jumpButton.y = -80;
+// Control button labels
+var leftLabel = new Text2('←', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+leftLabel.anchor.set(0.5, 0.5);
+leftButton.addChild(leftLabel);
+var rightLabel = new Text2('→', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+rightLabel.anchor.set(0.5, 0.5);
+rightButton.addChild(rightLabel);
+var jumpLabel = new Text2('↑', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+jumpLabel.anchor.set(0.5, 0.5);
+jumpButton.addChild(jumpLabel);
+function checkCollisions() {
+ var playerBottom = player.y;
+ var playerTop = player.y - 80;
+ var playerLeft = player.x - 40;
+ var playerRight = player.x + 40;
+ // Check ground collision
+ if (playerBottom >= ground.y - 50) {
+ if (player.velocityY > 0) {
+ player.y = ground.y - 50;
+ player.velocityY = 0;
+ player.onGround = true;
+ }
+ }
+ // Check platform collisions
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ var platformLeft = platform.x - platform.platformWidth / 2;
+ var platformRight = platform.x + platform.platformWidth / 2;
+ var platformTop = platform.y - platform.platformHeight / 2;
+ var platformBottom = platform.y + platform.platformHeight / 2;
+ // Check if player is horizontally aligned with platform
+ if (playerRight > platformLeft && playerLeft < platformRight) {
+ // Check if player is falling onto platform from above
+ if (player.velocityY > 0 && playerBottom >= platformTop && playerTop < platformTop) {
+ player.y = platformTop;
+ player.velocityY = 0;
+ player.onGround = true;
+ }
+ }
+ }
+}
+game.update = function () {
+ // Handle input
+ if (leftButton.isPressed) {
+ player.moveLeft();
+ } else if (rightButton.isPressed) {
+ player.moveRight();
+ } else {
+ player.stopHorizontalMovement();
+ }
+ if (jumpButton.isPressed) {
+ player.jump();
+ }
+ // Check collisions
+ checkCollisions();
+ // Check if player fell off screen
+ if (player.y > 2800) {
+ // Reset player position
+ player.x = 1024;
+ player.y = 2500;
+ player.velocityX = 0;
+ player.velocityY = 0;
+ }
+};
\ No newline at end of file
Poder de saltó. In-Game asset. 2d. High contrast. No shadows
Slow fall. In-Game asset. 2d. High contrast. No shadows
Paracaídas. In-Game asset. 2d. High contrast. No shadows
Flecha hacia la derecha. In-Game asset. 2d. High contrast. No shadows
Botas de super salto. In-Game asset. 2d. High contrast. No shadows
Cubo de slime con cara feliz. In-Game asset. 2d. High contrast. No shadows