Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration: update to pixi 7 and react 17, but particles not migrated … #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
"@types/howler": "^2.2.1",
"@types/jest": "^24.0.25",
"@types/node": "^13.1.2",
"@types/pixi.js": "^5.0.0",
"@types/querystringify": "^2.0.0",
"@types/rbush": "^3.0.0",
"@types/reach__router": "^1.2.6",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-helmet": "^5.0.14",
"concurrently": "^7.0.0",
"esbuild": "^0.14.25",
Expand Down
8 changes: 4 additions & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"@tosios/common": "0.1.0",
"colyseus.js": "^0.14.0",
"howler": "^2.2.1",
"pixi-particles": "^4.2.0",
"@pixi/particle-emitter": "^5.0.8",
"pixi-viewport": "^4.5.0",
"pixi.js": "^6.2.2",
"pixi.js": "^7.2.0",
"querystringify": "^2.1.1",
"react": "^16.12.0",
"react": "^17.0.0",
"react-device-detect": "^1.11.14",
"react-dom": "^16.12.0",
"react-dom": "^17.0.0",
"react-ga": "^3.2.0",
"react-helmet": "^5.2.1",
"react-nipple": "^1.0.1"
Expand Down
44 changes: 31 additions & 13 deletions packages/client/src/game/Game.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Collisions, Constants, Entities, Geometry, Maps, Maths, Models, Tiled, Types } from '@tosios/common';
import { Emitter } from 'pixi-particles';
import { Emitter } from '@pixi/particle-emitter';
import { Viewport } from 'pixi-viewport';
import { Application, Container, utils } from 'pixi.js';
import { GUITextures } from './assets/images';
Expand All @@ -10,6 +10,7 @@ import { BulletsManager, MonstersManager, PlayersManager, PropsManager } from '.
import { distanceBetween } from './utils/distance';
import { Inputs } from './utils/inputs';
import { getSpritesLayer, getTexturesSet } from './utils/tiled';
import { upgradeConfig } from '@pixi/particle-emitter';

const ZINDEXES = {
GROUND: 1,
Expand Down Expand Up @@ -103,6 +104,7 @@ export class Game {
autoDensity: true,
resolution: window.devicePixelRatio,
});
document.addEventListener("pointerlockchange", this.onPointerLockChange, false);

// Map
this.map = new Entities.Map(0, 0);
Expand Down Expand Up @@ -155,6 +157,24 @@ export class Game {
this.onActionSend = onActionSend;
}

private onPointerLockChange = () => {
if (document.pointerLockElement === this.app.view) {
// Pointer is locked, add mouse move listener
document.addEventListener("mousemove", this.onMouseMove, false);
} else {
// Pointer is unlocked, remove mouse move listener
document.removeEventListener("mousemove", this.onMouseMove, false);
}
};

private onMouseMove = (event: MouseEvent) => {
const movementX = event.movementX || 0; // Fallback for browsers that don't support movementX
const movementY = event.movementY || 0;

// Update your game logic based on movementX and movementY
this.rotate(movementX, movementY); // Call your rotate method with the movement values
};

