User prompt
Quando o laser toca no asteróide, ele diminuí 25% de seu tamanho
User prompt
Se o asteroide diminuír todo seu tamanho, ele explodirá em partículas que voam por ai,
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (lasers[i].intersects(asteroids[j])) {' Line Number: 236
User prompt
Se o laser acertar o asteroide, o asteroide diminuí 10% do tamanho dele
User prompt
Terá um sinturão de asteróides no meio, (12 asteróides) girando 109 por minuto
User prompt
Deixe a lua girando também, por 120 por minuto
User prompt
Deixe a terra girando por 341 por minuto
User prompt
Adicione o planeta Terra ao lado esquerdo, e a lua no lado direito mais pra baixo girando na velocidade 260
User prompt
Remova o contador de segundos
User prompt
Adicione um contador de segundos para saber quando o inimigo vai chegar
User prompt
O inimigo aparecerá há cada 5 segundos
User prompt
O inimigo terá 100 de vidas, se atirar nele ele perdeu -1 de vida, e aparecerá um contador de vidas deles quando ele aparecer
User prompt
Terá um contador de minutos, para quando vai aparecer o inimigo
User prompt
Terá um contador de minutos para aparecer o inimigo
User prompt
O fundo será preto mesmo
User prompt
O fundo será um ativo
User prompt
O fundo será amarelo
User prompt
Há cada 1 minuto, aparece dois inimigo (uma nave vermelha), eles atiram em você há cada 2 segundos com o maior laser que dá só 10 de dano, e você tem 400 vidas, terá um contador de vidas em cima
User prompt
As particulas se espalham
User prompt
Faça partículas pequenas!, (bolinhas) que desaparecem há 3 segundos com animação
User prompt
O raio laser deve ser vermelho e mais grosso, e sai partículas do laser com animação
Initial prompt
SpaceGate
/****
* Classes
****/
// Asteroid class
var Asteroid = Container.expand(function () {
var self = Container.call(this);
var asteroidGraphics = self.attachAsset('asteroid', {
anchorX: 0.5,
anchorY: 0.5
});
// Asteroid rotation speed
self.speed = 109 / 60 / 360; // 109 degrees per minute
// Update method for the asteroid
self.update = function () {
self.rotation += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.health = 100;
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
color: 0xFF0000,
shape: 'box',
width: 50,
height: 50
});
self.healthTxt = new Text2('Health: ' + self.health, {
size: 50,
fill: "#ffffff"
});
self.healthTxt.anchor.set(0.5, 0);
self.addChild(self.healthTxt);
// Enemy movement speed
self.speed = 1;
// Enemy's laser shooting method
self.shoot = function () {
var laser = new Laser();
laser.x = self.x;
laser.y = self.y;
game.addChild(laser);
lasers.push(laser);
};
// Update method for the enemy
self.update = function () {
self.y += self.speed;
// Remove the enemy if it goes off-screen
if (self.y > 2732) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
// ExplosionParticle class
var ExplosionParticle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
// Particle movement speed
self.speed = 5;
// Particle lifespan
self.lifespan = 60; // 1 second at 60FPS
// Update method for the particle
self.update = function () {
self.x += self.vx * self.speed;
self.y += self.vy * self.speed;
self.lifespan--;
// Remove the particle if it goes off-screen or lifespan ends
if (self.y < 0 || self.lifespan <= 0) {
self.destroy();
explosionParticles.splice(explosionParticles.indexOf(self), 1);
}
};
});
// Laser class
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 0.5,
color: 0xFF0000,
// Red color for the laser
shape: 'box',
width: 10,
height: 40
});
// Laser movement speed
self.speed = 10;
// Update method for the laser
self.update = function () {
self.y -= self.speed;
// Add particle animation
var particle = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
color: 0xFF0000,
shape: 'box',
width: 2,
height: 2
});
particle.x = self.x;
particle.y = self.y;
// Add random spread to the particles
particle.vx = Math.random() * 2 - 1;
particle.vy = Math.random() * 2 - 1;
game.addChild(particle);
// Remove the laser and particle if they go off-screen
if (self.y < 0) {
self.destroy();
lasers.splice(lasers.indexOf(self), 1);
particle.destroy();
} else {
for (var i = 0; i < enemies.length; i++) {
if (self.intersects(enemies[i])) {
enemies[i].health -= 1;
enemies[i].healthTxt.setText('Health: ' + enemies[i].health);
self.destroy();
lasers.splice(lasers.indexOf(self), 1);
particle.destroy();
}
}
}
};
});
// Particle class
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
color: 0xFF0000,
shape: 'box',
width: 2,
height: 2
});
// Particle movement speed
self.speed = 1;
// Particle lifespan
self.lifespan = 180; // 3 seconds at 60FPS
// Update method for the particle
self.update = function () {
self.x += self.vx * self.speed;
self.y += self.vy * self.speed;
self.lifespan--;
// Remove the particle if it goes off-screen or lifespan ends
if (self.y < 0 || self.lifespan <= 0) {
self.destroy();
particles.splice(particles.indexOf(self), 1);
}
};
});
// Assets will be automatically created and loaded by the LK engine based on usage in the code.
// Ship class
var Ship = Container.expand(function () {
var self = Container.call(this);
var shipGraphics = self.attachAsset('ship', {
anchorX: 0.5,
anchorY: 0.5
});
// Ship's laser shooting method
self.shoot = function () {
var laser = new Laser();
laser.x = self.x;
laser.y = self.y;
game.addChild(laser);
lasers.push(laser);
// Create a particle at the same position as the laser
var particle = new Particle();
particle.x = self.x;
particle.y = self.y;
game.addChild(particle);
particles.push(particle);
};
// Ship movement handler
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Initialize game with a black background
});
/****
* Game Code
****/
var healthTxt = new Text2('Health: ' + health, {
size: 50,
fill: "#ffffff"
});
healthTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(healthTxt);
// Initialize variables
var ship;
var earth;
var moon;
var lasers = [];
var particles = [];
var explosionParticles = [];
var enemies = [];
var asteroids = [];
var health = 400;
var timeInMinutes = 0;
// Create the ship and position it at the bottom center of the screen
earth = game.addChild(LK.getAsset('earth', {
anchorX: 0.5,
anchorY: 0.5,
x: 500,
y: 1366
}));
moon = game.addChild(LK.getAsset('moon', {
anchorX: 0.5,
anchorY: 0.5,
x: 1548,
y: 2000
}));
ship = game.addChild(new Ship());
// Create 12 asteroids and add them to the game
for (var i = 0; i < 12; i++) {
var asteroid = new Asteroid();
asteroid.x = 2048 / 2;
asteroid.y = 2732 / 2;
game.addChild(asteroid);
asteroids.push(asteroid);
}
ship.x = 2048 / 2; // Center horizontally
ship.y = 2732 - 100; // Position from the bottom
// Event listener for moving the ship
game.down = function (x, y, obj) {
var gamePos = game.toLocal(obj.global);
ship.move(gamePos.x, gamePos.y);
ship.shoot(); // Shoot a laser when the ship is touched
};
// Update function to handle game logic
game.update = function () {
// Update lasers
for (var i = lasers.length - 1; i >= 0; i--) {
lasers[i].update();
// Check for collision with asteroids
for (var j = asteroids.length - 1; j >= 0; j--) {
if (lasers[i] && asteroids[j] && lasers[i].intersects(asteroids[j])) {
// Reduce asteroid size by 25%
asteroids[j].scale.x *= 0.75;
asteroids[j].scale.y *= 0.75;
// If the asteroid is too small, destroy it and create explosion particles
if (asteroids[j].scale.x < 0.1) {
for (var k = 0; k < 10; k++) {
var explosionParticle = new ExplosionParticle();
explosionParticle.x = asteroids[j].x;
explosionParticle.y = asteroids[j].y;
// Add random spread to the particles
explosionParticle.vx = Math.random() * 2 - 1;
explosionParticle.vy = Math.random() * 2 - 1;
game.addChild(explosionParticle);
explosionParticles.push(explosionParticle);
}
asteroids[j].destroy();
asteroids.splice(j, 1);
}
// Remove the laser
lasers[i].destroy();
lasers.splice(i, 1);
break;
}
}
}
// Update particles
for (var i = particles.length - 1; i >= 0; i--) {
particles[i].update();
}
// Rotate the Earth
earth.rotation += 341 / 60 / 360; // 341 degrees per minute
// Rotate the Moon
moon.rotation += 120 / 60 / 360; // 120 degrees per minute
// Update asteroids
for (var i = 0; i < asteroids.length; i++) {
asteroids[i].update();
}
};
// Note: The LK engine automatically handles asset creation, game reset, and dynamic resizing.
// This code assumes the existence of 'ship' and 'laser' assets within the LK engine.
// Spawn an enemy every 5 seconds
if (LK.ticks % 300 == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
game.addChild(enemy);
enemies.push(enemy);
}
// Make enemies shoot every 2 seconds
if (LK.ticks % 120 == 0) {
for (var i = 0; i < enemies.length; i++) {
enemies[i].shoot();
}
}
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
// Check for collisions with the player's ship
if (enemies[i].intersects(ship)) {
health -= 10;
if (health <= 0) {
LK.showGameOver();
}
}
}
healthTxt.setText('Health: ' + health);
// Update explosion particles
for (var i = explosionParticles.length - 1; i >= 0; i--) {
explosionParticles[i].update();
} ===================================================================
--- original.js
+++ change.js
@@ -246,11 +246,11 @@
lasers[i].update();
// Check for collision with asteroids
for (var j = asteroids.length - 1; j >= 0; j--) {
if (lasers[i] && asteroids[j] && lasers[i].intersects(asteroids[j])) {
- // Reduce asteroid size by 10%
- asteroids[j].scale.x *= 0.9;
- asteroids[j].scale.y *= 0.9;
+ // Reduce asteroid size by 25%
+ asteroids[j].scale.x *= 0.75;
+ asteroids[j].scale.y *= 0.75;
// If the asteroid is too small, destroy it and create explosion particles
if (asteroids[j].scale.x < 0.1) {
for (var k = 0; k < 10; k++) {
var explosionParticle = new ExplosionParticle();
Uma nave virada para cima intergalactica, branca fundo png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Uma particula vermelha com gradiente preto torto. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Uma nave vermelha com patas de aranha de ferro intergalactico fundo png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
O planeta Terra fundo png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A lua fundo png. A lua, fundo png jogo 2d
Um asteroide torto com crateras, 2d jogo, fundo png. Asteroide torto