User prompt
zorg dat de enemy jou kan raken en dat dan dood gaaat
User prompt
Fix Bug: 'ReferenceError: enemyBullets is not defined' in this line: 'for (var b = enemyBullets.length - 1; b >= 0; b--) {' Line Number: 164
User prompt
remove the enemy bullet
User prompt
the enemy killt the hero
User prompt
if the enemy touch you, you dead
User prompt
Increase the speed of the enemy
User prompt
increase the speed of the enemy
User prompt
the bulletjes zorgen voor fps drops hoe kunnen we dat fixen zitten er misschien dubbele codes in de code die niks doen
User prompt
zorg dat de bulletjes na 2 seconde verdweinen
User prompt
zorg er voor dat ik de enemy kan killen
User prompt
improve performance
User prompt
fix the FPS drop
User prompt
laat de enemys op je afkomen en laat ze je proberen te killen
User prompt
de enemys doen nu niks fix het
===================================================================
--- original.js
+++ change.js
@@ -70,20 +70,13 @@
startButton.on('down', function () {
self.removeChild(startButton);
hero = self.addChild(new Hero());
var enemies = [];
+ var newEnemy = self.addChild(new Enemy());
+ enemies.push(newEnemy);
hero.x = 1024;
hero.y = 1366;
self.startingScene = false;
- var spawnEnemy = function () {
- var newEnemy = self.addChild(new Enemy());
- newEnemy.x = Math.random() * 2048;
- newEnemy.y = Math.random() * 2732;
- newEnemy.scale.x = newEnemy.scale.y = Math.random() * 2 + 0.5;
- enemies.push(newEnemy);
- LK.setTimeout(spawnEnemy, 2000);
- };
- LK.setTimeout(spawnEnemy, 2000);
});
var leftWall = self.addChild(new Wall());
leftWall.width = 81.92;
leftWall.height = 2732;
@@ -103,8 +96,17 @@
bottomWall.width = 2048;
bottomWall.height = 109.28;
bottomWall.x = 0;
bottomWall.y = 2732 - 109.28;
+ var spawnEnemy = function () {
+ var newEnemy = self.addChild(new Enemy());
+ newEnemy.x = Math.random() * 2048;
+ newEnemy.y = Math.random() * 2732;
+ newEnemy.scale.x = newEnemy.scale.y = Math.random() * 2 + 0.5;
+ enemies.push(newEnemy);
+ LK.setTimeout(spawnEnemy, 2000);
+ };
+ LK.setTimeout(spawnEnemy, 2000);
var heroBullets = [];
var enemyBullets = [];
var isGameOver = false;
var tickOffset = 0;
@@ -151,10 +153,10 @@
var other = enemies[i];
var dx = enemy.x - other.x;
var dy = enemy.y - other.y;
var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < (enemy.graphics.width + other.graphics.width) / 2) {
- var overlap = (enemy.graphics.width + other.graphics.width) / 2 - distance;
+ if (distance < enemy.graphics.width) {
+ var overlap = enemy.graphics.width - distance;
var adjustX = overlap / 2 * (dx / distance);
var adjustY = overlap / 2 * (dy / distance);
enemy.x += adjustX;
enemy.y += adjustY;
@@ -162,64 +164,55 @@
other.y -= adjustY;
}
}
}
- if (Math.random() < 0.01) {
- var newBullet = new EnemyBullet();
- newBullet.x = enemy.x;
- newBullet.y = enemy.y;
- var dx = hero.x - enemy.x;
- var dy = hero.y - enemy.y;
- var mag = Math.sqrt(dx * dx + dy * dy);
- newBullet.speedX = 10 * dx / mag;
- newBullet.speedY = 10 * dy / mag;
- enemyBullets.push(newBullet);
- self.addChild(newBullet);
- }
});
- for (var a = heroBullets.length - 1; a >= 0; a--) {
- heroBullets[a].move();
- if (heroBullets[a].y < 0 || heroBullets[a].y > 2732 || heroBullets[a].x < 0 || heroBullets[a].x > 2048) {
- heroBullets[a].destroy();
- heroBullets.splice(a, 1);
- }
- for (var b = enemyBullets.length - 1; b >= 0; b--) {
- if (heroBullets[a].intersects(enemyBullets[b])) {
+ self.updateBullets = function () {
+ for (var a = heroBullets.length - 1; a >= 0; a--) {
+ heroBullets[a].move();
+ if (heroBullets[a].y < 0 || heroBullets[a].y > 2732 || heroBullets[a].x < 0 || heroBullets[a].x > 2048) {
heroBullets[a].destroy();
- enemyBullets[b].destroy();
heroBullets.splice(a, 1);
- enemyBullets.splice(b, 1);
- break;
}
- }
- for (var e = enemies.length - 1; e >= 0; e--) {
- if (heroBullets[a] && enemies[e] && heroBullets[a].intersects(enemies[e])) {
- var explosion = self.createAsset('explosion', 'Explosion Animation', .5, .5);
- explosion.x = enemies[e].x;
- explosion.y = enemies[e].y;
- enemies[e].destroy();
- enemies.splice(e, 1);
- heroBullets[a].destroy();
- heroBullets.splice(a, 1);
- LK.setTimeout(function () {
- explosion.destroy();
- }, 1000);
- break;
+ for (var b = enemyBullets.length - 1; b >= 0; b--) {
+ if (heroBullets[a].intersects(enemyBullets[b])) {
+ heroBullets[a].destroy();
+ enemyBullets[b].destroy();
+ heroBullets.splice(a, 1);
+ enemyBullets.splice(b, 1);
+ break;
+ }
}
+ for (var e = enemies.length - 1; e >= 0; e--) {
+ if (heroBullets[a] && enemies[e] && heroBullets[a].intersects(enemies[e])) {
+ var explosion = self.createAsset('explosion', 'Explosion Animation', .5, .5);
+ explosion.x = enemies[e].x;
+ explosion.y = enemies[e].y;
+ enemies[e].destroy();
+ enemies.splice(e, 1);
+ heroBullets[a].destroy();
+ heroBullets.splice(a, 1);
+ LK.setTimeout(function () {
+ explosion.destroy();
+ }, 1000);
+ break;
+ }
+ }
}
- }
- for (var a = enemyBullets.length - 1; a >= 0; a--) {
- if (enemyBullets[a]) {
- enemyBullets[a].move();
- if (enemyBullets[a].y > 2732 + 50) {
- enemyBullets[a].destroy();
- enemyBullets.splice(a, 1);
+ for (var a = enemyBullets.length - 1; a >= 0; a--) {
+ if (enemyBullets[a]) {
+ enemyBullets[a].move();
+ if (enemyBullets[a].y > 2732 + 50) {
+ enemyBullets[a].destroy();
+ enemyBullets.splice(a, 1);
+ }
+ if (hero.intersects(enemyBullets[a])) {
+ isGameOver = true;
+ }
}
- if (hero.intersects(enemyBullets[a])) {
- isGameOver = true;
- }
}
- }
+ };
+ self.updateBullets();
var lastBulletTime = 0;
var bulletFireRate = 1000;
var lastBulletTime = 0;
var bulletFireRate = 500;
@@ -228,17 +221,8 @@
var touchDelay = 10000;
stage.on('down', function (obj) {
if (self.startingScene) {
self.startingScene = false;
- var spawnEnemy = function () {
- var newEnemy = self.addChild(new Enemy());
- newEnemy.x = Math.random() * 2048;
- newEnemy.y = Math.random() * 2732;
- newEnemy.scale.x = newEnemy.scale.y = Math.random() * 2 + 0.5;
- enemies.push(newEnemy);
- LK.setTimeout(spawnEnemy, 2000);
- };
- LK.setTimeout(spawnEnemy, 2000);
return;
}
var now = Date.now();
if (now - lastTouchTime < touchDelay) return;
watergun Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
water ball Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
water health bar Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
fire Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
blue play button Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
explosion smoke Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.