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
User prompt
rework : if (cellX >= 0 && cellX < gameMap.cells.length && cellY >= 0 && cellY < gameMap.cells[cellX].length) { var cell = gameMap.cells[cellX][cellY]; if (!cell.building) { currentSelection = null; selectionMarker.hide(); console.log("Nothing selected at " + cellX + ',' + cellY); updateActionBoard(); } else { console.log("Selected building at " + cellX + ',' + cellY); currentSelection = cell.building; selectionMarker.setOnElement(currentSelection); updateActionBoard(); } } to handle units
User prompt
in handleDragEnd, if cell has a unit, select it
Code edit (1 edits merged)
Please save this source code
User prompt
in Unit class, tint the units in the color of the player
User prompt
in the render function, render the units after the buildings
User prompt
add the newHarvester to the gameMap
Code edit (1 edits merged)
Please save this source code
User prompt
add a Unit class to hold units common properties
User prompt
Fix Bug: 'Timeout.tick error: UnitHarvester is not defined' in or related to this line: 'var newHarvester = new UnitHarvester(rockIlot1Center.x, rockIlot1Center.y - 2, player1.playerId);' Line Number: 605
User prompt
Fix Bug: 'Timeout.tick error: unitRepository is not defined' in or related to this line: 'var harvesterUnitInfo = unitRepository.getUnitInfo('unitHarvester');' Line Number: 603
User prompt
in prepareMap, after player1.addBuilding(initialConstructionYard); add a new harvester to player 1
User prompt
add a addUnit function to Player class
User prompt
add an array of units to the player class
Code edit (1 edits merged)
Please save this source code
User prompt
add a global UnitRepository, and first unit will be the 'Spice Harvester'
User prompt
when CancelActionButton pressed,call restoreLabel on all BuildableItemIcon
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