===================================================================
--- original.js
+++ change.js
@@ -1,18 +1,27 @@
+/****
+* Classes
+****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.createAsset('bullet', 'Bullet Graphics', .5, .5);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.speed = 20;
- self.move = function () {
+ self._move_migrated = function () {
self.x += self.speed * Math.cos(self.angle);
self.y += self.speed * Math.sin(self.angle);
self.rotation += 0.1;
};
});
var Enemy = Container.expand(function (hero) {
var self = Container.call(this);
- var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
- self.move = function () {
+ var enemyGraphics = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
self.x += dx / distance * 1.8;
@@ -20,10 +29,13 @@
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
- var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
- self.move = function () {
+ var heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self._move_migrated = function () {
if (self.targetPos) {
var dx = self.targetPos.x - self.x;
var dy = self.targetPos.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
@@ -37,80 +49,88 @@
}
}
};
});
-var Game = Container.expand(function () {
- var self = Container.call(this);
- LK.stageContainer.setBackgroundColor(0x008000);
- var hero = self.addChild(new Hero());
- hero.enemies = [];
- var heroBullets = [];
- var enemyBullets = [];
- hero.x = 2048 / 2;
- hero.y = 2732 / 2;
- self.targetPos = null;
- stage.on('down', function (obj) {
- hero.targetPos = obj.event.getLocalPosition(self);
- });
- var spawnEnemy = function () {
- var side = Math.floor(Math.random() * 4);
- var enemy = new Enemy(hero);
- switch (side) {
- case 0:
- enemy.x = Math.random() * 2048;
- enemy.y = 0;
- break;
- case 1:
- enemy.x = 2048;
- enemy.y = Math.random() * 2732;
- break;
- case 2:
- enemy.x = Math.random() * 2048;
- enemy.y = 2732;
- break;
- case 3:
- enemy.x = 0;
- enemy.y = Math.random() * 2732;
- break;
- }
- hero.enemies.push(enemy);
- self.addChild(enemy);
- };
- LK.on('tick', function () {
- hero.move();
- for (var i = 0; i < heroBullets.length; i++) {
- heroBullets[i].move();
- }
- for (var i = 0; i < enemyBullets.length; i++) {
- enemyBullets[i].move();
- }
- for (var i = 0; i < hero.enemies.length; i++) {
- hero.enemies[i].move();
- for (var j = 0; j < heroBullets.length; j++) {
- if (heroBullets[j].intersects(hero.enemies[i])) {
- heroBullets[j].destroy();
- heroBullets.splice(j, 1);
- hero.enemies[i].destroy();
- hero.enemies.splice(i, 1);
- i--;
- j--;
- }
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+game.setBackgroundColor(0x008000);
+var hero = game.addChild(new Hero());
+hero.enemies = [];
+var heroBullets = [];
+var enemyBullets = [];
+hero.x = 2048 / 2;
+hero.y = 2732 / 2;
+game.targetPos = null;
+game.on('down', function (x, y, obj) {
+ hero.targetPos = game.toLocal(obj.global);
+});
+var spawnEnemy = function spawnEnemy() {
+ var side = Math.floor(Math.random() * 4);
+ var enemy = new Enemy(hero);
+ switch (side) {
+ case 0:
+ enemy.x = Math.random() * 2048;
+ enemy.y = 0;
+ break;
+ case 1:
+ enemy.x = 2048;
+ enemy.y = Math.random() * 2732;
+ break;
+ case 2:
+ enemy.x = Math.random() * 2048;
+ enemy.y = 2732;
+ break;
+ case 3:
+ enemy.x = 0;
+ enemy.y = Math.random() * 2732;
+ break;
+ }
+ hero.enemies.push(enemy);
+ game.addChild(enemy);
+};
+LK.on('tick', function () {
+ hero._move_migrated();
+ for (var i = 0; i < heroBullets.length; i++) {
+ heroBullets[i]._move_migrated();
+ }
+ for (var i = 0; i < enemyBullets.length; i++) {
+ enemyBullets[i]._move_migrated();
+ }
+ for (var i = 0; i < hero.enemies.length; i++) {
+ hero.enemies[i]._move_migrated();
+ for (var j = 0; j < heroBullets.length; j++) {
+ if (heroBullets[j].intersects(hero.enemies[i])) {
+ heroBullets[j].destroy();
+ heroBullets.splice(j, 1);
+ hero.enemies[i].destroy();
+ hero.enemies.splice(i, 1);
+ i--;
+ j--;
}
- if (hero.intersects(hero.enemies[i])) {
- LK.showGameOver();
- }
}
- if (LK.ticks % 30 === 0) {
- spawnEnemy();
+ if (hero.intersects(hero.enemies[i])) {
+ LK.showGameOver();
}
- if (LK.ticks % 20 === 0 && hero.targetPos) {
- var bullet = new Bullet();
- bullet.x = hero.x;
- bullet.y = hero.y;
- var dx = hero.targetPos.x - hero.x;
- var dy = hero.targetPos.y - hero.y;
- bullet.angle = Math.atan2(dy, dx);
- heroBullets.push(bullet);
- self.addChild(bullet);
- }
- });
-});
+ }
+ if (LK.ticks % 30 === 0) {
+ spawnEnemy();
+ }
+ if (LK.ticks % 20 === 0 && hero.targetPos) {
+ var bullet = new Bullet();
+ bullet.x = hero.x;
+ bullet.y = hero.y;
+ var dx = hero.targetPos.x - hero.x;
+ var dy = hero.targetPos.y - hero.y;
+ bullet.angle = Math.atan2(dy, dx);
+ heroBullets.push(bullet);
+ game.addChild(bullet);
+ }
+});
\ No newline at end of file
vampire hunter pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art vampire, single sprite Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art boomerang Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.