User prompt
make the backround white
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'stuck')' in or related to this line: 'if (knives[i].stuck && !knives[i].falling) {' Line Number: 164
User prompt
once 15 points are received remove all knifes and make target a little smaller
User prompt
once 15 knifes are in target remove knifes form target
User prompt
remove power ups.
User prompt
Please fix the bug: 'ReferenceError: powerUps is not defined' in or related to this line: 'for (var j = 0; j < powerUps.length; j++) {' Line Number: 172
User prompt
Add slow down power up on target every once in a while
User prompt
Migrate to the latest version of LK
Remix started
Copy Santa's Christmas Knife Throw!
/****
* Classes
****/
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
});
var Knife = Container.expand(function () {
var self = Container.call(this);
self.angleTo = function (other) {
var dx = other.x - self.x;
var dy = other.y - self.y;
return Math.atan2(dy, dx);
};
var knifeGraphics = self.attachAsset('knife', {
anchorX: 0.5
});
self.speed = 30;
self.stuck = false;
self.falling = false;
self.spinDirection = Math.random() < 0.5 ? -1 : 1;
self._move_migrated = function () {
if (!self.stuck && !self.falling) {
self.y -= self.speed;
}
};
self.fall = function () {
if (self.falling) {
if (!self.fallInitiated) {
knifeGraphics.anchor.x = .5;
knifeGraphics.anchor.y = .5;
self.x += knifeGraphics.width / 2;
self.y += knifeGraphics.height / 2;
self.fallInitiated = true;
}
self.y += self.speed;
self.rotation += self.spinDirection * 0.1;
}
};
self.hit = function (knives) {
for (var i = 0; i < knives.length; i++) {
if (knives[i] !== self && knives[i].stuck) {
var angleDiff = Math.abs(knives[i].hitAngle % (2 * Math.PI) - self.hitAngle % (2 * Math.PI));
if (angleDiff < Math.PI / 24) {
return true;
}
}
}
return false;
};
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.y += self.speed;
};
});
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotationSpeed = 0.01;
self.rotation = 4 * Math.PI;
self.rotate = function () {
self.rotation += self.rotationSpeed;
};
self.hit = function () {
LK.effects.flashObject(self, 0x00ff00, 500);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var background = game.attachAsset('background', {});
background.width = 2048;
background.height = 2732;
var knives = [];
var targets = [];
var powerUps = []; // Define powerUps array
var score = 0;
var lives = [new Heart(), new Heart(), new Heart(), new Heart(), new Heart()];
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: 0xFF0000,
font: "'Comic Sans MS', cursive, sans-serif",
stroke: 0xFFFFFF,
strokeThickness: 6,
dropShadow: true,
dropShadowColor: 0x00FF00,
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(.5, 0);
LK.gui.top.addChild(scoreTxt);
for (var i = 0; i < lives.length; i++) {
lives[i].x = 2048 - (i + 1) * 130 - 15;
lives[i].y = 100 + 15;
game.addChild(lives[i]);
}
var knife = game.addChild(new Knife());
knife.x = 2048 / 2;
knife.y = 2732 - 200;
var target = game.addChild(new Target());
target.x = 2048 / 2;
target.y = 2732 / 2;
game.on('down', function (x, y, obj) {
var newKnife = new Knife();
newKnife.x = knife.x;
newKnife.y = knife.y;
knives.push(newKnife);
game.addChild(newKnife);
});
LK.on('tick', function () {
target.rotate();
for (var i = 0; i < knives.length; i++) {
knives[i]._move_migrated();
knives[i].fall();
}
// Add power ups every 200 ticks
if (LK.ticks % 200 == 0) {
var newPowerUp = new PowerUp();
newPowerUp.x = Math.random() * 2048; // Random x position
newPowerUp.y = 2732; // Start at the bottom of the screen
powerUps.push(newPowerUp); // Add new power up to powerUps array
game.addChild(newPowerUp);
}
for (var i = 0; i < knives.length; i++) {
if (Math.abs(knives[i].y - target.y) <= target.height / 2 && !knives[i].stuck) {
knives[i].stuck = true;
knives[i].hitAngle = target.rotation - Math.PI / 2;
if (knives[i].hit(knives)) {
knives[i].falling = true;
var lostLife = lives.pop();
lostLife.destroy();
scoreTxt.setText(score.toString());
if (lives.length > 0) {
LK.effects.flashScreen(0xff0000, 500);
}
} else {
target.hit();
target.rotationSpeed += 0.005 / 3;
score += 1;
scoreTxt.setText(score.toString());
}
// Check for power up collection
for (var j = 0; j < powerUps.length; j++) {
if (knives[i].intersects(powerUps[j])) {
// Slow down the game
target.rotationSpeed -= 0.005;
// Remove the power up
powerUps[j].destroy();
powerUps.splice(j, 1);
}
}
}
if (knives[i].stuck && !knives[i].falling) {
knives[i].rotation = target.rotation - knives[i].hitAngle - Math.PI / 2;
knives[i].x = target.x + Math.cos(target.rotation - knives[i].hitAngle) * target.width / 2;
knives[i].y = target.y + Math.sin(target.rotation - knives[i].hitAngle) * target.height / 2;
}
}
for (var i = knives.length - 1; i >= 0; i--) {
if (knives[i].y < -50) {
knives[i].destroy();
knives.splice(i, 1);
}
if (lives.length === 0) {
LK.showGameOver();
}
}
}); ===================================================================
--- original.js
+++ change.js
@@ -93,8 +93,9 @@
background.width = 2048;
background.height = 2732;
var knives = [];
var targets = [];
+var powerUps = []; // Define powerUps array
var score = 0;
var lives = [new Heart(), new Heart(), new Heart(), new Heart(), new Heart()];
var scoreTxt = new Text2(score.toString(), {
size: 150,
@@ -138,8 +139,9 @@
if (LK.ticks % 200 == 0) {
var newPowerUp = new PowerUp();
newPowerUp.x = Math.random() * 2048; // Random x position
newPowerUp.y = 2732; // Start at the bottom of the screen
+ powerUps.push(newPowerUp); // Add new power up to powerUps array
game.addChild(newPowerUp);
}
for (var i = 0; i < knives.length; i++) {
if (Math.abs(knives[i].y - target.y) <= target.height / 2 && !knives[i].stuck) {
Cartoon knife pointing up. Symmetrical. Vertical. Christmas designed. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a red heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a target with a picture of a stickman taped on it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a wall backround. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows