Skip to content

Commit

Permalink
Next v8: Bubbo Bubbo
Browse files Browse the repository at this point in the history
  • Loading branch information
bbazukun123 committed Jan 9, 2024
1 parent 6d188ed commit 6b4ddc4
Show file tree
Hide file tree
Showing 28 changed files with 518 additions and 835 deletions.
808 changes: 197 additions & 611 deletions bubbo-bubbo/package-lock.json

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions bubbo-bubbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@
"types": "tsc"
},
"dependencies": {
"@pixi/sound": "^5.2.2",
"@pixi/ui": "^0.9.1",
"gsap": "^3.12.2",
"pixi-filters": "^5.2.1",
"pixi.js": "^7.3.2",
"pixi.js": "^8.0.0-rc.2",
"typed-signals": "^2.5.0"
},
"devDependencies": {
"@assetpack/cli": "^0.7.0",
"@assetpack/core": "^0.7.0",
"@assetpack/plugin-compress": "^0.7.0",
"@assetpack/plugin-ffmpeg": "^0.7.0",
"@assetpack/plugin-json": "^0.7.0",
"@assetpack/plugin-manifest": "^0.7.0",
"@assetpack/plugin-mipmap": "^0.7.0",
"@assetpack/plugin-texture-packer": "^0.7.0",
"@assetpack/plugin-webfont": "^0.7.0",
"@assetpack/cli": "^0.8.0",
"@assetpack/core": "^0.8.0",
"@assetpack/plugin-compress": "^0.8.0",
"@assetpack/plugin-ffmpeg": "^0.8.0",
"@assetpack/plugin-json": "^0.8.0",
"@assetpack/plugin-manifest": "^0.8.0",
"@assetpack/plugin-mipmap": "^0.8.0",
"@assetpack/plugin-texture-packer": "^0.8.0",
"@assetpack/plugin-webfont": "^0.8.0",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.52.0",
Expand Down
5 changes: 2 additions & 3 deletions bubbo-bubbo/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
Assets,
extensions,
ExtensionType,
Resolver,
resolveTextureUrl,
ResolveURLParser,
settings,
UnresolvedAsset,
} from 'pixi.js';

Expand All @@ -13,8 +13,7 @@ import manifest from '../src/manifest.json';
export const resolveJsonUrl = {
extension: ExtensionType.ResolveParser,
test: (value: string): boolean =>
// @ts-expect-error should be fixed in the next version of pixi (RETINA_PREFIX is of type RegEx)
settings.RETINA_PREFIX.test(value) && value.endsWith('.json'),
Resolver.RETINA_PREFIX.test(value) && value.endsWith('.json'),
parse: resolveTextureUrl.parse,
} as ResolveURLParser;

Expand Down
22 changes: 11 additions & 11 deletions bubbo-bubbo/src/game/Game.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gsap from 'gsap';
import { DisplayObject, Point } from 'pixi.js';
import { Point } from 'pixi.js';
import { Container, Rectangle } from 'pixi.js';

import { navigation } from '../navigation';
Expand Down Expand Up @@ -55,22 +55,22 @@ export class Game {
}

