Code edit (14 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: rockIlot2Center is not defined' in or related to this line: 'baseBuilding = {' Line Number: 1740
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.getTime is not a function' in or related to this line: 'self.lastHitTime = LK.getTime();' Line Number: 1099
Code edit (2 edits merged)
Please save this source code
User prompt
could you implement findFactoryForUnit
Code edit (1 edits merged)
Please save this source code
User prompt
add a new function findEmplacementForBuilding(building, cellX, cellY) that scans the map around the given cellX,cellY to find a free area of rocks that fits the given building size
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: buildable.placeBuilding is not a function' in or related to this line: 'buildable.placeBuilding(placeX, placeY);' Line Number: 2117
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
in handleDragEnd, don't select buildings if they are under fog
User prompt
don't select ennemy units and building if they are under fog
User prompt
in updateFogOfWar remove the fog in a radius shape instead of a square
Code edit (2 edits merged)
Please save this source code
User prompt
in building growExplosion, remove building from player list of buildings
User prompt
in checkGameEnd, check if player1 of player2 have no more buildings game over if so
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
call updateFogOfWar(); after every building placement
Code edit (7 edits merged)
Please save this source code
User prompt
in updateFogOfWar, itterate through all player1 units and buildings and set gameMap.cells[x][y].fog to false 5 cells around them
User prompt
force fogOfWar tint to 0x000000
===================================================================
--- original.js
+++ change.js
@@ -136,10 +136,9 @@
'constructionYard': {
'name': 'Construction Yard',
'cost': 300,
'energy': 0,
- 'health': 2,
- //100, TEMP DEBUG !!!! TEMP DEBUG !!!! TEMP DEBUG !!!! TEMP DEBUG !!!!
+ 'health': 100,
'constructionTime': 10,
'className': 'ConstructionYard',
'buildable': ['windTrap', 'spiceRefinery', 'lightFactory', 'heavyFactory']
},
@@ -147,67 +146,73 @@
'name': 'Wind Trap',
'cost': 300,
'energy': 100,
'health': 50,
- 'constructionTime': 2,
+ 'constructionTime': 10,
'className': 'WindTrap',
'buildable': []
},
'spiceRefinery': {
'name': 'Spice Refinery',
'cost': 600,
'energy': -50,
'health': 75,
- 'constructionTime': 1,
+ 'constructionTime': 20,
'className': 'SpiceRefinery',
'buildable': []
},
'lightFactory': {
'name': 'Light Factory',
'cost': 400,
'energy': -30,
'health': 60,
- 'constructionTime': 1,
+ 'constructionTime': 15,
'className': 'LightFactory',
'buildable': ['unitQuad'],
- 'requires': '' //spiceRefinery
+ 'requires': 'spiceRefinery'
},
'heavyFactory': {
'name': 'Heavy Factory',
'cost': 600,
'energy': -50,
'health': 80,
- 'constructionTime': 1,
- // 30 TEMP DEBUG !!!!
+ 'constructionTime': 30,
'className': 'HeavyFactory',
- 'buildable': ['unitLightTank', 'unitHeavyTank'],
- 'requires': '' //lightFactory TEMP DEBUG !!!! TEMP DEBUG !!!!
+ 'buildable': ['unitLightTank', 'unitHeavyTank', 'unitHarvester'],
+ 'requires': 'lightFactory'
},
'unitQuad': {
'name': 'Quad',
'cost': 200,
'energy': 0,
- 'constructionTime': 1,
+ 'constructionTime': 5,
'className': 'UnitQuad',
'buildable': []
},
'unitLightTank': {
'name': 'Light Tank',
'cost': 400,
'energy': 0,
- 'constructionTime': 1,
+ 'constructionTime': 8,
// 5 TEMP DEBUG !!!
'className': 'UnitLightTank',
'buildable': []
},
'unitHeavyTank': {
'name': 'Heavy Tank',
'cost': 600,
'energy': 0,
- 'constructionTime': 1,
- // 10 TEMP DEBUG !!!
+ 'constructionTime': 15,
'className': 'UnitHeavyTank',
'buildable': []
+ },
+ 'unitHarvester': {
+ 'name': 'Harvester',
+ 'cost': 500,
+ 'energy': 0,
+ 'constructionTime': 12,
+ 'className': 'UnitHarvester',
+ 'buildable': []
}
// Add more buildables as needed
};
self.getBuildableInfo = function (type) {
@@ -465,9 +470,9 @@
x: 15,
y: 20
};
// Create a Text2 object to display the currentViewCenter coordinates
- self.viewCenterText = new Text2('Center', {
+ self.viewCenterText = new Text2('', {
size: 50,
fill: '#ffffff',
align: 'center'
});
@@ -500,8 +505,11 @@
}
// Render buildings
var building = cell.building;
if (building) {
+ if (building.playerId === player2.playerId) {
+ building.asset.visible = !cell.fog;
+ }
building.asset.x = screenX - (building.cellW - 2) / 2 * tileSize;
building.asset.y = screenY - (building.cellH - 2) / 2 * tileSize;
self.addChild(building.asset);
if (building.assetEffect) {
@@ -524,9 +532,9 @@
// Create and return the navigation mesh for pathfinding
};
self.findPath = function (start, end, range, ignoreSpecificBuilding) {
range = range || 0;
- console.log("findPath ", start, end, range);
+ //console.log("findPath ", start, end, range);
// A* pathfinding algorithm implementation
// Avoid buildings by checking if the cell is occupied
var openSet = [];
var closedSet = [];
@@ -574,9 +582,9 @@
}
curr = curr.parent;
}
path.reverse();
- console.log("Return path 1", path);
+ //console.log("Return path 1", path);
return path;
}
openSet.splice(lowestIndex, 1);
closedSet.push(currentNode);
@@ -631,9 +639,9 @@
}
path.reverse();
}
}
- console.log("Return best effort path", path);
+ //console.log("Return best effort path", path);
return path;
};
function heuristic(node, endNode) {
// Use Manhattan distance as heuristic
@@ -685,9 +693,9 @@
viewPort.wCellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, viewPort.wCellY + input.y));
viewPort.wX = viewPort.wCellX * tileSize;
viewPort.wY = viewPort.wCellY * tileSize;
// Update the Text2 object with the new coordinates
- self.viewCenterText.setText(viewPort.wCellX + ',' + viewPort.wCellY);
+ //self.viewCenterText.setText(viewPort.wCellX + ',' + viewPort.wCellY);
};
self.checkCollisions = function () {
// Handle collisions between units and obstacles
};
@@ -928,9 +936,11 @@
gameMap.cells[self.cellX][self.cellY].unit = null;
self.cellX = targetCell.cellX;
self.cellY = targetCell.cellY; // Update map
gameMap.cells[self.cellX][self.cellY].unit = self;
- updateFogOfWar();
+ if (self.playerId == player1.playerId) {
+ updateFogOfWar();
+ }
self.pathIndex++;
if (self.pathIndex >= self.path.length) {
self.isMoving = false;
if (self.onArrivedCallback) {
@@ -1117,10 +1127,10 @@
self.harvestedSpiceCapacity = 600;
self.harvestedSpiceOnTripCounter = 0;
self.harvestedSpiceOnCellCounter = 0;
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.harvestSpeed = 0.3; // Adjust this value to control the speed of harvesting
+ self.unloadSpeed = 0.4; // Adjust this value to control the speed of harvesting
self.setHarvesting = function () {
//console.log("Ok at site setHarvesting...");
self.harvestingMode = 1;
};
@@ -1251,10 +1261,9 @@
'energy': 0,
'constructionTime': 3,
'className': 'UnitQuad',
'actions': ['move', 'attack', 'return'],
- 'health': 3,
- //10, TEMP DEBUG !!!
+ 'health': 10,
'sightRange': 4,
'attackRange': 2,
'attackSpeed': 2,
'attackDamage': 1
@@ -1266,25 +1275,22 @@
'constructionTime': 2,
// 10
'className': 'UnitLightTank',
'actions': ['move', 'attack', 'return'],
- 'health': 3,
- //20, TEMP DEBUG !!!
+ 'health': 20,
'sightRange': 6,
'attackRange': 4,
'attackSpeed': 3,
'attackDamage': 3
},
'unitHeavyTank': {
'name': 'Heavy Tank',
- 'cost': 600,
+ 'cost': 800,
'energy': 0,
- 'constructionTime': 2,
- // 10
+ 'constructionTime': 15,
'className': 'UnitHeavyTank',
'actions': ['move', 'attack', 'return'],
- 'health': 5,
- //20, TEMP DEBUG !!!
+ 'health': 60,
'sightRange': 8,
'attackRange': 6,
'attackSpeed': 5,
'attackDamage': 6
@@ -1643,8 +1649,11 @@
break;
case 'UnitHeavyTank':
buildable = new UnitHeavyTank(0, 0, player1.playerId);
break;
+ case 'UnitHarvester':
+ buildable = new UnitHarvester(0, 0, player1.playerId);
+ break;
// Add cases for other buildings as needed
}
if (!buildable) {
console.error('Building object is not defined.');
@@ -1713,17 +1722,17 @@
if (building) {
for (var w = 0; w < building.cellW; w++) {
for (var h = 0; h < building.cellH; h++) {
if (cellX + w < gameMap.cells.length && cellY + h < gameMap.cells[0].length) {
- console.log("applyCellOccupation", cellX, cellY, " to ", cellX + w, cellY + h);
+ //console.log("applyCellOccupation", cellX, cellY, " to ", cellX + w, cellY + h);
gameMap.cells[cellX + w][cellY + h].building = building;
}
}
}
}
};
var getPlayerTint = function getPlayerTint(id) {
- console.log("getPlayerTint", id);
+ //console.log("getPlayerTint", id);
return player1.playerId === id ? player1.tint : player2.tint;
};
var gameIsRunning = false;
var mapXSize = 20 * 2;
@@ -1951,9 +1960,9 @@
gameMap.cells[x][y].fog = true;
gameMap.cells[x][y].fogAsset = LK.getAsset('fogOfWar', {
x: x * 100,
y: y * 100,
- tint: 0x000000
+ tint: 0x222222
});
}
}
}
@@ -1974,18 +1983,18 @@
//#region Event listeners
var dragStart = null;
var dragDelta = 0;
function handleDragStart(obj) {
- console.log("Drag start...");
+ //console.log("Drag start...");
dragStart = obj.event.getLocalPosition(game);
}
function handleDragMove(obj) {
var currentPos = obj.event.getLocalPosition(game);
var input = {
x: currentPos.x,
y: currentPos.y
};
- updateMouseCoords(input.x, input.y);
+ //updateMouseCoords(input.x, input.y);
if (currentUserActionState === UserActionState.PLACING_BUILDINGS) {
var cellCoord = screenCoordToWorldCell(input.x, input.y);
var cellX = cellCoord.wCellX;
var cellY = cellCoord.wCellY;
@@ -2018,11 +2027,11 @@
var input = {
x: currentPos.x,
y: currentPos.y
};
- console.log("Clicked at " + input.x + ',' + input.y);
+ //console.log("Clicked at " + input.x + ',' + input.y);
if (input.y > game.height * 0.80) {
- console.log("Clicked on board at " + input.x + ',' + input.y);
+ //console.log("Clicked on board at " + input.x + ',' + input.y);
dragStart = null;
dragDelta = 0;
return;
}
@@ -2033,9 +2042,9 @@
var isValidPlacement = checkBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
if (!isValidPlacement) {
return;
}
- console.log("Placing building ", currentBuildingForPlacement, " at " + cellX + ',' + cellY);
+ //console.log("Placing building ", currentBuildingForPlacement, " at " + cellX + ',' + cellY);
handleBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
currentUserActionState = UserActionState.NAVIGATING;
dragStart = null;
dragDelta = 0;
@@ -2047,17 +2056,17 @@
y: cellCoord.wCellY
};
// Call the action handler with the target position
if (currentSelection.actions && currentSelection.selectedAction) {
- console.log(currentSelection.selectedAction + ' received ');
+ //console.log(currentSelection.selectedAction + ' received ');
var actionInfo = actionRepository.getActionInfo(currentSelection.selectedAction);
if (actionInfo && actionInfo.handler) {
- console.log('Call action handler : ', actionInfo);
+ //console.log('Call action handler : ', actionInfo);
actionInfo.handler(currentSelection, cellCoord.wCellX, cellCoord.wCellY);
}
}
if (targetMoveCursor) {
- console.log('hiding move cursor ...');
+ //console.log('hiding move cursor ...');
targetMoveCursor.visible = false;
}
}
highlightBorder();
@@ -2071,9 +2080,9 @@
// Normal click
var clickCell = screenCoordToWorldCell(input.x, input.y);
var cellX = clickCell.wCellX;
var cellY = clickCell.wCellY;
- console.log("Click at cell " + cellX + ',' + cellY);
+ //console.log("Click at cell " + cellX + ',' + cellY);
var allUnits = player1.units.concat(player2.units);
allUnits.forEach(function (unit) {
unit.handleDrag(input);
unit.visible = true;
@@ -2089,19 +2098,19 @@
if (dragDelta < tileSize * 0.25) {
currentSelection = null;
selectionMarker.setOnElement();
selectionMarker.hide();
- console.log("Nothing selected at " + cellX + ',' + cellY, " deltaToSelection=" + deltaToSelection, " dragDelta=", dragDelta);
+ //console.log("Nothing selected at " + cellX + ',' + cellY, " deltaToSelection=" + deltaToSelection, " dragDelta=", dragDelta);
updateActionBoard();
}
} else if (cell.building) {
- console.log("Selected building at " + cellX + ',' + cellY);
+ //console.log("Selected building at " + cellX + ',' + cellY);
currentSelection = cell.building;
selectionMarker.setOnElement(currentSelection);
updateActionBoard();
} else if (cell.unit) {
- console.log("Selected cell with unit at " + cellX + ',' + cellY);
- console.log("unit at " + cell.unit.x + ',' + cell.unit.y);
+ //console.log("Selected cell with unit at " + cellX + ',' + cellY);
+ //console.log("unit at " + cell.unit.x + ',' + cell.unit.y);
}
}
dragStart = null;
dragDelta = 0;
@@ -2353,9 +2362,9 @@
gameMap.viewCenterText.setText(viewPort.wCellX + ',' + viewPort.wCellY);
};
// Global function to update base info text
var updateBaseInfo = function updateBaseInfo() {
- player1SpiceText.setText('| ' + player1.spice.toString());
+ player1SpiceText.setText('| ' + Math.floor(player1.spice).toString());
// Animate the change of the energy value
if (previousEnergyLevel !== player1.energy) {
var energyDifference = player1.energy - previousEnergyLevel;
var duration = 2000; // Duration of the animation in milliseconds
@@ -2414,28 +2423,28 @@
currentSelectionText.anchor.set(0.5, 6.8);
LK.gui.bottom.addChild(currentSelectionText);
// Create a Text2 object to display mouse coordinates
if (!game.mouseCoordsText) {
- game.mouseCoordsText = new Text2('0,0\r\n0,0', {
+ game.mouseCoordsText = new Text2('', {
size: 50,
fill: '#ffffff',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
game.mouseCoordsText.anchor.set(0, 0);
LK.gui.topLeft.addChild(game.mouseCoordsText);
}
// Create a Text2 object to display player1's spice level
- player1SpiceText = new Text2('| ' + player1.spice.toString(), {
+ player1SpiceText = new Text2('| ' + Math.floor(player1.spice).toString(), {
size: 50,
- fill: '#000000',
+ fill: '#FFFFFF',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
player1SpiceText.anchor.set(1.0, 0.25);
LK.gui.topRight.addChild(player1SpiceText);
// Create a Text2 object to display player1's energy level
player1EnergyText = new Text2(player1.energy.toString() + energyOffsetSufix, {
size: 50,
- fill: '#000000',
+ fill: '#FFFFFF',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
player1EnergyText.anchor.set(1.0, 0.25);
LK.gui.topRight.addChild(player1EnergyText);
@@ -2447,15 +2456,18 @@
});
fpsText.anchor.set(1.5, 1.0);
LK.gui.bottomRight.addChild(fpsText);
gameIsRunning = true;
- startFpsCounter();
+ //startFpsCounter();
}
// Game tick
LK.on('tick', function () {
// Render the map and update unit movement each tick
if (gameIsRunning) {
gameMap.render();
+ player2.units.forEach(function (unit) {
+ unit.asset.visible = !gameMap.cells[unit.cellX][unit.cellY].fog;
+ });
var allUnits = player1.units.concat(player2.units);
allUnits.forEach(function (unit) {
if (unit.isDestroyed) {
//console.log("unit is already destroyed");
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