Allow segment selection
This commit is contained in:
parent
f4e6e3cd52
commit
c6b70c3bdd
|
@ -32,7 +32,7 @@ export interface Layer {
|
||||||
colorMatrix: PIXIMissingColorMatrix
|
colorMatrix: PIXIMissingColorMatrix
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GameState(ctx: ContextI, selectedAnimal: string): StateI {
|
export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment: string): StateI {
|
||||||
//disableSound()
|
//disableSound()
|
||||||
let isNight = false
|
let isNight = false
|
||||||
let modeTimer = 0
|
let modeTimer = 0
|
||||||
|
@ -107,7 +107,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string): StateI {
|
||||||
lastTime = performance.now()
|
lastTime = performance.now()
|
||||||
hookKeyboard()
|
hookKeyboard()
|
||||||
// Load the world segment.
|
// Load the world segment.
|
||||||
let w = segments.world
|
let w = segments[selectedSegment]
|
||||||
if (!w) return ctx.pop()
|
if (!w) return ctx.pop()
|
||||||
|
|
||||||
// Add our world border.
|
// Add our world border.
|
||||||
|
@ -227,16 +227,16 @@ export function GameState(ctx: ContextI, selectedAnimal: string): StateI {
|
||||||
nightfall(true)
|
nightfall(true)
|
||||||
}
|
}
|
||||||
// Run world sim.
|
// Run world sim.
|
||||||
while (elapsed >= 1/5) {
|
while (elapsed >= 1/2) {
|
||||||
world.step(1/5)
|
world.step(1/2)
|
||||||
elapsed -= 1/5
|
elapsed -= 1/2
|
||||||
}
|
}
|
||||||
// Update/render.
|
// Update/render.
|
||||||
for (let layer of layers) {
|
/*for (let layer of layers) {
|
||||||
for (let decoration of layer.decorations) {
|
for (let decoration of layer.decorations) {
|
||||||
decoration.update(realDelta)
|
decoration.update(realDelta)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
for (let entity of entities) {
|
for (let entity of entities) {
|
||||||
if (isAnimalEntity(entity)) {
|
if (isAnimalEntity(entity)) {
|
||||||
if (entity.isPlayer) {
|
if (entity.isPlayer) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import * as PIXI from 'pixi.js'
|
||||||
import { GameState } from './Game'
|
import { GameState } from './Game'
|
||||||
import { SpriteInstance } from '../shared/sprites'
|
import { SpriteInstance } from '../shared/sprites'
|
||||||
import { animals } from '../data/animals'
|
import { animals } from '../data/animals'
|
||||||
|
import { segments } from '../shared/segments'
|
||||||
|
|
||||||
interface MenuItem {
|
interface MenuItem {
|
||||||
text: PIXI.Text,
|
text: PIXI.Text,
|
||||||
|
@ -14,6 +15,8 @@ export function MenuState(ctx: ContextI): StateI {
|
||||||
let container = new PIXI.Container()
|
let container = new PIXI.Container()
|
||||||
let scaryBoi = new SpriteInstance('ui.menu.decorative.scary-boi.0')
|
let scaryBoi = new SpriteInstance('ui.menu.decorative.scary-boi.0')
|
||||||
let scaryBun = new SpriteInstance('ui.menu.decorative.scary-bun.0')
|
let scaryBun = new SpriteInstance('ui.menu.decorative.scary-bun.0')
|
||||||
|
|
||||||
|
// Animal Selections
|
||||||
let animalSprites: SpriteInstance[] = Object.keys(animals).map(v => {
|
let animalSprites: SpriteInstance[] = Object.keys(animals).map(v => {
|
||||||
let s = new SpriteInstance(`${v}.animal.stand.west.0`)
|
let s = new SpriteInstance(`${v}.animal.stand.west.0`)
|
||||||
s.container.interactive = true
|
s.container.interactive = true
|
||||||
|
@ -39,6 +42,32 @@ export function MenuState(ctx: ContextI): StateI {
|
||||||
new OutlineFilter(2, 0x99ff99)
|
new OutlineFilter(2, 0x99ff99)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// Segment Selections
|
||||||
|
let segmentItems: PIXI.Text[] = Object.keys(segments).map(v => {
|
||||||
|
let s = new PIXI.Text(v, new PIXI.TextStyle({
|
||||||
|
fontFamily: 'Arial',
|
||||||
|
fontSize: 30,
|
||||||
|
fill: ['#000000'],
|
||||||
|
}))
|
||||||
|
s.interactive = true
|
||||||
|
s.on('pointerdown', () => {
|
||||||
|
selectedSegmentName = v
|
||||||
|
selectedSegmentItem.filters = []
|
||||||
|
selectedSegmentItem = s
|
||||||
|
selectedSegmentItem.filters = [
|
||||||
|
new OutlineFilter(2, 0x99ff99)
|
||||||
|
]
|
||||||
|
})
|
||||||
|
container.addChild(s)
|
||||||
|
return s
|
||||||
|
})
|
||||||
|
let selectedSegmentItem: PIXI.Text = segmentItems.find(v=>v.text==='world') ?? segmentItems[0]
|
||||||
|
let selectedSegmentName = 'world'
|
||||||
|
selectedSegmentItem.filters = [
|
||||||
|
new OutlineFilter(2, 0x99ff99)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
let selectedText = new PIXI.Text(selectedAnimalName, new PIXI.TextStyle({
|
let selectedText = new PIXI.Text(selectedAnimalName, new PIXI.TextStyle({
|
||||||
fontFamily: 'Arial',
|
fontFamily: 'Arial',
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
|
@ -76,7 +105,7 @@ export function MenuState(ctx: ContextI): StateI {
|
||||||
let el = new PIXI.Text('Start Game', blurStyle)
|
let el = new PIXI.Text('Start Game', blurStyle)
|
||||||
el.interactive = true
|
el.interactive = true
|
||||||
el.on('pointerdown', () => {
|
el.on('pointerdown', () => {
|
||||||
ctx.push(GameState(ctx, selectedAnimalName))
|
ctx.push(GameState(ctx, selectedAnimalName, selectedSegmentName))
|
||||||
})
|
})
|
||||||
el.on('pointerover', () => {
|
el.on('pointerover', () => {
|
||||||
el.style = hoverStyle
|
el.style = hoverStyle
|
||||||
|
@ -128,6 +157,18 @@ export function MenuState(ctx: ContextI): StateI {
|
||||||
}
|
}
|
||||||
yPos += animalSprites[0].container.height + 32
|
yPos += animalSprites[0].container.height + 32
|
||||||
|
|
||||||
|
// Draw our segment selections.
|
||||||
|
for (let item of segmentItems) {
|
||||||
|
item.x = ctx.app.view.width / 2 - item.width / 2
|
||||||
|
if (item.width > maxWidth) {
|
||||||
|
maxWidth = item.width
|
||||||
|
}
|
||||||
|
item.y = yPos
|
||||||
|
yPos += item.height + 8
|
||||||
|
}
|
||||||
|
yPos += 32
|
||||||
|
|
||||||
|
// Draw rest of the garbage.
|
||||||
for (let item of menuItems) {
|
for (let item of menuItems) {
|
||||||
item.x = ctx.app.view.width / 2 - item.width / 2
|
item.x = ctx.app.view.width / 2 - item.width / 2
|
||||||
if (item.width > maxWidth) {
|
if (item.width > maxWidth) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user