Merge branch 'main' of https://git.mindfire.games/jams/GGJ22 into main
This commit is contained in:
commit
46e44fb25e
|
@ -71,7 +71,8 @@ export class SegmentDecoration {
|
||||||
export class SegmentZone {
|
export class SegmentZone {
|
||||||
uuid: string
|
uuid: string
|
||||||
points: [number, number][] = []
|
points: [number, number][] = []
|
||||||
type: 'solid'|'fluid'
|
type: 'solid'|'fluid'|'trigger'
|
||||||
|
event: string = ''
|
||||||
constructor(o: any) {
|
constructor(o: any) {
|
||||||
this.uuid = o.uuid
|
this.uuid = o.uuid
|
||||||
this.points = o.points.map((v: any) => {
|
this.points = o.points.map((v: any) => {
|
||||||
|
@ -79,6 +80,9 @@ export class SegmentZone {
|
||||||
})
|
})
|
||||||
if (o.data.type === 'fluid') {
|
if (o.data.type === 'fluid') {
|
||||||
this.type = o.data.type
|
this.type = o.data.type
|
||||||
|
} else if (o.data.type === 'trigger') {
|
||||||
|
this.type = 'trigger'
|
||||||
|
this.event = o.data.event
|
||||||
} else {
|
} else {
|
||||||
this.type = 'solid'
|
this.type = 'solid'
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ export class AnimalEntity extends Entity {
|
||||||
this.desiredActions = adjustAction([], this.getCardinal(Math.random()*360), 1)
|
this.desiredActions = adjustAction([], this.getCardinal(Math.random()*360), 1)
|
||||||
}
|
}
|
||||||
if (Math.random() > 1 - this.mode.noisiness) {
|
if (Math.random() > 1 - this.mode.noisiness) {
|
||||||
this.yell(0.25)
|
this.yell(0.1)
|
||||||
}
|
}
|
||||||
this.wanderTimer = 0
|
this.wanderTimer = 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,27 @@ import { SegmentZone } from '../data/segment'
|
||||||
|
|
||||||
export class Zone {
|
export class Zone {
|
||||||
fixture: planck.Fixture|undefined
|
fixture: planck.Fixture|undefined
|
||||||
type: 'solid'|'fluid'
|
type: 'solid'|'fluid'|'trigger'
|
||||||
points: [number, number][]
|
points: [number, number][]
|
||||||
|
event: string = ''
|
||||||
constructor(z: SegmentZone) {
|
constructor(z: SegmentZone) {
|
||||||
this.type = z.type
|
this.type = z.type
|
||||||
this.points = z.points.map(v=>[v[0], v[1]])
|
this.points = z.points.map(v=>[v[0], v[1]])
|
||||||
|
this.event = z.event
|
||||||
|
}
|
||||||
|
get bounds(): [number, number, number, number] {
|
||||||
|
let xs = this.points.map(v=>v[0])
|
||||||
|
let ys = this.points.map(v=>v[1])
|
||||||
|
let minX = Math.min(...xs)
|
||||||
|
let minY = Math.min(...ys)
|
||||||
|
let maxX = Math.max(...xs)
|
||||||
|
let maxY = Math.max(...ys)
|
||||||
|
return [
|
||||||
|
minX,
|
||||||
|
minY,
|
||||||
|
maxX-minX,
|
||||||
|
maxY-maxY,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,8 +100,6 @@ export function playSound(name: string, volume: number): HTMLAudioElement|undefi
|
||||||
s.addEventListener('ended', () => {
|
s.addEventListener('ended', () => {
|
||||||
audioCache.push(s as HTMLAudioElement)
|
audioCache.push(s as HTMLAudioElement)
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
console.log('reused')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
let layers: Layer[] = []
|
let layers: Layer[] = []
|
||||||
let entities: Entity[] = []
|
let entities: Entity[] = []
|
||||||
let zones: Zone[] = []
|
let zones: Zone[] = []
|
||||||
|
let spawnZones: Record<string, Zone[]> = {}
|
||||||
|
|
||||||
let enter = () => {
|
let enter = () => {
|
||||||
lastTime = performance.now()
|
lastTime = performance.now()
|
||||||
|
@ -174,18 +175,33 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
addZone(new Zone(z))
|
addZone(new Zone(z))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add player entity
|
let playerSpawn = getSpawnZone('spawn')
|
||||||
player = new AnimalEntity(animals.deer)
|
if (!playerSpawn) {
|
||||||
player.isPlayer = true
|
// return to menu with an error?
|
||||||
addEntity(player, 'objects', 300, 100)
|
} else {
|
||||||
|
let bounds = playerSpawn.bounds
|
||||||
|
let x = bounds[0] + Math.floor(Math.random() * bounds[2])
|
||||||
|
let y = bounds[1] + Math.floor(Math.random() * bounds[3])
|
||||||
|
// Add player entity
|
||||||
|
player = new AnimalEntity(animals.deer)
|
||||||
|
player.isPlayer = true
|
||||||
|
addEntity(player, 'objects', x, y)
|
||||||
|
}
|
||||||
|
|
||||||
// Add fake others
|
// Add fake others
|
||||||
addEntity(new AnimalEntity(animals.turkey), 'objects', 200, 200)
|
// MOVE ME
|
||||||
addEntity(new AnimalEntity(animals.nutria), 'objects', Math.random()*w.width, Math.random()*w.height)
|
for (let animal of ['turkey','nutria','deer','salamander','rabbit']) {
|
||||||
addEntity(new AnimalEntity(animals.deer), 'objects', Math.random()*w.width, Math.random()*w.height)
|
let count = 2 + Math.floor(Math.random() * 8)
|
||||||
addEntity(new AnimalEntity(animals.salamander), 'objects', Math.random()*w.width, Math.random()*w.height)
|
for (let i = 0; i < count; i++) {
|
||||||
addEntity(new AnimalEntity(animals.rabbit), 'objects', Math.random()*w.width, Math.random()*w.height)
|
let spawn = getSpawnZone(animal)
|
||||||
|
if (!spawn) break
|
||||||
|
let bounds = spawn.bounds
|
||||||
|
let x = bounds[0] + Math.floor(Math.random() * bounds[2])
|
||||||
|
let y = bounds[1] + Math.floor(Math.random() * bounds[3])
|
||||||
|
|
||||||
|
addEntity(new AnimalEntity(animals[animal]), 'objects', x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
ctx.app.stage.addChild(rootContainer)
|
ctx.app.stage.addChild(rootContainer)
|
||||||
}
|
}
|
||||||
let leave = () => {
|
let leave = () => {
|
||||||
|
@ -211,9 +227,9 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
nightfall(true)
|
nightfall(true)
|
||||||
}
|
}
|
||||||
// Run world sim.
|
// Run world sim.
|
||||||
while (elapsed >= 1/60) {
|
while (elapsed >= 1/5) {
|
||||||
world.step(1/60)
|
world.step(1/5)
|
||||||
elapsed -= 1/60
|
elapsed -= 1/5
|
||||||
}
|
}
|
||||||
// Update/render.
|
// Update/render.
|
||||||
for (let layer of layers) {
|
for (let layer of layers) {
|
||||||
|
@ -243,9 +259,7 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
}
|
}
|
||||||
|
|
||||||
let addEntity = (entity: Entity, layerTitle: string, x: number, y: number) => {
|
let addEntity = (entity: Entity, layerTitle: string, x: number, y: number) => {
|
||||||
console.log('add called with', x, y)
|
|
||||||
if (entities.find(v=>v===entity)) return
|
if (entities.find(v=>v===entity)) return
|
||||||
console.log('add somethin', entity)
|
|
||||||
entities.push(entity)
|
entities.push(entity)
|
||||||
let layer = layers.find(v=>v.title===layerTitle)
|
let layer = layers.find(v=>v.title===layerTitle)
|
||||||
if (!layer) layer = playLayer
|
if (!layer) layer = playLayer
|
||||||
|
@ -280,23 +294,26 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
defaultLong = entity.def.animal.scent
|
defaultLong = entity.def.animal.scent
|
||||||
defaultShort = entity.def.animal.sight
|
defaultShort = entity.def.animal.sight
|
||||||
}
|
}
|
||||||
// Create a short sensor (vision).
|
if (entity instanceof AnimalEntity && !entity.isPlayer) {
|
||||||
let senseFixture = body.createFixture({
|
// Create a short sensor (vision).
|
||||||
shape: planck.Circle(planck.Vec2(entity.x, entity.y), defaultShort),
|
let senseFixture = body.createFixture({
|
||||||
isSensor: true,
|
shape: planck.Circle(planck.Vec2(entity.x, entity.y), defaultShort),
|
||||||
})
|
isSensor: true,
|
||||||
senseFixture.setUserData(new Sensor(entity, senseFixture, 'short'))
|
filterGroupIndex: -8
|
||||||
// Create a long sensor (scent).
|
})
|
||||||
let longSenseFixture = body.createFixture({
|
senseFixture.setUserData(new Sensor(entity, senseFixture, 'short'))
|
||||||
shape: planck.Circle(planck.Vec2(entity.x, entity.y), defaultLong),
|
// Create a long sensor (scent).
|
||||||
isSensor: true,
|
let longSenseFixture = body.createFixture({
|
||||||
})
|
shape: planck.Circle(planck.Vec2(entity.x, entity.y), defaultLong),
|
||||||
longSenseFixture.setUserData(new Sensor(entity, longSenseFixture, 'long'))
|
isSensor: true,
|
||||||
|
filterGroupIndex: -8
|
||||||
|
})
|
||||||
|
longSenseFixture.setUserData(new Sensor(entity, longSenseFixture, 'long'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity.x = x
|
entity.x = x
|
||||||
entity.y = y
|
entity.y = y
|
||||||
console.log('set entity xy', entity.x, entity.y)
|
|
||||||
}
|
}
|
||||||
let removeEntity = (entity: Entity) => {
|
let removeEntity = (entity: Entity) => {
|
||||||
entities = entities.filter(v=>v!==entity)
|
entities = entities.filter(v=>v!==entity)
|
||||||
|
@ -310,14 +327,23 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
// Zonage
|
// Zonage
|
||||||
let addZone = (zone: Zone) => {
|
let addZone = (zone: Zone) => {
|
||||||
if (zones.find(v=>v===zone)) return
|
if (zones.find(v=>v===zone)) return
|
||||||
let shape = planck.Polygon(zone.points.map(v=>planck.Vec2(v[0],v[1])))
|
// We're using triggers for spawning due to laziness.
|
||||||
zone.fixture = worldBody.createFixture({
|
if (zone.type === 'trigger') {
|
||||||
shape: shape,
|
if (!spawnZones[zone.event]) {
|
||||||
})
|
spawnZones[zone.event] = []
|
||||||
if (zone.type === 'fluid') {
|
}
|
||||||
zone.fixture.setSensor(true)
|
spawnZones[zone.event].push(zone)
|
||||||
|
} else {
|
||||||
|
let shape = planck.Polygon(zone.points.map(v=>planck.Vec2(v[0],v[1])))
|
||||||
|
zone.fixture = worldBody.createFixture({
|
||||||
|
shape: shape,
|
||||||
|
})
|
||||||
|
if (zone.type === 'fluid') {
|
||||||
|
zone.fixture.setSensor(true)
|
||||||
|
}
|
||||||
|
zone.fixture.setUserData(zone)
|
||||||
}
|
}
|
||||||
zone.fixture.setUserData(zone)
|
zones.push(zone)
|
||||||
}
|
}
|
||||||
let removeZone = (zone: Zone) => {
|
let removeZone = (zone: Zone) => {
|
||||||
zones = zones.filter(v=>v!==zone)
|
zones = zones.filter(v=>v!==zone)
|
||||||
|
@ -325,6 +351,12 @@ export function GameState(ctx: ContextI): StateI {
|
||||||
worldBody.destroyFixture(zone.fixture)
|
worldBody.destroyFixture(zone.fixture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let getSpawnZone = (name: string): Zone|undefined => {
|
||||||
|
if (!spawnZones[name] || !spawnZones[name].length) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return spawnZones[name][Math.floor(Math.random()*spawnZones[name].length)]
|
||||||
|
}
|
||||||
|
|
||||||
let worldContext: WorldContext = {
|
let worldContext: WorldContext = {
|
||||||
addEntity,
|
addEntity,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user