Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'viewPort.wCellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, rockIlot1Center.x - Math.floor(viewPort.cellW / 2)));' Line Number: 2035
User prompt
ok, but also set the viewport centered on the rockIlot1Center at start
User prompt
currently rockIlot1Center and rockIlot2Center are fixed on top left and bottom down. make them randomly 'rotate' so that players start at one of the corners randomly
Code edit (11 edits merged)
Please save this source code
User prompt
in checkGameEnd(), show popup asset before game over
User prompt
show popup asset before game over
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
under welcomeText, add a help text "how to play..."
Code edit (2 edits merged)
Please save this source code
User prompt
on the popup write the text "Welcome on Dune."
Code edit (1 edits merged)
Please save this source code
User prompt
before game starts, show popup Asset
User prompt
before the game starts display a popup
Code edit (6 edits merged)
Please save this source code
User prompt
how would you handle energy so that low energy level slow down constructions
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'type')' in or related to this line: 'player1.spice += buildableRepository.getBuildableInfo(currentBuildingForPlacement.type).cost;' Line Number: 462
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: unit is not defined' in or related to this line: 'switch (unit.type) {' Line Number: 2176
Code edit (1 edits merged)
Please save this source code
Code edit (14 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -22,9 +22,9 @@
highlightBorder();
}, 1000);
} else {
currentUserActionState = UserActionState.SET_ORDER_TARGET;
- console.log('Wait target for action ' + self.action.name);
+ //console.log('Wait target for action ' + self.action.name);
if (!targetMoveCursor) {
targetMoveCursor = game.addChild(new TargetMoveCursor());
}
highlightBorder(self.asset.x);
@@ -91,26 +91,26 @@
height: 200
});
self.asset.on('down', function () {
if (!self.asset.interactive) {
- console.log("BuildableItemIcon : Not interactive. ignore");
+ //console.log("BuildableItemIcon : Not interactive. ignore");
return;
} else {
- console.log("BuildableItemIcon : Is interactive. continue");
+ //console.log("BuildableItemIcon : Is interactive. continue");
}
if (currentBuildingForPlacement) {
currentUserActionState = UserActionState.PLACING_BUILDINGS;
- console.log("BuildableItemIcon : User is placing ", currentBuildingForPlacement);
+ //console.log("BuildableItemIcon : User is placing ", currentBuildingForPlacement);
game.addChild(currentBuildingForPlacement);
return;
} else {
- console.log("BuildableItemIcon : No current building for placement. ignore");
+ //console.log("BuildableItemIcon : No current building for placement. ignore");
}
if (!self.progressDisplay) {
- console.log("BuildableItemIcon : No progress display => create one");
+ //console.log("BuildableItemIcon : No progress display => create one");
self.progressDisplay = new BuildingProgressDisplay(self);
} else {
- console.log("BuildableItemIcon : Progress display already exists");
+ //console.log("BuildableItemIcon : Progress display already exists");
}
self.progressDisplay.show();
game.addChild(self.progressDisplay);
enqueueBuildable(self.type, self.sourceFactory, player1, self.progressDisplay);
@@ -260,18 +260,18 @@
self.lastHitTime = 0;
self.lastAttaker = null;
self.defenders = [];
self.damage = function (attacker) {
- console.log("Building " + self.name + " hit! " + attacker.attackDamage);
+ //console.log("Building " + self.name + " hit! " + attacker.attackDamage);
self.lastAttaker = attacker;
self.health -= attacker.attackDamage;
self.lastHitTime = Date.now();
self.asset.tint = 0xff0000;
LK.setTimeout(function () {
self.asset.tint = 0xFFFFFF;
}, 500);
if (self.health <= 0) {
- console.log("Building " + self.name + " destroyed");
+ //console.log("Building " + self.name + " destroyed");
self.clean();
self.assetEffect = self.attachAsset('buildingExplosion', {
anchorX: 0.5,
anchorY: 0.5,
@@ -295,9 +295,9 @@
gameMap.cells[self.cellX + w][self.cellY + h].building = null;
}
}
}
- console.log("update selection destroyed ", currentSelection, self, currentSelection == self);
+ //console.log("update selection destroyed ", currentSelection, self, currentSelection == self);
if (currentSelection && currentSelection == self) {
currentSelection = null;
selectionMarker.setOnElement();
}
@@ -428,12 +428,12 @@
if (currentSelection && currentSelection.buildingQueue.length > 0) {
// Check for non null buildable and stop it's constructionTimer
for (var i = 0; i < currentSelection.buildingQueue.length; i++) {
if (currentSelection.buildingQueue[i] && currentSelection.buildingQueue[i].constructionTimer) {
- console.log("Stop constructionTimer on ", currentSelection.buildingQueue[i]);
+ //console.log("Stop constructionTimer on ", currentSelection.buildingQueue[i]);
var initialCost = buildableRepository.getBuildableInfo(currentSelection.buildingQueue[i].type).cost;
var initialTime = buildableRepository.getBuildableInfo(currentSelection.buildingQueue[i].type).constructionTime;
- console.log("constructionProgress = ", currentSelection.buildingQueue[i].constructionProgress);
+ //console.log("constructionProgress = ", currentSelection.buildingQueue[i].constructionProgress);
player1.spice += initialCost * currentSelection.buildingQueue[i].constructionProgress * initialTime / 100;
updateBaseInfo();
LK.clearInterval(currentSelection.buildingQueue[i].constructionTimer);
currentSelection.buildingQueue[i].constructionTimer = null;
@@ -468,9 +468,9 @@
if (child instanceof BuildableItemIcon) {
child.restoreLabel();
}
});
- console.log('Cancel action button pressed and building placement cancelled.');
+ //console.log('Cancel action button pressed and building placement cancelled.');
});
return self;
});
// Command Panel class
@@ -606,9 +606,9 @@
};
self.findPath = function (start, end, range, ignoreSpecificBuilding) {
range = range || 0;
if (range == 13) {
- 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 = [];
@@ -642,9 +642,9 @@
var dx = currentNode.x - endNode.x;
var dy = currentNode.y - endNode.y;
if (Math.sqrt(dx * dx + dy * dy) <= range) {
if (range == 13) {
- console.log("findPath Ok Within range :", currentNode.x, currentNode.y + " / dist=" + Math.sqrt(dx * dx + dy * dy));
+ //console.log("findPath Ok Within range :", currentNode.x, currentNode.y + " / dist=" + Math.sqrt(dx * dx + dy * dy));
}
var curr = currentNode;
while (curr.parent) {
var prev = curr.parent;
@@ -661,9 +661,9 @@
curr = curr.parent;
}
path.reverse();
if (range == 13) {
- console.log("Return path 1", path);
+ //console.log("Return path 1", path);
}
return path;
}
openSet.splice(lowestIndex, 1);
@@ -818,14 +818,14 @@
// 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);
+ //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);
+ //console.log("Player " + self.playerId + " energy updated: " + self.energy);
};
return self;
});
var Rock = Container.expand(function (x, y) {
@@ -893,9 +893,9 @@
self.visible = true;
}
};
self.hide = function () {
- console.log('SelectionMarker hidden');
+ //console.log('SelectionMarker hidden');
self.visible = false;
};
return self;
});
@@ -958,27 +958,27 @@
self.x = screenCoord.x;
self.y = screenCoord.y;
self.cellW = 1;
self.cellH = 1;
- console.log("clear onArrivedCallback 0");
+ //console.log("clear onArrivedCallback 0");
self.onArrivedCallback = null;
- console.log("New unit " + self.name + ' at ', self.x, ',', self.y, ' [' + self.cellX + ',' + self.cellY + ']');
+ //console.log("New unit " + self.name + ' at ', self.x, ',', self.y, ' [' + self.cellX + ',' + self.cellY + ']');
self.asset.on('down', function () {
if (currentUserActionState === UserActionState.NAVIGATING || currentUserActionState === UserActionState.GIVING_ORDERS) {
- console.log("Unit selected");
+ //console.log("Unit selected");
currentSelection = self;
// Update map to fix unselectable units
gameMap.cells[self.cellX][self.cellY].unit = self;
selectionMarker.setOnElement(currentSelection);
currentUserActionState = UserActionState.GIVING_ORDERS;
updateActionBoard();
} else {
- console.log("Not Navigating don't select unit...", currentUserActionState);
+ //console.log("Not Navigating don't select unit...", currentUserActionState);
}
});
self.moveAlongPath = function (path, callback) {
if (self.isArmy) {
- console.log("Army " + self.type + " #" + self.id + " moveAlongPath", path, callback);
+ //console.log("Army " + self.type + " #" + self.id + " moveAlongPath", path, callback);
}
self.path = path;
self.pathIndex = 0;
self.isMoving = true;
@@ -1078,9 +1078,9 @@
}
}
});
if (enemies.length > 0) {
- console.log(enemies.length + " enemies spotted.");
+ //console.log(enemies.length + " enemies spotted.");
self.startAttack(enemies[0]); // Start attacking the first enemy spotted
}
};
self.attackTarget = null; // Target unit to attack
@@ -1098,16 +1098,16 @@
self.lastAttackTime = Date.now();
// Check if target is in range
var distanceToTarget = calculateDistance(self, self.attackTarget);
if (distanceToTarget <= self.attackRange) {
- console.log(self.playerId + " - " + self.type + " : Target at range => fire");
+ //console.log(self.playerId + " - " + self.type + " : Target at range => fire");
// Rotate towards the target
var angleToTarget = calculateAngle(self, self.attackTarget);
self.asset.rotation = angleToTarget;
// Fire at the target
self.fire();
} else {
- console.log(self.playerId + " - " + self.type + " : Target too far => move to target");
+ //console.log(self.playerId + " - " + self.type + " : Target too far => move to target");
self.attackMode = 2;
// Move towards the target if it's out of range
var path = gameMap.findPath({
x: self.cellX,
@@ -1115,11 +1115,11 @@
}, {
x: self.attackTarget.cellX,
y: self.attackTarget.cellY
}, self.attackRange);
- console.log("Path to target:", path);
+ //console.log("Path to target:", path);
self.moveAlongPath(path, function () {
- console.log("Reached to target !");
+ //console.log("Reached to target !");
self.attackMode = 1;
});
}
} else if (!self.isMoving) {
@@ -1127,9 +1127,9 @@
}
};
self.fire = function () {
// Code to perform firing action
- console.log("Firing at target!", self.attackTarget);
+ //console.log("Firing at target!", self.attackTarget);
if (self.attackTarget && self.health > 0) {
// Reduce target's health
self.attackTarget.damage(self);
if (!self.attackTarget || self.attackTarget.health <= 0) {
@@ -1138,9 +1138,9 @@
}
}
};
self.damage = function (attacker) {
- console.log("Unit " + self.name + " hit! ", attacker);
+ //console.log("Unit " + self.name + " hit! ", attacker);
self.asset.tint = 0xff0000;
self.lastAttaker = attacker;
self.lastHitTime = Date.now();
LK.setTimeout(function () {
@@ -1148,9 +1148,9 @@
}, 300);
self.health -= attacker.attackDamage;
if (self.health <= 0 && !self.isDestroying) {
self.isDestroying = true;
- console.log("Unit " + self.name + " destroyed");
+ //console.log("Unit " + self.name + " destroyed");
self.clean();
self.assetEffect = self.attachAsset('buildingExplosion', {
anchorX: 0.5,
anchorY: 0.5,
@@ -1167,9 +1167,9 @@
growExplosion(size + 3);
}, 5);
} else {
// Remove building from gameMap cells and game
- console.log("unit destruction...");
+ //console.log("unit destruction...");
gameMap.cells[self.cellX][self.cellY].unit = null;
game.removeChild(self);
if (self.assetEffect) {
game.removeChild(self.assetEffect);
@@ -1207,9 +1207,9 @@
self.attackMode = false;
self.attackTarget = null;
};
self.stopOtherActions = function () {
- console.log("Unit stopOtherActions :");
+ //console.log("Unit stopOtherActions :");
self.attackMode = false; // Stop attacking
};
self.clean = function () {
self.lastAttackTime = 0;
@@ -1489,12 +1489,12 @@
function findClosestConstructionYard(unit) {
var closestBuilding = null;
var minDistance = Number.MAX_VALUE;
var playerBuildings = unit.playerId === player1.playerId ? player1.buildings : player2.buildings;
- console.log("Player has " + playerBuildings.length + " buildings");
+ //console.log("Player has " + playerBuildings.length + " buildings");
playerBuildings.forEach(function (building) {
if (building instanceof ConstructionYard) {
- console.log("Found ConstructionYard at " + building.cellX + "," + building.cellY);
+ //console.log("Found ConstructionYard at " + building.cellX + "," + building.cellY);
var dx = unit.cellX - building.cellX;
var dy = unit.cellY - building.cellY;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < minDistance) {
@@ -1502,9 +1502,9 @@
minDistance = distance;
}
}
});
- console.log("OK result ", closestBuilding);
+ //console.log("OK result ", closestBuilding);
return closestBuilding ? {
cellX: closestBuilding.cellX,
cellY: closestBuilding.cellY
} : null;
@@ -1663,24 +1663,24 @@
}
return []; // No available position found
}
function findAvailableCellAtRange(targetX, targetY, range) {
- console.log("findAvailableCellAtRange", targetX, targetY, range);
+ //console.log("findAvailableCellAtRange", targetX, targetY, range);
range = range || 1;
for (var dx = -range; dx <= range; dx++) {
for (var dy = -range; dy <= range; dy++) {
var checkX = targetX + dx;
var checkY = targetY + dy;
if (gameMap.cells[checkX] && gameMap.cells[checkX][checkY] && !gameMap.cells[checkX][checkY].unit && !gameMap.cells[checkX][checkY].building && (dx !== 0 || dy !== 0)) {
- console.log("Found available cell at", checkX, checkY);
+ //console.log("Found available cell at", checkX, checkY);
return {
cellX: checkX,
cellY: checkY
}; // Return the absolute cell
}
}
}
- console.log("No available position found");
+ //console.log("No available position found");
return []; // No available position found
}
function _typeof(o) {
"@babel/helpers - typeof";
@@ -1690,9 +1690,9 @@
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function moveActionLogic(targetUnit, destinationX, destinationY, isAttack) {
- console.log("MoveActionLogic...", destinationX, ',', destinationY, ", isAttack=", isAttack);
+ //console.log("MoveActionLogic...", destinationX, ',', destinationY, ", isAttack=", isAttack);
if (targetUnit && targetUnit.isUnit) {
targetUnit.stopOtherActions();
var path = gameMap.findPath({
x: targetUnit.cellX,
@@ -1704,9 +1704,9 @@
targetUnit.moveAlongPath(path);
}
}
function attackActionLogic(theUnit, targetCellX, targetCellY) {
- console.log("AttackActionLogic...", targetCellX, ',', targetCellY);
+ //console.log("AttackActionLogic...", targetCellX, ',', targetCellY);
var target = gameMap.cells[targetCellX][targetCellY].unit || gameMap.cells[targetCellX][targetCellY].building;
if (theUnit && theUnit.isUnit && target) {
theUnit.stopOtherActions();
var attackPosition = findAvailableCellAtRange(targetCellX, targetCellY, theUnit.attackRange);
@@ -1722,9 +1722,9 @@
});
}
}
function harvestActionLogic(targetUnit, destinationX, destinationY) {
- console.log("HarvestActionLogic...", targetUnit, ' pos=', destinationX, ',', destinationY);
+ //console.log("HarvestActionLogic...", targetUnit, ' pos=', destinationX, ',', destinationY);
if (targetUnit && targetUnit.isUnit && targetUnit.type === "unitHarvester") {
var path = [];
if (destinationX && destinationY) {
path = gameMap.findPath({
@@ -1735,18 +1735,18 @@
y: destinationY
});
}
if (path && path.length > 0) {
- console.log("Valid harvesting, path:", path);
+ //console.log("Valid harvesting, path:", path);
targetUnit.moveAlongPath(path, targetUnit.startHarvesting);
} else {
- console.log("No path, direct harvesting ");
+ //console.log("No path, direct harvesting ");
targetUnit.startHarvesting();
}
}
}
function retreatActionLogic(targetUnit) {
- console.log("Retreat Action Logic...");
+ //console.log("Retreat Action Logic...");
if (targetUnit && targetUnit.isUnit) {
targetUnit.stopOtherActions();
var baseBuilding = findClosestConstructionYard(targetUnit);
if (!baseBuilding) {
@@ -1761,11 +1761,11 @@
cellY: rockIlot2Center.y
};
}
}
- console.log("Building = ", baseBuilding);
+ //console.log("Building = ", baseBuilding);
var freePosition = findAvailablePositionAroundBuilding(baseBuilding.cellX, baseBuilding.cellY);
- console.log("freePosition = ", freePosition);
+ //console.log("freePosition = ", freePosition);
if (freePosition && freePosition.length === 1) {
baseBuilding.cellX += freePosition[0].cellX;
baseBuilding.cellY += freePosition[0].cellY;
}
@@ -1775,9 +1775,9 @@
}, {
x: baseBuilding.cellX,
y: baseBuilding.cellY
}, 0, true);
- console.log("Retreat path:", path);
+ //console.log("Retreat path:", path);
targetUnit.moveAlongPath(path);
}
}
function highlightBorder(borderX) {
@@ -1810,16 +1810,16 @@
}
return true;
}
function enqueueBuildable(buildableType, buildableSourceFactory, currentPlayer, progressDisplay) {
- console.log(currentPlayer.playerId + " - enqueueBuildable...", buildableType, buildableSourceFactory);
+ //console.log(currentPlayer.playerId + " - enqueueBuildable...", buildableType, buildableSourceFactory);
if (currentPlayer.playerId === player1.playerId && (!currentSelection || !currentSelection.buildable.includes(buildableType))) {
- console.log(currentPlayer.playerId + " - Cannot build this item here.");
+ //console.log(currentPlayer.playerId + " - Cannot build this item here.");
return;
}
var buildableInfo = buildableRepository.getBuildableInfo(buildableType);
if (buildableInfo && currentPlayer.spice < buildableInfo.cost) {
- console.log(currentPlayer.playerId + " - Not enough resources to build.");
+ //console.log(currentPlayer.playerId + " - Not enough resources to build.");
if (currentPlayer.playerId === player1.playerId) {
progressDisplay.blinkRed();
}
return;
@@ -1878,15 +1878,15 @@
}
// When construction is complete...
if (buildable.constructionProgress >= constructionTime) {
LK.clearInterval(buildable.constructionTimer);
- console.log(currentPlayer.playerId + " - " + buildableType + " construction completed.");
+ //console.log(currentPlayer.playerId + " - " + buildableType + " construction completed.");
buildable.constructionTimer = null;
if (currentPlayer.playerId === player1.playerId) {
buildable.progressDisplay.hide();
if (buildable.isBuilding) {
currentPlayer.isCurrentlyBuilding = false;
- console.log(currentPlayer.playerId + " - Building Ready for placement ", buildable);
+ //console.log(currentPlayer.playerId + " - Building Ready for placement ", buildable);
if (progressDisplay.parentIcon && typeof progressDisplay.parentIcon.setLabelToPlace === 'function') {
progressDisplay.parentIcon.setLabelToPlace(); // Change label text to 'Place'
}
currentBuildingForPlacement = buildable;
@@ -1899,20 +1899,20 @@
aiPlaceBuilding(buildable);
}
}
if (buildable.isUnit) {
- console.log(currentPlayer.playerId + " - Unit Ready to spawn ", buildable);
+ //console.log(currentPlayer.playerId + " - Unit Ready to spawn ", buildable);
currentPlayer.isCurrentlyBuildingUnit = false;
var spawnCell = {
cellX: 0,
cellY: 0
};
if (buildableSourceFactory) {
- console.log(currentPlayer.playerId + " - Found source factory ", buildableSourceFactory);
+ //console.log(currentPlayer.playerId + " - Found source factory ", buildableSourceFactory);
spawnCell.cellX = buildableSourceFactory.cellX;
spawnCell.cellY = buildableSourceFactory.cellY;
} else {
- console.log(currentPlayer.playerId + " - No source factory found ", buildableSourceFactory);
+ //console.log(currentPlayer.playerId + " - No source factory found ", buildableSourceFactory);
}
spawnUnit(buildable.type, spawnCell.cellX, spawnCell.cellY, currentPlayer.playerId);
}
if (currentPlayer.playerId === player1.playerId) {
@@ -1969,15 +1969,15 @@
orderedEntityList.push({
entity: entity,
distance: distance
});
- console.log("entity", entity.id, " ", entity.type, " Pos:", entity.cellX, entity.cellY, " distance", distance);
+ //console.log("entity", entity.id, " ", entity.type, " Pos:", entity.cellX, entity.cellY, " distance", distance);
});
// Trier les unités en fonction de leurs distances
orderedEntityList.sort(function (a, b) {
return a.distance - b.distance;
});
- console.log("orderedEntityList", orderedEntityList);
+ //console.log("orderedEntityList", orderedEntityList);
return orderedEntityList;
};
/* ******************************************** GLOBAL GAME VARIABLES ******************************************** */
/* ******************************************** GLOBAL GAME VARIABLES ******************************************** */
@@ -2090,16 +2090,16 @@
var aiNeededAttackUnitsList = null;
var aiLastAttackWaveTime = 0;
var aiNextAttackWaveSize = 0;
var aiCurrentAttackWave = 1;
-var aiNextAttackWaveDelayMs = 1000 * 5; //1000 * 60; // TODO : handle in AiLevel
+var aiNextAttackWaveDelayMs = 1000 * 60; // TODO : handle in AiLevel
var aiUnderAttackDelayMs = aiCurrentLevel.thinkingDelay * 10;
// Think of what AI must do
function aiThinking() {
if (LK.ticks % aiCurrentLevel.thinkingDelay !== 0) {
return;
}
- console.log("aiThinking...");
+ //console.log("aiThinking...");
// Check buildings requirements
aiNeededBuildingList = checkBuildingRequirements();
// Check units requirements
aiNeededDefenseUnitsList = checkDefenseUnitsRequirements();
@@ -2110,10 +2110,10 @@
// Check attack opportunities
aiNeededAttackUnitsList = checkAttckWaveUnitNeeds();
}
function checkBuildingRequirements() {
- console.log("checkBuildingRequirements...");
- console.log("player2 buildings:", player2.buildings);
+ //console.log("checkBuildingRequirements...");
+ //console.log("player2 buildings:", player2.buildings);
// 1) Count currently owned buildings
var aiCurrentBuildingList = {
'windTrap': 0,
'spiceRefinery': 0,
@@ -2122,9 +2122,9 @@
};
player2.buildings.forEach(function (building) {
aiCurrentBuildingList[building.type] = (aiCurrentBuildingList[building.type] || 0) + 1;
});
- console.log("aiCurrentBuildingList:", aiCurrentBuildingList);
+ //console.log("aiCurrentBuildingList:", aiCurrentBuildingList);
// 2) Check if all requirements are met
var tempNeededBuildingList = {};
// Compare aiBaseBuildingList and aiCurrentBuildingList
for (var building in aiBaseBuildingList) {
@@ -2134,9 +2134,9 @@
}
return tempNeededBuildingList;
}
function checkBuildingUnderAttack() {
- console.log("checkBuildingUnderAttack...");
+ //console.log("checkBuildingUnderAttack...");
// Check delay since lastHitTime of all AI buildings
var tempUnderAttackBuildingArray = [];
player2.buildings.forEach(function (building) {
if (Date.now() - building.lastHitTime < aiUnderAttackDelayMs) {
@@ -2146,9 +2146,9 @@
});
return tempUnderAttackBuildingArray;
}
function checkUnitsUnderAttack() {
- console.log("checkUnitsUnderAttack...");
+ //console.log("checkUnitsUnderAttack...");
// Check delay since lastHitTime of all AI units except army
var tempUnderAttackUnitsArray = [];
player2.units.forEach(function (unit) {
if (!unit.isArmy && Date.now() - unit.lastHitTime < aiUnderAttackDelayMs) {
@@ -2158,18 +2158,18 @@
});
return tempUnderAttackUnitsArray;
}
function checkAttckWaveUnitNeeds() {
- console.log("checkAttckWaveUnitNeeds...Wave ", aiCurrentAttackWave);
+ //console.log("checkAttckWaveUnitNeeds...Wave ", aiCurrentAttackWave);
var tempNeededUnitList = {};
var aiBaseUnitListPerWave = getUnitNeedsPerWave(aiCurrentAttackWave);
//console.log("Wave requires :", aiBaseUnitListPerWave);
// aiThinking : evaluate army needs => list needed units
// Browse aiCurrentArmyUnits and compare with aiBaseUnitListPerWave
var tempNbQuads = 0;
var tempNbLightTanks = 0;
var tempNbHeavyTanks = 0;
- console.log("check current ", aiCurrentArmyUnits.length, " army units:", aiCurrentArmyUnits);
+ //console.log("check current ", aiCurrentArmyUnits.length, " army units:", aiCurrentArmyUnits);
for (var i = 0; i < aiCurrentArmyUnits.length; i++) {
//console.log("check army unit:", aiCurrentArmyUnits[i]);
if (!aiCurrentArmyUnits[i] || aiCurrentArmyUnits[i].health <= 0) {
continue;
@@ -2327,9 +2327,9 @@
if (aiArmyIsReady && Date.now() - aiLastAttackWaveTime > aiNextAttackWaveDelayMs) {
aiLastAttackWaveTime = Date.now();
//console.warn("6 - ATTACK !!! Wave "+aiCurrentAttackWave + " at ", (new Date()).toLocaleTimeString());
aiCurrentAttackWave++;
- aiNextAttackWaveDelayMs = Math.min(5 * 60 * 1000, aiCurrentAttackWave * 60 * 1000);
+ aiNextAttackWaveDelayMs = Math.min(3 * 60 * 1000, aiCurrentAttackWave * 60 * 1000);
// Find a building to attack
var firstAttaker = null;
for (var i = 0; i < aiCurrentArmyUnits.length; i++) {
if (!aiCurrentArmyUnits[i] || aiCurrentArmyUnits[i].health <= 0) {
@@ -2470,12 +2470,34 @@
});
gameMap = new Map();
gameMap.init(mapXSize, mapYSize); // Initialize with a 20x20 grid
// Define a fixed rock ilot near the center left of the map
- rockIlot1Center = {
+ // Randomize starting positions for rockIlot1Center and rockIlot2Center
+ var startingPositions = [{
x: 8,
y: 10
- };
+ },
+ // Top left
+ {
+ x: 30,
+ y: 10
+ },
+ // Top right
+ {
+ x: 8,
+ y: 30
+ },
+ // Bottom left
+ {
+ x: 30,
+ y: 30
+ } // Bottom right
+ ];
+ var randomIndex = Math.floor(Math.random() * startingPositions.length);
+ rockIlot1Center = startingPositions[randomIndex];
+ // Remove selected position and choose next for rockIlot2Center
+ startingPositions.splice(randomIndex, 1);
+ rockIlot2Center = startingPositions[Math.floor(Math.random() * startingPositions.length)];
//console.log("rockIlot1Center : ", rockIlot1Center);
var rockIlot1Radius = 4;
for (var x = rockIlot1Center.x - rockIlot1Radius; x <= rockIlot1Center.x + rockIlot1Radius; x++) {
for (var y = rockIlot1Center.y - rockIlot1Radius; y <= rockIlot1Center.y + rockIlot1Radius; y++) {
@@ -2487,23 +2509,23 @@
var initialConstructionYard = new ConstructionYard(rockIlot1Center.x, rockIlot1Center.y, 1);
gameMap.cells[rockIlot1Center.x][rockIlot1Center.y].building = initialConstructionYard;
applyCellOccupation(rockIlot1Center.x, rockIlot1Center.y);
player1.addBuilding(initialConstructionYard);
- // 2 quads for player 1
+ // 3 quads for player 1
var p1Quad1 = new UnitQuad(rockIlot1Center.x - 2, rockIlot1Center.y + 1, 1);
- gameMap.cells[rockIlot1Center.x][rockIlot1Center.y - 6].unit = p1Quad1;
+ gameMap.cells[rockIlot1Center.x - 2][rockIlot1Center.y + 1].unit = p1Quad1;
player1.addUnit(p1Quad1);
game.addChild(p1Quad1);
var p1Quad2 = new UnitQuad(rockIlot1Center.x + 3, rockIlot1Center.y + 1, 1);
- gameMap.cells[rockIlot1Center.x][rockIlot1Center.y + 6].unit = p1Quad2;
+ gameMap.cells[rockIlot1Center.x + 3][rockIlot1Center.y + 1].unit = p1Quad2;
player1.addUnit(p1Quad2);
game.addChild(p1Quad2);
+ var p1Quad3 = new UnitQuad(rockIlot1Center.x + 0, rockIlot1Center.y + 3, 1);
+ gameMap.cells[rockIlot1Center.x][rockIlot1Center.y + 3].unit = p1Quad3;
+ player1.addUnit(p1Quad3);
+ game.addChild(p1Quad3);
// Player 2 base
// Define a fixed rock ilot near the center right of the map
- rockIlot2Center = {
- x: 30,
- y: 30
- };
var rockIlot2Radius = 4;
for (var x = rockIlot2Center.x - rockIlot2Radius; x <= rockIlot2Center.x + rockIlot2Radius; x++) {
for (var y = rockIlot2Center.y - rockIlot2Radius; y <= rockIlot2Center.y + rockIlot2Radius; y++) {
if (x >= 0 && x < mapXSize && y >= 0 && y < mapYSize) {
@@ -2657,9 +2679,9 @@
if (currentUserActionState === UserActionState.PLACING_BUILDINGS) {
var cellCoord = screenCoordToWorldCell(input.x, input.y);
var cellX = cellCoord.wCellX;
var cellY = cellCoord.wCellY;
- console.log("Trying cell ", cellX + ',' + cellY);
+ //console.log("Trying cell ", cellX + ',' + cellY);
var isValidPlacement = checkBuildingPlacement(currentBuildingForPlacement, cellX, cellY);
if (currentBuildingForPlacement && currentBuildingForPlacement.asset) {
currentBuildingForPlacement.asset.tint = isValidPlacement ? 0x00FF00 : 0xFF0000;
currentBuildingForPlacement.visible = input.y + currentBuildingForPlacement.cellH * tileSize < mapHeight;
@@ -2705,9 +2727,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;
@@ -2743,9 +2765,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;
@@ -2759,9 +2781,9 @@
var cell = gameMap.cells[cellX][cellY];
if (!cell.building && !cell.unit && deltaToSelection > 1) {
if (dragDelta < tileSize * 0.25) {
if (currentSelection && currentSelection.isUnit && currentSelection.cellX == cellX && currentSelection.cellY == cellY) {
- console.log("Already selected unit at " + cellX + ',' + cellY);
+ //console.log("Already selected unit at " + cellX + ',' + cellY);
} else {
currentSelection = null;
selectionMarker.setOnElement();
selectionMarker.hide();
@@ -2769,9 +2791,9 @@
updateActionBoard();
}
}
} else if (cell.building && !cell.fog) {
- console.log("Selected building at " + cellX + ',' + cellY, " cell:", cell, " units:", player1.units);
+ //console.log("Selected building at " + cellX + ',' + cellY, " cell:", cell, " units:", player1.units);
if (!cell.unit) {
currentSelection = cell.building;
selectionMarker.setOnElement(currentSelection);
updateActionBoard();
@@ -2790,16 +2812,16 @@
game.on('up', handleDragEnd);
//#endregion Event listeners
// Global function to handle building placement
var handleBuildingPlacement = function handleBuildingPlacement(building, cellX, cellY) {
- console.log("handle " + building.name + " Placement at " + cellX + ',' + cellY);
+ //console.log("handle " + building.name + " Placement at " + cellX + ',' + cellY);
if (!gameMap.cells[cellX] || !gameMap.cells[cellX][cellY]) {
- console.log('Invalid cell for building placement.');
+ //console.log('Invalid cell for building placement.');
return;
}
var cell = gameMap.cells[cellX][cellY];
if (cell.building) {
- console.log('Cell is already occupied.');
+ //console.log('Cell is already occupied.');
return;
}
// Place the building on the map
cell.building = building;
@@ -2815,9 +2837,9 @@
} else if (building.playerId === player2.playerId) {
player2.addBuilding(building);
}
applyCellOccupation(cellX, cellY);
- console.log(building.name + ' placed at ' + cellX + ',' + cellY);
+ //console.log(building.name + ' placed at ' + cellX + ',' + cellY);
if (building instanceof SpiceRefinery) {
spawnUnit('unitHarvester', cellX, cellY, building.playerId);
}
if (player1.playerId === building.playerId) {
@@ -2948,9 +2970,9 @@
return closestSpot;
};
// Global function to handle action board updates
var updateActionBoard = function updateActionBoard(resetProgress) {
- console.log('updateActionBoard...' + (currentSelection ? currentSelection.name : 'No selection'));
+ //console.log('updateActionBoard...' + (currentSelection ? currentSelection.name : 'No selection'));
if (!currentSelection || currentSelection.health <= 0) {
currentSelection = null;
}
currentSelectionText.setText(currentSelection ? currentSelection.name : '');
@@ -2966,9 +2988,9 @@
border.destroy();
});
}
function displayBuildableItems(resetProgress) {
- console.log('displayBuildableItems...', currentSelection);
+ //console.log('displayBuildableItems...', currentSelection);
var buildableItemIcons = game.children.filter(function (child) {
return child instanceof BuildableItemIcon;
});
buildableItemIcons.forEach(function (icon) {
@@ -2980,9 +3002,9 @@
if (currentSelection && currentSelection.playerId === player1.playerId && currentSelection.buildable && currentSelection.buildable.length) {
var iconX = commandPanel.x + 200; // Starting X position for the first icon
var iconY = commandPanel.y + 220; // Y position for all icons
currentSelection.buildable.forEach(function (itemType) {
- console.log("Prepare icon for ", itemType);
+ //console.log("Prepare icon for ", itemType);
var buildableInfo = buildableRepository.getBuildableInfo(itemType);
if (buildableInfo.requires) {
var requiredBuildingExists = player1.buildings.some(function (building) {
return building.type === buildableInfo.requires;
@@ -2997,9 +3019,9 @@
// Search if icon already exists
var existingIcons = game.children.filter(function (child) {
return child instanceof BuildableItemIcon && child.type === itemType;
});
- console.log("Found existing icons", existingIcons);
+ //console.log("Found existing icons", existingIcons);
if (existingIcons.length > 0) {
icon = existingIcons[0];
if (resetProgress) {
icon.restoreLabel();
@@ -3018,31 +3040,31 @@
}
}
// Global function to display action items
var displayActionItems = function displayActionItems() {
- console.log('displayActionItems...', currentSelection);
+ //console.log('displayActionItems...', currentSelection);
var actionItemIcons = game.children.filter(function (child) {
return child instanceof ActionItemIcon;
});
actionItemIcons.forEach(function (icon) {
- console.log('removing...', icon.action.name);
+ //console.log('removing...', icon.action.name);
icon.destroy();
});
if (currentSelection && currentSelection.playerId === player1.playerId && currentSelection.isUnit && currentSelection.health > 0 && currentSelection.actions && currentSelection.actions.length) {
var iconX = commandPanel.x + 200; // Starting X position for the first icon
var iconY = commandPanel.y + 220; // Y position for all icons
currentSelection.actions.forEach(function (actionType) {
- console.log('Add action button for ', actionType);
+ //console.log('Add action button for ', actionType);
var actionInfo = actionRepository.getActionInfo(actionType);
if (actionInfo) {
- console.log('ok Action found => display', actionInfo);
+ //console.log('ok Action found => display', actionInfo);
var border = new IconBorder(iconX, iconY);
game.addChild(border);
var icon = new ActionItemIcon(actionInfo, iconX, iconY);
game.addChild(icon);
iconX += 300; // Increment X position for the next icon
} else {
- console.log('Action not found', actionType);
+ //console.log('Action not found', actionType);
}
});
}
};
@@ -3095,9 +3117,9 @@
fpsText.setText('FPS: ' + fps);
}, 1000); // 1000 milliseconds = 1 second
};
function checkGameEnd() {
- console.log("checkGameEnd...");
+ //console.log("checkGameEnd...");
// Check if either player1 or player2 has no more buildings
if (gameIsRunning && (player1.buildings.length === 0 || player2.buildings.length === 0)) {
LK.setTimeout(function () {
gameIsRunning = false;
@@ -3108,20 +3130,16 @@
anchorY: 0.5
});
var gameOverLabel = player1.buildings.length === 0 ? "DEFEAT!" : "VICTORY!";
var gameOverText = new Text2(gameOverLabel, {
- size: 90,
+ size: 100,
fill: "#ffffff",
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
- gameOverText.anchor.set(0.5, 6.6);
+ gameOverText.anchor.set(0.5, 6);
LK.gui.center.addChild(gameOverText);
- gameOverPopup.on('down', function () {
- game.removeChild(gameOverPopup);
- LK.gui.center.removeChild(gameOverText);
- LK.showGameOver();
- });
game.addChild(gameOverPopup);
+ LK.showGameOver();
}, 2000);
}
}
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