Code edit (1 edits merged)
Please save this source code
User prompt
in findAvailablePositionAroundRefinery, take other buildings into account
User prompt
when an Harvester is spawned on the Refinery, order it to move to the first available place around the refinery
User prompt
when a Spice Refinery is placed, automatically spawn an Harvester on it
User prompt
in spawnUnit use the playerId instead of always calling player1.addUnit()
User prompt
Fix Bug: 'Timeout.tick error: eval is not a function' in or related to this line: 'var unitClass = eval(unitInfo.className);' Line Number: 752
User prompt
in spawnUnit, user the unitInfo.className instead of calling UnitHarvester constructor
User prompt
extract the code : ``` var harvesterUnitInfo = unitRepository.getUnitInfo('unitHarvester'); var newHarvester = new UnitHarvester(rockIlot1Center.x, rockIlot1Center.y - 2, player1.playerId); gameMap.cells[rockIlot1Center.x][rockIlot1Center.y - 2].unit = newHarvester; player1.addUnit(newHarvester); game.addChild(newHarvester); ``` in a new global function spawnUnit() with all the required parameters
Code edit (15 edits merged)
Please save this source code
User prompt
update findPath to avoid buildings
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
add the fps update
Code edit (3 edits merged)
Please save this source code
User prompt
display the fps in the bottom right in black
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
in handleDrag ensure that self.currentViewCenter x & y are always integers and not floats
User prompt
in handleDrag, update the self.currentViewCenter gradually,
User prompt
in handleDrag, update the self.currentViewCenter gradually, but don't use floats in self.currentViewCenter x & y
User prompt
in handleDrag, update the self.currentViewCenter gradually, but ensure self.currentViewCenter x & y are integers, not floats !
User prompt
in handleDrag, update the self.currentViewCenter gradually
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'building')' in or related to this line: 'if (!cell.building && !cell.unit && deltaToSelection > 1) {' Line Number: 1009
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading '22.87842334540943')' in or related to this line: 'var cell = gameMap.cells[cellX][cellY];' Line Number: 1008
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading '20')' in or related to this line: 'var cell = gameMap.cells[cellX][cellY];' Line Number: 1008
===================================================================
--- original.js
+++ change.js
@@ -398,10 +398,13 @@
if (distance < step) {
console.log("reached step", distance);
self.x = targetCoords.x;
self.y = targetCoords.y;
+ // Update map
+ gameMap.cells[self.cellX][self.cellY].unit = null;
self.cellX = targetCell.cellX;
- self.cellY = targetCell.cellY;
+ self.cellY = targetCell.cellY; // Update map
+ gameMap.cells[self.cellX][self.cellY].unit = self;
self.pathIndex++;
if (self.pathIndex >= self.path.length) {
self.isMoving = false;
}
@@ -789,8 +792,10 @@
var previousEnergyLevel = 0;
var currentSelection = null;
var currentBuildingForPlacement = null;
var selectionMarker = null;
+var tickCounter = 0;
+var fps = 0;
// Gui
var commandPanel = null;
var player1SpiceText = null;
var player1EnergyText = null;
@@ -900,8 +905,22 @@
var inputPosition = {
x: Math.round(-deltaX / 100),
y: Math.round(-deltaY / 100)
};
+ var allUnits = player1.units.concat(player2.units);
+ allUnits.forEach(function (unit) {
+ var targetX = Math.max(11, Math.min(gameMap.currentViewCenter.x + inputPosition.x, mapXSize - 4));
+ var targetY = Math.max(14, Math.min(gameMap.currentViewCenter.y + inputPosition.y, mapYSize - 9));
+ var newCenterX = Math.round(gameMap.currentViewCenter.x + (targetX - gameMap.currentViewCenter.x) * dragSpeed);
+ var newCenterY = Math.round(gameMap.currentViewCenter.y + (targetY - gameMap.currentViewCenter.y) * dragSpeed);
+ var deltaX = gameMap.currentViewCenter.x - newCenterX;
+ var deltaY = gameMap.currentViewCenter.y - newCenterY;
+ console.log("unit coords : " + unit.x + ',' + unit.y);
+ console.log("target coords : " + targetX + ',' + targetY);
+ console.log("delta coords : " + deltaX + ',' + deltaY);
+ unit.x += deltaX * 100;
+ unit.y += deltaY * 100;
+ });
gameMap.handleDrag(inputPosition);
}
}
function handleDragEnd(obj) {
@@ -1188,13 +1207,17 @@
} else {
player1EnergyText.setText(player1.energy.toString() + energyOffsetSufix);
}
};
-var updateFps = function updateFps() {
- var fps = 60;
- if (fpsText) {
- fpsText.setText(Math.floor(fps));
- }
+var startFpsCounter = function startFpsCounter() {
+ var fpsInterval = LK.setInterval(function () {
+ // Set the FPS value to the tick counter
+ fps = tickCounter;
+ // Reset the tick counter
+ tickCounter = 0;
+ // Update the FPS text on the screen
+ fpsText.setText('FPS: ' + fps);
+ }, 1000); // 1000 milliseconds = 1 second
};
function initGame() {
// Create players
player1 = new Player(1, 0x5e86ff);
@@ -1237,16 +1260,17 @@
});
player1EnergyText.anchor.set(1.0, 0.25);
LK.gui.topRight.addChild(player1EnergyText);
// Create a Text2 object to display the FPS in the bottom right corner
- fpsText = new Text2('60', {
+ fpsText = new Text2('', {
size: 50,
fill: '#000000',
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
- fpsText.anchor.set(1.0, 1.0);
+ fpsText.anchor.set(1.5, 1.0);
LK.gui.bottomRight.addChild(fpsText);
gameIsRunning = true;
+ startFpsCounter();
}
// Game tick
LK.on('tick', function () {
// Render the map and update unit movement each tick
@@ -1271,8 +1295,9 @@
unit.x = screenX;
unit.y = screenY;*/
});
}
+ tickCounter++;
});
// Start the game with Player 1 construction yard preselected
LK.setTimeout(function () {
initGame();
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