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
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'name')' in or related to this line: 'return node.x === neighbor.x && node.y === neighbor.y;' Line Number: 441
Code edit (1 edits merged)
Please save this source code
User prompt
When harvester is full, call findClosestRefinery and move to it
User prompt
Create a new global function « findClosestRefinery » that takes an unit and returns the cellX,cellY of the closest refinery of the same player it it exists
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: newunit is not defined' in or related to this line: 'harvestActionLogic(newunit, cellX, cellY);' Line Number: 1324
Code edit (2 edits merged)
Please save this source code
User prompt
in harvestActionLogic, remplace the use of currentSelection, by the of a parameter 'targetUnit' and update the existing function calls
User prompt
in moveActionLogic, remplace the use of currentSelection, by the of a parameter 'targetUnit' and update the existing function calls
Code edit (1 edits merged)
Please save this source code
User prompt
in clearCellSpice also update the spiceSpots array
Code edit (8 edits merged)
Please save this source code
User prompt
when the harvester took 200 from a cell, call clearCellSpice()
User prompt
add a new method clearCellSpice in the Map class
Code edit (1 edits merged)
Please save this source code
User prompt
no rotate only when harvestedSpiceCounter%100 ==0
===================================================================
--- original.js
+++ change.js
@@ -1,36 +1,69 @@
/****
* Classes
****/
-var TargetMoveCursor = Container.expand(function () {
+var ActionItemIcon = Container.expand(function (action, x, y) {
var self = Container.call(this);
- self.asset = self.attachAsset('targetMoveCursor', {
+ self.action = action;
+ self.asset = self.attachAsset(action.icon, {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ x: x,
+ y: y,
+ width: 200,
+ height: 200
});
- 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) {
- if (currentUserActionState != UserActionState.SET_ORDER_TARGET) {
- return;
- }
- //console.log("moving cursor");
- var pos = obj.event.getLocalPosition(game);
- if (pos.y > game.height * 0.80) {
- self.visible = false;
+ self.asset.on('down', function () {
+ 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);
} else {
- self.visible = true;
- self.updatePosition(pos);
+ currentSelection.selectedAction = null;
}
});
- /*game.on('up', function () {
- self.destroy();
- });*/
+ self.label = new Text2(action.name, {
+ size: 30,
+ fill: '#000000',
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
+ });
+ self.label.x = self.asset.x - action.name.length / 2 * 13;
+ self.label.y = self.asset.y + 120;
+ self.addChild(self.label);
return self;
});
+var ActionRepository = Container.expand(function () {
+ var self = Container.call(this);
+ self.actions = {
+ 'harvest': {
+ 'code': 'harvest',
+ 'name': 'Harvest',
+ 'icon': 'harvestIcon',
+ 'handler': harvestActionLogic
+ },
+ 'move': {
+ 'code': 'move',
+ 'name': 'Move',
+ 'icon': 'moveIcon',
+ 'handler': moveActionLogic
+ },
+ 'return': {
+ 'code': 'return',
+ 'name': 'Retreat',
+ 'icon': 'returnIcon',
+ 'handler': function handler() {/* Return action logic */}
+ }
+ };
+ self.getActionInfo = function (actionType) {
+ return self.actions[actionType];
+ };
+ return self;
+});
var BuildableItemIcon = Container.expand(function (type, x, y) {
var self = Container.call(this);
self.type = type;
self.asset = self.attachAsset(type, {
@@ -78,8 +111,84 @@
self.label.x = self.asset.x - buildableInfo.name.length / 2 * 13; // Recalculate x position for new text
};
return self;
});
+// BuildableRepository class to store reference information about all buildables
+var BuildableRepository = Container.expand(function () {
+ var self = Container.call(this);
+ self.buildables = {
+ 'constructionYard': {
+ 'name': 'Construction Yard',
+ 'cost': 300,
+ 'energy': 0,
+ 'constructionTime': 10,
+ 'className': 'ConstructionYard',
+ 'buildable': ['windTrap', 'spiceRefinery']
+ },
+ 'windTrap': {
+ 'name': 'Wind Trap',
+ 'cost': 300,
+ 'energy': 100,
+ 'constructionTime': 2,
+ 'className': 'WindTrap',
+ 'buildable': []
+ },
+ 'spiceRefinery': {
+ 'name': 'Spice Refinery',
+ 'cost': 600,
+ 'energy': -50,
+ 'constructionTime': 4,
+ 'className': 'SpiceRefinery',
+ 'buildable': []
+ }
+ // Add more buildables as needed
+ };
+ self.getBuildableInfo = function (type) {
+ return self.buildables[type];
+ };
+ return self;
+});
+// Base Building class
+var Building = Container.expand(function (x, y, type, name, playerId, cellW, cellH, buildable) {
+ var self = Container.call(this);
+ 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.type = type;
+ self.isBuilding = true;
+ self.playerId = playerId;
+ 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), // 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);
+ // Additional properties and methods for WindTrap can be added here
+ return self;
+});
+var SpiceRefinery = Building.expand(function (x, y, playerId) {
+ var self = Building.call(this, x, y, 'spiceRefinery', 'Spice Refinery', playerId, 3, 2);
+ // Additional properties and methods for SpiceRefinery can be added here
+ return self;
+});
+var ConstructionYard = Building.expand(function (x, y, playerId) {
+ var self = Building.call(this, x, y, 'constructionYard', 'Construction Yard', playerId, 2, 2, buildableRepository.getBuildableInfo('constructionYard').buildable);
+ // Additional properties and methods for ConstructionYard can be added here
+ return self;
+});
var BuildingProgressDisplay = Container.expand(function (parentIcon) {
var self = Container.call(this);
self.parentIcon = parentIcon;
self.progressAsset = self.attachAsset('buildingProgress', {
@@ -100,8 +209,67 @@
self.visible = true;
};
return self;
});
+var CancelActionButton = Container.expand(function (x, y) {
+ var self = Container.call(this);
+ self.asset = self.attachAsset('cancelAction', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: x,
+ y: y
+ });
+ // Add a label 'Cancel' below the cancel action button
+ self.label = new Text2('Cancel', {
+ size: 30,
+ fill: '#000000',
+ font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
+ });
+ self.label.x = self.asset.x - 40;
+ self.label.y = self.asset.y + 120;
+ self.addChild(self.label);
+ self.asset.on('down', function () {
+ // Handle cancel action logic here
+ if (currentBuildingForPlacement) {
+ player1.spice += buildableRepository.getBuildableInfo(currentBuildingForPlacement.type).cost;
+ updateBaseInfo();
+ currentBuildingForPlacement.destroy();
+ currentBuildingForPlacement = null;
+ currentUserActionState = UserActionState.NAVIGATING;
+ self.visible = false; // Hide the CancelActionButton
+ }
+ // Restore labels on all BuildableItemIcon instances
+ game.children.forEach(function (child) {
+ if (child instanceof BuildableItemIcon) {
+ child.restoreLabel();
+ }
+ });
+ console.log('Cancel action button pressed and building placement cancelled.');
+ });
+ return self;
+});
+// Command Panel class
+var CommandPanel = Container.expand(function () {
+ var self = Container.call(this);
+ self.graphics = self.attachAsset('boardBackground', {
+ width: game.width,
+ height: game.height * 0.22,
+ color: 0x333333
+ });
+ // Set the center box position to the center of the screen
+ self.x = game.width / 2 - self.graphics.width / 2;
+ self.y = game.height - self.height + game.height * 0.01;
+});
+var IconBorder = Container.expand(function (x, y) {
+ var self = Container.call(this);
+ self.asset = self.attachAsset('iconBorder', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: x,
+ y: y
+ });
+ return self;
+});
// Initialize game elements
// Map class to represent the grid-based map system
var Map = Container.expand(function () {
var self = Container.call(this);
@@ -322,19 +490,59 @@
self.load = function (data) {
// Load map data from a file
};
});
-var Sand = Container.expand(function (x, y) {
+var Player = Container.expand(function (playerId, tint) {
var self = Container.call(this);
- self.asset = LK.getAsset('sand', {
+ self.playerId = playerId;
+ self.resources = 0;
+ 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
+ self.units = []; // Array to store all the player's units
+ // ...
+ self.addUnit = function (unit) {
+ // Add the unit to the player's units array
+ self.units.push(unit);
+ // Update any unit-related properties or behaviors
+ // ...
+ };
+ self.addBuilding = function (building) {
+ // Add the building to the player's buildings array
+ self.buildings.push(building);
+ // Update the energy production based on the new building
+ self.updateEnergy();
+ // If the building can produce or store resources, update those as well
+ // ... (additional resource management code can be added here)
+ };
+ self.updateEnergy = function () {
+ var counter = 0;
+ // Iterate through all buildings owned by the player
+ self.buildings.forEach(function (building) {
+ // Sum the energy provided by the building
+ var buildingInfo = buildableRepository.getBuildableInfo(building.type);
+ console.log("Count energy of " + buildingInfo.name);
+ var buildingInfo = buildableRepository.getBuildableInfo(building.type);
+ counter = Math.min(Math.max(counter + buildingInfo.energy, 0), 100);
+ });
+ self.energy = counter;
+ console.log("Player " + self.playerId + " energy updated: " + self.energy);
+ };
+ return self;
+});
+var Rock = Container.expand(function (x, y) {
+ var self = Container.call(this);
+ self.asset = LK.getAsset('rock', {
x: x * 100,
y: y * 100
}); // Pre-create the asset for this cell
return self.asset;
});
-var Rock = Container.expand(function (x, y) {
+var Sand = Container.expand(function (x, y) {
var self = Container.call(this);
- self.asset = LK.getAsset('rock', {
+ self.asset = LK.getAsset('sand', {
x: x * 100,
y: y * 100
}); // Pre-create the asset for this cell
return self.asset;
@@ -388,82 +596,35 @@
self.visible = false;
};
return self;
});
-// Base Building class
-var Building = Container.expand(function (x, y, type, name, playerId, cellW, cellH, buildable) {
+var TargetMoveCursor = Container.expand(function () {
var self = Container.call(this);
- 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.type = type;
- self.isBuilding = true;
- self.playerId = playerId;
- self.name = name;
- self.buildable = buildable || []; // New property to store what the building can build
- self.asset = self.attachAsset(type, {
+ self.asset = self.attachAsset('targetMoveCursor', {
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 ConstructionYard = Building.expand(function (x, y, playerId) {
- var self = Building.call(this, x, y, 'constructionYard', 'Construction Yard', playerId, 2, 2, buildableRepository.getBuildableInfo('constructionYard').buildable);
- // Additional properties and methods for ConstructionYard can be added here
- return self;
-});
-var WindTrap = Building.expand(function (x, y, playerId) {
- var self = Building.call(this, x, y, 'windTrap', 'Wind Trap', playerId, 2, 2);
- // Additional properties and methods for WindTrap can be added here
- return self;
-});
-var SpiceRefinery = Building.expand(function (x, y, playerId) {
- var self = Building.call(this, x, y, 'spiceRefinery', 'Spice Refinery', playerId, 3, 2);
- // Additional properties and methods for SpiceRefinery can be added here
- return self;
-});
-// BuildableRepository class to store reference information about all buildables
-var BuildableRepository = Container.expand(function () {
- var self = Container.call(this);
- self.buildables = {
- 'constructionYard': {
- 'name': 'Construction Yard',
- 'cost': 300,
- 'energy': 0,
- 'constructionTime': 10,
- 'className': 'ConstructionYard',
- 'buildable': ['windTrap', 'spiceRefinery']
- },
- 'windTrap': {
- 'name': 'Wind Trap',
- 'cost': 300,
- 'energy': 100,
- 'constructionTime': 2,
- 'className': 'WindTrap',
- 'buildable': []
- },
- 'spiceRefinery': {
- 'name': 'Spice Refinery',
- 'cost': 600,
- 'energy': -50,
- 'constructionTime': 4,
- 'className': 'SpiceRefinery',
- 'buildable': []
- }
- // Add more buildables as needed
+ self.updatePosition = function (position) {
+ //console.log("moving at : " + position.x + ',' + position.y);
+ self.x = position.x;
+ self.y = position.y;
};
- self.getBuildableInfo = function (type) {
- return self.buildables[type];
- };
+ game.on('move', function (obj) {
+ if (currentUserActionState != UserActionState.SET_ORDER_TARGET) {
+ return;
+ }
+ //console.log("moving cursor");
+ var pos = obj.event.getLocalPosition(game);
+ if (pos.y > game.height * 0.80) {
+ self.visible = false;
+ } else {
+ self.visible = true;
+ self.updatePosition(pos);
+ }
+ });
+ /*game.on('up', function () {
+ self.destroy();
+ });*/
return self;
});
var Unit = Container.expand(function (x, y, playerId, type) {
var self = Container.call(this);
@@ -607,35 +768,8 @@
};
// Additional properties and methods for UnitHarvester can be added here
return self;
});
-var ActionRepository = Container.expand(function () {
- var self = Container.call(this);
- self.actions = {
- 'harvest': {
- 'code': 'harvest',
- 'name': 'Harvest',
- 'icon': 'harvestIcon',
- 'handler': harvestActionLogic
- },
- 'move': {
- 'code': 'move',
- 'name': 'Move',
- 'icon': 'moveIcon',
- 'handler': moveActionLogic
- },
- 'return': {
- 'code': 'return',
- 'name': 'Retreat',
- 'icon': 'returnIcon',
- 'handler': function handler() {/* Return action logic */}
- }
- };
- self.getActionInfo = function (actionType) {
- return self.actions[actionType];
- };
- return self;
-});
//{15.1}
var UnitRepository = Container.expand(function () {
var self = Container.call(this);
self.units = {
@@ -653,142 +787,8 @@
return self.units[type];
};
return self;
});
-var Player = Container.expand(function (playerId, tint) {
- var self = Container.call(this);
- self.playerId = playerId;
- self.resources = 0;
- 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
- self.units = []; // Array to store all the player's units
- // ...
- self.addUnit = function (unit) {
- // Add the unit to the player's units array
- self.units.push(unit);
- // Update any unit-related properties or behaviors
- // ...
- };
- self.addBuilding = function (building) {
- // Add the building to the player's buildings array
- self.buildings.push(building);
- // Update the energy production based on the new building
- self.updateEnergy();
- // If the building can produce or store resources, update those as well
- // ... (additional resource management code can be added here)
- };
- self.updateEnergy = function () {
- var counter = 0;
- // Iterate through all buildings owned by the player
- self.buildings.forEach(function (building) {
- // Sum the energy provided by the building
- var buildingInfo = buildableRepository.getBuildableInfo(building.type);
- console.log("Count energy of " + buildingInfo.name);
- var buildingInfo = buildableRepository.getBuildableInfo(building.type);
- counter = Math.min(Math.max(counter + buildingInfo.energy, 0), 100);
- });
- self.energy = counter;
- console.log("Player " + self.playerId + " energy updated: " + self.energy);
- };
- return self;
-});
-// Command Panel class
-var CommandPanel = Container.expand(function () {
- var self = Container.call(this);
- self.graphics = self.attachAsset('boardBackground', {
- width: game.width,
- height: game.height * 0.22,
- color: 0x333333
- });
- // Set the center box position to the center of the screen
- self.x = game.width / 2 - self.graphics.width / 2;
- self.y = game.height - self.height + game.height * 0.01;
-});
-var CancelActionButton = Container.expand(function (x, y) {
- var self = Container.call(this);
- self.asset = self.attachAsset('cancelAction', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: x,
- y: y
- });
- // Add a label 'Cancel' below the cancel action button
- self.label = new Text2('Cancel', {
- size: 30,
- fill: '#000000',
- font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
- });
- self.label.x = self.asset.x - 40;
- self.label.y = self.asset.y + 120;
- self.addChild(self.label);
- self.asset.on('down', function () {
- // Handle cancel action logic here
- if (currentBuildingForPlacement) {
- player1.spice += buildableRepository.getBuildableInfo(currentBuildingForPlacement.type).cost;
- updateBaseInfo();
- currentBuildingForPlacement.destroy();
- currentBuildingForPlacement = null;
- currentUserActionState = UserActionState.NAVIGATING;
- self.visible = false; // Hide the CancelActionButton
- }
- // Restore labels on all BuildableItemIcon instances
- game.children.forEach(function (child) {
- if (child instanceof BuildableItemIcon) {
- child.restoreLabel();
- }
- });
- console.log('Cancel action button pressed and building placement cancelled.');
- });
- return self;
-});
-var ActionItemIcon = Container.expand(function (action, x, y) {
- var self = Container.call(this);
- self.action = action;
- self.asset = self.attachAsset(action.icon, {
- anchorX: 0.5,
- anchorY: 0.5,
- x: x,
- y: y,
- width: 200,
- height: 200
- });
- self.asset.on('down', function () {
- 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);
- } else {
- currentSelection.selectedAction = null;
- }
- });
- self.label = new Text2(action.name, {
- size: 30,
- fill: '#000000',
- font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
- });
- self.label.x = self.asset.x - action.name.length / 2 * 13;
- self.label.y = self.asset.y + 120;
- self.addChild(self.label);
- return self;
-});
-var IconBorder = Container.expand(function (x, y) {
- var self = Container.call(this);
- self.asset = self.attachAsset('iconBorder', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: x,
- y: y
- });
- return self;
-});
/****
* Initialize Game
****/
@@ -1065,9 +1065,9 @@
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);
+ //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)
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