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 { SpriteInstance, sprites } from "../shared/sprites"
|
||||
import { ShapeCircle, ShapePoints } from "../data/sprite"
|
||||
import { SegmentZone } from "../data/segment"
|
||||
|
||||
interface Action {
|
||||
type: string
|
||||
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 {
|
||||
sprite: SpriteInstance
|
||||
body?: planck.Body
|
||||
|
@ -197,10 +208,14 @@ export function GameState(ctx: ContextI): StateI {
|
|||
let world: planck.World = planck.World({
|
||||
gravity: planck.Vec2(0, 0),
|
||||
})
|
||||
let worldBody: planck.Body = world.createBody({
|
||||
type: 'static',
|
||||
})
|
||||
|
||||
let rootContainer = new PIXI.Container()
|
||||
let decorations: DecorationInstance[] = []
|
||||
let entities: Entity[] = []
|
||||
let zones: Zone[] = []
|
||||
|
||||
let enter = () => {
|
||||
hookKeyboard()
|
||||
|
@ -247,6 +262,10 @@ export function GameState(ctx: ContextI): StateI {
|
|||
rootContainer.addChild(container)
|
||||
}
|
||||
|
||||
for (let z of w.zones) {
|
||||
addZone(new Zone(z))
|
||||
}
|
||||
|
||||
// Add bogus entity
|
||||
//addEntity(new PlayerEntity('animals.deer.animal.west.0'), 0, 0)
|
||||
addEntity(new PlayerEntity('bogus-arrows.player.normal.w.0'), 0, 0)
|
||||
|
@ -326,7 +345,25 @@ export function GameState(ctx: ContextI): StateI {
|
|||
}
|
||||
}
|
||||
|
||||
let desiredActions: Action[] = []
|
||||
// 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 adjustAction = (type: string, v: number) => {
|
||||
let action = desiredActions.find(v=>v.type===type)
|
||||
if (!action) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user