Add gibs layer; randomize gib lifetime

This commit is contained in:
Ketchetwahmeegwun T. Southall 2022-01-30 06:42:07 -08:00
parent fcf431b76f
commit 72f64b4ca4
3 changed files with 20 additions and 4 deletions

View File

@ -284,18 +284,18 @@ export class AnimalEntity extends Entity {
let dir = Math.random() * 320
// 50% head gib
if (Math.random() > 0.5) {
ctx.addEntity(new GibletEntity(`giblets.${this.sprite.spriteKey}.head.default.0`, dir+Math.random()*40, force+Math.random()*10), 'objects', p[0], p[1])
ctx.addEntity(new GibletEntity(`giblets.${this.sprite.spriteKey}.head.default.0`, dir+Math.random()*40, force+Math.random()*10), 'gibs', p[0], p[1])
}
// 44% leg gib per leg
for (let i = 0; i < 4; i++) {
if (Math.random() > 0.66) {
ctx.addEntity(new GibletEntity(`giblets.${this.sprite.spriteKey}.leg.default.0`, dir+Math.random()*40, force+Math.random()*10), 'objects', p[0], p[1])
ctx.addEntity(new GibletEntity(`giblets.${this.sprite.spriteKey}.leg.default.0`, dir+Math.random()*40, force+Math.random()*10), 'gibs', p[0], p[1])
}
}
// 35% extra gibs per 8
for (let i = 0; i < 8; i++) {
if (Math.random() > 0.65) {
ctx.addEntity(new GibletEntity(`giblets.any.chunk${Math.floor(1+Math.random()*4)}.default.0`, dir+Math.random()*40, force+Math.random()*10), 'objects', p[0], p[1])
ctx.addEntity(new GibletEntity(`giblets.any.chunk${Math.floor(1+Math.random()*4)}.default.0`, dir+Math.random()*40, force+Math.random()*10), 'gibs', p[0], p[1])
}
}
playSound(`action/splat-v${1+Math.floor(Math.random()*7)}`, 0.5)

View File

@ -10,6 +10,7 @@ export class GibletEntity extends Entity {
let r = dir * (Math.PI/180)
this.velocity[0] = Math.cos(r) * force
this.velocity[1] = Math.sin(r) * force
this.lifetime = 10000 + Math.random()*10000
}
update(delta: number, ctx?: WorldContext) {
super.update(delta)

View File

@ -142,6 +142,18 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment
if (l.title === 'objects') {
playLayer = layer
layer.container.sortableChildren = true
// Quick, make the gibs layer!
let gibLayer: Layer = {
title: 'gibs',
container: new PIXI.Container(),
decorations: [],
colorMatrix: new PIXI.filters.ColorMatrixFilter()
}
gibLayer.container.filters = [gibLayer.colorMatrix]
gibLayer.container.width = w.width
gibLayer.container.height = w.height
rootContainer.addChild(gibLayer.container)
layers.push(gibLayer)
}
layers.push(layer)
@ -233,6 +245,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment
}
let elapsed: number = 0
let update = (delta: number) => {
let w = segments[selectedSegment]
let time = performance.now()
let realDelta = time - lastTime
lastTime = time
@ -263,7 +276,9 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment
entity.act(desiredActions)
// FIXME: This isn't the right place for this.
rootContainer.position.set(Math.round(ctx.app.renderer.width/2), Math.round(ctx.app.renderer.height/2))
rootContainer.pivot.set(Math.max(rootContainer.width/6, Math.min(entity.x, rootContainer.width/3)), Math.max(rootContainer.height/6, Math.min(entity.y, rootContainer.height/3)))
rootContainer.pivot.set(entity.x, entity.y)
//rootContainer.pivot.set(Math.max(w.width/6, Math.min(entity.x, w.width/3)), Math.max(w.height/6, Math.min(entity.y, w.height/3)))
} else {
entity.think(realDelta)
}