User prompt
in updateBaseInfo, also animate the energy color : red near 0%, orange around 50% and #037d50 near 100%
User prompt
in updateEnergy, clamp the energy between 0 and 100
Code edit (4 edits merged)
Please save this source code
User prompt
in updateBaseInfo, keep track of the previous energyLevel in a global variable and use it to animate the change of the energy value
User prompt
in enqueueBuildable, don't reduce spice by buildableInfo.cost directly, instead reduce it progressively during the building progress
Code edit (1 edits merged)
Please save this source code
User prompt
call addBuilding when a buiding is added in handleBuildingPlacement
User prompt
in updateEnergy, use buildings instead of gameMap
Code edit (1 edits merged)
Please save this source code
User prompt
in displayBuildableItems , only display BuildableItemIcons if currentSelection is the property of player 1
Code edit (5 edits merged)
Please save this source code
User prompt
do the same for player2
User prompt
call addBuilding() after the creation of the initial Construction Yard
User prompt
add a function 'addBuilding()' to Player class
User prompt
add an array property in Player to store all the player's buildings
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
in updateBaseInfo, also update player1EnergyText
User prompt
in updateEnergy(), check all building of the player and sum their energy
User prompt
in handleBuildingPlacement when player 1 place a new building, call updateEnergy then updateBaseInfo
Code edit (1 edits merged)
Please save this source code
User prompt
add a player1EnergyText after player1SpiceText
User prompt
in enqueueBuildable call updateBaseInfo instead of player1SpiceText.setText(player1.spice.toString());
Code edit (4 edits merged)
Please save this source code
User prompt
at the end of handleBuildingPlacement clear currentBuildingForPlacement
===================================================================
--- original.js
+++ change.js
@@ -283,9 +283,9 @@
// 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);
- self.energy += buildingInfo.energy;
+ self.energy = Math.min(Math.max(self.energy + buildingInfo.energy, 0), 100);
});
console.log("Player " + self.playerId + " energy updated: " + self.energy);
};
return self;
@@ -440,8 +440,9 @@
// Gui
var commandPanel = null;
var player1SpiceText = null;
var player1EnergyText = null;
+var energyOffsetSufix = '% ';
var currentSelectionText = null;
var rockIlot1Center = {
x: 0,
y: 0
@@ -635,27 +636,27 @@
player1SpiceText.setText('| ' + player1.spice.toString());
// Animate the change of the energy value
if (previousEnergyLevel !== player1.energy) {
var energyDifference = player1.energy - previousEnergyLevel;
- var duration = 1000; // Duration of the animation in milliseconds
+ var duration = 2000; // Duration of the animation in milliseconds
var steps = duration / (1000 / 60); // Number of steps based on 60FPS
var stepValue = energyDifference / steps;
var currentStep = 0;
var animateEnergyChange = function animateEnergyChange() {
if (currentStep < steps) {
previousEnergyLevel += stepValue;
- player1EnergyText.setText(previousEnergyLevel.toFixed(0).toString() + '% ');
+ player1EnergyText.setText(previousEnergyLevel.toFixed(0).toString() + energyOffsetSufix);
currentStep++;
LK.setTimeout(animateEnergyChange, 1000 / 60);
} else {
// Ensure the final value is set correctly
- player1EnergyText.setText(player1.energy.toString() + '% ');
+ player1EnergyText.setText(player1.energy.toString() + energyOffsetSufix);
previousEnergyLevel = player1.energy; // Update the previous energy level
}
};
animateEnergyChange();
} else {
- player1EnergyText.setText(player1.energy.toString() + '% ');
+ player1EnergyText.setText(player1.energy.toString() + energyOffsetSufix);
}
};
function initGame() {
// Create players
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