Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'y')' in or related to this line: 'self.label.y = self.asset.y + 50;' Line Number: 524
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'self.label.x = x - action.name.length / 2 * 13;' Line Number: 523
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'self.label.x = self.asset.x - action.name.length / 2 * 13;' Line Number: 523
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'on')' in or related to this line: 'self.asset.on('down', function () {' Line Number: 513
User prompt
add a new ActionRepository for units actions
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'self.asset = self.attachAsset(action.icon, {' Line Number: 478
Code edit (1 edits merged)
Please save this source code
User prompt
add an actions array in Unit calss
User prompt
implement displayActionItems with a logic similar to displayBuildableItems but for unit actions
Code edit (8 edits merged)
Please save this source code
User prompt
add a new global function displayActionItems()
User prompt
add a new class ActionItemIcon for units action/orders
User prompt
in unit repository add an array of possible actions for each unit
User prompt
when an unit is selected, enter in GIVING_ORDERS mode
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: unitRepository is not defined' in or related to this line: 'var unitInfo = unitRepository.getUnitInfo(type);' Line Number: 342
User prompt
in Unit class , set the name property using the UnitRepository
Code edit (1 edits merged)
Please save this source code
User prompt
in SelectionMarker define 2 assets : selectionCross and selectionCircle
User prompt
Fix Bug: 'Timeout.tick error: element is not defined' in or related to this line: 'if (element.isBuilding) {' Line Number: 210
User prompt
in SelectionMarker setOnElement, use asset selectionCross when element.isBuilding, and selectionCircle when element.isUnit
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -215,12 +215,16 @@
var elementDeltaY = 0;
if (element.isBuilding) {
elementDeltaX = (element.cellW - 2) / 2 * 100;
elementDeltaY = (element.cellH - 2) / 2 * 100;
+ self.selectionCross.alpha = 1;
+ self.selectionCircle.alpha = 0;
}
if (element.isUnit) {
elementDeltaX = -100;
elementDeltaY = -100;
+ self.selectionCross.alpha = 0;
+ self.selectionCircle.alpha = 0.9;
}
var centerDeltaX = (gameMap.currentViewCenter.x - 15) * 100;
var centerDeltaY = (gameMap.currentViewCenter.y - 15) * 100;
self.x = element.x - centerDeltaX + elementDeltaX;
@@ -248,10 +252,10 @@
self.name = name;
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)
+ anchorY: 0.5
+ //tint: getPlayerTint(playerId), // Color building to player tint
});
self.asset.x = self.x;
self.asset.y = self.y;
self.buildingQueue = [];
@@ -318,8 +322,10 @@
self.cellH = 1;
self.x = x * 100;
self.y = y * 100;
self.playerId = playerId;
+ var unitInfo = unitRepository.getUnitInfo(type);
+ self.name = unitInfo.name;
self.type = type;
self.isUnit = true;
self.asset = self.attachAsset(type, {
anchorX: 0.5,
@@ -327,8 +333,14 @@
tint: getPlayerTint(playerId)
});
self.asset.x = self.x;
self.asset.y = self.y;
+ self.asset.on('down', function () {
+ console.log("Unit selected");
+ currentSelection = self;
+ selectionMarker.setOnElement(currentSelection);
+ updateActionBoard();
+ });
return self;
});
var UnitHarvester = Unit.expand(function (x, y, playerId) {
var self = Unit.call(this, x, y, playerId, 'unitHarvester');
@@ -355,9 +367,9 @@
var Player = Container.expand(function (playerId, tint) {
var self = Container.call(this);
self.playerId = playerId;
self.resources = 0;
- self.tint = tint;
+ self.tint = 0xFFFFFF;
self.spice = 1000; // Initialize spice property with 1000
self.energy = 0; // Initialize spice property with 1000
// Initialize player-specific properties here
self.buildings = []; // Array to store all the player's buildings
@@ -684,9 +696,9 @@
var cellY = cellCoord.cellY;
var isValidPlacement = checkBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
console.log("Verif coords : " + cellX + ',' + cellY);
if (currentBuildingForPlacement && currentBuildingForPlacement.asset) {
- currentBuildingForPlacement.asset.tint = isValidPlacement ? 0xFFFFFF : 0xFF0000;
+ currentBuildingForPlacement.asset.tint = isValidPlacement ? 0x00FF00 : 0xFF0000;
}
var cursorCellCoord = getCursorCellForMovement(input, currentBuildingForPlacement);
//currentBuildingForPlacement.x = (cellX - 1 + currentBuildingForPlacement.cellW / 2) * 100;
//currentBuildingForPlacement.y = (cellY - 1 - 5 + currentBuildingForPlacement.cellH / 2) * 100;
@@ -727,28 +739,35 @@
handleBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
currentUserActionState = UserActionState.NAVIGATING;
dragStart = null;
} else {
+ var deltaToSelection = 0;
+ if (currentSelection) {
+ console.log("currentSelection = " + currentSelection.name + " at " + currentSelection.x + ',' + currentSelection.y);
+ deltaToSelection = Math.sqrt(Math.pow(Math.abs(input.x - currentSelection.x), 2) + Math.pow(Math.abs(input.y - currentSelection.y), 2)) / 100;
+ }
// 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);
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) {
currentSelection = null;
selectionMarker.hide();
- console.log("Nothing selected at " + cellX + ',' + cellY);
+ console.log("Nothing selected at " + cellX + ',' + cellY, " deltaToSelection=" + deltaToSelection);
updateActionBoard();
} else if (cell.building) {
console.log("Selected building at " + cellX + ',' + cellY);
currentSelection = cell.building;
selectionMarker.setOnElement(currentSelection);
updateActionBoard();
} else if (cell.unit) {
+ /*
console.log("Selected unit at " + cellX + ',' + cellY);
currentSelection = cell.unit;
selectionMarker.setOnElement(currentSelection);
updateActionBoard();
+ */
}
}
dragStart = null;
}
@@ -772,8 +791,9 @@
// Place the building on the map
cell.building = building;
building.x = cellX * 100;
building.y = cellY * 100;
+ building.asset.tint = 0xFFFFFF;
gameMap.addChild(building);
// Call addBuilding for the player who owns the building
if (building.playerId === player1.playerId) {
player1.addBuilding(building);
@@ -781,10 +801,8 @@
player2.addBuilding(building);
}
applyCellOccupation(cellX, cellY);
console.log(building.name + ' placed at ' + cellX + ',' + cellY);
- //currentSelection = building;
- //selectionMarker.setOnElement(building);
if (player1.playerId === building.playerId) {
player1.updateEnergy();
updateBaseInfo();
}
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