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
User prompt
The golden sausage chould add 10 points to the score instead of 1
User prompt
Fix Bug: 'TypeError: this.scale is undefined' in or related to this line: 'Bullet.prototype.originalWidth = Bullet.prototype.width;' Line Number: 65
User prompt
Change the power-up so that it makes the bullets bigger for 10 seconds instead of shooting 3 bullets a a time
User prompt
Fix Bug: 'TypeError: bullets[i].move is not a function' in or related to this line: 'bullets[i].move();' Line Number: 155
User prompt
create a new golden sausage that has a 1 in a 100 chance of appearing. When hit, it gives a temporary power-up to the hero. The power-up makes it so that the hero shoots 3 bullets a a time for 10 seconds.
User prompt
Fullt Delete sausage bits from the code as they cause bugs
User prompt
Make it so that sausage bits disappear after hitting a sausage
User prompt
Once created, the sausage bits should move straight in a random direction, until they hit a sausage or the borders of the game
User prompt
Each hit sausage should create 4 bits. Also, the bits should be sent in random directions. When the bits hit the border of the game, they disappear
User prompt
make it so that when a sausage is hit, it launches 4 small sausage bits in random directions. When the bits hit a sausage, it explodes as if it was hit by a bullet.
User prompt
make the hero move faster
User prompt
make it so that sausages explode when hit
User prompt
make the score visible in the up right corner
User prompt
add a score in the upright corner so that each destroyed sausage gives 1 point
User prompt
Fix Bug: 'TypeError: window.addEventListener is not a function' in or related to this line: 'window.addEventListener('keydown', function (event) {' Line Number: 72
User prompt
make it so that we can move the hero using the keyboard's directional arrows
User prompt
Make it so that we can move the hero to the right and the left
User prompt
Make it so that we can see the background image
User prompt
add a background which represents a kitchen's ground
Initial prompt
Sausage Hunter
/**** * Classes ****/ var SausageBit = Container.expand(function () { var self = Container.call(this); var sausageBitGraphics = self.attachAsset('sausage', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, // Scale down the sausage bit scaleY: 0.5 }); self.speedX = (Math.random() - 0.5) * 10; self.speedY = (Math.random() - 0.5) * 10; self.move = function () { self.x += self.speedX; self.y += self.speedY; }; }); 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 = 10; 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.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2; game.addChild(bullet); return bullet; }; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); 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; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ background: 'kitchenBackground' }); /**** * Game Code ****/ // Initialize score var sausageBits = []; function createExplosionAndSausageBits(x, y) { var explosion = new Explosion(); explosion.x = x; explosion.y = y; game.addChild(explosion); // Create 4 sausage bits for (var i = 0; i < 4; i++) { var sausageBit = new SausageBit(); sausageBit.x = x; sausageBit.y = y; sausageBits.push(sausageBit); game.addChild(sausageBit); } } var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff", anchorX: 0.5, // Center align horizontally anchorY: 0.0 // Top align }); LK.gui.topRight.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.push(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 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 score++; scoreTxt.setText(score.toString()); break; } } } // Check for sausage bit collisions with sausages for (var sb = sausageBits.length - 1; sb >= 0; sb--) { for (var s = sausages.length - 1; s >= 0; s--) { if (sausageBits[sb] && sausages[s] && sausageBits[sb].intersects(sausages[s])) { createExplosionAndSausageBits(sausages[s].x, sausages[s].y); sausageBits[sb].destroy(); sausageBits.splice(sb, 1); sausages[s].destroy(); sausages.splice(s, 1); // Update score score++; 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(); } } // Spawn sausages if (LK.ticks % 120 == 0) { var newSausage = new Sausage(); newSausage.x = Math.random() * (2048 - newSausage.width) + newSausage.width / 2; newSausage.y = -newSausage.height / 2; sausages.push(newSausage); game.addChild(newSausage); } });
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,23 @@
/****
* Classes
****/
+var SausageBit = Container.expand(function () {
+ var self = Container.call(this);
+ var sausageBitGraphics = self.attachAsset('sausage', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.5,
+ // Scale down the sausage bit
+ scaleY: 0.5
+ });
+ self.speedX = (Math.random() - 0.5) * 10;
+ self.speedY = (Math.random() - 0.5) * 10;
+ self.move = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ };
+});
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
@@ -72,8 +88,23 @@
/****
* Game Code
****/
// Initialize score
+var sausageBits = [];
+function createExplosionAndSausageBits(x, y) {
+ var explosion = new Explosion();
+ explosion.x = x;
+ explosion.y = y;
+ game.addChild(explosion);
+ // Create 4 sausage bits
+ for (var i = 0; i < 4; i++) {
+ var sausageBit = new SausageBit();
+ sausageBit.x = x;
+ sausageBit.y = y;
+ sausageBits.push(sausageBit);
+ game.addChild(sausageBit);
+ }
+}
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff",
@@ -129,12 +160,9 @@
// Check for collisions
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])) {
- var explosion = new Explosion();
- explosion.x = sausages[s].x;
- explosion.y = sausages[s].y;
- game.addChild(explosion);
+ createExplosionAndSausageBits(sausages[s].x, sausages[s].y);
bullets[b].destroy();
bullets.splice(b, 1);
sausages[s].destroy();
sausages.splice(s, 1);
@@ -144,8 +172,24 @@
break;
}
}
}
+ // Check for sausage bit collisions with sausages
+ for (var sb = sausageBits.length - 1; sb >= 0; sb--) {
+ for (var s = sausages.length - 1; s >= 0; s--) {
+ if (sausageBits[sb] && sausages[s] && sausageBits[sb].intersects(sausages[s])) {
+ createExplosionAndSausageBits(sausages[s].x, sausages[s].y);
+ sausageBits[sb].destroy();
+ sausageBits.splice(sb, 1);
+ sausages[s].destroy();
+ sausages.splice(s, 1);
+ // Update score
+ score++;
+ 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();
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.