Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: protagonist.customIntersect is not a function' in or related to this line: 'if (protagonist.customIntersect(obstacle)) {' Line Number: 382
User prompt
Please fix the bug: 'TypeError: protagonist.customIntersect is not a function' in or related to this line: 'if (protagonist.customIntersect(obstacle)) {' Line Number: 382
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: other.anchor is undefined' in or related to this line: 'otherBounds.x += other.x - other.width * other.anchor.x;' Line Number: 189
User prompt
Please fix the bug: 'TypeError: other.anchor is undefined' in or related to this line: 'otherBounds.x += other.x - other.width * other.anchor.x;' Line Number: 189
User prompt
Please fix the bug: 'TypeError: self.anchor is undefined' in or related to this line: 'selfBounds.x += self.x - self.width * self.anchor.x;' Line Number: 183
User prompt
the protagonist obstacles intersection doesn't work correctly
User prompt
if (self.x < -stoneAsset.width) { obstacles.splice(index, 1); self.destroy(); // Destroy the stone if it moves off screen } make this code correct
Code edit (1 edits merged)
Please save this source code
User prompt
Make this game.children.forEach(function (child) { if (child instanceof Stone && protagonist.customIntersect(child)) { // Trigger game over LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second LK.showGameOver(); // Show game over screen } }); to a obstacles.forEach function. Add each stone to obstacles and remove them, when they leave the screen
User prompt
Please fix the bug: 'ReferenceError: obstacles is not defined' in or related to this line: 'obstacles.add(stone);' Line Number: 368
User prompt
Please fix the bug: 'ReferenceError: obstacles is not defined' in or related to this line: 'obstacles.add(stone);' Line Number: 368
Code edit (2 edits merged)
Please save this source code
User prompt
Do a custom intersect for the protagonist
User prompt
if the protagonist collide with a stone, make a game over
Code edit (5 edits merged)
Please save this source code
User prompt
create a stone as obstacle. The stone move from right to left.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
speedcloud should have its own sprite
Code edit (6 edits merged)
Please save this source code
User prompt
create every 30/speed frame a small speedcloud left from the protagonist
User prompt
Please fix the bug: 'ReferenceError: failed is not defined' in or related to this line: 'if (!failed) {' Line Number: 146
Code edit (9 edits merged)
Please save this source code
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for Card
var Card = Container.expand(function () {
var self = Container.call(this);
var originalAsset = self.attachAsset('card', {
anchorX: 0.5,
anchorY: 0.5
});
var cardGraphics = originalAsset; // Referenz für das aktuelle Asset
self.type = null;
self.idNumber = 0;
self.isFlipped = false;
self.activeTimerMax = 90;
self.activeTimer = 0;
self.failed = false;
self.canBePlayed = true;
self.flip = function () {
if (!self.isFlipped) {
self.isFlipped = true;
// Alle anderen Karten zurückflippen
//cards.forEach(function (c) {
// if (c.isFlipped) {
// c.isFlipped = false;
// c.cardGraphics = c.attachAsset('card', {
// anchorX: 0.5,
// anchorY: 0.5
// });
// }
//});
// Diese Karte flippen
LK.getSound('TurnCard').play();
self.isActive = true;
self.activeTimer = self.activeTimerMax;
cardGraphics = self.attachAsset('flippedCard', {
anchorX: 0.5,
anchorY: 0.5
});
// Add a sprite to the card when it is flipped
self.sprite = self.attachAsset('jar' + self.type + 'Image', {
anchorX: 0.5,
anchorY: 0.5
});
if (self.type === 'Jump') {
if (!protagonist.isFalling) {
if (protagonist.isJumping) {
LK.getSound('JumpSuccess2').play();
} else {
LK.getSound('JumpSuccess').play();
}
protagonist.isJumping = true;
protagonist.jumpTimer = 60;
} else {
self.failed = true;
self.timerRect = self.attachAsset('timerRectFail', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5,
width: self.width,
height: self.height
});
LK.getSound('JumpFail').play();
}
} else if (self.type === 'Boot') {
if (protagonist.isJumping || protagonist.isFalling) {
self.failed = true;
self.timerRect = self.attachAsset('timerRectFail', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5,
width: self.width,
height: self.height
});
LK.getSound('RunFail').play();
} else {
speed++;
LK.getSound('RunSuccess').play();
}
}
if (!self.failed) {
// Create a timerRect and attach it to the card
self.timerRect = self.attachAsset('timerRect', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5,
width: self.width,
height: self.height
});
}
}
};
self.unflip = function () {
if (self.isFlipped) {
self.isFlipped = false;
self.cardGraphics = self.attachAsset('card', {
anchorX: 0.5,
anchorY: 0.5
});
LK.getSound('TurnCardBack').play();
// Remove the timerRect
self.timerRect.destroy();
if (!self.failed) {
if (self.type === 'Boot') {
speed--;
}
} else {
self.failed = false;
}
}
};
self.on('down', function (x, y, obj) {
if (self.canBePlayed) {
self.flip();
}
});
self.setType = function (type) {
self.type = type;
};
self.setId = function (number) {
self.idNumber = number;
};
});
// Class for Protagonist
var Protagonist = Container.expand(function () {
var self = Container.call(this);
var protagonistAsset = self.attachAsset('protagonist', {
anchorX: 0.5,
anchorY: 0.5
});
self.isJumping = false;
self.isFalling = false;
});
// Class for SpeedCloud
var SpeedCloud = Container.expand(function () {
var self = Container.call(this);
var cloudAsset = self.attachAsset('speedCloud', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.6
});
self.update = function () {
self.x -= 3 * speed; // Move the cloud to the left
if (self.x < -cloudAsset.width) {
self.destroy(); // Destroy the cloud if it moves off screen
}
};
});
// Class for Stone
var Stone = Container.expand(function () {
var self = Container.call(this);
var stoneAsset = self.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.x -= 2 * speed; // Move the stone to the left
if (self.x < -stoneAsset.width) {
self.destroy(); // Destroy the stone if it moves off screen
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var cards = [];
var cardTypes = ['Boot', 'Jump', 'Shield', 'Fist', 'Knife', 'Hammer', 'Trap'];
var score = 0;
var speed = 1;
var cardInformation = [{
name: 'dog',
beats: ['cat', 'bird'],
speed: 2,
canJump: true,
canClimb: false,
canSwim: true,
canFly: false,
canBreak: false
}, {
name: 'cat',
beats: ['rat', 'bird'],
speed: 2,
canJump: true,
canClimb: true,
canSwim: false,
canFly: false,
canBreak: false
}, {
name: 'rat',
beats: ['elephant'],
speed: 2,
canJump: true,
canClimb: true,
canSwim: true,
canFly: false,
canBreak: false
}, {
name: 'bird',
beats: ['rat'],
speed: 2,
canJump: false,
canClimb: false,
canSwim: true,
canFly: true,
canBreak: false
}, {
name: 'boar',
beats: ['rat', 'cat', 'dog'],
speed: 2,
canJump: false,
canClimb: false,
canSwim: true,
canFly: false,
canBreak: true
}, {
name: 'elephant',
beats: ['cat', 'dog', 'boar'],
speed: 2,
canJump: false,
canClimb: false,
canSwim: true,
canFly: false,
canBreak: true
}];
// Create and position cards
function createCards() {
var cardTypes = ['Boot', 'Boot', 'Boot', 'Jump', 'Jump', 'Fist', 'Knife', 'Knife'];
//var cardTypes = ['boot', 'cat', 'rat', 'mysticHand', 'bird', 'elephant', 'boar', 'magnifier'];
//cardTypes = cardTypes.concat(cardTypes); // duplicate the array
cardTypes.sort(function () {
return Math.random() - 0.5;
}); // shuffle the array
for (var i = 0; i < 8; i++) {
var card = new Card();
card.x = (game.width - 2 * 500) / 2 + i % 4 * 360; // Center the cards horizontally with increased margin
card.y = game.height - 4 * 400 + Math.floor(i / 4) * 420 + 100; // Position the cards at the bottom center with increased margin
card.setType(cardTypes[i]);
card.setId(i);
cards.push(card);
game.addChild(card);
if (cardTypes[i] === 'Boot') {
card.activeTimerMax = 300;
} else if (cardTypes[i] === 'Jump') {
card.activeTimerMax = 150;
}
}
}
// Check if selected cards match
// Attach the background images to the game
var topBackground = game.attachAsset('topBackground', {
anchorX: 0.5,
anchorY: 0.0,
x: game.width / 2,
y: -500
});
var bottomBackground = game.attachAsset('bottomBackground', {
anchorX: 0.5,
anchorY: 1.0,
x: game.width / 2,
y: game.height + 100
});
// Add protagonist character to the top center
var protagonist = new Protagonist();
protagonist.x = game.width / 2 - 200;
protagonist.y = 500;
game.addChild(protagonist);
// Initialize game
createCards();
// Update game state
game.update = function () {
for (var i = 0; i < cards.length; i++) {
if (cards[i].isFlipped) {
if (cards[i].activeTimer > 0) {
cards[i].activeTimer--;
// Update the height of the timerRect based on the activeTimer
cards[i].timerRect.height = cards[i].activeTimer / cards[i].activeTimerMax * cards[i].height;
} else {
cards[i].unflip();
// Reset the height of the timerRect
cards[i].timerRect.height = cards[i].height;
}
}
}
if (protagonist.isJumping) {
protagonist.jumpTimer--;
protagonist.y -= 3;
} else if (!protagonist.isJumping & protagonist.y < 500) {
protagonist.isFalling = true;
protagonist.y += 3;
} else {
protagonist.isFalling = false;
}
if (protagonist.jumpTimer <= 0) {
protagonist.isJumping = false;
}
if (LK.ticks % Math.floor(150 / speed) === 0) {
var speedCloud = new SpeedCloud();
speedCloud.x = protagonist.x - 50; // Position the cloud to the left of the protagonist
speedCloud.y = protagonist.y + 50;
game.addChild(speedCloud);
}
if (LK.ticks % Math.floor(500 / speed) === 0) {
var stone = new Stone();
stone.x = game.width + 50; // Start the stone off-screen to the right
stone.y = 550; // Set a fixed vertical position for the stone
game.addChild(stone);
}
// Check for collision between protagonist and stones
game.children.forEach(function (child) {
if (child instanceof Stone && protagonist.intersects(child)) {
// Trigger game over
LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second
LK.showGameOver(); // Show game over screen
}
});
};
// Play main theme
theme = 'MainTheme';
LK.playMusic(theme, {
loop: true
}); ===================================================================
--- original.js
+++ change.js
@@ -155,9 +155,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
- self.x -= 5; // Move the stone to the left
+ self.x -= 2 * speed; // Move the stone to the left
if (self.x < -stoneAsset.width) {
self.destroy(); // Destroy the stone if it moves off screen
}
};
@@ -304,17 +304,27 @@
if (protagonist.jumpTimer <= 0) {
protagonist.isJumping = false;
}
if (LK.ticks % Math.floor(150 / speed) === 0) {
- var stone = new Stone();
- stone.x = game.width + 50; // Start the stone off-screen to the right
- stone.y = 550; // Set a fixed vertical position for the stone
- game.addChild(stone);
var speedCloud = new SpeedCloud();
speedCloud.x = protagonist.x - 50; // Position the cloud to the left of the protagonist
speedCloud.y = protagonist.y + 50;
game.addChild(speedCloud);
}
+ if (LK.ticks % Math.floor(500 / speed) === 0) {
+ var stone = new Stone();
+ stone.x = game.width + 50; // Start the stone off-screen to the right
+ stone.y = 550; // Set a fixed vertical position for the stone
+ game.addChild(stone);
+ }
+ // Check for collision between protagonist and stones
+ game.children.forEach(function (child) {
+ if (child instanceof Stone && protagonist.intersects(child)) {
+ // Trigger game over
+ LK.effects.flashScreen(0xff0000, 1000); // Flash screen red for 1 second
+ LK.showGameOver(); // Show game over screen
+ }
+ });
};
// Play main theme
theme = 'MainTheme';
LK.playMusic(theme, {
Cardback with the Symbol ♾️ on it. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.
A cardback in brown empy color with mystical corners. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A good but dangerous elephant. Warcraft 3 art. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.
A good but dangerous falcon. Warcraft 3 art. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A good but dangerous boar. Warcraft 3 art. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A good but dangerous cat. Warcraft 3 art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A good but dangerous magnifier. Warcraft 3 art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A mystical spirit hand. Warcraft 3 art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A good but dangerous rat. Warcraft 3 art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A wooden play board with leaves. Fantasy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A mystical rectangle fantasy board with leaves.
Warcraft 3 art of a boot. Side-view.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Warcraft 3 art of a hammer.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Warcraft 3 image of a bow.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Warcraft 3 image of an arrow.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Warcraft 3 image of a medieval arrow.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Warcraft 3 art of a shield.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
warcraft 3 art of a fist.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.