Code edit (6 edits merged)
Please save this source code
User prompt
in handleDragEnd, don't select buildings if they are under fog
User prompt
don't select ennemy units and building if they are under fog
User prompt
in updateFogOfWar remove the fog in a radius shape instead of a square
Code edit (2 edits merged)
Please save this source code
User prompt
in building growExplosion, remove building from player list of buildings
User prompt
in checkGameEnd, check if player1 of player2 have no more buildings game over if so
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
call updateFogOfWar(); after every building placement
Code edit (7 edits merged)
Please save this source code
User prompt
in updateFogOfWar, itterate through all player1 units and buildings and set gameMap.cells[x][y].fog to false 5 cells around them
User prompt
force fogOfWar tint to 0x000000
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
in harvester update, when self.harvestingMode == 3, add spice to the unit player not always to player1
Code edit (1 edits merged)
Please save this source code
Code edit (20 edits merged)
Please save this source code
User prompt
in unitharvester stopOtherActions, user unit player tint instead of 0xFFFFFF
User prompt
implent fog of war
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Update the findPath A* algorithm to take into account the range when openSet.length === 0
User prompt
Update the findPath A* algorithm to take into account the range
Code edit (5 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -507,8 +507,16 @@
if (building.assetEffect) {
self.addChild(building.assetEffect);
}
}
+ if (cell.fog) {
+ var fogAsset = cell.fogAsset;
+ fogAsset.x = screenX - 1;
+ fogAsset.y = screenY - 1;
+ if (!fogAsset.parent) {
+ self.addChild(fogAsset);
+ }
+ }
}
}
}
};
@@ -1111,47 +1119,47 @@
self.harvestingMode = 0; // 0 : Idle / 1 : harvesting / 2 : returning / 3 : unload
self.harvestSpeed = 2; // TEMP DEBUG !!!TEMP DEBUG !!!TEMP DEBUG !!! 0.25; // Adjust this value to control the speed of harvesting
self.unloadSpeed = 1; // TEMP DEBUG !!!TEMP DEBUG !!!TEMP DEBUG !!! 0.25; // Adjust this value to control the speed of harvesting
self.setHarvesting = function () {
- console.log("Ok at site setHarvesting...");
+ //console.log("Ok at site setHarvesting...");
self.harvestingMode = 1;
};
self.startHarvesting = function (alternate) {
- console.log("startHarvesting...");
+ //console.log("startHarvesting...");
self.harvestingMode = 0;
var deltaX = 0;
var deltaY = 0;
if (alternate) {
- console.log("search alternate spot...");
+ //console.log("search alternate spot...");
deltaX = -1 + Math.random() * 2;
deltaY = -1 + Math.random() * 2;
}
var closestSpiceSpot = findClosestSpiceSpot(self.cellX + deltaX, self.cellY + deltaY);
if (closestSpiceSpot) {
- console.log("closestSpiceSpot :", closestSpiceSpot);
+ //console.log("closestSpiceSpot :", closestSpiceSpot);
var path = gameMap.findPath({
x: self.cellX,
y: self.cellY
}, {
x: closestSpiceSpot.x,
y: closestSpiceSpot.y
});
self.moveAlongPath(path); //self.setHarvesting
- console.log("Ok at site setHarvesting...");
+ //console.log("Ok at site setHarvesting...");
self.harvestingMode = 1;
} else {
- console.log("No spice found!");
+ //console.log("No spice found!");
}
};
self.startUnloading = function () {
self.harvestingMode = 3;
- console.log("Unloading spice...");
+ //console.log("Unloading spice...");
};
self.update = function () {
if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200) {
if (!gameMap.cells[self.cellX][self.cellY].spice) {
if (!self.isMoving) {
- console.log("No spice here ");
+ //console.log("No spice here ");
self.startHarvesting(true);
}
return;
}
@@ -1172,9 +1180,9 @@
x: closestRefinery.cellX,
y: closestRefinery.cellY
}, 0, closestRefinery);
if (path.length > 0) {
- console.log("Returning to Refiniery...");
+ //console.log("Returning to Refiniery...");
self.moveAlongPath(path, self.startUnloading);
} else {
console.warn("No path to Refinery !");
}
@@ -1202,18 +1210,18 @@
// Make the unit blink in green to indicate unloading
var blinkPhase = Math.sin(Date.now() * 0.01) * 0.5 + 0.5;
self.asset.tint = blinkPhase < 0.5 ? 0x00FFA5 : 0xFFFFFF;
if (self.harvestedSpiceOnTripCounter <= 0) {
- console.log("Unloading finished...");
+ //console.log("Unloading finished...");
self.asset.tint = getPlayerTint(self.playerId);
self.harvestedSpiceOnTripCounter = 0;
self.harvestingMode = 0; // Reset harvesting mode
self.startHarvesting(); // Start a new harvesting cycle
}
}
};
self.stopOtherActions = function () {
- console.log("UnitHarvester stopOtherActions :");
+ //console.log("UnitHarvester stopOtherActions :");
self.harvestingMode = 0; // Reset harvesting mode
self.asset.tint = getPlayerTint(self.playerId);
};
// Additional properties and methods for UnitHarvester can be added here
@@ -1716,10 +1724,10 @@
console.log("getPlayerTint", id);
return player1.playerId === id ? player1.tint : player2.tint;
};
var gameIsRunning = false;
-var mapXSize = 30 * 2;
-var mapYSize = 31 * 2;
+var mapXSize = 20 * 2;
+var mapYSize = 21 * 2;
var tileSize = 100;
var mapHeight = game.height * 0.80;
var viewSize = Math.ceil(Math.max(game.width, game.height) / 2 / 100);
var viewPort = {
@@ -1754,8 +1762,9 @@
var globalTerrain = null;
var player1 = null;
var player2 = null;
var spiceSpots = [];
+var fogOfWar = [];
// Global variable to keep track of the previous energy level
var previousEnergyLevel = 0;
var currentSelection = null;
var currentBuildingForPlacement = null;
@@ -1819,11 +1828,11 @@
player1.addBuilding(initialConstructionYard);
// Player 2 base
// Define a fixed rock ilot near the center right of the map
var rockIlot2Center = {
- x: 35,
+ x: 30,
//Math.floor(mapXSize * 0.85),// TEMP DEBUG !!!// TEMP DEBUG !!!// TEMP DEBUG !!!
- y: 35 //Math.floor(mapYSize * 0.5)// TEMP DEBUG !!!// TEMP DEBUG !!!// TEMP DEBUG !!!
+ y: 30 //Math.floor(mapYSize * 0.5)// TEMP DEBUG !!!// TEMP DEBUG !!!// TEMP DEBUG !!!
};
var rockIlot2Radius = 4;
for (var x = rockIlot2Center.x - rockIlot2Radius; x <= rockIlot2Center.x + rockIlot2Radius; x++) {
for (var y = rockIlot2Center.y - rockIlot2Radius; y <= rockIlot2Center.y + rockIlot2Radius; y++) {
@@ -1900,8 +1909,9 @@
// Add the map to the game
game.addChild(gameMap);
game.addChild(selectionMarker);
harvester1.startHarvesting();
+ initFogOfWar();
}
function initSpiceSpots() {
var quarterWidth = Math.floor(mapXSize / 2);
var quarterHeight = Math.floor(mapYSize / 2);
@@ -1909,9 +1919,9 @@
var startX = i % 2 * quarterWidth;
var startY = Math.floor(i / 2) * quarterHeight;
var ilotCenterX = startX + Math.floor(Math.random() * quarterWidth);
var ilotCenterY = startY + Math.floor(Math.random() * quarterHeight);
- var ilotRadius = 2 + Math.floor(Math.random() * 3); // Radius between 2 and 4
+ var ilotRadius = 4 + Math.floor(Math.random() * 3);
for (var x = ilotCenterX - ilotRadius; x <= ilotCenterX + ilotRadius; x++) {
for (var y = ilotCenterY - ilotRadius; y <= ilotCenterY + ilotRadius; y++) {
if (x >= 0 && x < mapXSize && y >= 0 && y < mapYSize && globalTerrain[x][y] === 0) {
globalTerrain[x][y] = 2; // Mark as spice
@@ -1928,8 +1938,27 @@
}
}
}
}
+function initFogOfWar() {
+ for (var x = 0; x < mapXSize; x++) {
+ for (var y = 0; y < mapYSize; y++) {
+ fogOfWar.push({
+ x: x,
+ y: y
+ });
+ gameMap.cells[x][y].fog = true;
+ gameMap.cells[x][y].fogAsset = LK.getAsset('fogOfWar', {
+ x: x * 100,
+ y: y * 100,
+ tint: 0x000000
+ });
+ }
+ }
+}
+function updateFogOfWar() {
+ console.log("updateFogOfWar...");
+}
//#region Event listeners
var dragStart = null;
var dragDelta = 0;
function handleDragStart(obj) {
a tileable sand terrain tile.
A square tileable rock terrain tile WITHOUT BBORDER. Single Game Texture. In-Game asset. 2d. No shadows. No Border
Zenith view of Dune's Wind Trap power facility square fence. Ressembles a bit to Sydney's Opera. Zenith view Directly from above.
grey cancel icon. UI
thin white circle empty.
0x5e86ff
Zenith view of a white rectangular Harvester shape of a garbage truck with a triangular head. Harvesting on sand, with flowing spice in the back. inside a square fence. Zenith view. Directly overhead. Plumb view.
Minimal Ui icon of an right sign aside with an icon of a target. sand background
Minimal icon of a home with direction icon pointing to the home. sand background
3 white flat isometric concentric circles like a target.
Remove background
Gray background
Minimal Ui icon of target sign on a fire icon.. sand background
top view of an explosion effect.
Simple heavy army tank factory buiding a tank with a crane. Square fence... Zenith view Directly overhead. Plumb view.
an empty black popup UI. UI