/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Monster = Container.expand(function () { var self = Container.call(this); var monsterGraphics = self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; // Monsters move to the left self.update = function () { self.x += self.speed; }; return self; }); //Library for using the camera (the background becomes the user's camera video feed) and the microphone. It can access face coordinates for interactive play, as well detect microphone volume / voice interactions // var facekit = LK.import('@upit/facekit.v1'); //Classes can only be defined here. You cannot create inline classes in the games code. var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.isJumping = false; self.velocityY = 0; self.gravity = 2; self.jumpStrength = -42; // Increased jump strength by 20% (-35 * 1.2 = -42) self.update = function () { self.x += self.speedX; // Move player horizontally if (self.isJumping) { self.y += self.velocityY; self.velocityY += self.gravity; // Check for landing on the platform if (self.y >= game.platformY - playerGraphics.height / 2) { self.y = game.platformY - playerGraphics.height / 2; self.isJumping = false; self.velocityY = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = self.jumpStrength; LK.getSound('jump').play(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0080ff }); /**** * Game Code ****/ // Create a single platform segment for the player to run on //Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property. //Only include the plugins you need to create the game. //We have access to the following plugins. (Note that the variable names used are mandetory for each plugin) // Initialize assets used in this game. Scale them according to what is needed for the game. // or via static code analysis based on their usage in the code. // Assets are automatically created and loaded either dynamically during gameplay /* Supported Types: 1. Shape: - Simple geometric figures with these properties: * width: (required) pixel width of the shape. * height: (required) pixel height of the shape. * color: (required) color of the shape. * shape: (required) type of shape. Valid options: 'box', 'ellipse'. 2. Image: - Imported images with these properties: * width: (required) pixel resolution width. * height: (required) pixel resolution height. * id: (required) identifier for the image. * flipX: (optional) horizontal flip. Valid values: 0 (no flip), 1 (flip). * flipY: (optional) vertical flip. Valid values: 0 (no flip), 1 (flip). * orientation: (optional) rotation in multiples of 90 degrees, clockwise. Valid values: - 0: No rotation. - 1: Rotate 90 degrees. - 2: Rotate 180 degrees. - 3: Rotate 270 degrees. Note: Width and height remain unchanged upon flipping. 3. Sound: - Sound effects with these properties: * id: (required) identifier for the sound. * volume: (optional) custom volume. Valid values are a float from 0 to 1. 4. Music: - In contract to sound effects, only one music can be played at a time - Music is using the same API to initilize just like sound. - Music loops by default - Music with these config options: * id: (required) identifier for the sound. * volume: (optional) custom volume. Valid values are a float from 0 to 1. * start: (optional) a float from 0 to 1 used for cropping and indicates the start of the cropping * end: (optional) a float from 0 to 1 used for cropping and indicates the end of the cropping */ //Note game dimensions are 2048x2732 // Create a visually richer platform by stacking several platform segments with slight offsets and tints var platform = game.addChild(LK.getAsset('platform', { x: 2048 / 2, y: 2732 - 50 / 2, anchorX: 0.5, anchorY: 0.5 })); game.platformY = platform.y - platform.height / 2; // Y-coordinate of the top of the platform var player = game.addChild(new Player()); player.x = 200; player.y = game.platformY - player.height / 2; // Position player on the platform player.speedX = 10; // Add horizontal speed property game.nextPlatformX = 2048; // Initialize the x-coordinate for the next platform segment var monsters = []; var scoreTxt = new Text2(LK.getScore(), { size: 150, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreTxt); scoreTxt.anchor.set(0.5, 0); // Center horizontally, top edge scoreTxt.x = 2048 / 2; scoreTxt.y = 0; // Monster passed counter var monstersPassed = 0; var monstersPassedTxt = new Text2('0', { size: 100, fill: 0xFFFF00 }); LK.gui.topRight.addChild(monstersPassedTxt); monstersPassedTxt.anchor.set(1, 0); // right-top monstersPassedTxt.x = 0; monstersPassedTxt.y = 0; var monsterSpawnTimer = LK.setInterval(function () { var newMonster = new Monster(); // Spawn at a random X position ahead of the player, within a range (e.g. 2048 to 2048+1500) var minX = player.x + 1024; var maxX = player.x + 2048; newMonster.x = minX + Math.random() * (maxX - minX); newMonster.y = game.platformY - newMonster.height / 2; // Position on the platform monsters.push(newMonster); game.addChild(newMonster); }, 1000 + Math.random() * 1000); // Spawn a monster every 1-2 seconds randomly game.down = function (x, y, obj) { player.jump(); }; game.update = function () { // Score is now updated only when a monster is passed, not every frame scoreTxt.setText(LK.getScore()); // Follow the player character game.x = -player.x + 2048 / 4; // Offset to keep player centered, but allow seeing ahead // Pre-generate a single platform segment ahead of the player for smoother loading while (player.x > game.nextPlatformX - 2048 / 2) { var newPlatformSegment = game.addChild(LK.getAsset('platform', { x: game.nextPlatformX + 2048 / 2, y: 2732 - 50 / 2, anchorX: 0.5, anchorY: 0.5 })); game.nextPlatformX += 2048; // Update the position for the next platform segment } for (var i = monsters.length - 1; i >= 0; i--) { var monster = monsters[i]; // Track if monster was already passed if (monster.lastX === undefined) { monster.lastX = monster.x; } // Check if player has just passed the monster (player's left side just passed monster's right side) if (monster.lastX >= player.x && monster.x < player.x) { monstersPassed++; monstersPassedTxt.setText(monstersPassed + " canavar geçtim"); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); } // Remove monsters that go off screen if (monster.x < player.x - 2048 / 2 - monster.width / 2) { // Check if off screen relative to the camera monster.destroy(); monsters.splice(i, 1); continue; } // Check for collision with player if (player.intersects(monster)) { LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); } monster.lastX = monster.x; } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Monster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('monster', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10; // Monsters move to the left
self.update = function () {
self.x += self.speed;
};
return self;
});
//Library for using the camera (the background becomes the user's camera video feed) and the microphone. It can access face coordinates for interactive play, as well detect microphone volume / voice interactions
// var facekit = LK.import('@upit/facekit.v1');
//Classes can only be defined here. You cannot create inline classes in the games code.
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.isJumping = false;
self.velocityY = 0;
self.gravity = 2;
self.jumpStrength = -42; // Increased jump strength by 20% (-35 * 1.2 = -42)
self.update = function () {
self.x += self.speedX; // Move player horizontally
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += self.gravity;
// Check for landing on the platform
if (self.y >= game.platformY - playerGraphics.height / 2) {
self.y = game.platformY - playerGraphics.height / 2;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = self.jumpStrength;
LK.getSound('jump').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0080ff
});
/****
* Game Code
****/
// Create a single platform segment for the player to run on
//Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property.
//Only include the plugins you need to create the game.
//We have access to the following plugins. (Note that the variable names used are mandetory for each plugin)
// Initialize assets used in this game. Scale them according to what is needed for the game.
// or via static code analysis based on their usage in the code.
// Assets are automatically created and loaded either dynamically during gameplay
/*
Supported Types:
1. Shape:
- Simple geometric figures with these properties:
* width: (required) pixel width of the shape.
* height: (required) pixel height of the shape.
* color: (required) color of the shape.
* shape: (required) type of shape. Valid options: 'box', 'ellipse'.
2. Image:
- Imported images with these properties:
* width: (required) pixel resolution width.
* height: (required) pixel resolution height.
* id: (required) identifier for the image.
* flipX: (optional) horizontal flip. Valid values: 0 (no flip), 1 (flip).
* flipY: (optional) vertical flip. Valid values: 0 (no flip), 1 (flip).
* orientation: (optional) rotation in multiples of 90 degrees, clockwise. Valid values:
- 0: No rotation.
- 1: Rotate 90 degrees.
- 2: Rotate 180 degrees.
- 3: Rotate 270 degrees.
Note: Width and height remain unchanged upon flipping.
3. Sound:
- Sound effects with these properties:
* id: (required) identifier for the sound.
* volume: (optional) custom volume. Valid values are a float from 0 to 1.
4. Music:
- In contract to sound effects, only one music can be played at a time
- Music is using the same API to initilize just like sound.
- Music loops by default
- Music with these config options:
* id: (required) identifier for the sound.
* volume: (optional) custom volume. Valid values are a float from 0 to 1.
* start: (optional) a float from 0 to 1 used for cropping and indicates the start of the cropping
* end: (optional) a float from 0 to 1 used for cropping and indicates the end of the cropping
*/
//Note game dimensions are 2048x2732
// Create a visually richer platform by stacking several platform segments with slight offsets and tints
var platform = game.addChild(LK.getAsset('platform', {
x: 2048 / 2,
y: 2732 - 50 / 2,
anchorX: 0.5,
anchorY: 0.5
}));
game.platformY = platform.y - platform.height / 2; // Y-coordinate of the top of the platform
var player = game.addChild(new Player());
player.x = 200;
player.y = game.platformY - player.height / 2; // Position player on the platform
player.speedX = 10; // Add horizontal speed property
game.nextPlatformX = 2048; // Initialize the x-coordinate for the next platform segment
var monsters = [];
var scoreTxt = new Text2(LK.getScore(), {
size: 150,
fill: 0xFFFFFF
});
LK.gui.top.addChild(scoreTxt);
scoreTxt.anchor.set(0.5, 0); // Center horizontally, top edge
scoreTxt.x = 2048 / 2;
scoreTxt.y = 0;
// Monster passed counter
var monstersPassed = 0;
var monstersPassedTxt = new Text2('0', {
size: 100,
fill: 0xFFFF00
});
LK.gui.topRight.addChild(monstersPassedTxt);
monstersPassedTxt.anchor.set(1, 0); // right-top
monstersPassedTxt.x = 0;
monstersPassedTxt.y = 0;
var monsterSpawnTimer = LK.setInterval(function () {
var newMonster = new Monster();
// Spawn at a random X position ahead of the player, within a range (e.g. 2048 to 2048+1500)
var minX = player.x + 1024;
var maxX = player.x + 2048;
newMonster.x = minX + Math.random() * (maxX - minX);
newMonster.y = game.platformY - newMonster.height / 2; // Position on the platform
monsters.push(newMonster);
game.addChild(newMonster);
}, 1000 + Math.random() * 1000); // Spawn a monster every 1-2 seconds randomly
game.down = function (x, y, obj) {
player.jump();
};
game.update = function () {
// Score is now updated only when a monster is passed, not every frame
scoreTxt.setText(LK.getScore());
// Follow the player character
game.x = -player.x + 2048 / 4; // Offset to keep player centered, but allow seeing ahead
// Pre-generate a single platform segment ahead of the player for smoother loading
while (player.x > game.nextPlatformX - 2048 / 2) {
var newPlatformSegment = game.addChild(LK.getAsset('platform', {
x: game.nextPlatformX + 2048 / 2,
y: 2732 - 50 / 2,
anchorX: 0.5,
anchorY: 0.5
}));
game.nextPlatformX += 2048; // Update the position for the next platform segment
}
for (var i = monsters.length - 1; i >= 0; i--) {
var monster = monsters[i];
// Track if monster was already passed
if (monster.lastX === undefined) {
monster.lastX = monster.x;
}
// Check if player has just passed the monster (player's left side just passed monster's right side)
if (monster.lastX >= player.x && monster.x < player.x) {
monstersPassed++;
monstersPassedTxt.setText(monstersPassed + " canavar geçtim");
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
// Remove monsters that go off screen
if (monster.x < player.x - 2048 / 2 - monster.width / 2) {
// Check if off screen relative to the camera
monster.destroy();
monsters.splice(i, 1);
continue;
}
// Check for collision with player
if (player.intersects(monster)) {
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
}
monster.lastX = monster.x;
}
};