User prompt
переделай систему спавна врагов, что бы они появлялись в разное время
User prompt
из убитых врагов может выпасть дополнительная жизнь с шансом 1 к 100, игрок может подобрать жизнь восстановив себе 1 единицу жизни, после подбора значок жизни исчезает с карты
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'powerUp.x = enemies[j].x;' Line Number: 258
User prompt
игрок может поднимать бонусы прикоснувшись к нему
User prompt
из убитых врагов может с небольшим шансом выпасть бонус. добавь 3 вида бонусов например: временное увеличение скорости передвижения героя", увеличение скорости стрельбы
User prompt
Fix Bug: 'ReferenceError: ShootingEnemy is not defined' in this line: 'enemy = new ShootingEnemy();' Line Number: 156
===================================================================
--- original.js
+++ change.js
@@ -1,14 +1,15 @@
/****
* Classes
****/
-var PowerUp = Container.expand(function () {
+// LifePickup class
+var LifePickup = Container.expand(function () {
var self = Container.call(this);
- self.type = Math.floor(Math.random() * 3);
- var powerUpGraphics = self.createAsset('powerUp' + self.type, 'PowerUp Graphics', 0.5, 0.5);
- self.speed = 2;
- self.move = function () {
- self.y += self.speed;
+ var lifeGraphics = self.createAsset('lifePickup', 'Extra Life Pickup', 0.5, 0.5);
+ self.pickup = function (hero) {
+ hero.lives += 1;
+ livesDisplay.updateLives(hero.lives);
+ self.destroy();
};
});
// HealthBar class
var LivesDisplay = Container.expand(function () {
@@ -156,9 +157,8 @@
// Initialize enemies and bullets arrays
var enemies = [];
var bullets = [];
var enemyBullets = []; // Array for bullets shot by ShootingEnemy
-var powerUps = []; // Array for power-ups that are currently in the game
// Initialize firing rate, enemy spawn rate, and wave system
var firingRate = 30; // Increased firing rate (ticks)
var spawnRate = 180; // Increased enemy spawn rate (ticks) to decrease intensity
var waveCount = 0; // Number of waves that have passed
@@ -247,18 +247,17 @@
// Destroy enemy and update score
score += 1; // Increment score
scoreDisplay.updateScore(score); // Update score display
spawnRate = Math.max(30, spawnRate - 5); // Decrease spawn rate by 5 ticks to a minimum of 30 ticks
+ // Chance to drop a LifePickup
+ if (Math.random() < 0.01) {
+ var lifePickup = new LifePickup();
+ lifePickup.x = enemies[j].x;
+ lifePickup.y = enemies[j].y;
+ game.addChild(lifePickup);
+ }
enemies[j].destroy();
enemies.splice(j, 1);
- // 20% chance to spawn a power-up
- if (Math.random() < 0.2) {
- var powerUp = new PowerUp();
- powerUp.x = bullets[i].x;
- powerUp.y = bullets[i].y;
- powerUps.push(powerUp);
- game.addChild(powerUp);
- }
// Destroy bullet
bullets[i].destroy();
bullets.splice(i, 1);
break; // Break out of the enemies loop since the bullet is destroyed
@@ -282,38 +281,8 @@
if (hero.lives <= 0) {
LK.showGameOver(); // If no lives left, show game over
return;
}
- // Move power-ups and check for collisions with the hero
- for (var i = powerUps.length - 1; i >= 0; i--) {
- powerUps[i].move();
- if (powerUps[i].intersects(hero)) {
- // Apply power-up effect based on its type
- switch (powerUps[i].type) {
- case 0:
- // Increase hero's movement speed temporarily
- hero.speed += 2;
- LK.setTimeout(function () {
- hero.speed -= 2;
- }, 5000);
- break;
- case 1:
- // Increase hero's firing rate temporarily
- firingRate = Math.max(10, firingRate - 10);
- LK.setTimeout(function () {
- firingRate = Math.min(30, firingRate + 10);
- }, 5000);
- break;
- case 2:
- // Increase hero's lives
- hero.lives = Math.min(5, hero.lives + 1);
- livesDisplay.updateLives(hero.lives);
- break;
- }
- powerUps[i].destroy();
- powerUps.splice(i, 1);
- }
- }
}
enemies[j].destroy(); // Destroy the enemy that collided with the hero
enemies.splice(j, 1);
}
@@ -348,8 +317,14 @@
enemyBullets[i].destroy();
enemyBullets.splice(i, 1);
}
}
+ // Check for hero collision with LifePickup
+ for (var i = game.children.length - 1; i >= 0; i--) {
+ if (game.children[i] instanceof LifePickup && game.children[i].intersects(hero)) {
+ game.children[i].pickup(hero);
+ }
+ }
// Fire bullets
if (LK.ticks % firingRate === 0) {
fireBullet();
hero with a gun, shoots forward, top view, topdown. Single Game Texture. In-Game asset. 2d.TopDown. Blank background. High contrast. No shadows.
metal ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A fireball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
zombie kamikaze, vertical top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
opponent for the game, zombie kamikaze, vertical top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.