create defense post

This commit is contained in:
Evan
2024-12-01 19:54:04 -08:00
parent e479c15ef9
commit d133092317
12 changed files with 127 additions and 29 deletions
+14 -1
View File
@@ -1,4 +1,4 @@
import { Colord } from "colord";
import { colord, Colord } from "colord";
import { Theme } from "../../../core/configuration/Config";
import { Unit, UnitEvent, Cell, Game, Tile, UnitType } from "../../../core/game/Game";
import { bfs, dist, euclDist } from "../../../core/Util";
@@ -160,6 +160,19 @@ export class StructureLayer implements Layer {
onUnitEvent(event: UnitEvent) {
this.handleUnitRendering(event);
if (event.unit.type() == UnitType.DefensePost) {
if (!event.unit.isActive()) {
return
}
// Array.from(
// bfs(
// event.unit.tile(),
// dist(event.unit.tile(), this.game.config().defensePostRange())
// )
// ).filter(t => t.isBorder() && t.owner() == event.unit.owner()).forEach(t => {
// this.paintCell(t.cell(), colord({ r: 255, g: 255, b: 255 }), 255)
// })
}
}
paintCell(cell: Cell, color: Colord, alpha: number) {
+30 -14
View File
@@ -1,7 +1,7 @@
import { PriorityQueue } from "@datastructures-js/priority-queue";
import { Cell, Game, Player, Tile, TileEvent } from "../../../core/game/Game";
import { Cell, Game, Player, Tile, TileEvent, UnitEvent, UnitType } from "../../../core/game/Game";
import { PseudoRandom } from "../../../core/PseudoRandom";
import { Colord } from "colord";
import { colord, Colord } from "colord";
import { bfs, dist } from "../../../core/Util";
import { Theme } from "../../../core/configuration/Config";
import { Layer } from "./Layer";
@@ -13,12 +13,10 @@ export class TerritoryLayer implements Layer {
private context: CanvasRenderingContext2D
private imageData: ImageData
private tileToRenderQueue: PriorityQueue<{ tileEvent: TileEvent, lastUpdate: number }> = new PriorityQueue((a, b) => { return a.lastUpdate - b.lastUpdate })
private tileToRenderQueue: PriorityQueue<{ tile: Tile, lastUpdate: number }> = new PriorityQueue((a, b) => { return a.lastUpdate - b.lastUpdate })
private random = new PseudoRandom(123)
private theme: Theme = null
constructor(private game: Game, eventBus: EventBus) {
this.theme = game.config().theme()
eventBus.on(TileEvent, e => this.tileUpdate(e))
@@ -70,9 +68,9 @@ export class TerritoryLayer implements Layer {
while (numToRender > 0) {
numToRender--
const event = this.tileToRenderQueue.pop().tileEvent
this.paintTerritory(event.tile)
event.tile.neighbors().forEach(t => this.paintTerritory(t))
const tile = this.tileToRenderQueue.pop().tile
this.paintTerritory(tile)
tile.neighbors().forEach(t => this.paintTerritory(t))
}
}
@@ -83,11 +81,19 @@ export class TerritoryLayer implements Layer {
}
const owner = tile.owner() as Player
if (tile.isBorder()) {
this.paintCell(
tile.cell(),
this.theme.borderColor(owner.info()),
255
)
if (tile.defenseBonuses().filter(db => db.unit.owner() == owner).length > 0) {
this.paintCell(
tile.cell(),
colord({ r: 0, g: 0, b: 0 }),
255
)
} else {
this.paintCell(
tile.cell(),
this.theme.borderColor(owner.info()),
255
)
}
} else {
this.paintCell(
tile.cell(),
@@ -112,7 +118,17 @@ export class TerritoryLayer implements Layer {
this.imageData.data[offset + 3] = 0; // Set alpha to 0 (fully transparent)
}
unitEvent(event: UnitEvent) {
if (event.unit.type() == UnitType.DefensePost) {
bfs(event.unit.tile(), dist(event.unit.tile(), this.game.config().defensePostRange())).forEach(t => this.enqueue(t))
}
}
tileUpdate(event: TileEvent) {
this.tileToRenderQueue.push({ tileEvent: event, lastUpdate: this.game.ticks() + this.random.nextFloat(0, .5) })
this.enqueue(event.tile)
}
enqueue(tile: Tile) {
this.tileToRenderQueue.push({ tile: tile, lastUpdate: this.game.ticks() + this.random.nextFloat(0, .5) })
}
}
+5 -5
View File
@@ -28,7 +28,7 @@
</svg>
</a>
<h1 class="text-7xl sm:text-5xl md:text-6xl lg:text-7xl mb-2">OpenFront.io</h1>
<h2 class="text-3xl sm:text-4xl md:text-5xl lg:text-6xl mb-4">(v0.10.0)</h2>
<h2 class="text-3xl sm:text-4xl md:text-5xl lg:text-6xl mb-4">(v0.10.1)</h2>
<div class="flex justify-center items-start">
<div class="w-full max-w-3xl p-4 space-y-4">
<br />
@@ -42,11 +42,11 @@
</div>
<br />
<!-- Button layout -->
<div class="flex space-x-4 max-w-xs mx-auto">
<div class="flex space-x-4 max-w-xs mx-auto/>
<!-- Single Player button -->
<button id="single-player"
class="flex-1 h-31 px-6 py-8 text-xl font-bold text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 transition duration-300 ease-in-out">
Single Player
<button id=" single-player"
class="flex-1 h-31 px-6 py-8 text-xl font-bold text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 transition duration-300 ease-in-out">
Single Player
</button>
<!-- Create and Join Lobby buttons stacked -->