Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: unit is not defined' in or related to this line: 'switch (unit.type) {' Line Number: 2176
Code edit (1 edits merged)
Please save this source code
Code edit (14 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: rockIlot2Center is not defined' in or related to this line: 'baseBuilding = {' Line Number: 1740
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.getTime is not a function' in or related to this line: 'self.lastHitTime = LK.getTime();' Line Number: 1099
Code edit (2 edits merged)
Please save this source code
User prompt
could you implement findFactoryForUnit
Code edit (1 edits merged)
Please save this source code
User prompt
add a new function findEmplacementForBuilding(building, cellX, cellY) that scans the map around the given cellX,cellY to find a free area of rocks that fits the given building size
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: buildable.placeBuilding is not a function' in or related to this line: 'buildable.placeBuilding(placeX, placeY);' Line Number: 2117
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -530,9 +530,9 @@
if (building.assetEffect) {
self.addChild(building.assetEffect);
}
}
- if (false && cell.fog) {
+ if (cell.fog) {
// TEMP DEBUG !!! TEMP DEBUG !!! TEMP DEBUG !!! TEMP DEBUG !!!
var fogAsset = cell.fogAsset;
fogAsset.x = screenX - 1;
fogAsset.y = screenY - 1;
@@ -1333,50 +1333,8 @@
/****
* Game Code
****/
-// Function to find an emplacement for a building based on its size and a starting cell
-function findEmplacementForBuilding(building, cellX, cellY) {
- // Check if the building size is defined
- if (!building.cellW || !building.cellH) {
- console.error("Building size is not defined.");
- return null;
- }
- // Define the search area around the given cellX, cellY
- var searchRadius = 5; // Search within 5 cells around the given cell
- for (var dx = -searchRadius; dx <= searchRadius; dx++) {
- for (var dy = -searchRadius; dy <= searchRadius; dy++) {
- var candidateX = cellX + dx;
- var candidateY = cellY + dy;
- // Check if the candidate area is within the map bounds
- if (candidateX >= 0 && candidateX + building.cellW <= mapXSize && candidateY >= 0 && candidateY + building.cellH <= mapYSize) {
- var fits = true;
- // Check if the entire building area is on rocks and not occupied
- for (var w = 0; w < building.cellW; w++) {
- for (var h = 0; h < building.cellH; h++) {
- var targetCell = gameMap.cells[candidateX + w][candidateY + h];
- if (targetCell.terrain !== 'rock' || targetCell.building) {
- fits = false;
- break;
- }
- }
- if (!fits) {
- break;
- }
- }
- // If the area fits, return the top-left corner cell of the area
- if (fits) {
- return {
- cellX: candidateX,
- cellY: candidateY
- };
- }
- }
- }
- }
- // If no suitable area is found, return null
- return null;
-}
// Global function to calculate the angle between two points
function calculateAngle(element1, element2) {
var dx = element2.cellX - element1.cellX;
var dy = element2.cellY - element1.cellY;
@@ -1437,8 +1395,50 @@
cellX: closestBuilding.cellX,
cellY: closestBuilding.cellY
} : null;
}
+// Function to find an emplacement for a building based on its size and a starting cell
+function findEmplacementForBuilding(building, cellX, cellY) {
+ // Check if the building size is defined
+ if (!building.cellW || !building.cellH) {
+ console.error("Building size is not defined.");
+ return null;
+ }
+ // Define the search area around the given cellX, cellY
+ var searchRadius = 10; // Search within 5 cells around the given cell
+ for (var dx = -searchRadius; dx <= searchRadius; dx++) {
+ for (var dy = -searchRadius; dy <= searchRadius; dy++) {
+ var candidateX = cellX + dx;
+ var candidateY = cellY + dy;
+ // Check if the candidate area is within the map bounds
+ if (candidateX >= 0 && candidateX + building.cellW <= mapXSize && candidateY >= 0 && candidateY + building.cellH <= mapYSize) {
+ var fits = true;
+ // Check if the entire building area is on rocks and not occupied
+ for (var w = 0; w < building.cellW; w++) {
+ for (var h = 0; h < building.cellH; h++) {
+ var targetCell = gameMap.cells[candidateX + w][candidateY + h];
+ if (targetCell.terrain !== 'rock' || targetCell.building) {
+ fits = false;
+ break;
+ }
+ }
+ if (!fits) {
+ break;
+ }
+ }
+ // If the area fits, return the top-left corner cell of the area
+ if (fits) {
+ return {
+ cellX: candidateX,
+ cellY: candidateY
+ };
+ }
+ }
+ }
+ }
+ // If no suitable area is found, return null
+ return null;
+}
function spawnUnit(unitType, x, y, playerId) {
var unitInfo = unitRepository.getUnitInfo(unitType);
var unit;
switch (unitInfo.className) {
@@ -2102,30 +2102,19 @@
if (!buildable || !buildable.isBuilding) {
return;
}
var baseBuilding = findClosestConstructionYard(buildable);
- /*
- if (!baseBuilding) {
- if (buildable.player1Id === player1.playerId) {
- baseBuilding = {
- cellX: rockIlot1Center.x,
- cellY: rockIlot1Center.y
- };
- } else {
- baseBuilding = {
- cellX: rockIlot2Center.x,
- cellY: rockIlot2Center.y
- };
- }
- }
- */
- var freePosition = findAvailablePositionAroundBuilding(baseBuilding.cellX, baseBuilding.cellY);
- var placeX = baseBuilding.cellX;
- var placeY = baseBuilding.cellY;
- if (freePosition && freePosition.length === 1) {
- placeX += freePosition[0].cellX;
- placeY += freePosition[0].cellY;
+ if (!baseBuilding) {
+ console.warn(buildable.playerId + " - No Construction Yard to place building " + buildable.type + " around");
+ return;
}
+ var freePosition = findEmplacementForBuilding(buildable, baseBuilding.cellX, baseBuilding.cellY);
+ if (!freePosition) {
+ console.warn(buildable.playerId + " - No free space to place building " + buildable.type);
+ return;
+ }
+ var placeX = freePosition.cellX;
+ var placeY = freePosition.cellY;
handleBuildingPlacement(buildable, placeX, placeY);
}
/* ***************************************************************************************************** */
/* ********************************************* INIT FUNCTIONS ****************************************** */
@@ -2285,9 +2274,9 @@
fogOfWar.push({
x: x,
y: y
});
- gameMap.cells[x][y].fog = true;
+ gameMap.cells[x][y].fog = false; // true; // TEMP DEBUG !!!// TEMP DEBUG !!!// TEMP DEBUG !!!
gameMap.cells[x][y].fogAsset = LK.getAsset('fogOfWar', {
x: x * 100,
y: y * 100,
tint: 0x222222
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