Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: s is not defined' in or related to this line: 's;' Line Number: 1927
Code edit (1 edits merged)
Please save this source code
User prompt
Current log is : findPath {x: 6, y: 5} {x: 6, y: 10} Return adjusted path [] Fix the adjusted path
Code edit (7 edits merged)
Please save this source code
User prompt
Update findPath function so that it returns the path to the closest reachable point if the destination isn't reachable.
Code edit (1 edits merged)
Please save this source code
User prompt
in enqueueBuildable call blinkRed when Not enough resources to build.
User prompt
move the code : ``` progressDisplay.progressAsset.tint = 0xFF0000; // Set progress display color to red progressDisplay.setProgress(1); progressDisplay.progressAsset.alpha = 0.5; // Make it fully visible progressDisplay.visible = true; // Ensure it's visible LK.setInterval(function () { progressDisplay.progressAsset.alpha = progressDisplay.progressAsset.alpha === 1 ? 0 : 1; }, 250); // Blink effect ``` inside a function in progressDisplay
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: parentIcon is not defined' in or related to this line: 'progressDisplay.progressAsset.width = parentIcon.asset.width; // Set progress to 100%' Line Number: 1134
User prompt
when "Not enough resources to build", set the progressDisplay to 100% and visible
User prompt
When "Not enough resources to build." make the progressDisplay blink red
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 undefined (reading 'cost')' in or related to this line: 'if (player1.spice < buildableInfo.cost) {' Line Number: 1106
Code edit (1 edits merged)
Please save this source code
User prompt
in spawnUnit() function handle the case of the unitQuad
User prompt
in UnitRepository add an a new entry for the unitQuad
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'units')' in or related to this line: 'self.units['unitQuad'] = {' Line Number: 937
User prompt
add unitQuad to the UnitRepository
User prompt
add all required code to handle unitQuad that is : - UnitQuad class - the entry in UnitRepository - the handling in spawnUnit() function
User prompt
add all required code to handle unitQuad
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'name')' in or related to this line: 'self.label = new Text2(buildableInfo.name, {' Line Number: 122
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -61,11 +61,12 @@
return self.actions[actionType];
};
return self;
});
-var BuildableItemIcon = Container.expand(function (type, x, y) {
+var BuildableItemIcon = Container.expand(function (type, x, y, sourceFactory) {
var self = Container.call(this);
self.type = type;
+ self.sourceFactory = sourceFactory;
self.asset = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5,
x: x,
@@ -624,11 +625,13 @@
elementDeltaY = 0;
self.selectionCross.alpha = 0;
self.selectionCircle.alpha = 0.9;
}
- var eltCoord = worldCoordToScreenCoord(element.x, element.y);
- self.x = eltCoord.x + elementDeltaX;
- self.y = eltCoord.y + elementDeltaY;
+ //var eltCoord = worldCoordToScreenCoord(element.x, element.y);
+ var eltCoord = worldCellToScreenCell(element.cellX, element.cellY);
+ self.x = eltCoord.cellX * tileSize + elementDeltaX;
+ self.y = eltCoord.cellY * tileSize + elementDeltaY;
+ console.log("setOnElement => " + element.x + ',' + element.y, ' => ' + self.x + ',' + self.y);
if (self.y > mapHeight) {
self.visible = false;
} else {
self.visible = true;
@@ -748,10 +751,10 @@
});
self.speed = 200; // Set the unit speed
self.cellX = cellX;
self.cellY = cellY;
- self.x = cellX * tileSize;
- self.y = cellY * tileSize;
+ self.x = cellX * tileSize + tileSize / 2;
+ self.y = cellY * tileSize + tileSize / 2;
self.cellW = 1;
self.cellH = 1;
console.log("New unit " + self.name + ' at ', self.x, ',', self.y, ' [' + self.cellX + ',' + self.cellY + ']');
self.asset.on('down', function () {
@@ -953,17 +956,21 @@
switch (unitInfo.className) {
case 'UnitHarvester':
unit = new UnitHarvester(x, y, playerId);
// Find the first available place around the refinery
- var path = findAvailablePositionAroundRefinery(x, y);
+ var path = findAvailablePositionAroundBuilding(x, y);
if (path.length > 0) {
unit.moveAlongPath(path, function () {
harvestActionLogic(unit);
});
}
break;
case 'UnitQuad':
unit = new UnitQuad(x, y, playerId);
+ var path = findAvailablePositionAroundBuilding(x, y);
+ if (path.length > 0) {
+ unit.moveAlongPath(path, function () {});
+ }
break;
// Add additional cases for other unit classes as needed
default:
throw new Error('Unknown unit class: ' + unitInfo.className);
@@ -976,9 +983,9 @@
}
game.addChild(unit);
return unit;
}
-function findAvailablePositionAroundRefinery(refineryX, refineryY) {
+function findAvailablePositionAroundBuilding(buildingX, buildingY) {
var directions = [{
x: -1,
y: 0
}, {
@@ -989,12 +996,18 @@
y: -1
}, {
x: 0,
y: 1
+ }, {
+ x: -1,
+ y: -1
+ }, {
+ x: 1,
+ y: 1
}];
for (var i = 0; i < directions.length; i++) {
- var checkX = refineryX + directions[i].x;
- var checkY = refineryY + directions[i].y;
+ var checkX = buildingX + directions[i].x;
+ var checkY = buildingY + directions[i].y;
if (gameMap.cells[checkX] && gameMap.cells[checkX][checkY] && !gameMap.cells[checkX][checkY].unit && !gameMap.cells[checkX][checkY].building) {
return [{
cellX: directions[i].x,
cellY: directions[i].y
@@ -1089,57 +1102,78 @@
return;
}
updateBaseInfo();
var constructionTime = buildableInfo.constructionTime;
- var building;
+ var buildable;
switch (buildableInfo.className) {
case 'ConstructionYard':
- building = new ConstructionYard(0, 0, player1.playerId);
+ buildable = new ConstructionYard(0, 0, player1.playerId);
break;
case 'WindTrap':
- building = new WindTrap(0, 0, player1.playerId);
+ buildable = new WindTrap(0, 0, player1.playerId);
break;
case 'SpiceRefinery':
- building = new SpiceRefinery(0, 0, player1.playerId);
+ buildable = new SpiceRefinery(0, 0, player1.playerId);
break;
case 'LightFactory':
- building = new LightFactory(0, 0, player1.playerId);
+ buildable = new LightFactory(0, 0, player1.playerId);
break;
+ case 'UnitQuad':
+ buildable = new UnitQuad(0, 0, player1.playerId);
+ break;
// Add cases for other buildings as needed
}
- if (!building) {
+ if (!buildable) {
console.error('Building object is not defined.');
return;
}
- building.constructionProgress = 0;
- building.constructionTimer = LK.setInterval(function () {
- building.constructionProgress += 0.1;
- var progressFraction = building.constructionProgress / constructionTime;
- building.progressDisplay.setProgress(progressFraction);
+ buildable.constructionProgress = 0;
+ buildable.constructionTimer = LK.setInterval(function () {
+ buildable.constructionProgress += 0.1;
+ var progressFraction = buildable.constructionProgress / constructionTime;
+ buildable.progressDisplay.setProgress(progressFraction);
// Deduct spice progressively based on construction progress
var costPerTick = buildableInfo.cost * 0.1 / constructionTime;
player1.spice -= costPerTick;
updateBaseInfo();
- if (building.constructionProgress >= constructionTime) {
- LK.clearInterval(building.constructionTimer);
+ // When construction is complete...
+ if (buildable.constructionProgress >= constructionTime) {
+ LK.clearInterval(buildable.constructionTimer);
console.log(selectedBuildable.type + " construction completed.");
- building.constructionTimer = null;
- building.progressDisplay.hide();
- if (progressDisplay.parentIcon && typeof progressDisplay.parentIcon.setLabelToPlace === 'function') {
- progressDisplay.parentIcon.setLabelToPlace(); // Change label text to 'Place'
+ buildable.constructionTimer = null;
+ buildable.progressDisplay.hide();
+ if (buildable.isBuilding) {
+ console.log("Building Ready for placement ", buildable);
+ if (progressDisplay.parentIcon && typeof progressDisplay.parentIcon.setLabelToPlace === 'function') {
+ progressDisplay.parentIcon.setLabelToPlace(); // Change label text to 'Place'
+ }
+ currentBuildingForPlacement = buildable;
}
- console.log("Building Ready for placement ", building);
- currentBuildingForPlacement = building;
+ if (buildable.isUnit) {
+ console.log("Unit Ready to spawn ", buildable);
+ var spawnCell = {
+ cellX: 0,
+ cellY: 0
+ };
+ if (selectedBuildable && selectedBuildable.sourceFactory) {
+ console.log("Found source factory ", selectedBuildable.sourceFactory);
+ spawnCell.cellX = selectedBuildable.sourceFactory.cellX;
+ spawnCell.cellY = selectedBuildable.sourceFactory.cellY;
+ } else {
+ console.log("No source factory found ", selectedBuildable);
+ }
+ spawnUnit(buildable.type, spawnCell.cellX, spawnCell.cellY, player1.playerId);
+ }
game.children.forEach(function (child) {
if (child instanceof BuildableItemIcon) {
child.asset.interactive = true;
child.alpha = 1.0;
}
});
}
}, 100);
- building.progressDisplay = progressDisplay;
- currentSelection.buildingQueue.push(building);
+ buildable.progressDisplay = progressDisplay;
+ currentSelection.buildingQueue.push(buildable);
game.children.forEach(function (child) {
if (child instanceof BuildableItemIcon) {
child.asset.interactive = false;
}
@@ -1336,10 +1370,10 @@
y: Math.round(-deltaY / tileSize)
};
var allUnits = player1.units.concat(player2.units);
allUnits.forEach(function (unit) {
- //unit.handleDrag(inputPosition);
- unit.visible = false;
+ unit.handleDrag(inputPosition);
+ //unit.visible = false;
});
gameMap.handleDrag(inputPosition);
dragDelta = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
selectionMarker.setOnElement(currentSelection);
@@ -1624,9 +1658,9 @@
var iconY = commandPanel.y + 220; // Y position for all icons
currentSelection.buildable.forEach(function (itemType) {
var border = new IconBorder(iconX, iconY);
game.addChild(border);
- var icon = new BuildableItemIcon(itemType, iconX, iconY);
+ var icon = new BuildableItemIcon(itemType, iconX, iconY, currentSelection);
game.addChild(icon);
iconX += 300; // Increment X position for the next icon
});
}
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