Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'var triangle = new Graphics();' Line Number: 38
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'var triangle = new Graphics();' Line Number: 38
User prompt
Rend torchlight triangulaire
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'var triangle = new Graphics();' Line Number: 38
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'var triangle = new Graphics();' Line Number: 38
User prompt
Fait en sorte que la forme de la texture torchlight soit triangulaire comme la zone d'éclairage reel de la lampe
User prompt
L'orientation de la torchlight n'est pas bonne, elle doit être face au hero
User prompt
L'orientation de la torchlight n'est pas bonne, elle doit être face au hero
User prompt
Fix Bug: 'ReferenceError: graphics is not defined' in this line: 'graphics.alpha = 0.3;' Line Number: 45
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'var graphics = new Graphics();' Line Number: 38
User prompt
Fix Bug: 'TypeError: Graphics is not a constructor' in this line: 'var graphics = new Graphics();' Line Number: 38
User prompt
Deforme la TorchLight pour que la texture soit triangulaire comme la zone d'eclairage de la lampe
User prompt
L'orientation de TorchLight n'est pas bonne, elle doit être en face du hero dans le sens de sa lampe
User prompt
Corrige la forme de TorchLight , cela doit avoir la forme de la zone d'eclairage
User prompt
Créer une texture qui à la forme de la zone d'éclairage de la torche et s'affiche sur le sol de la map, la texture doit donc être triangulaire et prendre la taille de toute la zone d'eclairage
User prompt
Créer une texture qui à la forme de la zone d'éclairage de la torche et s'affiche sur le sol de la map
User prompt
Créer une texture qui à la forme de la zone d'eclairage de la torche
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'updateVisibility')' in this line: 'fog.updateVisibility(torchPos, torchAngle);' Line Number: 187
/**** 
* Classes
****/
// Define the TorchLight class
var TorchLight = Container.expand(function () {
	var self = Container.call(this);
	var lightGraphics = self.createAsset('torchLight', 'Torch light area', 0.5, 0.5);
	self.updateVisibility = function (zombie, torchAngle) {
		var angleToZombie = Math.atan2(zombie.y - self.y, zombie.x - self.x);
		var angleDifference = Math.abs(torchAngle - angleToZombie);
		if (angleDifference < 0.5) {
			// Assuming torch has a cone of visibility of 0.5 radians
			zombie.visible = true;
		} else {
			zombie.visible = false;
		}
	};
});
// Define the Hero class
var Hero = Container.expand(function () {
	var self = Container.call(this);
	var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5);
	self.torchGraphics = self.createAsset('torch', 'Hero torch', 0.5, 0);
	self.torchGraphics.visible = false;
	self.torchLight = new TorchLight();
	self.torchLight.x = self.x;
	self.torchLight.y = self.y - self.torchGraphics.height;
	game.addChild(self.torchLight);
	self.orientTorch = function (mousePos) {
		var angle = Math.atan2(mousePos.y - self.y, mousePos.x - self.x);
		self.torchGraphics.rotation = angle;
		self.torchLight.rotation = angle;
	};
	self.speed = 5;
	self.shoot = function () {
		var bullet = new HeroBullet();
		bullet.x = self.x;
		bullet.y = self.y;
		game.addChild(bullet);
		bullets.push(bullet);
	};
	self.move = function (direction) {
		self.x += direction.x * self.speed;
		self.y += direction.y * self.speed;
	};
});
// Define the HeroBullet class
var HeroBullet = Container.expand(function () {
	var self = Container.call(this);
	var bulletGraphics = self.createAsset('heroBullet', 'Hero bullet', 0.5, 1);
	self.speed = -10;
	self.move = function () {
		self.y += self.speed;
	};
});
// Define the Zombie class
var Zombie = Container.expand(function () {
	var self = Container.call(this);
	var zombieGraphics = self.createAsset('zombie', 'Zombie enemy', 0.5, 0.5);
	self.speed = 1;
	self.move = function (torchPos, torchAngle) {
		self.y += self.speed;
	};
});
/**** 
* Initialize Game
****/
var game = new LK.Game({
	backgroundColor: 0x000000 // Init game with black background
});
/**** 
* Game Code
****/
// Initialize important asset arrays
var bullets = [];
var zombies = [];
var hero;
var isGameOver = false;
// Create the hero
hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 100; // Position hero near the bottom of the screen
// Game logic and event handlers
LK.on('keydown', function (obj) {
	var direction = {
		x: 0,
		y: 0
	};
	var e = obj.event;
	switch (e.keyCode) {
		case 37:
			// left arrow
			direction.x = -1;
			break;
		case 39:
			// right arrow
			direction.x = 1;
			break;
		case 38:
			// up arrow
			direction.y = -1;
			break;
		case 40:
			// down arrow
			direction.y = 1;
			break;
	}
	hero.move(direction);
});
LK.on('tick', function () {
	if (isGameOver) {
		LK.showGameOver();
		return;
	}
	// Move bullets and check for off-screen
	for (var i = bullets.length - 1; i >= 0; i--) {
		bullets[i].move();
		if (bullets[i].y < 0) {
			bullets[i].destroy();
			bullets.splice(i, 1);
		}
	}
	// Handle torch orientation and make zombies visible if illuminated
	var torchPos = {
		x: hero.x,
		y: hero.y
	};
	var torchAngle = hero.torchGraphics.rotation;
	// Move zombies and check for collision with hero
	for (var j = zombies.length - 1; j >= 0; j--) {
		zombies[j].move();
		hero.torchLight.updateVisibility(zombies[j], torchAngle);
		if (zombies[j].y > 2732) {
			zombies[j].destroy();
			zombies.splice(j, 1);
		} else if (zombies[j].intersects(hero) && zombies[j].visible) {
			isGameOver = true;
		}
	}
	game.on('move', function (obj) {
		var mousePos = obj.event.getLocalPosition(game);
		hero.orientTorch(mousePos);
	});
	// Spawn zombies
	if (LK.ticks % 120 == 0) {
		// Spawn a zombie every 2 seconds
		var zombie = new Zombie();
		zombie.x = Math.random() * 2048;
		zombie.y = -50; // Start off-screen
		zombies.push(zombie);
		game.addChild(zombie);
	}
}); ===================================================================
--- original.js
+++ change.js
@@ -1,53 +1,36 @@
 /**** 
 * Classes
 ****/
