Code edit (2 edits merged)
Please save this source code
User prompt
Create a score multiplier, so that as time goes on the player gets more points from enemies (including golden sausages and onions)
User prompt
Make it so that if an onion touches the bottom it takes 10 points away from the player
Code edit (3 edits merged)
Please save this source code
User prompt
Remove the lives counter
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: livesTxt is not defined' in or related to this line: 'livesTxt.setText(lives.toString());' Line Number: 115
User prompt
fix the code so that golden sausages give ten points
User prompt
Make it so that the skin of the hero when he has all of his lives is the base skin "hero"
User prompt
make it so that the hero changes appearance each time he loses a life. There should be 5 appearances, which correspond to these number of lives left : 1, 2, 3, 4, 5.
User prompt
Keep the lives system but delete the visible counter
User prompt
Put the lives counter at the bottom right of the game
Code edit (2 edits merged)
Please save this source code
User prompt
Move the lives counter slightly to the Right and change its color to red
Code edit (1 edits merged)
Please save this source code
User prompt
Add a life system. The player starts with 5 lives. When an onion hits the bottom of the screen, the player loses a life. Other enemies don't affect it.
User prompt
Add a new enemy, the onion. It has the same properties as the sausage except it is worth 5 points. It has a 1 in 50 chance of spawning.
Code edit (1 edits merged)
Please save this source code
User prompt
Make it so that the sausages' fall speed slowly increases with time
User prompt
The background isn't currently working as it is invisible. Fix it.
User prompt
make it so that points also count when sausages hit the player
User prompt
Move the score tab to the middle top of the screen
User prompt
make the game slightly wider
User prompt
add a golden sausage explosion to the golden sausage for when it is hit
User prompt
make it so that sausages explode when they touch the hero
/**** * Classes ****/ var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5 }); self.scaleX = 0; self.scaleY = 0; self.animate = function () { if (self.scaleX < 1) { self.scaleX += 0.1; self.scaleY += 0.1; } else { self.destroy(); } }; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 30; self.moveLeft = function () { self.x = Math.max(self.width / 2, self.x - self.speed); }; self.moveRight = function () { self.x = Math.min(2048 - self.width / 2, self.x + self.speed); }; self.poweredUp = false; self.powerUpTimer = null; self.shoot = function () { var bullets = []; if (self.poweredUp) { // Power-up effect will be handled in the Bullet class } else { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2; if (self.poweredUp) { bullet.applyPowerUp(); } game.addChild(bullet); bullets.push(bullet); } return bullets; }; self.activatePowerUp = function () { self.poweredUp = true; if (self.powerUpTimer) { LK.clearTimeout(self.powerUpTimer); } self.powerUpTimer = LK.setTimeout(function () { // Power-up effect will be handled in the Bullet class }, 10000); }; self.changeAppearance = function () {}; }); var Bullet = Container.expand(function () { var self = Container.call(this); Bullet.prototype.applyPowerUp = function () { this.width = this.originalWidth * 2; this.height = this.originalHeight * 2; if (this.powerUpTimer) { LK.clearTimeout(this.powerUpTimer); } this.powerUpTimer = LK.setTimeout(function (bullet) { bullet.width = bullet.originalWidth; bullet.height = bullet.originalHeight; }, 10000, this); }; var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.originalWidth = bulletGraphics.width; self.originalHeight = bulletGraphics.height; self.speed = -10; self.move = function () { self.y += self.speed; }; }); var Sausage = Container.expand(function () { var self = Container.call(this); var sausageGraphics = self.attachAsset('sausage', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.move = function () { self.y += self.speed * sausageSpeedMultiplier; }; }); var Onion = Container.expand(function () { var self = Container.call(this); var onionGraphics = self.attachAsset('onion', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.move = function () { self.y += self.speed * sausageSpeedMultiplier; if (self.y > 2732) { score -= 10; scoreTxt.setText(score.toString()); self.destroy(); } }; }); var GoldenSausage = Container.expand(function () { var self = Container.call(this); var goldenSausageGraphics = self.attachAsset('goldenSausage', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.move = function () { self.y += self.speed * sausageSpeedMultiplier; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundImage: 'kitchenBackground' }); /**** * Game Code ****/ var sausageSpeedMultiplier = 1.0; // Initialize score function createExplosionAndSausageBits(x, y) { var explosion = new Explosion(); explosion.x = x; explosion.y = y; game.addChild(explosion); } var score = 0; var scoreMultiplier = 1.0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff", anchorX: 0.7, // Center align horizontally anchorY: 0.0 // Top align }); LK.gui.top.addChild(scoreTxt); var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 150; var bullets = []; var sausages = []; game.on('down', function (obj) { var touchPos = obj.event.getLocalPosition(game); if (touchPos.x < hero.x) { hero.moveLeft(); } else if (touchPos.x > hero.x) { hero.moveRight(); } bullets = bullets.concat(hero.shoot()); }); LK.on('keydown', function (obj) { var event = obj.event; switch (event.keyCode) { case 37: // Left arrow key hero.moveLeft(); break; case 39: // Right arrow key hero.moveRight(); break; } }); LK.on('tick', function () { // Move bullets for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].move(); if (bullets[i].y < 0) { bullets[i].destroy(); bullets.splice(i, 1); } } // Move sausages for (var j = sausages.length - 1; j >= 0; j--) { sausages[j].move(); if (sausages[j].y > 2732) { sausages[j].destroy(); sausages.splice(j, 1); } } // Check for collisions between sausages and hero for (var s = sausages.length - 1; s >= 0; s--) { if (sausages[s] && hero.intersects(sausages[s])) { createExplosionAndSausageBits(sausages[s].x, sausages[s].y); // Update score when sausages hit the hero var points = sausages[s] instanceof Onion ? 5 : 1; score += Math.round(points * scoreMultiplier); scoreTxt.setText(score.toString()); sausages[s].destroy(); sausages.splice(s, 1); } } // Check for collisions between bullets and sausages for (var b = bullets.length - 1; b >= 0; b--) { for (var s = sausages.length - 1; s >= 0; s--) { if (bullets[b] && sausages[s] && bullets[b].intersects(sausages[s])) { createExplosionAndSausageBits(sausages[s].x, sausages[s].y); bullets[b].destroy(); bullets.splice(b, 1); sausages[s].destroy(); sausages.splice(s, 1); // Update score by 10 for golden sausage score += Math.round(10 * scoreMultiplier); scoreTxt.setText(score.toString()); break; } } } // Animate explosions for (var e = game.children.length - 1; e >= 0; e--) { if (game.children[e] instanceof Explosion) { game.children[e].animate(); } } sausageSpeedMultiplier += 0.0002; // Increment speed multiplier over time scoreMultiplier += 0.0001; // Increment score multiplier over time // Spawn sausages and occasionally a golden sausage if (LK.ticks % 120 == 0) { var sausageType = Math.random() < 0.02 ? GoldenSausage : Math.random() < 0.02 ? Onion : Sausage; var newSausage = new sausageType(); newSausage.x = Math.random() * (2048 - newSausage.width) + newSausage.width / 2; newSausage.y = -newSausage.height / 2; sausages.push(newSausage); game.addChild(newSausage); } // Check for collisions with golden sausages for (var b = bullets.length - 1; b >= 0; b--) { for (var s = sausages.length - 1; s >= 0; s--) { if (bullets[b] && sausages[s] instanceof GoldenSausage && bullets[b].intersects(sausages[s])) { hero.activatePowerUp(); createExplosionAndSausageBits(sausages[s].x, sausages[s].y); var goldenExplosion = new Explosion(); goldenExplosion.x = sausages[s].x; goldenExplosion.y = sausages[s].y; game.addChild(goldenExplosion); bullets[b].destroy(); bullets.splice(b, 1); sausages[s].destroy(); sausages.splice(s, 1); // Update score by 10 for golden sausage score += Math.round(10 * scoreMultiplier); scoreTxt.setText(score.toString()); break; } } } });
===================================================================
--- original.js
+++ change.js
@@ -141,8 +141,9 @@
explosion.y = y;
game.addChild(explosion);
}
var score = 0;
+var scoreMultiplier = 1.0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff",
anchorX: 0.7,
@@ -199,9 +200,9 @@
if (sausages[s] && hero.intersects(sausages[s])) {
createExplosionAndSausageBits(sausages[s].x, sausages[s].y);
// Update score when sausages hit the hero
var points = sausages[s] instanceof Onion ? 5 : 1;
- score += points;
+ score += Math.round(points * scoreMultiplier);
scoreTxt.setText(score.toString());
sausages[s].destroy();
sausages.splice(s, 1);
}
@@ -215,9 +216,9 @@
bullets.splice(b, 1);
sausages[s].destroy();
sausages.splice(s, 1);
// Update score by 10 for golden sausage
- score += 10;
+ score += Math.round(10 * scoreMultiplier);
scoreTxt.setText(score.toString());
break;
}
}
@@ -228,8 +229,9 @@
game.children[e].animate();
}
}
sausageSpeedMultiplier += 0.0002; // Increment speed multiplier over time
+ scoreMultiplier += 0.0001; // Increment score multiplier over time
// Spawn sausages and occasionally a golden sausage
if (LK.ticks % 120 == 0) {
var sausageType = Math.random() < 0.02 ? GoldenSausage : Math.random() < 0.02 ? Onion : Sausage;
var newSausage = new sausageType();
@@ -252,9 +254,9 @@
bullets.splice(b, 1);
sausages[s].destroy();
sausages.splice(s, 1);
// Update score by 10 for golden sausage
- score += 10;
+ score += Math.round(10 * scoreMultiplier);
scoreTxt.setText(score.toString());
break;
}
}
A crook sausage. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A heroic potato. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A background which represents a kitchen's ground. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A bullet shaped potato. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An exploding sausage. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A gold sausage. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An angry-looking onion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An onion exploding like a bomb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A carp which looks dumb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An ice cube. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.