User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading '7')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading '6')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'spice')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'spice')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'unit')' in or related to this line: 'gameMap.cells[self.cellX][self.cellY].unit = self;' Line Number: 747
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'spice')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'spice')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading '9.366666666666676')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'spice')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'spice')' in or related to this line: 'if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {' Line Number: 833
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (17 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: screenCoordsToWorldCell is not defined' in or related to this line: 'var cellElt = screenCoordsToWorldCell(element.x, element.y);' Line Number: 645
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -360,10 +360,10 @@
// Render buildings
var building = cell.building;
if (building) {
//console.log("Building at ", x, y, " screen : ", screenX, screenY);
- building.asset.x = screenX; // + (building.cellW - 2) * tileSize; // Adjust for building size
- building.asset.y = screenY; // + (building.cellH - 2) * tileSize; // Adjust for building size
+ building.asset.x = screenX - (building.cellW - 2) / 2 * tileSize; // Adjust for building size
+ building.asset.y = screenY - (building.cellH - 2) / 2 * tileSize; // Adjust for building size
self.addChild(building.asset);
}
}
}
@@ -661,9 +661,9 @@
self.destroy();
});*/
return self;
});
-var Unit = Container.expand(function (x, y, playerId, type) {
+var Unit = Container.expand(function (cellX, cellY, playerId, type) {
var self = Container.call(this);
self.moveAlongPath = function (path, callback) {
console.log("moveAlongPath", path, callback);
self.path = path;
@@ -702,19 +702,20 @@
//console.log("moving...", {
// x: self.cellX,
// y: self.cellY
//}, ' to ', targetCell, ' fixed :' + fixedX + ',' + fixedY);
- var targetCoords = getCoordsForUnit(targetCell);
- //console.log("targetCoords", targetCoords.x, targetCoords.y);
- var dx = targetCoords.x - self.x;
- var dy = targetCoords.y - self.y;
+ //var targetCoords = getCoordsForUnit(targetCell);
+ var targetCoords = worldCellToScreenCoord(targetCell.cellX, targetCell.cellY);
+ console.log("targetCoords", targetCoords.x, targetCoords.y);
+ var dx = targetCoords.x + tileSize / 2 - self.x;
+ var dy = targetCoords.y + tileSize / 2 - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
//console.log("distance", distance, ' / dx,dy=' + dx, ',', dy);
var step = self.speed * delta;
if (distance < step) {
//console.log("reached step", distance);
- self.x = targetCoords.x;
- self.y = targetCoords.y;
+ self.x = targetCoords.x + tileSize / 2;
+ self.y = targetCoords.y + tileSize / 2;
// Update map
gameMap.cells[self.cellX][self.cellY].unit = null;
self.cellX = targetCell.cellX;
self.cellY = targetCell.cellY; // Update map
@@ -751,15 +752,19 @@
anchorY: 0.5,
tint: getPlayerTint(playerId)
});
self.speed = 200; // Set the unit speed
- self.cellX = x;
- self.cellY = y;
+ self.cellX = cellX;
+ self.cellY = cellY;
+ self.x = cellX * tileSize;
+ self.y = cellY * tileSize;
self.cellW = 1;
self.cellH = 1;
+ /*
var targetCoords = getCoordsForUnit(self);
self.x = targetCoords.x;
self.y = targetCoords.y;
+ */
console.log("New unit " + self.name + ' at ', self.x, ',', self.y, ' [' + self.cellX + ',' + self.cellY + ']');
self.asset.on('down', function () {
console.log("Unit selected");
currentSelection = self;
@@ -781,15 +786,17 @@
self.startHarvesting = function () {
console.log("startHarvesting...");
var closestSpiceSpot = findClosestSpiceSpot(self.cellX, self.cellY);
if (closestSpiceSpot) {
+ console.log("closestSpiceSpot :", closestSpiceSpot);
var path = gameMap.findPath({
x: self.cellX,
y: self.cellY
}, {
x: closestSpiceSpot.x,
y: closestSpiceSpot.y
});
+ console.log("path :", path);
self.moveAlongPath(path);
self.harvestingMode = 1;
}
};
@@ -1271,19 +1278,20 @@
};
updateMouseCoords(input.x, input.y);
if (currentUserActionState === UserActionState.PLACING_BUILDINGS) {
//console.log("User is moving building..." + Math.floor(input.x) + ',' + Math.floor(input.y), currentBuildingForPlacement);
- var cellCoord = getCellForPlacement(input.x, input.y, currentBuildingForPlacement);
- var cellX = cellCoord.cellX;
- var cellY = cellCoord.cellY;
+ var cellCoord = screenCoordToWorldCell(input.x, input.y); //getCellForPlacement(input.x, input.y, currentBuildingForPlacement);
+ var cellX = cellCoord.wCellX;
+ var cellY = cellCoord.wCellY;
var isValidPlacement = checkBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
//console.log("Verif coords : " + cellX + ',' + cellY);
if (currentBuildingForPlacement && currentBuildingForPlacement.asset) {
currentBuildingForPlacement.asset.tint = isValidPlacement ? 0x00FF00 : 0xFF0000;
+ currentBuildingForPlacement.visible = input.y + currentBuildingForPlacement.cellH * tileSize < mapHeight;
}
- var cursorCellCoord = getCursorCellForMovement(input, currentBuildingForPlacement);
- currentBuildingForPlacement.x = cursorCellCoord.cellX;
- currentBuildingForPlacement.y = cursorCellCoord.cellY;
+ //var cursorCellCoord = getCursorCellForMovement(input, currentBuildingForPlacement);
+ currentBuildingForPlacement.x = (cellX + currentBuildingForPlacement.cellW / 2) * tileSize; //cursorCellCoord.cellX;
+ currentBuildingForPlacement.y = (cellY + currentBuildingForPlacement.cellH / 2) * tileSize; //cursorCellCoord.cellY;
//console.log("Follow coords : " + currentBuildingForPlacement.x + ',' + currentBuildingForPlacement.y);
} else if (dragStart) {
//console.log("Drag move...");
var deltaX = currentPos.x - dragStart.x;
@@ -1299,19 +1307,19 @@
var newCenterX = Math.round(gameMap.currentViewCenter.x + (targetX - gameMap.currentViewCenter.x) * dragSpeed);
var newCenterY = Math.round(gameMap.currentViewCenter.y + (targetY - gameMap.currentViewCenter.y) * dragSpeed);
var deltaX = gameMap.currentViewCenter.x - newCenterX;
var deltaY = gameMap.currentViewCenter.y - newCenterY;
- //console.log("unit coords : " + unit.x + ',' + unit.y);
+ console.log("unit coords : " + unit.x + ',' + unit.y);
//console.log("target coords : " + targetX + ',' + targetY);
//console.log("center coords : " + gameMap.currentViewCenter.x + ',' + gameMap.currentViewCenter.y);
//console.log("input coords : " + inputPosition.x + ',' + inputPosition.y);
- //console.log("delta coords : " + deltaX + ',' + deltaY);
+ console.log("delta coords : " + deltaX + ',' + deltaY);
unit.x += deltaX * tileSize;
unit.y += deltaY * tileSize;
});
gameMap.handleDrag(inputPosition);
dragDelta = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- //selectionMarker.setOnElement(currentSelection);
+ selectionMarker.setOnElement(currentSelection);
}
}
function handleDragEnd(obj) {
var currentPos = obj.event.getLocalPosition(game);
@@ -1326,11 +1334,16 @@
dragDelta = 0;
return;
}
if (currentUserActionState === UserActionState.PLACING_BUILDINGS) {
+ var cellCoord = screenCoordToWorldCell(input.x, input.y); //getCellForPlacement(input.x, input.y, currentBuildingForPlacement);
+ var cellX = cellCoord.wCellX;
+ var cellY = cellCoord.wCellY;
+ /*
var cellCoord = getCellForPlacement(input.x, input.y, currentBuildingForPlacement);
var cellX = cellCoord.cellX;
var cellY = cellCoord.cellY;
+ */
var isValidPlacement = checkBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
if (!isValidPlacement) {
return;
}
@@ -1379,13 +1392,15 @@
}
if (cellX >= 0 && cellX < gameMap.cells.length && cellY >= 0 && cellY < gameMap.cells[cellX].length) {
var cell = gameMap.cells[cellX][cellY];
if (!cell.building && !cell.unit && deltaToSelection > 1) {
- currentSelection = null;
- selectionMarker.setOnElement();
- selectionMarker.hide();
- console.log("Nothing selected at " + cellX + ',' + cellY, " deltaToSelection=" + deltaToSelection, " dragDelta=", dragDelta);
- updateActionBoard();
+ if (dragDelta < tileSize * 0.25) {
+ currentSelection = null;
+ selectionMarker.setOnElement();
+ selectionMarker.hide();
+ console.log("Nothing selected at " + cellX + ',' + cellY, " deltaToSelection=" + deltaToSelection, " dragDelta=", dragDelta);
+ updateActionBoard();
+ }
} else if (cell.building) {
console.log("Selected building at " + cellX + ',' + cellY);
currentSelection = cell.building;
selectionMarker.setOnElement(currentSelection);
@@ -1418,10 +1433,10 @@
// Place the building on the map
cell.building = building;
building.cellX = cellX;
building.cellY = cellY;
- building.x = cellX * 100;
- building.y = cellY * 100;
+ building.x = cellX * tileSize;
+ building.y = cellY * tileSize;
building.asset.tint = 0xFFFFFF;
gameMap.addChild(building);
// Call addBuilding for the player who owns the building
if (building.playerId === player1.playerId) {
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