/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); var facekit = LK.import("@upit/facekit.v1"); /**** * Classes ****/ //Classes can only be defined here. You cannot create inline classes in the games code. var Fox = Container.expand(function () { var self = Container.call(this); //Create and attach asset. This is the same as calling var xxx = self.addChild(LK.getAsset(...)) var foxGraphics = self.attachAsset('fox', { anchorX: 0.5, anchorY: 0.5 }); //Set fox speed self.speed = 2; // Initial fox speed self.scoreValue = 1; // Points gained for scaring a fox //Event handler called when a press happens on element. This is automatically called on press if character is attached. //Do not call this from the game source code as well. self.down = function (x, y, obj) { LK.setScore(LK.getScore() + self.scoreValue); scoreTxt.setText(LK.getScore()); self.destroy(); // Destroy the fox when clicked LK.getSound('scare').play(); // Play scare sound // Find the index of the destroyed fox in the foxes array and remove it var index = foxes.indexOf(self); if (index > -1) { foxes.splice(index, 1); } }; //If this instance of bullet is attached, this method will be called every tick by the LK engine automatically. //To not manually call .updated methods. If you want to manually call a method every tick on a class, use a different name than update. //As .update is called from the LK engine directly, .update cannot have method arguments. self.update = function () { // Move the fox towards the toilet var angle = Math.atan2(toilet.y - self.y, toilet.x - self.x); self.x += Math.cos(angle) * self.speed; self.y += Math.sin(angle) * self.speed; }; return self; //You must return self if you want other classes to be able to inherit from this class }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 // Init game with forest green background }); /**** * Game Code ****/ //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 //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) // Orange color for foxes // 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 //Note game dimensions are 2048x2732 //Change background color game.setBackgroundColor(0x228B22); //Change background color to forest green var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF //Optional (this is the default string) //font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", //Optional (this is the default string) }); // Update and display the score in the game. scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start. // Center the score text horizontally, anchor point set at the middle of its top edge. scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text. // Define valid targets for positioning GUI elements: // gui.topLeft: Position at top-left corner (x=0, y=0). // gui.top: Position at top-center (x=width/2, y=0). // gui.topRight: Position at top-right corner (x=width, y=0). // gui.left: Position at middle-left (x=0, y=height/2). // gui.center: Position at center (x=width/2, y=height/2). // gui.right: Position at middle-right (x=width, y=height/2). // gui.bottomLeft: Position at bottom-left corner (x=0, y=height). // gui.bottom: Position at bottom-center (x=width/2, y=height). // gui.bottomRight: Position at bottom-right corner (x=width, y=height). // Add the score text to the GUI overlay. // The score text is attached to the top-center of the screen. // Use LK.gui for overlaying interface elements that should be on top of the game scene. // LK.gui does not have the same resolution as Game to allow for dynamically scaled GUI. Therefore take care to position elements relative to the core GUI targets. LK.gui.top.addChild(scoreTxt); // Create the toilet object and position it at the bottom center var toilet = LK.getAsset('toilet', { anchorX: 0.5, anchorY: 1.0, x: 2048 / 2, y: 2732 }); game.addChild(toilet); //Keep track of similar elements using arrays in the main 'Game' class var foxes = []; // Timer to spawn foxes var foxSpawnTimer = LK.setInterval(function () { // Spawn a new fox from a random position at the top of the screen var newFox = new Fox(); newFox.x = Math.random() * 2048; newFox.y = -100; // Start above the screen foxes.push(newFox); game.addChild(newFox); }, 1000); // Spawn a fox every second // Ask LK engine to update game every game tick game.update = function () { // Always call move and tick methods from the main tick method in the 'Game' class. for (var i = foxes.length - 1; i >= 0; i--) { var fox = foxes[i]; // Check if fox reached the toilet if (fox.y >= toilet.y - toilet.height / 2 && fox.intersects(toilet)) { // Fox reached the toilet, game over LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second LK.showGameOver(); // Show game over fox.destroy(); foxes.splice(i, 1); continue; } } }; // Play music track with these musicOptions: /* * loop: (optional) a boolean which indicates if to loop the music track. Default is true and doesn't need to be passed if the track should be looping. * fade: (optional) an object {fade: start: Number Volume to fade from (0.0 to 1.0), end: Number Volume to fade to (0.0 to 1.0), duration: number in miliseconds to fade} } */ // LK.playMusic('bgmusic'); // Assuming you have a 'bgmusic' asset initialized
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,133 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+var facekit = LK.import("@upit/facekit.v1");
+
+/****
+* Classes
+****/
+//Classes can only be defined here. You cannot create inline classes in the games code.
+var Fox = Container.expand(function () {
+ var self = Container.call(this);
+ //Create and attach asset. This is the same as calling var xxx = self.addChild(LK.getAsset(...))
+ var foxGraphics = self.attachAsset('fox', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ //Set fox speed
+ self.speed = 2; // Initial fox speed
+ self.scoreValue = 1; // Points gained for scaring a fox
+ //Event handler called when a press happens on element. This is automatically called on press if character is attached.
+ //Do not call this from the game source code as well.
+ self.down = function (x, y, obj) {
+ LK.setScore(LK.getScore() + self.scoreValue);
+ scoreTxt.setText(LK.getScore());
+ self.destroy(); // Destroy the fox when clicked
+ LK.getSound('scare').play(); // Play scare sound
+ // Find the index of the destroyed fox in the foxes array and remove it
+ var index = foxes.indexOf(self);
+ if (index > -1) {
+ foxes.splice(index, 1);
+ }
+ };
+ //If this instance of bullet is attached, this method will be called every tick by the LK engine automatically.
+ //To not manually call .updated methods. If you want to manually call a method every tick on a class, use a different name than update.
+ //As .update is called from the LK engine directly, .update cannot have method arguments.
+ self.update = function () {
+ // Move the fox towards the toilet
+ var angle = Math.atan2(toilet.y - self.y, toilet.x - self.x);
+ self.x += Math.cos(angle) * self.speed;
+ self.y += Math.sin(angle) * self.speed;
+ };
+ return self; //You must return self if you want other classes to be able to inherit from this class
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x228B22 // Init game with forest green background
+});
+
+/****
+* Game Code
+****/
+//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
+//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)
+// Orange color for foxes
+// 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
+//Note game dimensions are 2048x2732
+//Change background color
+game.setBackgroundColor(0x228B22); //Change background color to forest green
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: 0xFFFFFF //Optional (this is the default string)
+ //font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", //Optional (this is the default string)
+});
+// Update and display the score in the game.
+scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start.
+// Center the score text horizontally, anchor point set at the middle of its top edge.
+scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text.
+// Define valid targets for positioning GUI elements:
+// gui.topLeft: Position at top-left corner (x=0, y=0).
+// gui.top: Position at top-center (x=width/2, y=0).
+// gui.topRight: Position at top-right corner (x=width, y=0).
+// gui.left: Position at middle-left (x=0, y=height/2).
+// gui.center: Position at center (x=width/2, y=height/2).
+// gui.right: Position at middle-right (x=width, y=height/2).
+// gui.bottomLeft: Position at bottom-left corner (x=0, y=height).
+// gui.bottom: Position at bottom-center (x=width/2, y=height).
+// gui.bottomRight: Position at bottom-right corner (x=width, y=height).
+// Add the score text to the GUI overlay.
+// The score text is attached to the top-center of the screen.
+// Use LK.gui for overlaying interface elements that should be on top of the game scene.
+// LK.gui does not have the same resolution as Game to allow for dynamically scaled GUI. Therefore take care to position elements relative to the core GUI targets.
+LK.gui.top.addChild(scoreTxt);
+// Create the toilet object and position it at the bottom center
+var toilet = LK.getAsset('toilet', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ x: 2048 / 2,
+ y: 2732
+});
+game.addChild(toilet);
+//Keep track of similar elements using arrays in the main 'Game' class
+var foxes = [];
+// Timer to spawn foxes
+var foxSpawnTimer = LK.setInterval(function () {
+ // Spawn a new fox from a random position at the top of the screen
+ var newFox = new Fox();
+ newFox.x = Math.random() * 2048;
+ newFox.y = -100; // Start above the screen
+ foxes.push(newFox);
+ game.addChild(newFox);
+}, 1000); // Spawn a fox every second
+// Ask LK engine to update game every game tick
+game.update = function () {
+ // Always call move and tick methods from the main tick method in the 'Game' class.
+ for (var i = foxes.length - 1; i >= 0; i--) {
+ var fox = foxes[i];
+ // Check if fox reached the toilet
+ if (fox.y >= toilet.y - toilet.height / 2 && fox.intersects(toilet)) {
+ // Fox reached the toilet, game over
+ LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second
+ LK.showGameOver(); // Show game over
+ fox.destroy();
+ foxes.splice(i, 1);
+ continue;
+ }
+ }
+};
+// Play music track with these musicOptions:
+/*
+ * loop: (optional) a boolean which indicates if to loop the music track. Default is true and doesn't need to be passed if the track should be looping.
+ * fade: (optional) an object {fade: start: Number Volume to fade from (0.0 to 1.0), end: Number Volume to fade to (0.0 to 1.0), duration: number in miliseconds to fade} }
+*/
+// LK.playMusic('bgmusic'); // Assuming you have a 'bgmusic' asset initialized
\ No newline at end of file
A bathroom with a pink toilet. In-Game asset. 2d. High contrast. No shadows
Make a toilet with a small bit of water leaking of the side. In-Game asset. 2d. High contrast. No shadows. Realistic
Make a realistic fox that is sooooo cute. In-Game asset. 2d. High contrast. No shadows. Realistic
Add a Minecraft emerald sword.