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
var Wall = Container.expand(function () {
var self = Container.call(this);
self.createAsset('wall', 'Wall', 0, 0);
self.isBarrier = true;
});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet Graphics', .5, .5);
self.speed = -10;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
self.timer = LK.setTimeout(function () {
self.destroy();
}, 5000);
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('enemyBullet', 'Enemy Bullet Graphics', .5, .5);
self.speed = 10;
self.move = function () {
self.x += self.speed;
};
self.timer = LK.setTimeout(function () {
self.destroy();
}, 5000);
});
var Hero = Container.expand(function () {
var self = Container.call(this);
self.update = function () {
if (self.dx && self.dy) {
self.x -= self.dx;
self.y -= self.dy;
self.dx *= 0.95;
self.dy *= 0.95;
if (Math.abs(self.dx) < 0.01 && Math.abs(self.dy) < 0.01) {
self.dx = 0;
self.dy = 0;
}
}
};
var heroGraphics = self.createAsset('hero', 'Hero character', .5, .5);
heroGraphics.rotation = 42 * (Math.PI / 180);
self.knockback = function (dx, dy) {
self.dx = -dx * 116.886 * 3.645;
self.dy = -dy * 116.886 * 3.645;
};
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.createAsset('enemy', 'Enemy character', .5, .5);
self.followHero = function (hero) {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var mag = Math.sqrt(dx * dx + dy * dy);
self.x += 3.85 * dx / mag;
self.y += 3.85 * dy / mag;
};
self.shoot = function (hero) {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var mag = Math.sqrt(dx * dx + dy * dy);
var newBullet = new EnemyBullet();
newBullet.x = self.x;
newBullet.y = self.y;
newBullet.speedX = 10 * dx / mag;
newBullet.speedY = 10 * dy / mag;
return newBullet;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var enemies = [];
LK.stageContainer.setBackgroundColor(0x000000);
self.startingScene = true;
var startButton = self.createAsset('startButton', 'Start Button', .5, .5);
startButton.x = 1024;
startButton.y = 1366;
var hero;
startButton.on('down', function () {
self.removeChild(startButton);
hero = self.addChild(new Hero());
var enemies = [];
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;
leftWall.x = 0;
leftWall.y = 0;
var rightWall = self.addChild(new Wall());
rightWall.width = 81.92;
rightWall.height = 2732;
rightWall.x = 2048 - 81.92;
rightWall.y = 0;
var topWall = self.addChild(new Wall());
topWall.width = 2048;
topWall.height = 109.28;
topWall.x = 0;
topWall.y = 0;
var bottomWall = self.addChild(new Wall());
bottomWall.width = 2048;
bottomWall.height = 109.28;
bottomWall.x = 0;
bottomWall.y = 2732 - 109.28;
var heroBullets = [];
var enemyBullets = [];
var isGameOver = false;
var tickOffset = 0;
var fpsCounter = new Text2('0', {
size: 50,
fill: '#ffffff'
});
LK.gui.topCenter.addChild(fpsCounter);
var gameTimerCounter = new Text2('0', {
size: 50,
fill: '#ffffff'
});
gameTimerCounter.x = -50;
LK.gui.topRight.addChild(gameTimerCounter);
var gameStartTime = Date.now();
var lastTick = Date.now();
var frameCount = 0;
LK.on('tick', function () {
if (self.startingScene) {
return;
}
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
frameCount++;
var now = Date.now();
if (now - lastTick >= 1000) {
fpsCounter.setText(frameCount);
frameCount = 0;
lastTick = now;
var gameElapsedTime = Math.floor((now - gameStartTime) / 1000);
gameTimerCounter.setText(gameElapsedTime.toString());
}
hero.update();
if (hero.x < leftWall.width + 0.025 * 2048) hero.x = leftWall.width + 0.025 * 2048;
if (hero.x > 2048 - rightWall.width - 0.025 * 2048) hero.x = 2048 - rightWall.width - 0.025 * 2048;
if (hero.y < topWall.height + 0.025 * 2732) hero.y = topWall.height + 0.025 * 2732;
if (hero.y > 2732 - bottomWall.height - 0.025 * 2732) hero.y = 2732 - bottomWall.height - 0.025 * 2732;
enemies.forEach(function (enemy, index) {
enemy.followHero(hero);
if (Math.random() < 0.01) {
var bullet = enemy.shoot(hero);
enemyBullets.push(bullet);
self.addChild(bullet);
}
for (var i = 0; i < enemies.length; i++) {
if (i !== index) {
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;
var adjustX = overlap / 2 * (dx / distance);
var adjustY = overlap / 2 * (dy / distance);
enemy.x += adjustX;
enemy.y += adjustY;
other.x -= adjustX;
other.y -= adjustY;
}
}
}
});
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])) {
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);
}
if (hero.intersects(enemyBullets[a])) {
isGameOver = true;
}
}
}
var lastBulletTime = 0;
var bulletFireRate = 1000;
var lastBulletTime = 0;
var bulletFireRate = 500;
var lastBulletTime = 0;
var lastTouchTime = 0;
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;
lastTouchTime = now;
if (now - lastBulletTime < bulletFireRate) return;
lastBulletTime = now;
var event = obj.event;
var pos = event.getLocalPosition(self);
var newBullet = new HeroBullet();
newBullet.x = hero.x;
newBullet.y = hero.y;
var dx = pos.x - hero.x;
var dy = pos.y - hero.y;
var mag = Math.sqrt(dx * dx + dy * dy);
newBullet.speedX = 10 * dx / mag;
newBullet.speedY = 10 * dy / mag;
heroBullets.push(newBullet);
self.addChild(newBullet);
hero.knockback(-dx / (mag * 10), -dy / (mag * 10));
if (dx < 0) {
hero.scale.x = 1;
} else {
hero.scale.x = -1;
}
});
});
});
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.