/**** * Classes ****/ // Define an 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 = 2; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; self.x = Math.random() * 2048; } }; }); //<Assets used in the game will automatically appear here> // Define a Player class var Player = Container.expand(function () { var self = Container.call(this); var playerBody = self.attachAsset('playerBody', { anchorX: 0.5, anchorY: 0.5 }); playerBody.y = 10; var playerHead = self.attachAsset('playerHead', { anchorX: 0.5, anchorY: 0.5 }); playerHead.y = -20; self.speed = 5; self.update = function () { // Player update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 150; // Initialize enemies var enemies = []; for (var i = 0; i < 5; i++) { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = Math.random() * 1000; enemies.push(enemy); game.addChild(enemy); } // Bullet array initialization removed // Handle player movement game.move = function (x, y, obj) { player.x = x; player.y = y; }; // Handle shooting game.down = function (x, y, obj) { // Shooting logic removed }; // Game update loop game.update = function () { // Update enemies for (var i = 0; i < enemies.length; i++) { enemies[i].update(); if (player.intersects(enemies[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Bullet update logic removed };
===================================================================
--- original.js
+++ change.js
@@ -20,12 +20,18 @@
//<Assets used in the game will automatically appear here>
// Define a Player class
var Player = Container.expand(function () {
var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
+ var playerBody = self.attachAsset('playerBody', {
anchorX: 0.5,
anchorY: 0.5
});
+ playerBody.y = 10;
+ var playerHead = self.attachAsset('playerHead', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ playerHead.y = -20;
self.speed = 5;
self.update = function () {
// Player update logic
};