/**
* Adds `DisplayObject`s to the game container.
* @param displayObjects - The `DisplayObject`s to add to the game container.
* Adds views (Containers, Sprites, etc.) to the game container.
* @param views - The views to add to the game container.
*/
public addToGame(...displayObjects: DisplayObject[]) {
displayObjects.forEach((displayObject) => {
this.gameContainer.addChild(displayObject);
public addToGame(...views: Container[]) {
views.forEach((view) => {
this.gameContainer.addChild(view);
});
}

/**
* Removes `DisplayObject`s from the game container.
* @param displayObjects - The `DisplayObject`s to remove from the game container.
* Removes views (Containers, Sprites, etc.) from the game container.
* @param views - The views to remove from the game container.
*/
public removeFromGame(...displayObjects: DisplayObject[]) {
displayObjects.forEach((displayObject) => {
displayObject.removeFromParent();
public removeFromGame(...views: Container[]) {
views.forEach((view) => {
view.removeFromParent();
});
}

Expand Down
6 changes: 3 additions & 3 deletions bubbo-bubbo/src/game/entities/Bubble.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gsap from 'gsap';
import type { IPointData } from 'pixi.js';
import type { PointData } from 'pixi.js';
import { Container, Graphics } from 'pixi.js';

import { sfx } from '../../audio';
Expand Down Expand Up @@ -82,7 +82,7 @@ export class Bubble extends SpoofBubble {
// Used to debug the visuals of the physics body, only accounts for body radius and centers on bubble view
if (designConfig.debugBody) {
this.view.addChild(
new Graphics().beginFill(0xffffff, 0.5).drawCircle(0, 0, this.body.radius),
new Graphics().circle(0, 0, this.body.radius).fill({ color: 0xffffff, alpha: 0.5 }),
);
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export class Bubble extends SpoofBubble {
* @param direction - The x and y direction of the impact animation.
* @returns - A gsap animation object.
*/
public impact(direction: IPointData) {
public impact(direction: PointData) {
return gsap.to(this.bubbleView.view, {
x: direction.x,
y: direction.y,
Expand Down
10 changes: 8 additions & 2 deletions bubbo-bubbo/src/game/entities/BubbleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BubbleView {
*/
constructor(type?: BubbleType) {
// Initialize the sprite for the bubble
this._sprite = Sprite.from(type ? `bubble-${type}` : Texture.WHITE);
this._sprite = type ? Sprite.from(`bubble-${type}`) : new Sprite(Texture.WHITE);
this._sprite.anchor.set(0.5);
this._sprite.width = boardConfig.bubbleSize;
this._sprite.height = boardConfig.bubbleSize;
Expand All @@ -52,7 +52,9 @@ export class BubbleView {
this._shine.visible = false;

// Add the shine effect to the bubble sprite
this._sprite.addChild(this._shine);
this.view.addChild(this._sprite, this._shine);
// TODO: Confirm Transform Hierarchy
// this._sprite.addChild(this._shine);

// Add the shadow and bubble sprite to the root container
this.view.addChild(this._shadow, this._sprite);
Expand Down Expand Up @@ -110,6 +112,10 @@ export class BubbleView {
// Update the texture of the sprite based on the new type
this._sprite.texture = Texture.from(`bubble-${this._type}`);

// TODO: Resolve sizing issue when setting size on Texture.WHITE Sprite before setting texture
this._sprite.width = boardConfig.bubbleSize;
this._sprite.height = boardConfig.bubbleSize;

// Update the tint of the shadow based on the new type
this._shadow.tint = boardConfig.bubbleTypeToColor[value] ?? 0x606060;

Expand Down
4 changes: 2 additions & 2 deletions bubbo-bubbo/src/game/systems/AimSystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gsap from 'gsap';
import { Container, IPointData, Point, Sprite } from 'pixi.js';
import { Container, PointData, Point, Sprite } from 'pixi.js';

import { boardConfig } from '../boardConfig';
import { designConfig } from '../designConfig';
Expand Down Expand Up @@ -299,7 +299,7 @@ export class AimSystem implements System {
const n = Math.ceil(distance / stepSize); // rounding up

// Initialise an array to hold the new points
const points: IPointData[] = [];
const points: PointData[] = [];

// Calculate the step values for x and y
const stepX = (end.x - start.x) / n;
Expand Down
8 changes: 4 additions & 4 deletions bubbo-bubbo/src/game/systems/EffectsSystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ShockwaveFilter } from 'pixi-filters';
// TODO: Filters v8 Types?
import { ShockwaveFilter } from '@pixi/filter-shockwave';

import { sfx } from '../../audio';
import { randomRange } from '../../utils/maths/rand';
Expand Down Expand Up @@ -82,9 +83,8 @@ export class EffectsSystem implements System {
this._activeShockwave = false;

// Remove any filters from the game container
if (this.game.gameContainer.filters?.length) {
this.game.gameContainer.filters.length = 0;
}
// TODO: Better way to clear filters??
this.game.gameContainer.filters = [];

// Set the game container position back to its original position
this.game.gameContainer.x = this.game.gameContainerPosition.x;
Expand Down
24 changes: 12 additions & 12 deletions bubbo-bubbo/src/game/systems/HudSystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gsap from 'gsap';
import { Container, Graphics, NineSlicePlane, Sprite, Texture } from 'pixi.js';
import { Container, Graphics, NineSliceSprite, Sprite, Texture } from 'pixi.js';

import { IconButton } from '../../ui/buttons/IconButton';
import { HelperPanel } from '../../ui/HelperPanel';
Expand Down Expand Up @@ -40,12 +40,12 @@ export class HudSystem implements System {

// All the visuals for the hud elements
private _laserLine!: LaserLine;
private _topTray!: NineSlicePlane;
private _topTray!: NineSliceSprite;
private _roundedTray!: Sprite;
private _hiddenTitle!: Title;
private _bottomTray!: NineSlicePlane;
private _leftBorder!: NineSlicePlane;
private _rightBorder!: NineSlicePlane;
private _bottomTray!: NineSliceSprite;
private _leftBorder!: NineSliceSprite;
private _rightBorder!: NineSliceSprite;
private _pauseButton!: IconButton;
private _scoreCounter!: ScoreCounter;
private _helperPanel!: HelperPanel;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class HudSystem implements System {

// Create the top section of the hud
// Create the top hud element
this._topTray = new NineSlicePlane(Texture.from('top-tray'));
this._topTray = new NineSliceSprite({ texture: Texture.from('top-tray')});
this._topTray.x = -designConfig.content.width * 0.5;
this._topTray.width = designConfig.content.width;

Expand All @@ -97,7 +97,7 @@ export class HudSystem implements System {
this._roundedTray.addChild(this._hiddenTitle.view);

// Create the bottom section of the hud
this._bottomTray = new NineSlicePlane(Texture.from('bottom-tray'));
this._bottomTray = new NineSliceSprite({ texture: Texture.from('bottom-tray')});
this._bottomTray.height = boardConfig.bounceLine - 30;
this._bottomTray.pivot.y = this._bottomTray.height;
this._bottomTray.x -= designConfig.content.width * 0.5;
Expand All @@ -107,11 +107,11 @@ export class HudSystem implements System {
this._scoreCounter = new ScoreCounter();

// Create the visual representation of the left bounds
this._leftBorder = new NineSlicePlane(Texture.from('game-side-border'));
this._leftBorder = new NineSliceSprite({ texture: Texture.from('game-side-border')});
this._leftBorder.x = -(designConfig.content.width * 0.5) - this._leftBorder.width;

// Create the visual representation of the right bounds
this._rightBorder = new NineSlicePlane(Texture.from('game-side-border'));
this._rightBorder = new NineSliceSprite({ texture: Texture.from('game-side-border')});
this._rightBorder.x = designConfig.content.width * 0.5;

// Get a reference to the pause system
Expand All @@ -128,13 +128,13 @@ export class HudSystem implements System {

// Create a mask and fit it to the game bounds
this._mask = new Graphics()
.beginFill(0x030320)
.drawRect(
.rect(
-designConfig.content.width * 0.5,
-designConfig.content.height,
designConfig.content.width,
designConfig.content.height,
);
)
.fill({ color: 0x030320});

// Create the tutorial popout
this._helperPanel = new HelperPanel();
Expand Down
4 changes: 2 additions & 2 deletions bubbo-bubbo/src/game/systems/SpaceDecorSystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Container, IPointData, Sprite } from 'pixi.js';
import { Container, PointData, Sprite } from 'pixi.js';

import { device } from '../../utils/device';
import { distance } from '../../utils/maths/point';
Expand Down Expand Up @@ -282,7 +282,7 @@ export class SpaceDecorSystem {
* Creates new decor elements at the specified points.
* @param points An array of points where the new decor elements will be placed.
*/
private _createDecor(points: IPointData[]) {
private _createDecor(points: PointData[]) {
// Loop through all the points
points.forEach((point) => {
// Determine whether to create a BubbleOrbit or Satellite decor element
Expand Down
21 changes: 13 additions & 8 deletions bubbo-bubbo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { storage } from './storage';
import { getUrlParam } from './utils/utils';

/** The PixiJS app Application instance, shared across the project */
export const app = new Application<HTMLCanvasElement>({
resolution: Math.max(window.devicePixelRatio, 2),
backgroundColor: 0xffffff,
});
export const app = new Application();

let hasInteracted = false;

Expand All @@ -33,8 +30,8 @@ function resize() {
const height = windowHeight * scale;

// Update canvas style dimensions and scroll window up to avoid issues on mobile resize
app.renderer.view.style.width = `${windowWidth}px`;
app.renderer.view.style.height = `${windowHeight}px`;
app.renderer.canvas.style.width = `${windowWidth}px`;
app.renderer.canvas.style.height = `${windowHeight}px`;
window.scrollTo(0, 0);

// Update renderer and navigation screens dimensions
Expand All @@ -45,8 +42,16 @@ function resize() {

/** Setup app and initialise assets */
async function init() {
// Add pixi canvas element (app.view) to the document's body
document.body.appendChild(app.view);
// Initialize the app
await app.init({
// TODO: Fix a couple of WebGPU only issues
preference: 'webgl',
resolution: Math.max(window.devicePixelRatio, 2),
backgroundColor: 0xffffff,
});

// Add pixi canvas element to the document's body
document.body.appendChild(app.canvas);

// Whenever the window resizes, call the 'resize' function
window.addEventListener('resize', resize);
Expand Down
4 changes: 2 additions & 2 deletions bubbo-bubbo/src/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Assets, Container } from 'pixi.js';
import { Assets, Container, Ticker } from 'pixi.js';

import { areBundlesLoaded } from './assets';
import { app } from './main';
Expand All @@ -8,7 +8,7 @@ export interface AppScreen<T = any> extends Container {
prepare?: (data?: T) => void;
show?: () => Promise<void>;
hide?: () => Promise<void>;
update?: (delta: number) => void;
update?: (time: Ticker) => void;
resize?: (w: number, h: number) => void;
}

Expand Down
20 changes: 13 additions & 7 deletions bubbo-bubbo/src/screens/GameScreen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gsap from 'gsap';
import { Container, Texture, TilingSprite } from 'pixi.js';
import { Container, Texture, Ticker, TilingSprite } from 'pixi.js';

import { designConfig } from '../game/designConfig';
import { Game } from '../game/Game';
Expand All @@ -19,9 +19,15 @@ export class GameScreen extends Container implements AppScreen {
super();

// Create the background
this._background = new TilingSprite(Texture.from('background-tile-space'), 64, 64);
this._background.tileScale.set(designConfig.backgroundTileScale);

this._background = new TilingSprite({
texture: Texture.from('background-tile-space'),
width: 64,
height: 64,
tileScale: {
x: designConfig.backgroundTileScale,
y: designConfig.backgroundTileScale,
},
});
this.addChild(this._background);

// Create an instance of the game and initialise
Expand Down Expand Up @@ -58,10 +64,10 @@ export class GameScreen extends Container implements AppScreen {

/**
* Called every frame.
* @param delta - The time elapsed since the last update.
* @param time - Ticker object with time related data.
*/
public update(delta: number) {
this._game.update(delta);
public update(time: Ticker) {
this._game.update(time.deltaTime);
}

/**
Expand Down
Loading

0 comments on commit 6b4ddc4

Please sign in to comment.