/**** * Classes ****/ // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins 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.speed = 10; self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - heroGraphics.height / 2; game.addChild(bullet); heroBullets.push(bullet); }; }); // HeroBullet class var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; if (self.y < 0) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var background = game.attachAsset('background', { anchorX: 0.0, anchorY: 0.0 }); // Initialize variables var hero; var enemies = []; var heroBullets = []; var score = 0; var health = 5; // Initialize hero's health to 5 var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y += 60; // Create hero hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 200; // Create health text field var healthTxt = new Text2('Health: 5', { size: 100, fill: 0xFFFFFF }); healthTxt.anchor.set(0.5, 0); LK.gui.top.addChild(healthTxt); // Handle game events game.down = function (x, y, obj) { hero.x = x; }; game.move = function (x, y, obj) { hero.x = x; }; game.update = function () { // Update hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].update(); for (var j = enemies.length - 1; j >= 0; j--) { if (heroBullets[i].intersects(enemies[j]) && enemies[j].y > 0) { enemies[j].destroy(); heroBullets[i].destroy(); enemies.splice(j, 1); heroBullets.splice(i, 1); score++; scoreTxt.setText(score); break; } } } // Update enemies for (var k = enemies.length - 1; k >= 0; k--) { enemies[k].update(); if (enemies[k].intersects(hero)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Decrease hero's health only when an enemy passes by if (enemies[k].y > 2732 && !enemies[k].passed) { enemies[k].passed = true; health--; healthTxt.setText('Health: ' + health); // End the game if the hero's health reaches 0 if (health <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } // Spawn enemies if (LK.ticks % 60 == 0) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -50; game.addChild(enemy); enemies.push(enemy); } // Hero shooting if (LK.ticks % 60 == 0) { hero.shoot(); } };
/****
* Classes
****/
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins 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.speed = 10;
self.shoot = function () {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
if (self.y < 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0.0,
anchorY: 0.0
});
// Initialize variables
var hero;
var enemies = [];
var heroBullets = [];
var score = 0;
var health = 5; // Initialize hero's health to 5
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y += 60;
// Create hero
hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 200;
// Create health text field
var healthTxt = new Text2('Health: 5', {
size: 100,
fill: 0xFFFFFF
});
healthTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(healthTxt);
// Handle game events
game.down = function (x, y, obj) {
hero.x = x;
};
game.move = function (x, y, obj) {
hero.x = x;
};
game.update = function () {
// Update hero bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
heroBullets[i].update();
for (var j = enemies.length - 1; j >= 0; j--) {
if (heroBullets[i].intersects(enemies[j]) && enemies[j].y > 0) {
enemies[j].destroy();
heroBullets[i].destroy();
enemies.splice(j, 1);
heroBullets.splice(i, 1);
score++;
scoreTxt.setText(score);
break;
}
}
}
// Update enemies
for (var k = enemies.length - 1; k >= 0; k--) {
enemies[k].update();
if (enemies[k].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
// Decrease hero's health only when an enemy passes by
if (enemies[k].y > 2732 && !enemies[k].passed) {
enemies[k].passed = true;
health--;
healthTxt.setText('Health: ' + health);
// End the game if the hero's health reaches 0
if (health <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
// Spawn enemies
if (LK.ticks % 60 == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -50;
game.addChild(enemy);
enemies.push(enemy);
}
// Hero shooting
if (LK.ticks % 60 == 0) {
hero.shoot();
}
};
F16 2 boyut çapraz değil düz. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
ışın kılıcı ucu. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2 boyut kanlı bir arkaplan. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2 boyut roket. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.