-// Define the Fog class
-var Fog = Container.expand(function () {
+// Define the TorchLight class
+var TorchLight = Container.expand(function () {
 	var self = Container.call(this);
-	var fogGraphics = self.createAsset('fog', 'Night fog', 0, 0);
-	fogGraphics.width = 2048;
-	fogGraphics.height = 2732;
-	fogGraphics.alpha = 0.5; // Semi-transparent fog
-	self.updateVisibility = function (torchPos, torchAngle) {
-		// Calculate the visibility of the fog based on the torch light
-		var dx = torchPos.x - self.x;
-		var dy = torchPos.y - self.y;
-		var distance = Math.sqrt(dx * dx + dy * dy);
-		var angleToTorch = Math.atan2(dy, dx);
-		if (distance < 300 && Math.abs(torchAngle - angleToTorch) < 0.5) {
+	var lightGraphics = self.createAsset('torchLight', 'Torch light area', 0.5, 0.5);
+	self.updateVisibility = function (zombie, torchAngle) {
+		var angleToZombie = Math.atan2(zombie.y - self.y, zombie.x - self.x);
+		var angleDifference = Math.abs(torchAngle - angleToZombie);
+		if (angleDifference < 0.5) {
 			// Assuming torch has a cone of visibility of 0.5 radians
-			fogGraphics.alpha = Math.max(0, fogGraphics.alpha - 0.05); // Gradually make the fog more transparent
+			zombie.visible = true;
 		} else {
-			fogGraphics.alpha = 0.5; // Reset fog visibility
+			zombie.visible = false;
 		}
 	};
 });
-// Define the TorchLight class
-var TorchLight = Container.expand(function () {
-	var self = Container.call(this);
-	var lightGraphics = self.createAsset('torchLight', 'Torch light area', 0.5, 0.5);
-	self.update = function (torchPos, torchAngle) {
-		self.x = torchPos.x;
-		self.y = torchPos.y;
-		self.rotation = torchAngle;
-		self.visible = true;
-	};
-});
 // Define the Hero class
 var Hero = Container.expand(function () {
 	var self = Container.call(this);
 	var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5);
 	self.torchGraphics = self.createAsset('torch', 'Hero torch', 0.5, 0);
 	self.torchGraphics.visible = false;
+	self.torchLight = new TorchLight();
+	self.torchLight.x = self.x;
+	self.torchLight.y = self.y - self.torchGraphics.height;
+	game.addChild(self.torchLight);
 	self.orientTorch = function (mousePos) {
 		var angle = Math.atan2(mousePos.y - self.y, mousePos.x - self.x);
 		self.torchGraphics.rotation = angle;
-		torchLight.update({
-			x: self.x,
-			y: self.y
-		}, angle);
-		torchLight.visible = true;
+		self.torchLight.rotation = angle;
 	};
 	self.speed = 5;
 	self.shoot = function () {
 		var bullet = new HeroBullet();
@@ -76,55 +59,21 @@
 	var zombieGraphics = self.createAsset('zombie', 'Zombie enemy', 0.5, 0.5);
 	self.speed = 1;
 	self.move = function (torchPos, torchAngle) {
 		self.y += self.speed;
-		if (torchPos) {
-			var angleToZombie = Math.atan2(self.y - torchPos.y, self.x - torchPos.x);
-			var angleDifference = Math.abs(torchAngle - angleToZombie);
-			if (angleDifference < 0.5) {
-				// Assuming torch has a cone of visibility of 0.5 radians
-				self.visible = true;
-			} else {
-				self.visible = false;
-			}
-		}
 	};
 });
 
 /**** 
 * Initialize Game
 ****/
 var game = new LK.Game({
-	backgroundColor: 0x000000 // Set a default background color
+	backgroundColor: 0x000000 // Init game with black background
 });
 
 /**** 
 * Game Code
 ****/
-// Initialize the fog
-var fog;
-// Create the fog but do not add it to the game yet
-function createFog() {
-	fog = new Fog();
-	fog.x = 0;
-	fog.y = 0;
-}
-// Create the earth texture and set it as the background
-// Create a smaller earth texture
-var earthTexture = game.createAsset('earthTexture', 'Earth ground texture', 0, 0);
-earthTexture.width = 64;
-earthTexture.height = 64;
-// Create a grid to fill the map with the texture
-for (var i = 0; i < 50; i++) {
-	for (var j = 0; j < 50; j++) {
-		var textureClone = game.createAsset('earthTexture', 'Earth ground texture', 0, 0);
-		textureClone.width = 64;
-		textureClone.height = 64;
-		textureClone.x = i * earthTexture.width;
-		textureClone.y = j * earthTexture.height;
-		game.addChild(textureClone);
-	}
-}
 // Initialize important asset arrays
 var bullets = [];
 var zombies = [];
 var hero;
@@ -132,12 +81,8 @@
 // Create the hero
 hero = game.addChild(new Hero());
 hero.x = 2048 / 2;
 hero.y = 2732 - 100; // Position hero near the bottom of the screen
-// Create the torch light area
-var torchLight = game.addChild(new TorchLight());
-torchLight.x = hero.x;
-torchLight.y = hero.y;
 // Game logic and event handlers
 LK.on('keydown', function (obj) {
 	var direction = {
 		x: 0,
@@ -182,13 +127,12 @@
 		x: hero.x,
 		y: hero.y
 	};
 	var torchAngle = hero.torchGraphics.rotation;
-	// Update fog visibility
-	fog.updateVisibility(torchPos, torchAngle);
 	// Move zombies and check for collision with hero
 	for (var j = zombies.length - 1; j >= 0; j--) {
-		zombies[j].move(torchPos, torchAngle);
+		zombies[j].move();
+		hero.torchLight.updateVisibility(zombies[j], torchAngle);
 		if (zombies[j].y > 2732) {
 			zombies[j].destroy();
 			zombies.splice(j, 1);
 		} else if (zombies[j].intersects(hero) && zombies[j].visible) {
@@ -207,19 +151,5 @@
 		zombie.y = -50; // Start off-screen
 		zombies.push(zombie);
 		game.addChild(zombie);
 	}
-	// Initialize the fog before updating its visibility
-	if (!fog) {
-		createFog();
-		game.addChild(fog);
-	}
-	// Initialize the fog before updating its visibility
-	if (!fog) {
-		createFog();
-		game.addChild(fog);
-	}
-	// Ensure fog is defined before calling updateVisibility
-	if (fog) {
-		fog.updateVisibility(torchPos, torchAngle);
-	}
 });
\ No newline at end of file
:quality(85)/https://cdn.frvr.ai/65a587523047400dd7aca131.png%3F3) 
 Un zombie en 2D vue du dessus. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65a59c71c7f2cd91869b7f53.png%3F3) 
 Bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65a5a4edc7f2cd91869b7fa9.png%3F3) 
 top down shooter blood. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65a5a87ac7f2cd91869b8014.png%3F3) 
 top down shooter blood texture. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65a5aab9c7f2cd91869b805e.png%3F3) 
 top down character with gun de dos. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. topdown shooter
:quality(85)/https://cdn.frvr.ai/65a5b095c7014704a23393f0.png%3F3) 
 top down robot with gun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. topdown shooter
:quality(85)/https://cdn.frvr.ai/65a703cedd8adf36bf99aff5.png%3F3) 
 2d top down zombie boss. Single Game Texture. In-Game asset. 2d. no background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65a7b3b8ec6a05b2bc5a13dc.png%3F3) 
 weapon reload 2d icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65a7e1a3ec6a05b2bc5a1694.png%3F3) 
 Dark background horror. 2d. Blank background. High contrast. No shadows.
:quality(85)/https://cdn.frvr.ai/65aaf19870cae27edb2a6f7e.png%3F3) 
 replace robot by wall
:quality(85)/https://cdn.frvr.ai/65aaf37770cae27edb2a6fa5.png%3F3) 
 barbelé militaire 2d
:quality(85)/https://cdn.frvr.ai/67d87f86e29a93a861dd0d29.png%3F3) 
 Arrière plan sombre d'horreur avec un angle vu depuis le haut. 2d. Blank background. High contrast. No shadows.