Add basic zone implementation
This commit is contained in:
parent
6983454ce3
commit
6f6c6628fc
|
@ -6,12 +6,23 @@ import * as planck from 'planck'
|
||||||
import { DecorationInstance } from "../shared/decors"
|
import { DecorationInstance } from "../shared/decors"
|
||||||
import { SpriteInstance, sprites } from "../shared/sprites"
|
import { SpriteInstance, sprites } from "../shared/sprites"
|
||||||
import { ShapeCircle, ShapePoints } from "../data/sprite"
|
import { ShapeCircle, ShapePoints } from "../data/sprite"
|
||||||
|
import { SegmentZone } from "../data/segment"
|
||||||
|
|
||||||
interface Action {
|
interface Action {
|
||||||
type: string
|
type: string
|
||||||
priority: number
|
priority: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Zone {
|
||||||
|
fixture: planck.Fixture|undefined
|
||||||
|
type: 'solid'|'fluid'
|
||||||
|
points: [number, number][]
|
||||||
|
constructor(z: SegmentZone) {
|
||||||
|
this.type = z.type
|
||||||
|
this.points = z.points.map(v=>[v[0], v[1]])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
sprite: SpriteInstance
|
sprite: SpriteInstance
|
||||||
body?: planck.Body
|
body?: planck.Body
|
||||||
|
@ -197,10 +208,14 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
let world: planck.World = planck.World({
|
let world: planck.World = planck.World({
|
||||||
gravity: planck.Vec2(0, 0),
|
gravity: planck.Vec2(0, 0),
|
||||||
})
|
})
|
||||||
|
let worldBody: planck.Body = world.createBody({
|
||||||
|
type: 'static',
|
||||||
|
})
|
||||||
|
|
||||||
let rootContainer = new PIXI.Container()
|
let rootContainer = new PIXI.Container()
|
||||||
let decorations: DecorationInstance[] = []
|
let decorations: DecorationInstance[] = []
|
||||||
let entities: Entity[] = []
|
let entities: Entity[] = []
|
||||||
|
let zones: Zone[] = []
|
||||||
|
|
||||||
let enter = () => {
|
let enter = () => {
|
||||||
hookKeyboard()
|
hookKeyboard()
|
||||||
|
@ -247,6 +262,10 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
rootContainer.addChild(container)
|
rootContainer.addChild(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let z of w.zones) {
|
||||||
|
addZone(new Zone(z))
|
||||||
|
}
|
||||||
|
|
||||||
// Add bogus entity
|
// Add bogus entity
|
||||||
//addEntity(new PlayerEntity('animals.deer.animal.west.0'), 0, 0)
|
//addEntity(new PlayerEntity('animals.deer.animal.west.0'), 0, 0)
|
||||||
addEntity(new PlayerEntity('bogus-arrows.player.normal.w.0'), 0, 0)
|
addEntity(new PlayerEntity('bogus-arrows.player.normal.w.0'), 0, 0)
|
||||||
|
@ -326,6 +345,24 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zonage
|
||||||
|
let addZone = (zone: Zone) => {
|
||||||
|
if (zones.find(v=>v===zone)) return
|
||||||
|
let shape = planck.Chain(zone.points.map(v=>planck.Vec2(v[0],v[1])))
|
||||||
|
zone.fixture = worldBody.createFixture({
|
||||||
|
shape: shape,
|
||||||
|
})
|
||||||
|
if (zone.type === 'fluid') {
|
||||||
|
zone.fixture.setSensor(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let removeZone = (zone: Zone) => {
|
||||||
|
zones = zones.filter(v=>v!==zone)
|
||||||
|
if (zone.fixture) {
|
||||||
|
worldBody.destroyFixture(zone.fixture)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let desiredActions: Action[] = []
|
let desiredActions: Action[] = []
|
||||||
let adjustAction = (type: string, v: number) => {
|
let adjustAction = (type: string, v: number) => {
|
||||||
let action = desiredActions.find(v=>v.type===type)
|
let action = desiredActions.find(v=>v.type===type)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user