Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: sself is not defined' in or related to this line: 'sself.y += self.speed * multiplier;' Line Number: 106
Code edit (2 edits merged)
Please save this source code
User prompt
When enemies spawn, their speed is not always the same.
User prompt
Every time an enemy changes direction, its speed can change. It speeds up or slows down
Code edit (1 edits merged)
Please save this source code
User prompt
Stars must also die when they leave the game zone.
User prompt
When projectiles and enemies leave the game zone, they die.
Code edit (2 edits merged)
Please save this source code
User prompt
Enemies can only change direction every 60 ticks
User prompt
Enemies must also move from left to right as they descend.
Code edit (4 edits merged)
Please save this source code
User prompt
The hero must follow the movement of the player's mouse cursor while moving at maximum speed.
User prompt
Integrate a scrollable star fiel, behind everything, providing an illusion of ongoing forward movement. Faster moving stars should beb more visible
Code edit (1 edits merged)
Please save this source code
User prompt
Enemy projectiles must move downwards
User prompt
The hero must die if he touches an enemy
User prompt
The hero must die if he hits a projectile
User prompt
The speed of enemy projectiles must be faster than the speed of enemy movement.
User prompt
Enemies must fire projectiles
User prompt
Enemies no longer fire projectiles
Initial prompt
Demo_SpaceInvaderTribute
/**** * Classes ****/ var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.move = function (x, y) { self.x = x; self.y = y; }; self.shoot = function () { var bullet = new HeroBullet(); bullet.x = self.x; bullet.y = self.y - self.height / 2; game.addChild(bullet); return bullet; }; }); 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.move = function () { self.y += self.speed; }; self.shoot = function () { var bullet = new EnemyBullet(); bullet.x = self.x; bullet.y = self.y + self.height / 2; game.addChild(bullet); return bullet; }; }); var HeroBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('heroBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.move = function () { self.y += self.speed; }; }); var EnemyBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('enemyBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.move = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 100; var enemies = []; var heroBullets = []; var enemyBullets = []; var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.on('down', function (obj) { var pos = obj.event.getLocalPosition(game); hero.move(pos.x, pos.y); }); LK.on('tick', function () { // Move hero bullets for (var i = heroBullets.length - 1; i >= 0; i--) { heroBullets[i].move(); if (heroBullets[i].y < 0) { heroBullets[i].destroy(); heroBullets.splice(i, 1); } } // Move enemies and make them shoot for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].move(); if (LK.ticks % 120 == 0) { enemyBullets.push(enemies[j].shoot()); } if (enemies[j].y > 2732) { enemies[j].destroy(); enemies.splice(j, 1); } } // Check for collisions for (var k = heroBullets.length - 1; k >= 0; k--) { for (var l = enemies.length - 1; l >= 0; l--) { if (heroBullets[k].intersects(enemies[l])) { heroBullets[k].destroy(); heroBullets.splice(k, 1); enemies[l].destroy(); enemies.splice(l, 1); score += 10; scoreTxt.setText(score.toString()); break; } } } // Spawn enemies if (LK.ticks % 120 == 0) { var enemy = new Enemy(); enemy.x = Math.random() * (2048 - enemy.width) + enemy.width / 2; enemy.y = -enemy.height / 2; enemies.push(enemy); game.addChild(enemy); } // Hero shoot if (LK.ticks % 30 == 0) { heroBullets.push(hero.shoot()); } });
===================================================================
--- original.js
+++ change.js
@@ -53,9 +53,9 @@
var bulletGraphics = self.attachAsset('enemyBullet', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 5;
+ self.speed = 10;
self.move = function () {
self.y += self.speed;
};
});