/****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = LK.getAsset('obstacle', {
scaleX: 0.5,
scaleY: 0.5
});
obstacleGraphics.anchor.set(0.5, 0.5);
self.addChild(obstacleGraphics);
this.baseSpeed = 15;
this.speed = this.baseSpeed;
this._update_migrated = function () {
this.speed = this.baseSpeed + Math.floor(LK.ticks / 500);
this.y += this.speed;
if (!this.soundPlayed) {
LK.getSound('coconut').play();
this.soundPlayed = true;
}
if (this.y > player.y && !this.passed) {
this.passed = true;
score++;
scoreText.setText(score.toString());
}
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = LK.getAsset('player', {
scaleX: 0.5,
scaleY: 0.5
});
playerGraphics.anchor.set(0.5, 0.5);
self.addChild(playerGraphics);
this.targetX = null;
this.speed = 60;
this.moveToLane = function (targetX) {
this.targetX = targetX;
};
this._update_migrated = function () {
if (this.targetX !== null) {
var direction = this.targetX > this.x ? 1 : -1;
this.x += direction * this.speed;
if (direction > 0 && this.x >= this.targetX || direction < 0 && this.x <= this.targetX) {
this.x = this.targetX;
this.targetX = null;
}
}
};
});
var Power = Container.expand(function () {
var self = Container.call(this);
var powerGraphics = LK.getAsset('power', {
scaleX: 0.5,
scaleY: 0.5
});
powerGraphics.anchor.set(0.5, 0.5);
self.addChild(powerGraphics);
this.baseSpeed = 15;
this.speed = this.baseSpeed;
this._update_migrated = function () {
this.speed = (this.baseSpeed + Math.floor(LK.ticks / 2000)) * 0.5;
this.y += this.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var score = 0;
var scoreText = new Text2(score, {
size: 150,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var lanes = [512, 1024, 1536]; // Three lanes for the player to move between
var trackGraphics = [];
lanes.forEach(function (lane) {
var track = LK.getAsset('track', {});
track.anchor.set(0.5, 0);
track.x = lane;
track.y = 0;
trackGraphics.push(track);
game.addChild(track);
});
var player = game.addChild(new Player());
var palmTree = LK.getAsset('palmTree', {
scaleX: 1.5 * 1.5 * 1.5 * 1.5 * 1.5 * 1.4
});
palmTree.anchor.set(0.5, 0);
palmTree.x = 1024;
palmTree.y = 0;
game.addChild(palmTree);
player.y = 2732 - player.height - 2732 * 0.04; // Position the player 4% up from the bottom of the screen
player.x = lanes[1]; // Start the player in the middle lane
var powers = [];
var obstacles = [];
function spawnPower(lane) {
var power = new Power();
power.x = lane;
power.y = -power.height;
powers.push(power);
game.addChild(power);
}
function spawnObstacle(lane) {
var obstacle = new Obstacle();
obstacle.x = lane;
obstacle.y = -obstacle.height;
obstacles.push(obstacle);
game.addChild(obstacle);
}
var lastSpawnedLane = null;
function spawnObstaclePattern() {
var pattern = Math.floor(Math.random() * 2);
switch (pattern) {
case 0:
spawnObstacle(lanes[0]);
LK.setTimeout(function () {
return spawnObstacle(lanes[2]);
}, 1000);
break;
case 1:
spawnObstacle(lanes[1]);
LK.setTimeout(function () {
return spawnObstacle(lanes[0]);
}, 1000);
break;
}
LK.setTimeout(spawnObstaclePattern, 3000);
if (Math.random() < 0.3) {
spawnPower(lanes[Math.floor(Math.random() * lanes.length)]);
}
}
spawnObstaclePattern();
function updateGame() {
player._update_migrated();
obstacles.forEach(function (obstacle) {
obstacle._update_migrated();
if (obstacle.y > player.y && !obstacle.passed) {
obstacle.passed = true;
}
if (player.intersects(obstacle)) {
score += 6;
scoreText.setText(score.toString());
obstacle.destroy();
obstacles.splice(obstacles.indexOf(obstacle), 1);
}
powers.forEach(function (power) {
power._update_migrated();
if (player.intersects(power)) {
LK.showGameOver(restartGame);
}
});
});
}
LK.on('tick', updateGame);
var swipeStartX = null;
game.on('down', function (x, y, obj) {
swipeStartX = game.toLocal(obj.global).x;
});
game.on('up', function (x, y, obj) {
var swipeEndX = game.toLocal(obj.global).x;
var swipeDistance = swipeEndX - swipeStartX;
if (swipeDistance > 100 && player.x < lanes[2]) {
// Swipe right
player.moveToLane(lanes[lanes.indexOf(player.x) + 1]);
} else if (swipeDistance < -100 && player.x > lanes[0]) {
// Swipe left
player.moveToLane(lanes[lanes.indexOf(player.x) - 1]);
}
swipeStartX = null;
});
function restartGame() {
obstacles.forEach(function (obstacle) {
obstacle.destroy();
});
powers.forEach(function (power) {
power.destroy();
});
powers = [];
obstacles = [];
player.x = lanes[1];
player.y = 2732 - player.height;
LK.submitScore(score); // Submit the score
score = 0;
scoreText.setText(score);
}
// Create three buttons at the bottom of the screen
var leftButton = LK.getAsset('button', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box'
});
leftButton.x = 200 + 200 * 1.0; // Move the button 20% to the right
leftButton.y = 2732 - 100 - 15 - 100;
leftButton.on('down', function () {
player.moveToLane(lanes[0]);
LK.getSound('buttons').play();
});
game.addChild(leftButton);
var middleButton = LK.getAsset('button', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box'
});
middleButton.x = 1024 - 1024 * 0.1; // Move the button 10% to the left
middleButton.y = 2732 - 100 - 15 - 100;
middleButton.on('down', function () {
player.moveToLane(lanes[1]);
LK.getSound('buttons').play();
});
game.addChild(middleButton);
var rightButton = LK.getAsset('button', {
width: 200,
height: 200,
color: 0x00ff00,
shape: 'box'
});
rightButton.x = 1848 - 1848 * 0.2; // Move the button 20% to the left
rightButton.y = 2732 - 100 - 15 - 100;
rightButton.on('down', function () {
player.moveToLane(lanes[2]);
LK.getSound('buttons').play();
});
game.addChild(rightButton);
;
summoning round blue button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Make an image og a coconut. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Make more variations
Make a banana. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.