Code edit (11 edits merged)
Please save this source code
User prompt
allow diagonal movements for units
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: newCell is not defined' in or related to this line: 'self.cellX = Math.floor(newCell.cellX / tileSize);' Line Number: 805
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading '8')' 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 '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
===================================================================
--- original.js
+++ change.js
@@ -16,9 +16,8 @@
if (self.action && typeof self.action.handler === 'function') {
currentSelection.selectedAction = self.action.code;
currentUserActionState = UserActionState.SET_ORDER_TARGET;
console.log('Wait target for action ' + self.action.name);
- //self.action.handler();
if (!targetMoveCursor) {
targetMoveCursor = game.addChild(new TargetMoveCursor());
}
highlightBorder(self.asset.x);
@@ -163,15 +162,12 @@
self.buildable = buildable || []; // New property to store what the building can build
self.asset = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
- //tint: getPlayerTint(playerId), // Color building to player tint
});
self.asset.x = self.x;
self.asset.y = self.y;
self.buildingQueue = [];
- // Initialize building-specific properties here
- // ...
return self;
});
var WindTrap = Building.expand(function (x, y, playerId) {
var self = Building.call(this, x, y, 'windTrap', 'Wind Trap', playerId, 2, 2);
@@ -317,9 +313,9 @@
x: 15,
y: 20
};
// Create a Text2 object to display the currentViewCenter coordinates
- self.viewCenterText = new Text2(self.currentViewCenter.x + ', ' + self.currentViewCenter.y, {
+ self.viewCenterText = new Text2('Center', {
size: 50,
fill: '#ffffff',
align: 'center'
});
@@ -327,20 +323,13 @@
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 * 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;
@@ -359,11 +348,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) / 2 * tileSize; // Adjust for building size
- building.asset.y = screenY - (building.cellH - 2) / 2 * tileSize; // Adjust for building size
+ building.asset.x = screenX - (building.cellW - 2) / 2 * tileSize;
+ building.asset.y = screenY - (building.cellH - 2) / 2 * tileSize;
self.addChild(building.asset);
}
}
}
@@ -489,28 +477,14 @@
return neighbors;
}
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 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 + '\r\n' + viewPort.wCellX + ',' + viewPort.wCellY);
- //selectionMarker.setOnElement(currentSelection);
+ self.viewCenterText.setText(viewPort.wCellX + ',' + viewPort.wCellY);
};
self.checkCollisions = function () {
// Handle collisions between units and obstacles
};
@@ -609,23 +583,16 @@
self.selectionCross.alpha = 1;
self.selectionCircle.alpha = 0;
}
if (element.isUnit) {
- elementDeltaX = 0;
- elementDeltaY = 500;
+ elementDeltaX = 0; //tileSize/2;
+ elementDeltaY = 0; //tileSize/2;
self.selectionCross.alpha = 0;
self.selectionCircle.alpha = 0.9;
}
- var centerDeltaX = (gameMap.currentViewCenter.x - 15) * 100;
- var centerDeltaY = (gameMap.currentViewCenter.y - 15) * 100;
- //var cellElt = screenCoordToWorldCell(element.x, element.y);
- var cellElt = worldCoordToScreenCell(element.x, element.y);
- console.log("element at : " + element.x + ',' + element.y);
- //self.x = element.x - centerDeltaX + elementDeltaX;
- //self.y = element.y - centerDeltaY + elementDeltaY;
- self.x = cellElt.cellX * tileSize + elementDeltaX;
- self.y = cellElt.cellY * tileSize + elementDeltaY;
- console.log("SelectionMarker at : " + cellElt.wCellX + ',' + cellElt.wCellY + ' => ' + self.x + ',' + self.y);
+ var eltCoord = worldCoordToScreenCoord(element.x, element.y);
+ self.x = eltCoord.x + elementDeltaX;
+ self.y = eltCoord.y + elementDeltaY;
self.visible = true;
};
self.hide = function () {
console.log('SelectionMarker hidden');
@@ -639,9 +606,8 @@
anchorX: 0.5,
anchorY: 0.5
});
self.updatePosition = function (position) {
- //console.log("moving at : " + position.x + ',' + position.y);
self.x = position.x;
self.y = position.y;
};
game.on('move', function (obj) {
@@ -656,11 +622,8 @@
self.visible = true;
self.updatePosition(pos);
}
});
- /*game.on('up', function () {
- self.destroy();
- });*/
return self;
});
var Unit = Container.expand(function (cellX, cellY, playerId, type) {
var self = Container.call(this);
@@ -671,11 +634,9 @@
self.isMoving = true;
self.onArrivedCallback = callback;
};
self.updateMovement = function (delta) {
- //console.log("updateMovement", delta);
if (!self.isMoving) {
- //console.log("updateMovement not moving ", self.path, self.pathIndex, self.onArrivedCallback);
return;
}
if (!self.path || self.pathIndex >= self.path.length) {
console.log("updateMovement will stop ", self.path, self.pathIndex, self.onArrivedCallback);
@@ -691,29 +652,14 @@
var targetCell = {
cellX: self.cellX + targetPathStep.cellX,
cellY: self.cellY + targetPathStep.cellY
};
- var fixedX = Math.floor((self.x - (gameMap.currentViewCenter.x + viewSize) * 100) / 100);
- var fixedY = Math.floor((self.y - (gameMap.currentViewCenter.y + viewSize) * 100) / 100);
- var coords = getCoordsForUnit(self);
- //console.log("self.x/y", self.x, self.y);
- //console.log("asset.x/y", self.asset.x, self.asset.y);
- //console.log("parent.x/y", self.parent.x, self.parent.y);
- //console.log("coords", coords.x, coords.y);
- //console.log("moving...", {
- // x: self.cellX,
- // y: self.cellY
- //}, ' to ', targetCell, ' fixed :' + fixedX + ',' + fixedY);
- //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 + tileSize / 2;
self.y = targetCoords.y + tileSize / 2;
// Update map
gameMap.cells[self.cellX][self.cellY].unit = null;
@@ -729,16 +675,14 @@
self.onArrivedCallback = null;
}
}
} else {
- //console.log("advance by ", dx / distance * step);
var angle = Math.atan2(dy, dx);
self.asset.rotation = angle - Math.PI / 2;
self.x += Math.cos(angle) * step;
self.y += Math.sin(angle) * step;
}
if (selectionMarker.currentElement == self) {
- //console.log("current selection moving...");
selectionMarker.setOnElement(self);
}
};
self.playerId = playerId;
@@ -758,13 +702,8 @@
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;
@@ -774,24 +713,19 @@
});
self.onArrivedCallback = null;
self.handleDrag = function () {
var newCoord = worldCellToScreenCoord(self.cellX, self.cellY);
- self.x = newCoord.x;
- self.y = newCoord.y;
- self.cellX = Math.floor(self.x / tileSize);
- self.cellY = Math.floor(self.y / tileSize);
- /*var newCell= worldCellToScreenCell(self.cellX, self.cellY);
- self.cellX = newCell.cellX;
- self.cellY = newCell.cellY;*/
+ self.x = newCoord.x + tileSize / 2;
+ self.y = newCoord.y + tileSize / 2;
};
return self;
});
var UnitHarvester = Unit.expand(function (x, y, playerId) {
var self = Unit.call(this, x, y, playerId, 'unitHarvester');
self.harvestedSpiceCapacity = 600;
self.harvestedSpiceOnTripCounter = 0;
self.harvestedSpiceOnCellCounter = 0;
- self.harvestingMode = 0; // 0 : Idle / 1 : harvesting / 2 : unload
+ 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.startHarvesting = function () {
console.log("startHarvesting...");
@@ -804,26 +738,25 @@
}, {
x: closestSpiceSpot.x,
y: closestSpiceSpot.y
});
- console.log("path :", path);
self.moveAlongPath(path);
self.harvestingMode = 1;
}
};
self.startUnloading = function () {
- self.harvestingMode = 2;
+ self.harvestingMode = 3;
console.log("Unloading spice...");
};
self.update = function () {
if (self.harvestingMode == 1 && self.harvestedSpiceOnCellCounter < 200 && gameMap.cells[self.cellX][self.cellY].spice) {
self.harvestedSpiceOnTripCounter += self.harvestSpeed;
self.harvestedSpiceOnCellCounter += self.harvestSpeed;
- //console.log('Harvested Spice Counter:', self.harvestedSpiceOnCellCounter); //, ' cell ' + self.cellX + ',' + self.cellY, ' of map ', gameMap.cells[self.cellX][self.cellY]);
if (self.harvestedSpiceOnCellCounter >= 200) {
self.asset.tint = 0xFFFFFF;
gameMap.clearCellSpice(self.cellX, self.cellY);
if (self.harvestedSpiceOnTripCounter >= self.harvestedSpiceCapacity) {
+ self.harvestingMode = 2; // Returning
self.harvestedSpiceOnCellCounter = 0;
var closestRefinery = findClosestRefinery(self);
if (closestRefinery) {
var path = gameMap.findPath({
@@ -850,9 +783,9 @@
self.asset.tint = blinkPhase < 0.5 ? 0xFFA500 : 0xFFFFFF;
self.asset.rotation += 45 / 400 * (Math.PI / 180);
}
}
- if (self.harvestingMode == 2) {
+ if (self.harvestingMode == 3) {
self.harvestedSpiceOnTripCounter -= self.unloadSpeed;
// Add the unloaded spice to the player's spice counter
player1.spice += self.unloadSpeed; // TODO : update for Player 2
updateBaseInfo();
@@ -936,9 +869,9 @@
// Find the first available place around the refinery
var path = findAvailablePositionAroundRefinery(x, y);
if (path.length > 0) {
unit.moveAlongPath(path, function () {
- harvestActionLogic(unit);
+ harvestActionLogic(unit); // TEMP DEBUG !!!// TEMP DEBUG !!!// TEMP DEBUG !!!
});
}
break;
// Add additional cases for other unit classes as needed
@@ -1143,15 +1076,15 @@
wX: 0,
wY: 0,
wCellX: 0,
wCellY: 0,
- cellW: Math.floor(game.width / tileSize),
+ cellW: Math.floor(game.width / tileSize) + 1,
// ~20
- cellH: Math.floor(mapHeight / tileSize) // ~21
+ cellH: Math.floor(mapHeight / tileSize) + 1 // ~21
};
// Init view port
-viewPort.wCellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, viewPort.wCellX)); // + game.width/2));
-viewPort.wCellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, viewPort.wCellY)); // + game.height/2));
+viewPort.wCellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, viewPort.wCellX));
+viewPort.wCellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, viewPort.wCellY));
viewPort.wX = viewPort.wCellX * tileSize;
viewPort.wY = viewPort.wCellY * tileSize;
var dragSpeed = 0.15;
var gameMap = new Map();
@@ -1218,9 +1151,8 @@
gameMap.cells[rockIlot1Center.x][rockIlot1Center.y].building = initialConstructionYard;
applyCellOccupation(rockIlot1Center.x, rockIlot1Center.y);
player1.addBuilding(initialConstructionYard);
// Add a new harvester to player 1
- //spawnUnit('unitHarvester', rockIlot1Center.x, rockIlot1Center.y - 2, player1.playerId);
// Define a fixed rock ilot near the center right of the map
var rockIlot2Center = {
x: Math.floor(mapXSize * 0.85),
y: Math.floor(mapYSize * 0.5)
@@ -1287,82 +1219,29 @@
y: currentPos.y
};
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 = screenCoordToWorldCell(input.x, input.y); //getCellForPlacement(input.x, input.y, currentBuildingForPlacement);
+ var cellCoord = screenCoordToWorldCell(input.x, input.y);
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 = (cellX + currentBuildingForPlacement.cellW / 2) * tileSize; //cursorCellCoord.cellX;
- currentBuildingForPlacement.y = (cellY + currentBuildingForPlacement.cellH / 2) * tileSize; //cursorCellCoord.cellY;
- //console.log("Follow coords : " + currentBuildingForPlacement.x + ',' + currentBuildingForPlacement.y);
+ currentBuildingForPlacement.x = (cellX + currentBuildingForPlacement.cellW / 2) * tileSize;
+ currentBuildingForPlacement.y = (cellY + currentBuildingForPlacement.cellH / 2) * tileSize;
} else if (dragStart) {
- //console.log("Drag move...");
var deltaX = currentPos.x - dragStart.x;
var deltaY = currentPos.y - dragStart.y;
var inputPosition = {
x: Math.round(-deltaX / tileSize),
y: Math.round(-deltaY / tileSize)
};
var allUnits = player1.units.concat(player2.units);
- var vpWX = viewPort.wX;
- var vpWY = viewPort.wY;
- console.log("vp before : " + viewPort.wX + ',' + viewPort.wY);
gameMap.handleDrag(inputPosition);
allUnits.forEach(function (unit) {
- console.log("unit coords : " + unit.x + ',' + unit.y);
unit.handleDrag(inputPosition);
- /*
- console.log("unit cells : " + unit.cellX + ',' + unit.cellY);
- console.log("delta coords : " + deltaX + ',' + deltaY);
- console.log("vp after : " + (viewPort.wX) + ',' + (viewPort.wY));
- console.log("vp Delta : " + (viewPort.wX-vpWX) + ',' + (viewPort.wY-vpWY));
- */
- //var newCoord = worldCoordToScreenCoord(unit.x, unit.y);
- //console.log("newCoord : " + newCoord.x + ',' + newCoord.y);
- /*unit.x = newCoord.x;
- unit.y = newCoord.y;
- unit.cellX = Math.floor(unit.x / tileSize);
- unit.cellY = Math.floor(unit.y / tileSize);
- */
- //unit.cellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, unit.cellX + inputPosition.x));
- //unit.cellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, unit.cellY + inputPosition.y));
- /*
- var worldOldPos = worldCoordToScreenCoord(unit.x, unit.y);
- var newWorldPos = screenCoordToWorldCoord(worldOldPos.x, worldOldPos.y);
- console.log("newWorldPos : " + newWorldPos.wX + ',' + newWorldPos.wY);
- unit.x = newWorldPos.wX;
- unit.y = newWorldPos.wY;
- unit.cellX = Math.floor(unit.x / tileSize);
- unit.cellX = Math.floor(unit.y * tileSize);
- */
- /*
- unit.cellX += deltaX;
- unit.cellY += deltaY;
- unit.x += deltaX * tileSize;
- unit.y += deltaY * tileSize;
- */
- /*
- var targetX = Math.max(11, Math.min(gameMap.currentViewCenter.x + inputPosition.x, mapXSize - 4));
- var targetY = Math.max(14, Math.min(gameMap.currentViewCenter.y + inputPosition.y, mapYSize - 9));
- 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("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);
- unit.x += deltaX * tileSize;
- unit.y += deltaY * tileSize;
- */
});
dragDelta = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
selectionMarker.setOnElement(currentSelection);
}
@@ -1380,16 +1259,11 @@
dragDelta = 0;
return;
}
if (currentUserActionState === UserActionState.PLACING_BUILDINGS) {
- var cellCoord = screenCoordToWorldCell(input.x, input.y); //getCellForPlacement(input.x, input.y, currentBuildingForPlacement);
+ var cellCoord = screenCoordToWorldCell(input.x, input.y);
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;
}
@@ -1399,21 +1273,20 @@
dragStart = null;
dragDelta = 0;
} else if (currentUserActionState === UserActionState.SET_ORDER_TARGET) {
if (currentSelection && currentSelection.isUnit) {
- var cellCoord = convertCoordsToCell(input.x, input.y);
+ var cellCoord = screenCoordToWorldCell(input.x, input.y); //convertCoordsToCell(input.x, input.y);
currentSelection.destinationTarget = {
- x: cellCoord.cellX,
- y: cellCoord.cellY
+ x: cellCoord.wCellX,
+ y: cellCoord.wCellY
};
- console.log(currentSelection.name + ' received new destination target: ' + cellCoord.cellX + ',' + cellCoord.cellY);
// Call the action handler with the target position
if (currentSelection.actions && currentSelection.selectedAction) {
console.log(currentSelection.selectedAction + ' received ');
var actionInfo = actionRepository.getActionInfo(currentSelection.selectedAction);
if (actionInfo && actionInfo.handler) {
console.log('Call action handler : ', actionInfo);
- actionInfo.handler(currentSelection, cellCoord.cellX, cellCoord.cellY);
+ actionInfo.handler(currentSelection, cellCoord.wCellX, cellCoord.wCellY);
}
}
if (targetMoveCursor) {
console.log('hiding move cursor ...');
@@ -1432,9 +1305,8 @@
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);
deltaToSelection = Math.sqrt(Math.pow(Math.abs(selCell.cellX - cellX), 2) + Math.pow(Math.abs(selCell.cellY - cellY), 2));
}
if (cellX >= 0 && cellX < gameMap.cells.length && cellY >= 0 && cellY < gameMap.cells[cellX].length) {
var cell = gameMap.cells[cellX][cellY];
@@ -1593,23 +1465,8 @@
cellX: Math.floor(x / 100) + gameMap.currentViewCenter.x - Math.ceil(game.width / 2 / 100) - 3,
cellY: Math.floor(y / 100) + gameMap.currentViewCenter.y - Math.ceil(game.height / 2 / 100)
};
};
-var getCellForPlacement = function getCellForPlacement(x, y, building) {
- var cX = Math.floor(x / 100) + gameMap.currentViewCenter.x - Math.ceil(game.width / 2 / 100) - 4;
- var cY = Math.floor(y / 100) + gameMap.currentViewCenter.y - Math.ceil(game.height / 2 / 100) - 1;
- if (building && building.cellW && building.cellH) {
- return {
- cellX: cX + Math.floor(building.cellW / 2),
- cellY: cY + Math.floor(building.cellH / 2)
- };
- } else {
- return {
- cellX: cX,
- cellY: cY
- };
- }
-};
var getCellForUnit = function getCellForUnit(unit) {
var centerDeltaX = gameMap.currentViewCenter.x - Math.ceil(game.width / 2 / 100);
var centerDeltaY = gameMap.currentViewCenter.y - Math.ceil(game.height / 2 / 100);
var cX = Math.floor(unit.x / 100) + centerDeltaX + unit.cellW / 2 + Math.floor(unit.cellW / 2) - 5;
@@ -1618,37 +1475,8 @@
cellX: cX,
cellY: cY
};
};
-var getCoordsForUnit = function getCoordsForCell(cell) {
- //console.log("getCoordsForUnit :", cell.cellX, ',', cell.cellY);
- //console.log("currentViewCenter :", gameMap.currentViewCenter.x, ',', gameMap.currentViewCenter.y);
- var centerDeltaX = -1;
- var centerDeltaY = -6;
- var x = (cell.cellX + centerDeltaX) * 100 + 50;
- var y = (cell.cellY + centerDeltaY) * 100 + 50;
- /*
- var centerDeltaX = gameMap.currentViewCenter.x - Math.ceil(game.width / 2 / 100) - 4;
- var centerDeltaY = gameMap.currentViewCenter.y - Math.ceil(game.height / 2 / 100) - 6;
- var x = (cell.cellX + centerDeltaX) * 100;
- var y = (cell.cellY + centerDeltaY) * 100;
- */
- //console.log("=> :", x, ',', y);
- return {
- x: x,
- y: y
- };
-};
-var getCursorCellForMovement = function getCursorCellForMovement(input, building) {
- var centerDeltaX = gameMap.currentViewCenter.x - Math.ceil(game.width / 2 / 100);
- var centerDeltaY = gameMap.currentViewCenter.y - Math.ceil(game.height / 2 / 100);
- var cX = (Math.floor(input.x / 100) + centerDeltaX + building.cellW / 2 + Math.floor(building.cellW / 2) - 5) * 100;
- var cY = (Math.floor(input.y / 100) + centerDeltaY + Math.floor(building.cellH / 2) + building.cellH / 2 - 7) * 100;
- return {
- cellX: cX,
- cellY: cY
- };
-};
// Global function to find the closest spice spot to a given position
var findClosestSpiceSpot = function findClosestSpiceSpot(x, y) {
var closestSpot = null;
var minDistance = Number.MAX_VALUE;
@@ -1684,16 +1512,14 @@
var buildableItemIcons = game.children.filter(function (child) {
return child instanceof BuildableItemIcon;
});
buildableItemIcons.forEach(function (icon) {
- //console.log('removing...', icon.type);
icon.destroy();
});
if (currentSelection && currentSelection.playerId === player1.playerId && currentSelection.buildable && currentSelection.buildable.length) {
var iconX = commandPanel.x + 200; // Starting X position for the first icon
var iconY = commandPanel.y + 220; // Y position for all icons
currentSelection.buildable.forEach(function (itemType) {
- //console.log('Add build button for ' + itemType);
var border = new IconBorder(iconX, iconY);
game.addChild(border);
var icon = new BuildableItemIcon(itemType, iconX, iconY);
game.addChild(icon);
@@ -1731,25 +1557,13 @@
}
};
// Global function to update mouse coordinates text
var updateMouseCoords = function updateMouseCoords(x, y) {
- /*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));
- }
- */
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);
+ gameMap.viewCenterText.setText(viewPort.wCellX + ',' + viewPort.wCellY);
};
// Global function to update base info text
var updateBaseInfo = function updateBaseInfo() {
player1SpiceText.setText('| ' + player1.spice.toString());
@@ -1848,30 +1662,15 @@
LK.on('tick', function () {
// Render the map and update unit movement each tick
if (gameIsRunning) {
gameMap.render();
- /*if (currentSelection && currentSelection.isUnit) {
- currentSelection.updateMovement(1 / 60); // Assuming tick operates at 60FPS
- }*/
- //game.addChild(newHarvester.asset); // TEMP DEBUG
var allUnits = player1.units.concat(player2.units);
allUnits.forEach(function (unit) {
- //console.log("render unit " + unit.name, unit.x, unit.y);
- // Ensure the unit is added to the game container, not 'self' which is not defined in this context
- //console.log(" unit parent ", unit.asset.parent.parent.parent);
- /*if (!unit.asset.parent.parent.parent) {
- console.log("First add unit !", unit.asset.parent.parent.parent);
- game.addChild(unit.asset);
- } else { }*/
- //unit.updateMovement(1 / 60); // Assuming tick operates at 60FPS
+ unit.updateMovement(1 / 60); // Assuming tick operates at 60FPS
if (unit.update) {
- //unit.update();
+ unit.update();
}
game.addChild(unit);
- /*var screenX = (unit.cellX - 2 - gameMap.currentViewCenter.x + viewSize) * unit.asset.width;
- var screenY = (unit.cellY - 3 - gameMap.currentViewCenter.y + viewSize) * unit.asset.height;
- unit.x = screenX;
- unit.y = screenY;*/
});
}
tickCounter++;
});
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