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
User prompt
Please fix the bug: 'ReferenceError: getScreenToWorldCoord is not defined' in or related to this line: 'var wCoordCoords = getScreenToWorldCoord(x, y);' Line Number: 1657
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: getScreenToWorldCell is not defined' in or related to this line: 'var wCellCoords = getScreenToWorldCell(x, y);' Line Number: 1650
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
update the Map.render function to use the viewPort and world coordinates
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in or related to this line: 'Map.viewCenterText.setText(Map.currentViewCenter.x + ', ' + Map.currentViewCenter.y);' Line Number: 1619
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: newCoords is not defined' in or related to this line: 'game.mouseCoordsText.setText("S:" + Math.floor(x) + ',' + Math.floor(y) + '\r\n' + newCoords.wCellX + ',' + newCoords.wCellY + '\r\nW:' + wCellCoords.wCellX + ',' + wCellCoords.wCellY + '\r\n' + wCoordCoords.wX + ',' + wCoordCoords.wY);' Line Number: 1615
Code edit (2 edits merged)
Please save this source code
User prompt
in findAvailablePositionAroundRefinery, return relative values, instead of aboslute cell coordinates
Code edit (1 edits merged)
Please save this source code
User prompt
For a move from [9,11 to 8,11 find Path returned a path [{8,11}], instead of [{-1,0}]. Fix that
User prompt
now that findPath returns relative values, update the instruction var targetCell = { cellX: targetPathStep.x, cellY: targetPathStep.y }; in Unit.updateMovement accordingly
User prompt
in Map.findPath(), instead of returning and array of targetCells, return an array of relative moves. ie: instead of : [{cellX: 5, cellY: 5}, {cellX: 6, cellY: 5}, {cellX: 6, cellY: 6}] return : [{cellX: +1, cellY: 0}, {cellX: 0, cellY: +1}]
Code edit (16 edits merged)
Please save this source code
User prompt
in UnitHarvester, in update function, implement the case of spice unloading (self.harvestingMode == 2) In this mode, harvestedSpiceOnTripCounter is decremented by self.unloadSpeed. during this decrement, unit blinks in green. Each spice decremented is added to the player spice counter. When harvestedSpiceOnTripCounter reaches 0, the units starts a new harvesting cycle (self.startHarvesting()).
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'name')' in or related to this line: 'return node.x === neighbor.x && node.y === neighbor.y;' Line Number: 441
===================================================================
--- original.js
+++ change.js
@@ -153,10 +153,10 @@
self.cellX = x;
self.cellY = y;
self.cellW = cellW || 1; // Default to 1x1 if not specified
self.cellH = cellH || 1; // Default to 1x1 if not specified
- self.x = x * 100;
- self.y = y * 100;
+ self.x = x * tileSize;
+ self.y = y * tileSize;
self.type = type;
self.isBuilding = true;
self.playerId = playerId;
self.name = name;
@@ -327,16 +327,23 @@
LK.gui.top.addChild(self.viewCenterText);
self.render = function () {
self.removeChildren();
// Move tiles instead of the view
+ //console.log("viewPort ", viewPort);
for (var x = viewPort.wCellX; x < viewPort.wCellX + viewPort.cellW; x++) {
for (var y = viewPort.wCellY; y < viewPort.wCellY + viewPort.cellH; y++) {
if (x >= 0 && x < self.cells.length && y >= 0 && y < self.cells[x].length) {
var cell = self.cells[x][y];
var asset = cell.asset;
+ /*
var coord = worldCellToScreenCell(x, y);
- var screenX = coord.cellX;
- var screenY = coord.cellY;
+ var screenX = coord.cellX * 100;
+ var screenY = coord.cellY * 100;
+ */
+ //console.log("cell " + x, ',' + y + " =>" + screenX, screenY);
+ var screenCoord = worldCellToScreenCoord(x, y);
+ var screenX = screenCoord.x;
+ var screenY = screenCoord.y;
asset.x = screenX;
asset.y = screenY;
if (!asset.parent) {
self.addChild(asset);
@@ -482,17 +489,26 @@
}
self.lastInputPosition = null;
self.handleDrag = function (input) {
// Clamp the view center to the map boundaries
- var targetX = Math.max(11, Math.min(self.currentViewCenter.x + input.x, mapXSize - 4));
+ /*var targetX = Math.max(11, Math.min(self.currentViewCenter.x + input.x, mapXSize - 4));
var targetY = Math.max(14, Math.min(self.currentViewCenter.y + input.y, mapYSize - 9));
self.currentViewCenter.x = Math.round(self.currentViewCenter.x + (targetX - self.currentViewCenter.x) * dragSpeed);
self.currentViewCenter.y = Math.round(self.currentViewCenter.y + (targetY - self.currentViewCenter.y) * dragSpeed);
+ */
+ /*
viewPort.wX = Math.max(0, Math.min(mapXSize - viewPort.cellW, viewPort.wX + input.x));
viewPort.wY = Math.max(0, Math.min(mapYSize - viewPort.cellH, viewPort.wY + input.y));
+ viewPort.wCellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, viewPort.wX + input.x));
+ viewPort.wCellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, viewPort.wY + input.y));
+ */
+ viewPort.wCellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, viewPort.wCellX + input.x));
+ viewPort.wCellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, viewPort.wCellY + input.y));
+ viewPort.wX = viewPort.wCellX * tileSize;
+ viewPort.wY = viewPort.wCellY * tileSize;
console.log("handling drag...", input, input.x, input.y);
// Update the Text2 object with the new coordinates
- self.viewCenterText.setText(self.currentViewCenter.x + ', ' + self.currentViewCenter.y);
+ self.viewCenterText.setText(self.currentViewCenter.x + ', ' + self.currentViewCenter.y + '\r\n' + viewPort.wCellX + ',' + viewPort.wCellY);
//selectionMarker.setOnElement(currentSelection);
};
self.checkCollisions = function () {
// Handle collisions between units and obstacles
@@ -1082,8 +1098,9 @@
if (building) {
for (var w = 0; w < building.cellW; w++) {
for (var h = 0; h < building.cellH; h++) {
if (cellX + w < gameMap.cells.length && cellY + h < gameMap.cells[0].length) {
+ console.log("applyCellOccupation", cellX, cellY, " to ", cellX + w, cellY + h);
gameMap.cells[cellX + w][cellY + h].building = building;
}
}
}
@@ -1100,8 +1117,10 @@
var viewSize = Math.ceil(Math.max(game.width, game.height) / 2 / 100);
var viewPort = {
wX: 0,
wY: 0,
+ wCellX: 0,
+ wCellY: 0,
cellW: Math.floor(game.width / tileSize),
// ~20
cellH: Math.floor(mapHeight / tileSize) // ~21
};
@@ -1328,11 +1347,13 @@
highlightBorder();
currentUserActionState = UserActionState.NAVIGATING;
dragStart = null;
} else {
- // Existing code for handling drag end without a building placement
- var cellX = Math.floor(input.x / 100) + gameMap.currentViewCenter.x - Math.ceil(game.width / 2 / 100) - 3;
- var cellY = Math.floor(input.y / 100) + gameMap.currentViewCenter.y - Math.ceil(game.height / 2 / 100);
+ // Normal click
+ var clickCell = screenCoordToWorldCell(input.x, input.y);
+ var cellX = clickCell.wCellX;
+ var cellY = clickCell.wCellY;
+ console.log("Click at cell " + cellX + ',' + cellY);
var deltaToSelection = 99;
if (currentSelection && currentSelection.isUnit) {
var selCell = getCellForUnit(currentSelection);
console.log("currentSelection = " + currentSelection.name + " at " + selCell.cellX + ',' + selCell.cellY);
@@ -1454,17 +1475,17 @@
x: x,
y: y
};
};
-var worldCellToScreenCell = function worldCoordToScreenCell(wCellX, wCellY) {
+var worldCellToScreenCell = function worldCellToScreenCell(wCellX, wCellY) {
var cellX = wCellX - viewPort.wCellX;
var cellY = wCellY - viewPort.wCellY;
return {
cellX: cellX,
cellY: cellY
};
};
-var worldCellToScreenCoord = function worldCoordToScreenCoord(wCellX, wCellY) {
+var worldCellToScreenCoord = function worldCellToScreenCoord(wCellX, wCellY) {
var x = wCellX * tileSize - viewPort.wX;
var y = wCellY * tileSize - viewPort.wY;
return {
x: x,
@@ -1634,14 +1655,21 @@
/*var cellCoord = convertCoordsToCell(x, y);
if (game.mouseCoordsText) {
game.mouseCoordsText.setText(Math.floor(x) + ',' + Math.floor(y) + '\r\n' + cellCoord.cellX + ',' + cellCoord.cellY);
}*/
+ /*
var wCellCoords = getScreenToWorldCell(x, y);
var wCoordCoords = getScreenToWorldCoord(x, y);
if (game.mouseCoordsText) {
- game.mouseCoordsText.setText("S:" + Math.floor(x) + ',' + Math.floor(y) + '\r\n' + Math.floor(x / tileSize) + ',' + Math.floor(y / tileSize) + '\r\nW:' + Math.floor(wCellCoords.wCellX) + ',' + Math.floor(wCellCoords.wCellY) + '\r\n' + Math.floor(wCoordCoords.wX) + ',' + Math.floor(wCoordCoords.wY));
+ game.mouseCoordsText.setText("S:" + Math.floor(x) + ',' + Math.floor(y)
+ + '\r\n' + Math.floor(x / tileSize) + ',' + Math.floor(y / tileSize) + '\r\nW:' + Math.floor(wCellCoords.wCellX) + ',' + Math.floor(wCellCoords.wCellY) + '\r\n' + Math.floor(wCoordCoords.wX) + ',' + Math.floor(wCoordCoords.wY));
}
- gameMap.viewCenterText.setText(gameMap.currentViewCenter.x + ', ' + gameMap.currentViewCenter.y + '\r\n' + viewPort.wX + ',' + viewPort.wY);
+ */
+ var wCell = screenCoordToWorldCell(x, y);
+ if (game.mouseCoordsText) {
+ game.mouseCoordsText.setText("S:" + Math.floor(x) + ',' + Math.floor(y) + '\r\n' + Math.floor(x / tileSize) + ',' + Math.floor(y / tileSize) + '\r\nW:' + Math.floor(wCell.wCellX) + ',' + Math.floor(wCell.wCellY));
+ }
+ gameMap.viewCenterText.setText(gameMap.currentViewCenter.x + ', ' + gameMap.currentViewCenter.y + '\r\n' + viewPort.wCellX + ',' + viewPort.wCellY);
};
// Global function to update base info text
var updateBaseInfo = function updateBaseInfo() {
player1SpiceText.setText('| ' + player1.spice.toString());
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