User prompt
Half the wave counter size
User prompt
Move the Wave: text next to the pause button.
User prompt
Move the Wave: text closer to the pause button.
User prompt
Move the Wave: text next to the pause button.
User prompt
Move the Wave: text to the topright corner of the map
User prompt
Place the Wave: text to the left bottom corner of the map
User prompt
Remove block from the game
User prompt
Remove boss enemy from the game
User prompt
Ensure hero is not shoot from the center of the asset but from the left and right edge of the asset
User prompt
Migrate to the latest version of LK
Remix started
Copy Air Force War (UPDATE 3.5)
===================================================================
--- original.js
+++ change.js
@@ -1,57 +1,96 @@
/****
* Classes
-****/
-var Star = Container.expand(function () {
+****/
+// Define the ArrowSelector class
+var ArrowSelector = Container.expand(function () {
var self = Container.call(this);
- var starGraphics = self.attachAsset('whiteStar', {
+ var colors = [0x4fd54a, 0xff0000, 0x0000ff, 0xffff00]; // Array of colors to choose from
+ var currentColorIndex = 0; // Start with the first color
+ var leftArrow = self.attachAsset('block', {
+ width: 50,
+ height: 100,
+ color: 0x777777,
anchorX: 0.5,
anchorY: 0.5
});
- // Set a random scale for the star to vary its size
- var scale = Math.random() * 0.5 + 0.5;
- self.scaleX = scale;
- self.scaleY = scale;
- // Set a random alpha for the star to vary its brightness
- self.alpha = Math.random() * 0.5 + 0.5;
- // Set a random speed for the star to move downwards
- self.speed = Math.random() * 1 + 0.5;
- self.move = function () {
- self.y += self.speed;
- // Reset star position if it moves off screen
- if (self.y > 2732) {
- self.y = -10;
- self.x = Math.random() * 2048;
+ var rightArrow = self.attachAsset('block', {
+ width: 50,
+ height: 100,
+ color: 0x777777,
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ leftArrow.x = 100; // Position left arrow
+ leftArrow.y = 2732 - 200; // Position at the bottom of the screen
+ rightArrow.x = 2048 - 100; // Position right arrow
+ rightArrow.y = 2732 - 200; // Position at the bottom of the screen
+ leftArrow.on('down', function () {
+ currentColorIndex--;
+ if (currentColorIndex < 0) {
+ currentColorIndex = colors.length - 1;
}
- };
+ hero.setColor(colors[currentColorIndex]); // Update hero color to the left
+ updateHeroColorText(colors[currentColorIndex]); // Update the text displaying the hero's color
+ });
+ rightArrow.on('down', function () {
+ currentColorIndex++;
+ if (currentColorIndex >= colors.length) {
+ currentColorIndex = 0;
+ }
+ hero.setColor(colors[currentColorIndex]); // Update hero color to the right
+ updateHeroColorText(colors[currentColorIndex]); // Update the text displaying the hero's color
+ });
+ self.addChild(leftArrow);
+ self.addChild(rightArrow);
});
-// Define the Hero class
-var Hero = Container.expand(function () {
+// Define the Block class
+var Block = Container.expand(function () {
var self = Container.call(this);
- var heroGraphics = self.attachAsset('hero', {
+ var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
- self.health = 5; // Player must be hit 5 times before dying
- self.shootInterval = 27; // 0.45 seconds at 60FPS
- self.lastShotTick = 0;
- self.update = function () {
+});
+// Define the BossEnemy class
+var BossEnemy = Container.expand(function () {
+ var self = Container.call(this);
+ var bossGraphics = self.attachAsset('bossEnemy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Initialize boss-specific properties
+ self.health = 50; // Boss has more health
+ self.speed = 2; // Boss moves slower
+ self.shootInterval = 21; // Boss shoots every 0.35 seconds at 60FPS
+ self.lastShotTick = 0; // Track the last shot tick
+ // Initialize direction for structured movement
+ self.directionX = Math.random() < 0.5 ? -1 : 1;
+ self.directionY = Math.random() < 0.5 ? -1 : 1;
+ self._update_migrated = function () {
+ // Boss update logic with structured movement
+ self.x += self.directionX * self.speed;
+ self.y += self.directionY * self.speed;
+ // Reverse direction when hitting the screen boundaries
+ if (self.x <= 100 || self.x >= 1948) {
+ self.directionX *= -1;
+ }
+ if (self.y <= 100 || self.y >= 2732 / 2 - 100) {
+ self.directionY *= -1;
+ }
+ // Boss specific logic for shooting
+ self.shoot();
+ };
+ self.shoot = function () {
if (LK.ticks - self.lastShotTick >= self.shootInterval) {
- this.shoot();
+ var bullet = new EnemyBullet();
+ bullet.x = self.x;
+ bullet.y = self.y + 50; // Adjust bullet start position
+ enemyBullets.push(bullet);
+ game.addChild(bullet);
self.lastShotTick = LK.ticks;
}
- self.setColor = function (color) {
- heroGraphics.tint = color; // Change the tint of the hero
- };
- // Hero update logic
};
- self.shoot = function () {
- var bullet = new HeroBullet();
- bullet.x = this.x;
- bullet.y = this.y - 50; // Adjust bullet start position
- heroBullets.push(bullet);
- game.addChild(bullet);
- };
});
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
@@ -64,9 +103,9 @@
// Initialize direction and speed for structured movement
self.directionX = Math.random() < 0.5 ? -1 : 1;
self.directionY = Math.random() < 0.5 ? -1 : 1;
self.speed = 5;
- self.update = function () {
+ self._update_migrated = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
// Reverse direction when hitting the screen boundaries
if (self.x <= 100 || self.x >= 1948) {
@@ -76,71 +115,82 @@
self.directionY *= -1;
}
};
});
-// Define the HeroBullet class
-var HeroBullet = Container.expand(function () {
+// Define the EnemyBullet class
+var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.attachAsset('heroBullet', {
+ var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = -10;
- self.move = function () {
+ self.speed = 10;
+ self._move_migrated = function () {
self.y += self.speed;
};
});
-// Define the EnemyBullet class
-var EnemyBullet = Container.expand(function () {
+// Define the Hero class
+var Hero = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.attachAsset('enemyBullet', {
+ var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 10;
- self.move = function () {
+ self.health = 5; // Player must be hit 5 times before dying
+ self.shootInterval = 27; // 0.45 seconds at 60FPS
+ self.lastShotTick = 0;
+ self._update_migrated = function () {
+ if (LK.ticks - self.lastShotTick >= self.shootInterval) {
+ this.shoot();
+ self.lastShotTick = LK.ticks;
+ }
+ self.setColor = function (color) {
+ heroGraphics.tint = color; // Change the tint of the hero
+ };
+ // Hero update logic
+ };
+ self.shoot = function () {
+ var bullet = new HeroBullet();
+ bullet.x = this.x;
+ bullet.y = this.y - 50; // Adjust bullet start position
+ heroBullets.push(bullet);
+ game.addChild(bullet);
+ };
+});
+// Define the 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._move_migrated = function () {
self.y += self.speed;
};
});
-// Define the BossEnemy class
-var BossEnemy = Container.expand(function () {
+var Star = Container.expand(function () {
var self = Container.call(this);
- var bossGraphics = self.attachAsset('bossEnemy', {
+ var starGraphics = self.attachAsset('whiteStar', {
anchorX: 0.5,
anchorY: 0.5
});
- // Initialize boss-specific properties
- self.health = 50; // Boss has more health
- self.speed = 2; // Boss moves slower
- self.shootInterval = 21; // Boss shoots every 0.35 seconds at 60FPS
- self.lastShotTick = 0; // Track the last shot tick
- // Initialize direction for structured movement
- self.directionX = Math.random() < 0.5 ? -1 : 1;
- self.directionY = Math.random() < 0.5 ? -1 : 1;
- self.update = function () {
- // Boss update logic with structured movement
- self.x += self.directionX * self.speed;
- self.y += self.directionY * self.speed;
- // Reverse direction when hitting the screen boundaries
- if (self.x <= 100 || self.x >= 1948) {
- self.directionX *= -1;
+ // Set a random scale for the star to vary its size
+ var scale = Math.random() * 0.5 + 0.5;
+ self.scaleX = scale;
+ self.scaleY = scale;
+ // Set a random alpha for the star to vary its brightness
+ self.alpha = Math.random() * 0.5 + 0.5;
+ // Set a random speed for the star to move downwards
+ self.speed = Math.random() * 1 + 0.5;
+ self._move_migrated = function () {
+ self.y += self.speed;
+ // Reset star position if it moves off screen
+ if (self.y > 2732) {
+ self.y = -10;
+ self.x = Math.random() * 2048;
}
- if (self.y <= 100 || self.y >= 2732 / 2 - 100) {
- self.directionY *= -1;
- }
- // Boss specific logic for shooting
- self.shoot();
};
- self.shoot = function () {
- if (LK.ticks - self.lastShotTick >= self.shootInterval) {
- var bullet = new EnemyBullet();
- bullet.x = self.x;
- bullet.y = self.y + 50; // Adjust bullet start position
- enemyBullets.push(bullet);
- game.addChild(bullet);
- self.lastShotTick = LK.ticks;
- }
- };
});
var WaveManager = Container.expand(function () {
var self = Container.call(this);
self.waveCount = 0;
@@ -165,69 +215,19 @@
self.waveCount++;
waveCounterTxt.setText('Wave: ' + (self.waveCount + 1));
};
});
-// Define the Block class
-var Block = Container.expand(function () {
- var self = Container.call(this);
- var blockGraphics = self.attachAsset('block', {
- anchorX: 0.5,
- anchorY: 0.5
- });
-});
-// Define the ArrowSelector class
-var ArrowSelector = Container.expand(function () {
- var self = Container.call(this);
- var colors = [0x4fd54a, 0xff0000, 0x0000ff, 0xffff00]; // Array of colors to choose from
- var currentColorIndex = 0; // Start with the first color
- var leftArrow = self.attachAsset('block', {
- width: 50,
- height: 100,
- color: 0x777777,
- anchorX: 0.5,
- anchorY: 0.5
- });
- var rightArrow = self.attachAsset('block', {
- width: 50,
- height: 100,
- color: 0x777777,
- anchorX: 0.5,
- anchorY: 0.5
- });
- leftArrow.x = 100; // Position left arrow
- leftArrow.y = 2732 - 200; // Position at the bottom of the screen
- rightArrow.x = 2048 - 100; // Position right arrow
- rightArrow.y = 2732 - 200; // Position at the bottom of the screen
- leftArrow.on('down', function () {
- currentColorIndex--;
- if (currentColorIndex < 0) {
- currentColorIndex = colors.length - 1;
- }
- hero.setColor(colors[currentColorIndex]); // Update hero color to the left
- updateHeroColorText(colors[currentColorIndex]); // Update the text displaying the hero's color
- });
- rightArrow.on('down', function () {
- currentColorIndex++;
- if (currentColorIndex >= colors.length) {
- currentColorIndex = 0;
- }
- hero.setColor(colors[currentColorIndex]); // Update hero color to the right
- updateHeroColorText(colors[currentColorIndex]); // Update the text displaying the hero's color
- });
- self.addChild(leftArrow);
- self.addChild(rightArrow);
-});
/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
-****/
+****/
var colorSelector = game.addChild(new ArrowSelector());
var stars = [];
for (var i = 0; i < 100; i++) {
var star = new Star();
@@ -238,16 +238,16 @@
}
// Update the stars in the game tick event
LK.on('tick', function () {
for (var i = 0; i < stars.length; i++) {
- stars[i].move();
+ stars[i]._move_migrated();
}
// Existing game tick code...
});
var waveManager = game.addChild(new WaveManager());
var waveCounterTxt = new Text2('Wave: 0', {
size: 100,
- fill: "#ffffff"
+ fill: 0xFFFFFF
});
LK.gui.top.addChild(waveCounterTxt);
waveManager.createWave();
// Define assets for the game
@@ -261,17 +261,17 @@
var blocks = [];
// Game tick event
LK.on('tick', function () {
// Update hero
- hero.update();
+ hero._update_migrated();
// Update enemies
for (var i = 0; i < waveManager.enemies.length; i++) {
- waveManager.enemies[i].update();
+ waveManager.enemies[i]._update_migrated();
}
// Move hero bullets and check for collisions with enemies
for (var i = heroBullets.length - 1; i >= 0; i--) {
var bullet = heroBullets[i];
- bullet.move();
+ bullet._move_migrated();
// Check for bullet collision with enemies or off-screen
for (var j = waveManager.enemies.length - 1; j >= 0; j--) {
if (bullet.intersects(waveManager.enemies[j])) {
// Decrease enemy health and check if it should be destroyed
@@ -307,9 +307,9 @@
}
// Move enemy bullets and check for collisions
for (var i = enemyBullets.length - 1; i >= 0; i--) {
var bullet = enemyBullets[i];
- bullet.move();
+ bullet._move_migrated();
// Check for bullet collision with hero or off-screen
if (bullet.intersects(hero)) {
hero.health -= 1; // Decrease hero's health by one
LK.effects.flashObject(hero, 0xff0000, 500);
@@ -327,15 +327,15 @@
}
}
});
// Touch event handling for hero movement and shooting
-game.on('down', function (obj) {
- var pos = obj.event.getLocalPosition(game);
+game.on('down', function (x, y, obj) {
+ var pos = game.toLocal(obj.global);
hero.x = pos.x;
});
var heroColorText = new Text2('', {
size: 50,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
x: 2048 / 2,
y: 2732 - 100
});
LK.gui.bottom.addChild(heroColorText);
@@ -356,12 +356,12 @@
heroBullets.push(bullet);
game.addChild(bullet);
};
// Update the hero's position based on touch movement
-game.on('move', function (obj) {
- var pos = obj.event.getLocalPosition(game);
+game.on('move', function (x, y, obj) {
+ var pos = game.toLocal(obj.global);
hero.x = pos.x;
});
// Ensure the hero stays within the game boundaries
-Hero.prototype.update = function () {
+Hero.prototype._update_migrated = function () {
this.x = Math.max(50, Math.min(this.x, 2048 - 50));
};
\ No newline at end of file