/****
* Classes
****/
// 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_migrated = function (newX, newY) {
self.x = newX;
self.y = newY;
};
});
// 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_migrated = 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_migrated = 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;
}
}
};
});
// 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_migrated = function () {
self.x += self.speed * self.direction;
if (self.x < -self.width || self.x > 2048 + self.width) {
self.direction *= -1;
}
};
});
// 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_migrated = function () {
self.x += self.speed;
if (self.x > 2048) {
self.x = -self.width;
}
};
});
// 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_migrated = function () {
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);
// Method to handle the start of dragging the balloon
game.down = function (x, y, obj) {
dragNode = balloon;
};
// Method to handle the dragging movement of the balloon
function handleMove(obj) {
var event = obj.event;
var pos = game.toLocal(event.global);
if (dragNode) {
dragNode._move_migrated(pos.x, pos.y);
}
}
// Add move event listener to the game
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
};
// Method to handle the end of dragging the balloon
game.up = function (x, y, 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_migrated();
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_migrated();
if (extraPointsBalloons[i].y > 2732 + extraPointsBalloons[i].height) {
extraPointsBalloons[i].destroy();
extraPointsBalloons.splice(i, 1);
LK.getSound('coinCollect').play();
} else if (balloon.intersects(extraPointsBalloons[i])) {
score += 10;
extraPointsBalloons[i].destroy();
extraPointsBalloons.splice(i, 1);
}
}
// Move clouds and update score
for (var c = clouds.length - 1; c >= 0; c--) {
clouds[c]._move_migrated();
}
// 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.