refactor: move world concepts into engine
This commit is contained in:
parent
eeedcb8e48
commit
2d15c7ab8d
52 changed files with 3298 additions and 1558 deletions
|
|
@ -1,18 +1,31 @@
|
|||
import { Terrain } from "../../Terrain"
|
||||
import type { Mesh } from "../../../engine/scene/Mesh"
|
||||
import type { Mob } from "../Mob"
|
||||
import type { Entity } from "../../../engine/scene/Actor"
|
||||
import { Terrain, type Terrain as Ground } from "../../../engine/world/Terrain"
|
||||
import { Mesh, type Mesh as Geometry } from "../../../engine/scene/Mesh"
|
||||
import type { Material } from "../../../engine/render/Material"
|
||||
import type { ActorDefinition } from "../../../engine/scene/Actor"
|
||||
import { Mob, type MobState } from "../Mob"
|
||||
import { ellipsoid, nextRand, wanderHeading } from "./mobkit"
|
||||
|
||||
// Everything about the robin: round red-breasted bird that mostly hops like a frog
|
||||
// but now and then takes a short powered flight to a new perch.
|
||||
|
||||
export const robin: Entity<Mob, Terrain> = {
|
||||
name: "robin",
|
||||
build,
|
||||
update,
|
||||
boundingRadius: 0.45,
|
||||
bodyHeight: 0.55,
|
||||
export type Robin = ActorDefinition<MobState, Ground>
|
||||
|
||||
export namespace Robin {
|
||||
export function create(material: Material): Robin {
|
||||
const mesh = Mesh.create()
|
||||
build(mesh)
|
||||
return {
|
||||
prototype: {
|
||||
groups: [{ mesh, material }],
|
||||
radius: 0.5,
|
||||
minY: -0.5,
|
||||
maxY: 1,
|
||||
},
|
||||
update,
|
||||
transform: Mob.transform,
|
||||
collider: (state) => Mob.collider(state, 0.45, 0.55, state.grounded),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const LEASH = 6
|
||||
|
|
@ -27,7 +40,7 @@ const FLY_IMPULSE = 3.5
|
|||
const CRUISE = 0.8
|
||||
const GRAVITY = 14
|
||||
|
||||
function build(mesh: Mesh): void {
|
||||
function build(mesh: Geometry): void {
|
||||
// Round European robin: plump brown body, an orange-red breast bulging on the
|
||||
// front, a round brown head with two dark eyes + a small dark beak, short tail.
|
||||
// UVs: robin texture is brown (left), orange breast (mid), dark eye/beak (right).
|
||||
|
|
@ -40,7 +53,7 @@ function build(mesh: Mesh): void {
|
|||
ellipsoid(mesh, 0, 0.26, -0.32, 0.09, 0.05, 0.16, 4, 2, 0, 0.38, 0, 1) // tail (brown)
|
||||
}
|
||||
|
||||
function update(mob: Mob, dt: number, terrain: Terrain): void {
|
||||
function update(mob: MobState, dt: number, terrain: Ground): void {
|
||||
if (mob.grounded) {
|
||||
mob.timer -= dt
|
||||
mob.position.y = Terrain.height(terrain, mob.position.x, mob.position.z)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue