User prompt
When collecting the Balloons play a short Coin-collect-sound
User prompt
Center the point count text at the top center
User prompt
make the Player object follow the mouse
User prompt
Please fix the bug: 'Uncaught TypeError: balloon.containsPoint is not a function' in or related to this line: 'if (balloon.containsPoint(game_position)) {' Line Number: 157
User prompt
Make sure the following: 1. **Initialize Dragging**: In the `down` event, check if the touch/click is on the balloon and set `dragNode` to the balloon. 2. **Update Position**: In the `move` event, if `dragNode` is set, update the balloon's position based on the touch/mouse movement. 3. **Terminate Dragging**: In the `up` event, reset `dragNode` to `null`.
User prompt
The Player Balloon should be dragged with the mouse
User prompt
There seems to be a problem you need to correct. The Player Balloon should only be moved by dragging
User prompt
Migrate to the latest version of LK
User prompt
Make a starting menu, that has the text: "Avoid planes. Get ballons for bonus points." and a button that says "Start".
User prompt
fix the balloon so it can be dragged
User prompt
make sure that there is not missing logic between the down event, move event, and up event
User prompt
make sure that the move event handler check if the drag flag is set so we can more the balloon
User prompt
make sure the move event handler updates the balloon position during drag
User prompt
make sure that there is a check in the down event handler that checks that touch coordinates are within the balloon bound
User prompt
Fix Bug: 'TypeError: balloon.hitTest is not a function' in or related to this line: 'if (balloon.hitTest(touchPos)) {' Line Number: 149
User prompt
Fix Bug: 'TypeError: balloon.balloonGraphics.containsPoint is not a function' in or related to this line: 'if (balloon.balloonGraphics.containsPoint(touchPos)) {' Line Number: 149
User prompt
update so the balloon does not jump to click position but can only be dragged
User prompt
Fix Bug: 'TypeError: balloon.hitTestPoint is not a function' in or related to this line: 'if (balloon.hitTestPoint(touchPos.x, touchPos.y)) {' Line Number: 153
User prompt
Fix Bug: 'TypeError: balloon.balloonGraphics.contains is not a function' in or related to this line: 'if (balloon.balloonGraphics.contains(touchPos)) {' Line Number: 153
User prompt
Fix Bug: 'ReferenceError: balloonGraphics is not defined' in or related to this line: 'if (balloonGraphics.contains(touchPos)) {' Line Number: 153
User prompt
Fix Bug: 'TypeError: balloon.contains is not a function' in or related to this line: 'if (balloon.contains(touchPos)) {' Line Number: 153
User prompt
Fix Bug: 'TypeError: balloon.containsPoint is not a function' in or related to this line: 'if (balloon.containsPoint(touchPos)) {' Line Number: 153
User prompt
make an event listener, that checks if the down touch is done inside the balloon
User prompt
remove the handleTouch function to move the balloon to the touch position
User prompt
Fix Bug: 'TypeError: game.getChildrenByClass is not a function' in or related to this line: 'var scorePopups = game.getChildrenByClass(ScorePopup);' Line Number: 249
/****
* Classes
****/
var ScorePopup = Container.expand(function (initialX, initialY) {
var self = Container.call(this);
var scoreText = self.attachAsset(new Text2('+100', {
size: 100,
fill: '#ffffff',
anchorX: 0.5,
anchorY: 0.5
}), {});
self.x = initialX;
self.y = initialY;
self.move = function () {
self.y -= 2;
if (self.y < 0) {
self.destroy();
}
};
});
// HorizontalExtraPointsBalloon class
var HorizontalExtraPointsBalloon = Container.expand(function () {
var self = Container.call(this);
var balloonGraphics = self.attachAsset('ExtraPointsBalloon', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0.5;
self.direction = Math.random() < 0.5 ? -1 : 1;
self.move = function () {
self.x += self.speed * self.direction;
if (self.x < -self.width || self.x > 2048 + self.width) {
self.direction *= -1;
}
};
});
// RightDanger class
var RightDanger = Container.expand(function () {
var self = Container.call(this);
var dangerGraphics = self.attachAsset('danger', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.direction = Math.random() < 0.5 ? -1 : 1;
self.move = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.x = 2048;
}
};
});
// Balloon class
var Balloon = Container.expand(function () {
var self = Container.call(this);
var balloonGraphics = self.attachAsset('balloon', {
anchorX: 0.5,
anchorY: 1
});
self.speed = 5;
self.move = function (newX, newY) {
self.x = newX;
self.y = newY;
};
});
// LeftDanger class
var LeftDanger = Container.expand(function () {
var self = Container.call(this);
var dangerGraphics = self.attachAsset('danger', {
anchorX: 0.5,
anchorY: 0.5
});
dangerGraphics.scale.x = -1;
self.speed = 3;
self.direction = Math.random() < 0.5 ? -1 : 1;
self.move = function () {
self.x += self.speed;
if (self.x > 2048) {
self.x = -self.width;
}
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 0.5;
self.move = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -self.height;
}
};
});
// Danger2 class
var Danger2 = Container.expand(function () {
var self = Container.call(this);
var dangerGraphics = self.attachAsset('Danger2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.direction = Math.random() < 0.5 ? -1 : 1;
self.move = function () {
// Randomly choose to move left or right
if (self.direction === 1) {
self.x += self.speed;
if (self.x > 2048) {
self.x = -self.width;
}
} else {
self.x -= self.speed;
if (self.x < -self.width) {
self.x = 2048;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize clouds array
var clouds = [];
// Create and position clouds
for (var i = 0; i < 5; i++) {
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 2732;
clouds.push(cloud);
game.addChild(cloud);
}
// Initialize important asset arrays, drag state, and score
var dangers = [];
var extraPointsBalloons = [];
var isGameOver = false;
var balloon;
var dragNode = null;
var score = 0; // Score based on survival time
// Create the balloon and position it at the bottom center of the screen
balloon = game.addChild(new Balloon());
balloon.x = 2048 / 2;
balloon.y = 2732 - 100;
// Create and display the score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(scoreTxt);
// Game touch event handling
function handleTouch(obj) {
var touchPos = obj.event.getLocalPosition(game);
balloon.move(touchPos.x, touchPos.y);
}
// Method to handle the start of dragging the balloon
game.on('down', function (obj) {
dragNode = balloon;
handleMove(obj); // Call move handler immediately to update position
});
// Method to handle the dragging movement of the balloon
function handleMove(obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
if (dragNode) {
dragNode.move(pos.x, pos.y);
}
}
// Add move event listener to the game
game.on('move', handleMove);
// Method to handle the end of dragging the balloon
game.on('up', function (obj) {
dragNode = null;
});
// Game tick event
LK.on('tick', function () {
// Spawn LeftDanger
if (LK.ticks % 180 === 0) {
var leftDanger = new LeftDanger();
leftDanger.x = -leftDanger.width;
leftDanger.y = Math.random() * 2732;
dangers.push(leftDanger);
game.addChild(leftDanger);
}
// Spawn RightDanger
if (LK.ticks % 120 === 0) {
var rightDanger = new RightDanger();
rightDanger.x = 2048 + rightDanger.width;
rightDanger.y = Math.random() * 2732;
dangers.push(rightDanger);
game.addChild(rightDanger);
}
// Spawn Danger2
if (LK.ticks % 240 === 0) {
var danger2 = new Danger2();
danger2.x = Math.random() < 0.5 ? -danger2.width : 2048 + danger2.width;
danger2.y = Math.random() * 2732;
dangers.push(danger2);
game.addChild(danger2);
}
// Spawn HorizontalExtraPointsBalloon
if (LK.ticks % 300 === 0) {
var horizontalExtraPointsBalloon = new HorizontalExtraPointsBalloon();
horizontalExtraPointsBalloon.x = Math.random() < 0.5 ? -horizontalExtraPointsBalloon.width : 2048 + horizontalExtraPointsBalloon.width;
horizontalExtraPointsBalloon.y = Math.random() * 2732;
extraPointsBalloons.push(horizontalExtraPointsBalloon);
game.addChild(horizontalExtraPointsBalloon);
}
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
// Move dangers and ExtraPointsBalloons
for (var i = dangers.length - 1; i >= 0; i--) {
dangers[i].move();
if (dangers[i].y > 2732 + dangers[i].height) {
dangers[i].destroy();
dangers.splice(i, 1);
} else if (balloon.intersects(dangers[i])) {
isGameOver = true;
}
}
for (var i = extraPointsBalloons.length - 1; i >= 0; i--) {
extraPointsBalloons[i].move();
if (extraPointsBalloons[i].y > 2732 + extraPointsBalloons[i].height) {
var scorePopup = new ScorePopup(extraPointsBalloons[i].x, extraPointsBalloons[i].y);
game.addChild(scorePopup);
extraPointsBalloons[i].destroy();
extraPointsBalloons.splice(i, 1);
} else if (balloon.intersects(extraPointsBalloons[i])) {
score += 10;
extraPointsBalloons[i].destroy();
extraPointsBalloons.splice(i, 1);
}
}
// Move clouds, score popups, and update score
var scorePopups = game.children.filter(function (child) {
return child instanceof ScorePopup;
});
for (var c = clouds.length - 1; c >= 0; c--) {
clouds[c].move();
}
for (var p = scorePopups.length - 1; p >= 0; p--) {
scorePopups[p].move();
}
// Increment score by 1 every tick if the game is not over and update the score text
if (!isGameOver) {
score += 1;
scoreTxt.setText(score.toString());
}
});
a pixel cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a pixel hot air balloon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a simpel pixel biplane sideview. Blank background, 2d. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a simple red balloon on a string. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a 2d ufo sideview. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.