Skip to content

Commit

Permalink
v0.9.3 parameterize background color (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderclarktx authored Jan 15, 2025
1 parent 7159582 commit 9fa0e3a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
1 change: 0 additions & 1 deletion core/src/ecs/entities/ui/Shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const Shop = (): Entity => {
const background = pixiGraphics()
const outline = pixiGraphics()

// const coords: TwoPoints = [width / 6, height / 6, width / 1.5, height / 1.5]
const coords: TwoPoints = [width / 6, height / 4, width / 1.5, height / 2]

background.rect(0, 0, width, height).fill({ color: 0x000000, alpha: 0.5 })
Expand Down
1 change: 0 additions & 1 deletion core/src/ecs/systems/core/PhysicsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const PhysicsSystem: SystemBuilder<"PhysicsSystem"> = {
})
colliders.clear()
physics.free()
// physics = new RapierWorld({ x: 0, y: 4000 })
physics = new RapierWorld({ x: 0, y: 0 })
physics.switchToSmallStepsPgsSolver(); // https://github.com/dimforge/rapier.js/blob/master/src.ts/pipeline/world.ts#L400
physics.timestep = 0.025
Expand Down
8 changes: 5 additions & 3 deletions core/src/graphics/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Renderer = {
camera: Camera
guiRenderables: Renderable[]
resizedFlag: boolean
setBgColor: (color: number) => void
init: () => Promise<void>
handleResize: () => void
addGui: (renderable: Renderable) => void
Expand All @@ -30,6 +31,9 @@ export const Renderer = (props: RendererProps): Renderer => {
camera: Camera(app),
guiRenderables: [],
resizedFlag: false,
setBgColor: (color: number) => {
renderer.app.renderer.background.color = color
},
init: async () => {
const { canvas } = props

Expand All @@ -39,9 +43,7 @@ export const Renderer = (props: RendererProps): Renderer => {
resolution: 1,
antialias: true,
autoDensity: true,
backgroundColor: 0x006633,
// backgroundColor: 0x003311,
// backgroundColor: 0x000000,
backgroundColor: 0x000000,
width: renderer.props.width ?? 800,
height: renderer.props.height ?? 600
})
Expand Down
8 changes: 5 additions & 3 deletions core/src/runtime/DefaultGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export const DefaultGame = <T extends string>(gameBuilder: GameBuilder<T>): Game
init: (world) => {
const game = gameBuilder.init(world)

if (world.runtimeMode === "client") isMobile() ?
game.entities.push(Joystick()) :
game.entities.push(FullscreenButton(), Cursor(), Chat())
if (world.runtimeMode === "client") {
isMobile() ?
game.entities.push(Joystick()) :
game.entities.push(FullscreenButton(), Cursor(), Chat())
}

return game
}
Expand Down
1 change: 1 addition & 0 deletions core/src/runtime/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Game<T extends string = string> = {
systems: SystemBuilder[]
commands?: Command[]
tileMap?: number[]
bgColor?: number
}

export type GameBuilder<T extends string = string> = {
Expand Down
12 changes: 8 additions & 4 deletions core/src/runtime/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,17 @@ export const World = ({ commands, games, systems, renderer, runtimeMode }: World
// set new game
world.currentGame = game.init(world)

const { tileMap, bgColor, entities, systems } = world.currentGame

// set tileMap
world.tileMap = world.currentGame.tileMap
world.tileMap = tileMap

if (bgColor !== undefined) world.renderer?.setBgColor(bgColor)

// initialize new game
world.addEntities(world.currentGame.entities)
world.addSystemBuilders(world.currentGame.systems)
world.currentGame.commands?.forEach((command) => world.commands[command.id] = command)
world.addEntities(entities)
world.addSystemBuilders(systems)
commands?.forEach((command) => world.commands[command.id] = command)
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/piggo-gg-min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion games/flappy/Flappy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const Flappy = DefaultGame({
id: "flappy",
init: () => ({
id: "flappy",
systems: [],
bgColor: 0x000000,
systems: [SkellySpawnSystem],
entities: [
isMobile() ? MobilePvEHUD() : PvEHUD(),
// Zomi(),
Expand Down
1 change: 1 addition & 0 deletions games/sandbox/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const Sandbox = DefaultGame({
init: () => ({
id: "sandbox",
systems: [SkellySpawnSystem],
bgColor: 0x006633,
entities: [
isMobile() ? MobilePvEHUD() : PvEHUD(),
Zomi(),
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const Header = ({ world, netState, setNetState }: HeaderProps) => (

<div style={{ position: 'absolute', right: 0, bottom: 0 }}>
<span style={{ fontFamily: "sans-serif", fontSize: 14, marginRight: 5, verticalAlign: "-70%" }}>
v<b>0.9.2</b>
v<b>0.9.3</b>
</span>
<a style={{ margin: 0, color: "inherit", textDecoration: "none" }} target="_blank" href="https://discord.gg/VfFG9XqDpJ">
<FaDiscord size={20} style={{ color: "white", verticalAlign: "-80%" }}></FaDiscord>
Expand Down

0 comments on commit 9fa0e3a

Please sign in to comment.