/**** * 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 = -35; self.update = function () { 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: 0x444444 // Init game with grey background }); /**** * Game Code ****/ //Storage library which should be used for persistent game data //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 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 var monsters = []; var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreTxt); scoreTxt.x = 2048 / 2; var monsterSpawnTimer = LK.setInterval(function () { var newMonster = new Monster(); newMonster.x = 2048 + newMonster.width / 2; // Start off screen to the right newMonster.y = game.platformY - newMonster.height / 2; // Position on the platform monsters.push(newMonster); game.addChild(newMonster); }, 1500); // Spawn a monster every 1.5 seconds game.down = function (x, y, obj) { player.jump(); }; game.update = function () { // Update score based on distance traveled (simple time-based score for now) LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); for (var i = monsters.length - 1; i >= 0; i--) { var monster = monsters[i]; // Remove monsters that go off screen if (monster.x < -monster.width / 2) { monster.destroy(); monsters.splice(i, 1); continue; } // Check for collision with player if (player.intersects(monster)) { LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); } } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,155 @@
-/****
+/****
+* 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 = -35;
+ self.update = function () {
+ 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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x444444 // Init game with grey background
+});
+
+/****
+* Game Code
+****/
+//Storage library which should be used for persistent game data
+//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
+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
+var monsters = [];
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: 0xFFFFFF
+});
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.x = 2048 / 2;
+var monsterSpawnTimer = LK.setInterval(function () {
+ var newMonster = new Monster();
+ newMonster.x = 2048 + newMonster.width / 2; // Start off screen to the right
+ newMonster.y = game.platformY - newMonster.height / 2; // Position on the platform
+ monsters.push(newMonster);
+ game.addChild(newMonster);
+}, 1500); // Spawn a monster every 1.5 seconds
+game.down = function (x, y, obj) {
+ player.jump();
+};
+game.update = function () {
+ // Update score based on distance traveled (simple time-based score for now)
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ for (var i = monsters.length - 1; i >= 0; i--) {
+ var monster = monsters[i];
+ // Remove monsters that go off screen
+ if (monster.x < -monster.width / 2) {
+ monster.destroy();
+ monsters.splice(i, 1);
+ continue;
+ }
+ // Check for collision with player
+ if (player.intersects(monster)) {
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ }
+ }
+};
\ No newline at end of file