start = (renderView: any) => {
renderView.appendChild(this.app.view);
this.app.start();
Expand Down Expand Up @@ -197,7 +217,7 @@ export class Game {
}

// Rotate
this.rotate();
// this.rotate();

// Shoot
if (this.inputs.shoot) {
Expand Down Expand Up @@ -249,7 +269,7 @@ export class Game {

bullet.kill(distanceBetween(this.me?.body, bullet.body));
player.hurt();
this.spawnImpact(bullet.x, bullet.y);
// this.spawnImpact(bullet.x, bullet.y);
continue;
}

Expand All @@ -262,7 +282,7 @@ export class Game {
) {
bullet.kill(distanceBetween(this.me?.body, bullet.body));
this.me.hurt();
this.spawnImpact(bullet.x, bullet.y);
// this.spawnImpact(bullet.x, bullet.y);
continue;
}

Expand All @@ -274,21 +294,21 @@ export class Game {

bullet.kill(distanceBetween(this.me?.body, bullet.body));
monster.hurt();
this.spawnImpact(bullet.x, bullet.y);
// this.spawnImpact(bullet.x, bullet.y);
continue;
}

// Collisions: Walls
if (this.walls.collidesWithCircle(bullet.body, 'half')) {
bullet.kill(distanceBetween(this.me?.body, bullet.body));
this.spawnImpact(bullet.x, bullet.y);
// this.spawnImpact(bullet.x, bullet.y);
continue;
}

// Collisions: Map
if (this.map.isCircleOutside(bullet.body)) {
bullet.kill(distanceBetween(this.me?.body, bullet.body));
this.spawnImpact(Maths.clamp(bullet.x, 0, this.map.width), Maths.clamp(bullet.y, 0, this.map.height));
// this.spawnImpact(Maths.clamp(bullet.x, 0, this.map.width), Maths.clamp(bullet.y, 0, this.map.height));
continue;
}
}
Expand Down Expand Up @@ -450,12 +470,10 @@ export class Game {

// SPAWNERS
private spawnImpact = (x: number, y: number, color = '#ffffff') => {
new Emitter(this.playersManager, [ImpactTexture], {
...ImpactConfig,
color: {
start: color,
end: color,
},
const upgradedImpactConfig = upgradeConfig(ImpactConfig, [ImpactTexture]);

new Emitter(this.particlesContainer, [ImpactTexture], {
...upgradedImpactConfig,
pos: {
x,
y,
Expand Down
22 changes: 11 additions & 11 deletions packages/client/src/game/entities/Bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Constants, Maths, Models, Types } from '@tosios/common';
import { Container, utils } from 'pixi.js';
import { Trail100Texture, Trail25Texture, Trail50Texture, TrailConfig } from '../assets/particles';
import { BaseEntity } from '.';
import { Emitter } from 'pixi-particles';
import { Emitter } from '@pixi/particle-emitter';
import { ExplosionSound } from '../assets/sounds';
import { WeaponTextures } from '../assets/images';

Expand All @@ -23,7 +23,7 @@ export class Bullet extends BaseEntity {

private _shotAt: number = 0;

private _trailEmitter: Emitter;
// private _trailEmitter: Emitter;

// Init
constructor(bullet: Models.BulletJSON, particlesContainer: Container) {
Expand All @@ -36,10 +36,10 @@ export class Bullet extends BaseEntity {
});

// Trail emitter
this._trailEmitter = new Emitter(particlesContainer, [Trail100Texture, Trail50Texture, Trail25Texture], {
...TrailConfig,
});
this._trailEmitter.autoUpdate = true;
// this._trailEmitter = new Emitter(particlesContainer, [Trail100Texture, Trail50Texture, Trail25Texture], {
// ...TrailConfig,
// });
// this._trailEmitter.autoUpdate = true;

// Bullet
this.rotation = bullet.rotation;
Expand All @@ -63,25 +63,25 @@ export class Bullet extends BaseEntity {
this.active = bullet.active;
this.color = bullet.color;
this.shotAt = bullet.shotAt;
this._trailEmitter.cleanup();
// this._trailEmitter.cleanup();
this.updateTrail();
}

move = (speed: number) => {
this.x += Math.cos(this.rotation) * speed;
this.y += Math.sin(this.rotation) * speed;

this._trailEmitter.updateSpawnPos(this.x, this.y);
// this._trailEmitter.updateSpawnPos(this.x, this.y);
};

updateTrail = () => {
this._trailEmitter.updateSpawnPos(this.x, this.y);
// this._trailEmitter.updateSpawnPos(this.x, this.y);

if (this.active) {
this._trailEmitter.emit = true;
// this._trailEmitter.emit = true;
this.container.rotation = this.rotation;
} else {
this._trailEmitter.emit = false;
// this._trailEmitter.emit = false;
}
};

Expand Down
11 changes: 7 additions & 4 deletions packages/client/src/game/entities/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Effects, PlayerLivesSprite, TextSprite } from '../sprites';
import { PlayerTextures, WeaponTextures } from '../assets/images';
import { SmokeConfig, SmokeTexture } from '../assets/particles';
import { BaseEntity } from '.';
import { Emitter } from 'pixi-particles';
import { Emitter } from '@pixi/particle-emitter';
import { upgradeConfig } from '@pixi/particle-emitter';

const NAME_OFFSET = 4;
const LIVES_OFFSET = 10;
Expand Down Expand Up @@ -222,8 +223,10 @@ export class Player extends BaseEntity {
return;
}

const upgradedConfig = upgradeConfig(SmokeConfig, [SmokeTexture]);

new Emitter(this._particlesContainer, [SmokeTexture], {
...SmokeConfig,
...upgradedConfig,
pos: {
x: this.body.x,
y: this.body.y + this.body.radius / 2,
Expand All @@ -237,13 +240,13 @@ export class Player extends BaseEntity {
set x(x: number) {
this.container.x = x;
this.body.x = x;
this.spawnSmoke();
// this.spawnSmoke();
}

set y(y: number) {
this.container.y = y;
this.body.y = y;
this.spawnSmoke();
// this.spawnSmoke();
}

set toX(toX: number) {
Expand Down
Loading