Add bogus entity query
This commit is contained in:
parent
c968f7a9a6
commit
a886c73047
|
@ -1,6 +1,10 @@
|
||||||
import { Entity } from "./Entity"
|
import { Entity } from "./Entity"
|
||||||
|
import * as planck from 'planck'
|
||||||
|
|
||||||
export interface WorldContext {
|
export interface WorldContext {
|
||||||
addEntity(entity: Entity, layerTitle: string, x: number, y: number): void
|
addEntity(entity: Entity, layerTitle: string, x: number, y: number): void
|
||||||
removeEntity(entity: Entity): void
|
removeEntity(entity: Entity): void
|
||||||
|
queryAABB(aabb: planck.AABB, callback: (fixture: planck.Fixture) => boolean): void
|
||||||
|
rayCast(point1: planck.Vec2, point2: planck.Vec2, callback: (fixture: planck.Fixture, pointer: planck.Vec2, normal: planck.Vec2, fraction: number) => boolean): void
|
||||||
|
queryEntities(min: [number, number], max: [number, number]): Entity[]
|
||||||
}
|
}
|
|
@ -254,10 +254,6 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment
|
||||||
|
|
||||||
let entity = new AnimalEntity(animals[animal])
|
let entity = new AnimalEntity(animals[animal])
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
entity.dead = true
|
|
||||||
entity.shouldGib = true
|
|
||||||
}, 1000+Math.random()*3000)
|
|
||||||
|
|
||||||
addEntity(entity, 'objects', x, y)
|
addEntity(entity, 'objects', x, y)
|
||||||
}
|
}
|
||||||
|
@ -373,6 +369,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment
|
||||||
shape = planck.Polygon(spriteShape.points.map(v=>planck.Vec2(v[0], v[1])))
|
shape = planck.Polygon(spriteShape.points.map(v=>planck.Vec2(v[0], v[1])))
|
||||||
}
|
}
|
||||||
if (shape !== undefined) {
|
if (shape !== undefined) {
|
||||||
|
entity.shape = shape
|
||||||
let body = world.createDynamicBody({
|
let body = world.createDynamicBody({
|
||||||
position: planck.Vec2(entity.x, entity.y),
|
position: planck.Vec2(entity.x, entity.y),
|
||||||
fixedRotation: true,
|
fixedRotation: true,
|
||||||
|
@ -460,6 +457,41 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment
|
||||||
let worldContext: WorldContext = {
|
let worldContext: WorldContext = {
|
||||||
addEntity,
|
addEntity,
|
||||||
removeEntity,
|
removeEntity,
|
||||||
|
queryAABB: (aabb: planck.AABB, callback: (fixture: planck.Fixture) => boolean) => {
|
||||||
|
world.queryAABB(aabb, callback)
|
||||||
|
},
|
||||||
|
rayCast: (point1: planck.Vec2, point2: planck.Vec2, callback: (fixture: planck.Fixture, point: planck.Vec2, normal: planck.Vec2, fraction: number) => boolean) => {
|
||||||
|
world.rayCast(point1, point2, callback)
|
||||||
|
},
|
||||||
|
queryEntities: (min: [number, number], max: [number, number]): Entity[] => {
|
||||||
|
let ret: Entity[] = []
|
||||||
|
for (let entity of entities) {
|
||||||
|
if (!entity.shape) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
let p = entity.position
|
||||||
|
let r = entity.shape.getRadius()
|
||||||
|
let a = {
|
||||||
|
x: min[0],
|
||||||
|
w: max[0] - min[0],
|
||||||
|
y: min[1],
|
||||||
|
h: max[1] - min[1],
|
||||||
|
}
|
||||||
|
let b = {
|
||||||
|
x: p[0],
|
||||||
|
w: r,
|
||||||
|
y: p[1],
|
||||||
|
h: r,
|
||||||
|
}
|
||||||
|
console.log(a, 'vs', b)
|
||||||
|
if (
|
||||||
|
(Math.abs(min[0] - (p[0]-r)) * 2 < ((max[0]-min[0]) + r)) &&
|
||||||
|
(Math.abs(min[1] - (p[1]-r)) * 2 < ((max[1]-min[1]) + r))) {
|
||||||
|
ret.push(entity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let desiredActions: Action[] = []
|
let desiredActions: Action[] = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user