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,17 +1,30 @@
|
|||
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 frog: squat, ground-bound, sits then springs a ballistic hop.
|
||||
|
||||
export const frog: Entity<Mob, Terrain> = {
|
||||
name: "frog",
|
||||
build,
|
||||
update,
|
||||
boundingRadius: 0.7,
|
||||
bodyHeight: 0.6,
|
||||
export type Frog = ActorDefinition<MobState, Ground>
|
||||
|
||||
export namespace Frog {
|
||||
export function create(material: Material): Frog {
|
||||
const mesh = Mesh.create()
|
||||
build(mesh)
|
||||
return {
|
||||
prototype: {
|
||||
groups: [{ mesh, material }],
|
||||
radius: 0.7,
|
||||
minY: -0.7,
|
||||
maxY: 1.3,
|
||||
},
|
||||
update,
|
||||
transform: Mob.transform,
|
||||
collider: (state) => Mob.collider(state, 0.7, 0.6, state.grounded),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const LEASH = 5
|
||||
|
|
@ -21,7 +34,7 @@ const HOP_SPEED = 1.6
|
|||
const HOP_IMPULSE = 3.2
|
||||
const GRAVITY = 14
|
||||
|
||||
function build(mesh: Mesh): void {
|
||||
function build(mesh: Geometry): void {
|
||||
// Wide squat body, two eye bumps on the top-front, two hind haunches. UVs:
|
||||
// the frog texture is green skin on the left, a dark eye tone on the right.
|
||||
ellipsoid(mesh, 0, 0.26, 0, 0.5, 0.28, 0.52, 6, 4, 0, 0.68, 0, 1)
|
||||
|
|
@ -31,7 +44,7 @@ function build(mesh: Mesh): void {
|
|||
ellipsoid(mesh, -0.3, 0.2, -0.26, 0.2, 0.2, 0.26, 4, 3, 0, 0.68, 0, 1)
|
||||
}
|
||||
|
||||
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