/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cannon = Container.expand(function () {
var self = Container.call(this);
self.currentFruit = 'coconut';
self.fruitIndex = 0;
var cannonGraphics = self.attachAsset('cannon', {
anchorX: 0.5,
anchorY: 0.5
});
self.setFruitType = function (type) {
self.currentFruit = type;
if (type === 'coconut') {
cannonGraphics.tint = 0x8B4513;
} else if (type === 'melon') {
cannonGraphics.tint = 0x228B22;
} else if (type === 'banana') {
cannonGraphics.tint = 0xFFD700;
}
};
self.cycleFruit = function () {
var fruits = ['coconut', 'melon', 'banana'];
self.fruitIndex = (self.fruitIndex + 1) % fruits.length;
self.setFruitType(fruits[self.fruitIndex]);
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.maxHealth = 100;
self.health = 100;
self.speed = 2;
self.score = 50;
self.lastY = 0;
self.lastIntersecting = false;
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.takeDamage = function (damage) {
self.health -= damage;
};
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
var EnemyProjectile = Container.expand(function () {
var self = Container.call(this);
self.speed = 8;
self.damage = 20;
self.lastY = 0;
var projectileGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
projectileGraphics.tint = 0xFF6347;
projectileGraphics.scaleX = 0.5;
projectileGraphics.scaleY = 0.5;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
var Fruit = Container.expand(function () {
var self = Container.call(this);
self.fruitType = 'coconut';
self.speed = -12;
self.damage = 100;
self.lastY = 0;
var fruitGraphics = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.setFruitType = function (type) {
self.fruitType = type;
self.removeChild(fruitGraphics);
if (type === 'coconut') {
fruitGraphics = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.damage = 100;
self.speed = -12;
} else if (type === 'melon') {
fruitGraphics = self.attachAsset('melon', {
anchorX: 0.5,
anchorY: 0.5
});
self.damage = 60;
self.speed = -14;
} else if (type === 'banana') {
fruitGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.damage = 30;
self.speed = -16;
}
};
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
var ToughEnemy = Container.expand(function () {
var self = Container.call(this);
self.maxHealth = 250;
self.health = 250;
self.speed = 1;
self.score = 150;
self.lastY = 0;
self.lastIntersecting = false;
var toughEnemyGraphics = self.attachAsset('toughEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.takeDamage = function (damage) {
self.health -= damage;
};
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var cannon = game.addChild(new Cannon());
cannon.x = 2048 / 2;
cannon.y = 2600;
cannon.maxHealth = 100;
cannon.health = 100;
var fruits = [];
var enemies = [];
var enemyProjectiles = [];
var waveCount = 0;
var waveEnemyCount = 0;
var waveEnemySpawned = 0;
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var fruitTypeTxt = new Text2('Fruit: Coconut', {
size: 60,
fill: 0xFFFFFF
});
fruitTypeTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(fruitTypeTxt);
var waveTxt = new Text2('Wave: 1', {
size: 60,
fill: 0xFFFFFF
});
waveTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(waveTxt);
var healthTxt = new Text2('Health: 100', {
size: 60,
fill: 0xFF0000
});
healthTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(healthTxt);
var dragNode = null;
function startNewWave() {
waveCount++;
waveEnemyCount = 3 + waveCount;
waveEnemySpawned = 0;
waveTxt.setText('Wave: ' + waveCount);
}
function spawnEnemy() {
var enemyType = waveCount > 2 && Math.random() > 0.7 ? 'tough' : 'normal';
var newEnemy;
if (enemyType === 'tough') {
newEnemy = new ToughEnemy();
} else {
newEnemy = new Enemy();
}
newEnemy.x = Math.random() * (2048 - 120) + 60;
newEnemy.y = -100;
newEnemy.lastY = newEnemy.y;
newEnemy.lastIntersecting = false;
newEnemy.shootTimer = 0;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
function handleGameOver() {
LK.showGameOver();
}
startNewWave();
var spawnTimer = LK.setInterval(function () {
if (waveEnemySpawned < waveEnemyCount) {
spawnEnemy();
waveEnemySpawned++;
}
}, 1500);
function handleMove(x, y, obj) {
if (dragNode) {
var newX = x;
if (newX < 60) newX = 60;
if (newX > 2048 - 60) newX = 2048 - 60;
dragNode.x = newX;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = cannon;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
var shootInterval = LK.setInterval(function () {
var newFruit = new Fruit();
newFruit.setFruitType(cannon.currentFruit);
newFruit.x = cannon.x;
newFruit.y = cannon.y - 60;
newFruit.lastY = newFruit.y;
fruits.push(newFruit);
game.addChild(newFruit);
LK.getSound('shoot').play();
}, 300);
game.update = function () {
for (var a = fruits.length - 1; a >= 0; a--) {
var fruit = fruits[a];
if (fruit.lastY >= 0 && fruit.y < 0) {
fruit.destroy();
fruits.splice(a, 1);
continue;
}
var fruitHit = false;
for (var b = enemies.length - 1; b >= 0; b--) {
var enemy = enemies[b];
if (fruit.intersects(enemy)) {
enemy.takeDamage(fruit.damage);
LK.getSound('hit').play();
if (enemy.health <= 0) {
LK.setScore(LK.getScore() + enemy.score);
scoreTxt.setText(LK.getScore());
enemy.destroy();
enemies.splice(b, 1);
}
fruit.destroy();
fruits.splice(a, 1);
fruitHit = true;
break;
}
}
for (var d = enemyProjectiles.length - 1; d >= 0; d--) {
var projectile = enemyProjectiles[d];
if (fruit.intersects(projectile)) {
projectile.destroy();
enemyProjectiles.splice(d, 1);
fruit.destroy();
fruits.splice(a, 1);
fruitHit = true;
break;
}
}
}
for (var c = enemies.length - 1; c >= 0; c--) {
var enemy = enemies[c];
enemy.lastY = enemy.y;
enemy.shootTimer++;
if (enemy.shootTimer > 120) {
var newProjectile = new EnemyProjectile();
newProjectile.x = enemy.x;
newProjectile.y = enemy.y;
newProjectile.lastY = newProjectile.y;
enemyProjectiles.push(newProjectile);
game.addChild(newProjectile);
enemy.shootTimer = 0;
}
if (enemy.lastY <= 2732 && enemy.y > 2732) {
handleGameOver();
return;
}
if (enemy.intersects(cannon)) {
handleGameOver();
return;
}
}
for (var e = enemyProjectiles.length - 1; e >= 0; e--) {
var projectile = enemyProjectiles[e];
projectile.lastY = projectile.y;
if (projectile.lastY <= 2732 && projectile.y > 2732) {
projectile.destroy();
enemyProjectiles.splice(e, 1);
continue;
}
if (projectile.intersects(cannon)) {
cannon.health -= projectile.damage;
healthTxt.setText('Health: ' + cannon.health);
LK.getSound('hit').play();
projectile.destroy();
enemyProjectiles.splice(e, 1);
if (cannon.health <= 0) {
handleGameOver();
return;
}
}
}
if (enemies.length === 0 && waveEnemySpawned >= waveEnemyCount) {
startNewWave();
}
if (LK.ticks % 60 === 0) {
cannon.cycleFruit();
fruitTypeTxt.setText('Fruit: ' + cannon.currentFruit.charAt(0).toUpperCase() + cannon.currentFruit.slice(1));
}
};
LK.playMusic('bgmusic', {
loop: true
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cannon = Container.expand(function () {
var self = Container.call(this);
self.currentFruit = 'coconut';
self.fruitIndex = 0;
var cannonGraphics = self.attachAsset('cannon', {
anchorX: 0.5,
anchorY: 0.5
});
self.setFruitType = function (type) {
self.currentFruit = type;
if (type === 'coconut') {
cannonGraphics.tint = 0x8B4513;
} else if (type === 'melon') {
cannonGraphics.tint = 0x228B22;
} else if (type === 'banana') {
cannonGraphics.tint = 0xFFD700;
}
};
self.cycleFruit = function () {
var fruits = ['coconut', 'melon', 'banana'];
self.fruitIndex = (self.fruitIndex + 1) % fruits.length;
self.setFruitType(fruits[self.fruitIndex]);
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.maxHealth = 100;
self.health = 100;
self.speed = 2;
self.score = 50;
self.lastY = 0;
self.lastIntersecting = false;
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.takeDamage = function (damage) {
self.health -= damage;
};
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
var EnemyProjectile = Container.expand(function () {
var self = Container.call(this);
self.speed = 8;
self.damage = 20;
self.lastY = 0;
var projectileGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
projectileGraphics.tint = 0xFF6347;
projectileGraphics.scaleX = 0.5;
projectileGraphics.scaleY = 0.5;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
var Fruit = Container.expand(function () {
var self = Container.call(this);
self.fruitType = 'coconut';
self.speed = -12;
self.damage = 100;
self.lastY = 0;
var fruitGraphics = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.setFruitType = function (type) {
self.fruitType = type;
self.removeChild(fruitGraphics);
if (type === 'coconut') {
fruitGraphics = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.damage = 100;
self.speed = -12;
} else if (type === 'melon') {
fruitGraphics = self.attachAsset('melon', {
anchorX: 0.5,
anchorY: 0.5
});
self.damage = 60;
self.speed = -14;
} else if (type === 'banana') {
fruitGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.damage = 30;
self.speed = -16;
}
};
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
var ToughEnemy = Container.expand(function () {
var self = Container.call(this);
self.maxHealth = 250;
self.health = 250;
self.speed = 1;
self.score = 150;
self.lastY = 0;
self.lastIntersecting = false;
var toughEnemyGraphics = self.attachAsset('toughEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.takeDamage = function (damage) {
self.health -= damage;
};
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var cannon = game.addChild(new Cannon());
cannon.x = 2048 / 2;
cannon.y = 2600;
cannon.maxHealth = 100;
cannon.health = 100;
var fruits = [];
var enemies = [];
var enemyProjectiles = [];
var waveCount = 0;
var waveEnemyCount = 0;
var waveEnemySpawned = 0;
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var fruitTypeTxt = new Text2('Fruit: Coconut', {
size: 60,
fill: 0xFFFFFF
});
fruitTypeTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(fruitTypeTxt);
var waveTxt = new Text2('Wave: 1', {
size: 60,
fill: 0xFFFFFF
});
waveTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(waveTxt);
var healthTxt = new Text2('Health: 100', {
size: 60,
fill: 0xFF0000
});
healthTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(healthTxt);
var dragNode = null;
function startNewWave() {
waveCount++;
waveEnemyCount = 3 + waveCount;
waveEnemySpawned = 0;
waveTxt.setText('Wave: ' + waveCount);
}
function spawnEnemy() {
var enemyType = waveCount > 2 && Math.random() > 0.7 ? 'tough' : 'normal';
var newEnemy;
if (enemyType === 'tough') {
newEnemy = new ToughEnemy();
} else {
newEnemy = new Enemy();
}
newEnemy.x = Math.random() * (2048 - 120) + 60;
newEnemy.y = -100;
newEnemy.lastY = newEnemy.y;
newEnemy.lastIntersecting = false;
newEnemy.shootTimer = 0;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
function handleGameOver() {
LK.showGameOver();
}
startNewWave();
var spawnTimer = LK.setInterval(function () {
if (waveEnemySpawned < waveEnemyCount) {
spawnEnemy();
waveEnemySpawned++;
}
}, 1500);
function handleMove(x, y, obj) {
if (dragNode) {
var newX = x;
if (newX < 60) newX = 60;
if (newX > 2048 - 60) newX = 2048 - 60;
dragNode.x = newX;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = cannon;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
var shootInterval = LK.setInterval(function () {
var newFruit = new Fruit();
newFruit.setFruitType(cannon.currentFruit);
newFruit.x = cannon.x;
newFruit.y = cannon.y - 60;
newFruit.lastY = newFruit.y;
fruits.push(newFruit);
game.addChild(newFruit);
LK.getSound('shoot').play();
}, 300);
game.update = function () {
for (var a = fruits.length - 1; a >= 0; a--) {
var fruit = fruits[a];
if (fruit.lastY >= 0 && fruit.y < 0) {
fruit.destroy();
fruits.splice(a, 1);
continue;
}
var fruitHit = false;
for (var b = enemies.length - 1; b >= 0; b--) {
var enemy = enemies[b];
if (fruit.intersects(enemy)) {
enemy.takeDamage(fruit.damage);
LK.getSound('hit').play();
if (enemy.health <= 0) {
LK.setScore(LK.getScore() + enemy.score);
scoreTxt.setText(LK.getScore());
enemy.destroy();
enemies.splice(b, 1);
}
fruit.destroy();
fruits.splice(a, 1);
fruitHit = true;
break;
}
}
for (var d = enemyProjectiles.length - 1; d >= 0; d--) {
var projectile = enemyProjectiles[d];
if (fruit.intersects(projectile)) {
projectile.destroy();
enemyProjectiles.splice(d, 1);
fruit.destroy();
fruits.splice(a, 1);
fruitHit = true;
break;
}
}
}
for (var c = enemies.length - 1; c >= 0; c--) {
var enemy = enemies[c];
enemy.lastY = enemy.y;
enemy.shootTimer++;
if (enemy.shootTimer > 120) {
var newProjectile = new EnemyProjectile();
newProjectile.x = enemy.x;
newProjectile.y = enemy.y;
newProjectile.lastY = newProjectile.y;
enemyProjectiles.push(newProjectile);
game.addChild(newProjectile);
enemy.shootTimer = 0;
}
if (enemy.lastY <= 2732 && enemy.y > 2732) {
handleGameOver();
return;
}
if (enemy.intersects(cannon)) {
handleGameOver();
return;
}
}
for (var e = enemyProjectiles.length - 1; e >= 0; e--) {
var projectile = enemyProjectiles[e];
projectile.lastY = projectile.y;
if (projectile.lastY <= 2732 && projectile.y > 2732) {
projectile.destroy();
enemyProjectiles.splice(e, 1);
continue;
}
if (projectile.intersects(cannon)) {
cannon.health -= projectile.damage;
healthTxt.setText('Health: ' + cannon.health);
LK.getSound('hit').play();
projectile.destroy();
enemyProjectiles.splice(e, 1);
if (cannon.health <= 0) {
handleGameOver();
return;
}
}
}
if (enemies.length === 0 && waveEnemySpawned >= waveEnemyCount) {
startNewWave();
}
if (LK.ticks % 60 === 0) {
cannon.cycleFruit();
fruitTypeTxt.setText('Fruit: ' + cannon.currentFruit.charAt(0).toUpperCase() + cannon.currentFruit.slice(1));
}
};
LK.playMusic('bgmusic', {
loop: true
});
Un banana. In-Game asset. 2d. High contrast. No shadows
Un cañon. In-Game asset. 2d. High contrast. No shadows
Un coco. In-Game asset. 2d. High contrast. No shadows
Una plátano rojo. In-Game asset. 2d. High contrast. No shadows
Un melon. In-Game asset. 2d. High contrast. No shadows
Un Melon rojo. In-Game asset. 2d. High contrast. No shadows