-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
544 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { generateSoldier } from "./generators"; | ||
|
||
const level: Level = { | ||
world: { | ||
colors: { | ||
top: { r: 0, g: 0, b: 0, a: 255 }, | ||
bottom: { r: 84, g: 98, b: 92, a: 255 }, | ||
}, | ||
}, | ||
music: 'dead-lift-yeti', | ||
map: [ | ||
[1, 1, 1, 1, 2, 1, 1, 1], | ||
[1, 0, 0, 0, 0, 0, 0, 1], | ||
[5, 0, 0, 0, 0, 0, 0, 1], | ||
[1, 0, 0, 0, 0, 0, 0, 1], | ||
[1, 0, 0, 0, 0, 0, 0, 1], | ||
[1, 0, 0, 0, 0, 0, 0, 1], | ||
[1, 1, 1, 1, 1, 1, 1, 1], | ||
], | ||
textures: { | ||
1: "TECH_1C", | ||
2: "TECH_1E", | ||
3: "TECH_2F", | ||
4: "DOOR_1A", | ||
5: "DOOR_1E", | ||
}, | ||
player: { | ||
x: 1.5, | ||
y: 2.5, | ||
angle: 0, | ||
health: 100, | ||
}, | ||
enemies: [ | ||
generateSoldier(4, 4, 4), | ||
generateSoldier(4, 4, 4), | ||
], | ||
exit: { | ||
x: 18, | ||
y: 2, | ||
}, | ||
}; | ||
|
||
export default level; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { minmax } from "../utils"; | ||
import { minmax } from "src/lib/utils"; | ||
|
||
interface CanvasProps { | ||
id?: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import ECS from "src/lib/ecs"; | ||
import { Entity } from "./Entity"; | ||
import { Component } from "./Component"; | ||
// import { Component } from "./Component"; | ||
|
||
type EntityCallback = (entity: Entity) => void; | ||
|
||
export default class ExtendedECS extends ECS { | ||
protected cbComponentAdd: Map<Function, Set<EntityCallback>> = new Map(); | ||
protected cbComponentDelete: Map<Function, Set<EntityCallback>> = new Map(); | ||
protected entitiesByQuery = new Map<string, Set<Entity>>(); | ||
|
||
public query(componentClasses: Function[]): Set<Entity> { | ||
// const key = componentClasses.map(type => type.name).sort().join(','); | ||
// if (!this.entitiesByQuery.has(key)) { | ||
const matchingEntities = new Set<Entity>(); | ||
for (const [entity, components] of this.entities.entries()) { | ||
if (components.all(componentClasses)) { | ||
matchingEntities.add(entity); | ||
} | ||
} | ||
// this.entitiesByQuery.set(key, matchingEntities); | ||
// } | ||
// return this.entitiesByQuery.get(key)!; | ||
return matchingEntities | ||
} | ||
|
||
public onComponentAdd(componentClass: Function, cb: EntityCallback) { | ||
if (this.cbComponentAdd.has(componentClass)) { | ||
this.cbComponentAdd.set(componentClass, new Set()); | ||
} | ||
this.cbComponentAdd.get(componentClass)?.add(cb); | ||
} | ||
|
||
public onComponentDelete(componentClass: Function, cb: EntityCallback) { | ||
this.cbComponentAdd.get(componentClass)?.delete(cb); | ||
} | ||
|
||
public addComponent(entity: Entity, component: Component) { | ||
super.addComponent(entity, component); | ||
|
||
this.cbComponentAdd.get(component.constructor)?.forEach(cb => cb(entity)); | ||
} | ||
|
||
public removeComponent(entity: Entity, componentClass: Function) { | ||
super.removeComponent(entity, componentClass); | ||
|
||
this.cbComponentAdd.get(componentClass)?.forEach(cb => cb(entity)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { Component } from "src/lib/ecs/Component"; | ||
|
||
export default class AIComponent implements Component { | ||
damage: number; | ||
distance: number; | ||
frequence: number; // seconds | ||
lastAttackTime: number = 0; | ||
damagePerSecond: number = 5; | ||
|
||
constructor(distance: number) { | ||
constructor(distance: number, damage: number, frequence: number = 1_000) { | ||
this.distance = distance; | ||
this.damage = damage; | ||
this.frequence = frequence; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.