/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Enemy update logic var speedIncrease; if (LK.getScore() >= 40) { speedIncrease = 4; } else if (LK.getScore() >= 30) { speedIncrease = 2; } else { speedIncrease = Math.floor(LK.getScore() / 30); } self.y += 2 + speedIncrease; // Move the enemy downwards }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Hero update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000, //Init game with black background name: 'Foot 2.0' }); /**** * Game Code ****/ // Initialize variables var hero; var enemies = []; var bullets = []; var score = 0; var scoreTxt; var dragNode = null; // Initialize game elements function initGame() { // Create background var background = LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0, x: 0, y: 0 }); game.addChild(background); // Create hero hero = new Hero(); hero.x = 2048 / 2; hero.y = 2732 - 200; game.addChild(hero); hero.zIndex = 1000; // Set a high z-index to make the 'hero' asset appear in front of other elements // Create score text scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create enemies for (var i = 0; i < 10; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 1000; enemies.push(enemy); game.addChild(enemy); } } // Handle game updates game.update = function () { // Update hero hero.update(); // Update enemies for (var i = 0; i < enemies.length; i++) { enemies[i].update(); if (hero.intersects(enemies[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Remove enemy if it is off the screen if (enemies[i].y > 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); enemies[i].destroy(); enemies.splice(i, 1); i--; } } // Create new enemy every 60 ticks // Double the spawn rate when the player reaches 50 points // Quadruple the spawn rate when the player reaches 150 points var spawnRate; if (score >= 200) { spawnRate = 120; } else if (score >= 150) { spawnRate = 15; } else if (score >= 50) { spawnRate = 30; } else { spawnRate = 60; } if (LK.ticks % spawnRate == 0) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -100; enemies.push(enemy); game.addChild(enemy); } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); if (bullets[j].y < -50) { bullets[j].destroy(); bullets.splice(j, 1); } for (var k = enemies.length - 1; k >= 0; k--) { if (bullets[j] && bullets[j].intersects(enemies[k])) { score++; scoreTxt.setText(score); bullets[j].destroy(); bullets.splice(j, 1); enemies[k].destroy(); enemies.splice(k, 1); break; } } } // Add a giant donut when the player reaches 100 points if (score == 100) { var donut = LK.getAsset('donut', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2, x: 2048 / 2, y: 2732 / 2 }); game.addChild(donut); } // Add a '3' asset when the player reaches 500 points to the right of the screen if (score == 500) { var three = LK.getAsset('3', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2, x: 2048 - 100, y: 2732 / 2 }); game.addChild(three); three.zIndex = 1000; // Set a high z-index to make the '3' asset appear in front of other elements } // Add a 'Raclette' asset when the player reaches 1000 points to the right of the screen if (score == 1000) { var raclette = LK.getAsset('Raclette', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2, x: 2048 - 100, y: 2732 / 2 }); game.addChild(raclette); } // Fire bullet var bulletSpawnRate = score >= 150 ? 3.75 : score >= 100 ? 7.5 : score >= 30 ? 15 : 30; if (LK.ticks % bulletSpawnRate == 0) { var newBullet = new Bullet(); newBullet.x = hero.x; newBullet.y = hero.y; bullets.push(newBullet); game.addChild(newBullet); } }; // Define handleMove function function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } } // Handle touch/mouse down game.down = function (x, y, obj) { dragNode = hero; handleMove(x, y, obj); }; // Handle touch/mouse up game.up = function (x, y, obj) { dragNode = null; }; // Handle touch/mouse move game.move = handleMove; // Initialize game initGame();
/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Enemy update logic
var speedIncrease;
if (LK.getScore() >= 40) {
speedIncrease = 4;
} else if (LK.getScore() >= 30) {
speedIncrease = 2;
} else {
speedIncrease = Math.floor(LK.getScore() / 30);
}
self.y += 2 + speedIncrease; // Move the enemy downwards
};
});
//<Assets used in the game will automatically appear here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Hero update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
//Init game with black background
name: 'Foot 2.0'
});
/****
* Game Code
****/
// Initialize variables
var hero;
var enemies = [];
var bullets = [];
var score = 0;
var scoreTxt;
var dragNode = null;
// Initialize game elements
function initGame() {
// Create background
var background = LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
});
game.addChild(background);
// Create hero
hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 200;
game.addChild(hero);
hero.zIndex = 1000; // Set a high z-index to make the 'hero' asset appear in front of other elements
// Create score text
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create enemies
for (var i = 0; i < 10; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
}
// Handle game updates
game.update = function () {
// Update hero
hero.update();
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
if (hero.intersects(enemies[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Remove enemy if it is off the screen
if (enemies[i].y > 2732) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
enemies[i].destroy();
enemies.splice(i, 1);
i--;
}
}
// Create new enemy every 60 ticks
// Double the spawn rate when the player reaches 50 points
// Quadruple the spawn rate when the player reaches 150 points
var spawnRate;
if (score >= 200) {
spawnRate = 120;
} else if (score >= 150) {
spawnRate = 15;
} else if (score >= 50) {
spawnRate = 30;
} else {
spawnRate = 60;
}
if (LK.ticks % spawnRate == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100;
enemies.push(enemy);
game.addChild(enemy);
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < -50) {
bullets[j].destroy();
bullets.splice(j, 1);
}
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j] && bullets[j].intersects(enemies[k])) {
score++;
scoreTxt.setText(score);
bullets[j].destroy();
bullets.splice(j, 1);
enemies[k].destroy();
enemies.splice(k, 1);
break;
}
}
}
// Add a giant donut when the player reaches 100 points
if (score == 100) {
var donut = LK.getAsset('donut', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(donut);
}
// Add a '3' asset when the player reaches 500 points to the right of the screen
if (score == 500) {
var three = LK.getAsset('3', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
x: 2048 - 100,
y: 2732 / 2
});
game.addChild(three);
three.zIndex = 1000; // Set a high z-index to make the '3' asset appear in front of other elements
}
// Add a 'Raclette' asset when the player reaches 1000 points to the right of the screen
if (score == 1000) {
var raclette = LK.getAsset('Raclette', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
x: 2048 - 100,
y: 2732 / 2
});
game.addChild(raclette);
}
// Fire bullet
var bulletSpawnRate = score >= 150 ? 3.75 : score >= 100 ? 7.5 : score >= 30 ? 15 : 30;
if (LK.ticks % bulletSpawnRate == 0) {
var newBullet = new Bullet();
newBullet.x = hero.x;
newBullet.y = hero.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};
// Define handleMove function
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
// Handle touch/mouse down
game.down = function (x, y, obj) {
dragNode = hero;
handleMove(x, y, obj);
};
// Handle touch/mouse up
game.up = function (x, y, obj) {
dragNode = null;
};
// Handle touch/mouse move
game.move = handleMove;
// Initialize game
initGame();
Balle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Footballeur couleur. Single Game Texture. In-Game asset. 3D Blank background. High contrast. No shadows.
Cage de foot. Single Game Texture. In-Game asset. 3D Blank background. High contrast. No shadows.
Donut nappage chocolat fraise. Single Game Texture. In-Game asset. 3D Blank background. High contrast. No shadows.
Pizza à l'ananas. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Raclette. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Stade de foot à Paris. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.