User prompt
Remove the fish from the game
User prompt
Do not let the fish to go above the penguin
User prompt
Allow the player to catch fish and add five points
User prompt
Let the game happen underwater
User prompt
Let the game end when penguin hits an obstacle or the player reaches 500
User prompt
Add the fish to the game and allow the penguins to catch them
User prompt
Animate the ocean
User prompt
Let the fish appear from the ocean
User prompt
Add the ocean
User prompt
Let the ocean be the background
User prompt
Add pingos to the game and allow the penguin to rest there
User prompt
Add pingos to be another obstacle that moves slowly
Code edit (2 edits merged)
Please save this source code
User prompt
Put water on the background
User prompt
Instead of blue background make it an ocean
User prompt
Play cool sounds once a penguin captures a fish
User prompt
Let the game elements move from left to right
User prompt
Make the coins to jump
User prompt
Make the fish jump up and down at random heights
User prompt
Add more coins moving from left to right
Code edit (1 edits merged)
Please save this source code
User prompt
Make the background 💙
User prompt
Let it end when it reaches 200 points
User prompt
Change the color of the background once the player hits 50 points
/**** * Classes ****/ // Coin class representing coins for the penguin to pick var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.value = 10; self.update = function () { self.x += self.speed; self.y += Math.sin(self.x / 100) * 10; // Add a sine wave movement to the y position if (self.x < -100) { self.destroy(); } }; }); // HighCoin class representing higher coins for the penguin to pick var HighCoin = Coin.expand(function () { var self = Coin.call(this); if (self) { self.value = 5; } }); // Level2Obstacle class representing level 2 obstacles on the path var Level2Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -7; // Increase speed for level 2 self.update = function () { self.x += self.speed; if (self.x < -100) { self.destroy(); } }; }); // Obstacle class representing obstacles on the path var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.x += self.speed; if (self.x < -100) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Penguin class representing the player character var Penguin = Container.expand(function () { var self = Container.call(this); var penguinGraphics = self.attachAsset('penguin', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpHeight = 55; self.isJumping = false; self.update = function () { if (self.isJumping) { self.y -= self.speed; if (self.y <= self.jumpHeight) { self.isJumping = false; self.jumpHeight = Math.random() * 200; // Randomize jump height between 0 and 200 } } else if (self.y < 2732 / 2) { self.y += self.speed; } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; } }; }); // Pingo class representing pingos for the penguin to rest var Pingo = Container.expand(function () { var self = Container.call(this); var pingoGraphics = self.attachAsset('pingo', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.x += self.speed; if (self.x < -100) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1E90FF // Set the background color to deep sky blue to represent an ocean }); /**** * Game Code ****/ // Initialize game variables var penguin = game.addChild(new Penguin()); penguin.x = 2048 / 2; penguin.y = 2732 / 2; var obstacles = []; var coins = []; var score = 0; var scoreTxt = new Text2('0', { size: 100, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var alternate = false; // Function to handle game updates game.update = function () { penguin.update(); for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); if (penguin.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } if (LK.ticks % 60 == 0) { var newObstacle = new Obstacle(); newObstacle.x = 2048; newObstacle.y = alternate ? 2732 / 3 : 2732 / 2; obstacles.push(newObstacle); game.addChild(newObstacle); alternate = !alternate; } // Add level 2 obstacles every 90 ticks if (LK.ticks % 90 == 0) { var newLevel2Obstacle = new Level2Obstacle(); newLevel2Obstacle.x = 2048; newLevel2Obstacle.y = alternate ? 2732 / 2 : 2732 / 3; obstacles.push(newLevel2Obstacle); game.addChild(newLevel2Obstacle); } // Add coins every 90 ticks if (LK.ticks % 90 == 0) { var newCoin = alternate ? new HighCoin() : new Coin(); newCoin.x = 2048; newCoin.y = alternate ? 2732 / 3 : 2732 / 2; // Position coins near the pingos coins.push(newCoin); game.addChild(newCoin); } // Add pingos every 180 ticks if (LK.ticks % 180 == 0) { var newPingo = new Pingo(); newPingo.x = 2048; newPingo.y = 2732 / 2; // Position pingos in the middle game.addChild(newPingo); } // Update the score when the penguin picks a coin for (var i = coins.length - 1; i >= 0; i--) { if (penguin.intersects(coins[i])) { score += coins[i].value; coins[i].destroy(); coins.splice(i, 1); // Play cool sound when penguin captures a fish LK.getSound('Cool').play(); } } scoreTxt.setText(score); }; // Event listener for touch down to make the penguin jump game.down = function (x, y, obj) { penguin.jump(); }; // Check if the penguin is on a pingo for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof Pingo && penguin.intersects(game.children[i])) { penguin.isJumping = false; // Allow the penguin to rest on the pingo } } // Change the color of the background once the player hits 50 points if (score >= 50) { game.setBackgroundColor(0x00FFFF); // Change the background color to blue } // Increase the speed of the obstacles and the coins once the user collects points worth 100 points if (score >= 100) { for (var i = 0; i < obstacles.length; i++) { obstacles[i].speed += 2; } for (var i = 0; i < coins.length; i++) { coins[i].speed += 2; } } // End the game when the player reaches 200 points if (score >= 100) { LK.showGameOver(); }
===================================================================
--- original.js
+++ change.js
@@ -82,16 +82,16 @@
self.isJumping = true;
}
};
});
-// Pingo class representing pingos as obstacles on the path
+// Pingo class representing pingos for the penguin to rest
var Pingo = Container.expand(function () {
var self = Container.call(this);
var pingoGraphics = self.attachAsset('pingo', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = -2; // Pingos move slower than other obstacles
+ self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
@@ -148,24 +148,23 @@
newLevel2Obstacle.y = alternate ? 2732 / 2 : 2732 / 3;
obstacles.push(newLevel2Obstacle);
game.addChild(newLevel2Obstacle);
}
- // Add pingos every 120 ticks
- if (LK.ticks % 120 == 0) {
- var newPingo = new Pingo();
- newPingo.x = 2048;
- newPingo.y = 2732 / 2;
- obstacles.push(newPingo);
- game.addChild(newPingo);
- }
// Add coins every 90 ticks
if (LK.ticks % 90 == 0) {
var newCoin = alternate ? new HighCoin() : new Coin();
newCoin.x = 2048;
newCoin.y = alternate ? 2732 / 3 : 2732 / 2; // Position coins near the pingos
coins.push(newCoin);
game.addChild(newCoin);
}
+ // Add pingos every 180 ticks
+ if (LK.ticks % 180 == 0) {
+ var newPingo = new Pingo();
+ newPingo.x = 2048;
+ newPingo.y = 2732 / 2; // Position pingos in the middle
+ game.addChild(newPingo);
+ }
// Update the score when the penguin picks a coin
for (var i = coins.length - 1; i >= 0; i--) {
if (penguin.intersects(coins[i])) {
score += coins[i].value;
@@ -180,8 +179,14 @@
// Event listener for touch down to make the penguin jump
game.down = function (x, y, obj) {
penguin.jump();
};
+// Check if the penguin is on a pingo
+for (var i = 0; i < game.children.length; i++) {
+ if (game.children[i] instanceof Pingo && penguin.intersects(game.children[i])) {
+ penguin.isJumping = false; // Allow the penguin to rest on the pingo
+ }
+}
// Change the color of the background once the player hits 50 points
if (score >= 50) {
game.setBackgroundColor(0x00FFFF); // Change the background color to blue
}