evotars 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +24 -0
- package/dist/config/constants.d.ts +1 -0
- package/dist/entities/EmoteSpitter.d.ts +15 -0
- package/dist/entities/Evotar.d.ts +78 -0
- package/dist/entities/Message.d.ts +27 -0
- package/dist/entities/Name.d.ts +14 -0
- package/dist/entities/SpriteContainer.d.ts +16 -0
- package/dist/entities/TrailEffect.d.ts +15 -0
- package/dist/evotars.d.ts +15 -0
- package/dist/evotars.js +705 -0
- package/dist/evotars.umd.cjs +1 -0
- package/dist/evotarsManager.d.ts +30 -0
- package/dist/helpers/timer.d.ts +14 -0
- package/dist/helpers/types.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/services/soundService.d.ts +14 -0
- package/dist/services/spriteService.d.ts +63 -0
- package/dist/types/dto/action.d.ts +56 -0
- package/{src/types/dto/chatter.ts → dist/types/dto/chatter.d.ts} +2 -2
- package/dist/types/dto/event.d.ts +9 -0
- package/dist/types/dto/message.d.ts +8 -0
- package/dist/types/dto/settings.d.ts +5 -0
- package/dist/types/dto/user.d.ts +12 -0
- package/package.json +30 -3
- package/.editorconfig +0 -13
- package/.prettierrc.json +0 -3
- package/index.html +0 -13
- package/index.ts +0 -1
- package/public/fonts/Rubik.ttf +0 -0
- package/public/sounds/jump.mp3 +0 -0
- package/public/sprites/agent/agent.json +0 -166
- package/public/sprites/agent/agent.png +0 -0
- package/public/sprites/cat/cat.json +0 -231
- package/public/sprites/cat/cat.png +0 -0
- package/public/sprites/dude/dude.json +0 -231
- package/public/sprites/dude/dude.png +0 -0
- package/public/sprites/girl/girl.json +0 -231
- package/public/sprites/girl/girl.png +0 -0
- package/public/sprites/nerd/nerd.json +0 -231
- package/public/sprites/nerd/nerd.png +0 -0
- package/public/sprites/senior/senior.json +0 -231
- package/public/sprites/senior/senior.png +0 -0
- package/public/sprites/sith/sith.json +0 -166
- package/public/sprites/sith/sith.png +0 -0
- package/src/app.ts +0 -63
- package/src/config/config.ts +0 -133
- package/src/config/constants.ts +0 -1
- package/src/dudes.ts +0 -71
- package/src/entities/Dude.ts +0 -453
- package/src/entities/DudeEmoteSpitter.ts +0 -60
- package/src/entities/DudeMessage.ts +0 -163
- package/src/entities/DudeName.ts +0 -39
- package/src/entities/DudeSpriteContainer.ts +0 -68
- package/src/entities/DudeTrailEffect.ts +0 -72
- package/src/helpers/timer.ts +0 -43
- package/src/helpers/types.ts +0 -11
- package/src/index.ts +0 -1
- package/src/main.ts +0 -75
- package/src/services/assetsLoader.ts +0 -27
- package/src/services/dudesManager.ts +0 -305
- package/src/services/soundService.ts +0 -28
- package/src/services/spriteProvider.ts +0 -93
- package/src/styles.css +0 -16
- package/src/types/dto/action.ts +0 -68
- package/src/types/dto/event.ts +0 -9
- package/src/types/dto/message.ts +0 -8
- package/src/types/dto/settings.ts +0 -5
- package/src/types/dto/user.ts +0 -13
- package/tsconfig.json +0 -23
- /package/{src/types/dto/index.ts → dist/types/dto/index.d.ts} +0 -0
- /package/{src/types/index.ts → dist/types/index.d.ts} +0 -0
package/src/entities/Dude.ts
DELETED
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import * as TWEEN from '@tweenjs/tween.js';
|
|
2
|
-
import * as PIXI from 'pixi.js';
|
|
3
|
-
import { app } from '../app';
|
|
4
|
-
import { SpriteConfig } from '../config/config';
|
|
5
|
-
import { FIXED_DELTA_TIME } from '../config/constants';
|
|
6
|
-
import { Timer } from '../helpers/timer';
|
|
7
|
-
import { dudesManager } from '../services/dudesManager';
|
|
8
|
-
import { soundService } from '../services/soundService';
|
|
9
|
-
import {
|
|
10
|
-
DudeSpriteLayers,
|
|
11
|
-
DudeSpriteTags,
|
|
12
|
-
DudeTagAnimatedSprites,
|
|
13
|
-
spriteProvider,
|
|
14
|
-
} from '../services/spriteProvider';
|
|
15
|
-
import { DudeEmoteSpitter } from './DudeEmoteSpitter';
|
|
16
|
-
import { DudeMessage } from './DudeMessage';
|
|
17
|
-
import { DudeName } from './DudeName';
|
|
18
|
-
import { DudeSpriteContainer } from './DudeSpriteContainer';
|
|
19
|
-
import { DudeTrailEffect } from './DudeTrailEffect';
|
|
20
|
-
|
|
21
|
-
export type DudeProps = {
|
|
22
|
-
name?: string;
|
|
23
|
-
sprite?: SpriteConfig;
|
|
24
|
-
color?: PIXI.Color;
|
|
25
|
-
direction?: number;
|
|
26
|
-
scale?: number;
|
|
27
|
-
isAnonymous?: boolean;
|
|
28
|
-
zIndex?: number;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type DudeSpawnProps = {
|
|
32
|
-
isFalling?: boolean;
|
|
33
|
-
positionX?: number;
|
|
34
|
-
onComplete?: () => void;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type DudeDepawnProps = {
|
|
38
|
-
onComplete?: () => void;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type DudeState = Required<DudeProps>;
|
|
42
|
-
|
|
43
|
-
type UserProps = {
|
|
44
|
-
color?: PIXI.Color;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const DEFAULT_DUDE_SCALE = 4;
|
|
48
|
-
|
|
49
|
-
export class Dude {
|
|
50
|
-
public container: PIXI.Container = new PIXI.Container();
|
|
51
|
-
|
|
52
|
-
private userState: UserProps = {};
|
|
53
|
-
|
|
54
|
-
private state: DudeState = {
|
|
55
|
-
name: '',
|
|
56
|
-
sprite: {
|
|
57
|
-
name: 'dude',
|
|
58
|
-
w: 32,
|
|
59
|
-
h: 32,
|
|
60
|
-
collider: {
|
|
61
|
-
x: 8,
|
|
62
|
-
y: 7,
|
|
63
|
-
w: 16,
|
|
64
|
-
h: 18,
|
|
65
|
-
},
|
|
66
|
-
pivot: {
|
|
67
|
-
x: 0,
|
|
68
|
-
y: 9,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
color: new PIXI.Color('#969696'),
|
|
72
|
-
direction: 1,
|
|
73
|
-
scale: DEFAULT_DUDE_SCALE,
|
|
74
|
-
isAnonymous: false,
|
|
75
|
-
zIndex: 0,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
private animationState?: DudeSpriteTags;
|
|
79
|
-
|
|
80
|
-
// TODO: Refactor sprite initializing, move logic to separate file
|
|
81
|
-
private sprite?: DudeSpriteContainer;
|
|
82
|
-
|
|
83
|
-
private tagSprites: DudeTagAnimatedSprites =
|
|
84
|
-
spriteProvider.createTagAnimatedSprites(this.state.sprite.name);
|
|
85
|
-
|
|
86
|
-
public trail: DudeTrailEffect = new DudeTrailEffect();
|
|
87
|
-
|
|
88
|
-
private name: DudeName = new DudeName();
|
|
89
|
-
|
|
90
|
-
private message: DudeMessage = new DudeMessage(() => {
|
|
91
|
-
this.state.zIndex = dudesManager.zIndexDudeMax(this.container.zIndex);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
private emoteSpitter: DudeEmoteSpitter = new DudeEmoteSpitter();
|
|
95
|
-
|
|
96
|
-
private velocity: PIXI.IPointData = {
|
|
97
|
-
x: 0,
|
|
98
|
-
y: 0,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
private runSpeed = 0.05;
|
|
102
|
-
|
|
103
|
-
private gravity = 0.2;
|
|
104
|
-
|
|
105
|
-
private dashAcc = 3;
|
|
106
|
-
|
|
107
|
-
private isJumping = false;
|
|
108
|
-
|
|
109
|
-
private isDashing = false;
|
|
110
|
-
|
|
111
|
-
private isDespawned = false;
|
|
112
|
-
|
|
113
|
-
landTimer?: Timer;
|
|
114
|
-
|
|
115
|
-
stateTimer?: Timer;
|
|
116
|
-
|
|
117
|
-
scaleTimer?: Timer;
|
|
118
|
-
|
|
119
|
-
spawnTween?: TWEEN.Tween<PIXI.Container>;
|
|
120
|
-
|
|
121
|
-
fadeTween?: TWEEN.Tween<PIXI.Container>;
|
|
122
|
-
|
|
123
|
-
scaleTween?: TWEEN.Tween<Dude>;
|
|
124
|
-
|
|
125
|
-
constructor(props: DudeProps = {}) {
|
|
126
|
-
this.container.addChild(this.name.text);
|
|
127
|
-
this.container.addChild(this.emoteSpitter.container);
|
|
128
|
-
this.container.addChild(this.message.container);
|
|
129
|
-
|
|
130
|
-
void this.setAnimationState(DudeSpriteTags.Idle);
|
|
131
|
-
|
|
132
|
-
if (props.sprite) {
|
|
133
|
-
this.setSprite(props.sprite);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
this.state = { ...this.state, ...props };
|
|
137
|
-
|
|
138
|
-
this.stateTimer = new Timer(5000, () => {
|
|
139
|
-
if (!this.isJumping) {
|
|
140
|
-
this.setAnimationState(DudeSpriteTags.Run);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
spawn(props: DudeSpawnProps = { isFalling: false }): void {
|
|
146
|
-
const collider = this.state.sprite.collider;
|
|
147
|
-
const fallingStartY = -(collider.y + collider.h - this.state.sprite.h / 2);
|
|
148
|
-
const spawnY = props.isFalling ? fallingStartY : app.renderer.height;
|
|
149
|
-
const spriteWidth = this.state.sprite.w * this.state.scale;
|
|
150
|
-
|
|
151
|
-
const x =
|
|
152
|
-
props.positionX != undefined
|
|
153
|
-
? props.positionX * app.renderer.width
|
|
154
|
-
: Math.random() * (app.renderer.width - spriteWidth) + spriteWidth / 2;
|
|
155
|
-
const y = spawnY * this.state.scale;
|
|
156
|
-
|
|
157
|
-
this.container.x = x;
|
|
158
|
-
this.container.y = y;
|
|
159
|
-
|
|
160
|
-
this.state.direction = Math.random() > 0.5 ? 1 : -1;
|
|
161
|
-
|
|
162
|
-
if (!props.isFalling) {
|
|
163
|
-
const zIndex = dudesManager.zIndexDudeMin(this.container.zIndex);
|
|
164
|
-
|
|
165
|
-
this.state.zIndex = zIndex;
|
|
166
|
-
this.container.alpha = 0;
|
|
167
|
-
|
|
168
|
-
this.spawnTween = new TWEEN.Tween(this.container)
|
|
169
|
-
.to({ alpha: 1 }, 500)
|
|
170
|
-
.onComplete(props.onComplete)
|
|
171
|
-
.start();
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
despawn(props: DudeDepawnProps = {}): void {
|
|
176
|
-
if (this.fadeTween && this.fadeTween.isPlaying()) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
this.fadeTween = new TWEEN.Tween(this.container)
|
|
181
|
-
.to({ alpha: 0 }, 1000)
|
|
182
|
-
.onComplete(() => {
|
|
183
|
-
this.isDespawned = true;
|
|
184
|
-
props.onComplete && props.onComplete();
|
|
185
|
-
})
|
|
186
|
-
.start();
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
scale(options: { value: number; duration: number; cooldown: number }): void {
|
|
190
|
-
if (this.scaleTween && this.scaleTween.isPlaying()) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (this.scaleTimer && !this.scaleTimer.isCompleted) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this.scaleTween = new TWEEN.Tween(this)
|
|
199
|
-
.to({ state: { scale: DEFAULT_DUDE_SCALE * (options.value ?? 2) } }, 2000)
|
|
200
|
-
.onComplete(() => {
|
|
201
|
-
this.scaleTimer = new Timer((options.duration ?? 10) * 1000, () => {
|
|
202
|
-
this.scaleTween = new TWEEN.Tween(this)
|
|
203
|
-
.to({ state: { scale: DEFAULT_DUDE_SCALE } }, 2000)
|
|
204
|
-
.start();
|
|
205
|
-
});
|
|
206
|
-
})
|
|
207
|
-
.start();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
jump(options: {
|
|
211
|
-
velocityX: number;
|
|
212
|
-
velocityY: number;
|
|
213
|
-
cooldown: number;
|
|
214
|
-
}): void {
|
|
215
|
-
if (this.isDespawned) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (!this.isJumping) {
|
|
220
|
-
this.isJumping = true;
|
|
221
|
-
|
|
222
|
-
this.velocity.x = this.state.direction * (options.velocityX ?? 3.5);
|
|
223
|
-
this.velocity.y = options.velocityY ?? -8;
|
|
224
|
-
|
|
225
|
-
this.setAnimationState(DudeSpriteTags.Jump);
|
|
226
|
-
|
|
227
|
-
soundService.play('jump');
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
dash(options: { force: number; cooldown: number }): void {
|
|
232
|
-
if (this.isDespawned) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (!this.isDashing) {
|
|
237
|
-
this.isDashing = true;
|
|
238
|
-
this.velocity.x = this.state.direction * (options.force ?? 14);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
setSprite(sprite: SpriteConfig) {
|
|
243
|
-
if (sprite.name && sprite.name != this.state.sprite.name) {
|
|
244
|
-
this.tagSprites = spriteProvider.createTagAnimatedSprites(sprite.name);
|
|
245
|
-
|
|
246
|
-
if (this.animationState) {
|
|
247
|
-
this.setAnimationState(this.animationState, true);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
setProps(props: DudeProps) {
|
|
253
|
-
if (props.sprite) {
|
|
254
|
-
this.setSprite(props.sprite);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
this.state = { ...this.state, ...props };
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
setUserProps(props: UserProps) {
|
|
261
|
-
this.userState = { ...this.userState, ...props };
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
private move() {
|
|
265
|
-
const collider = this.state.sprite.collider;
|
|
266
|
-
|
|
267
|
-
const position = {
|
|
268
|
-
x: this.container.position.x,
|
|
269
|
-
y: this.container.position.y,
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
if (this.isDashing) {
|
|
273
|
-
const currentVelocitySign = Math.sign(this.velocity.x);
|
|
274
|
-
|
|
275
|
-
this.velocity.x =
|
|
276
|
-
this.velocity.x -
|
|
277
|
-
(currentVelocitySign * this.dashAcc) / Math.abs(this.velocity.x);
|
|
278
|
-
|
|
279
|
-
if (currentVelocitySign != Math.sign(this.velocity.x)) {
|
|
280
|
-
this.isDashing = false;
|
|
281
|
-
this.velocity.x = 0;
|
|
282
|
-
} else {
|
|
283
|
-
position.x += this.velocity.x;
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
if (this.stateTimer?.isCompleted) {
|
|
287
|
-
this.stateTimer = new Timer(Math.random() * 5000, () => {
|
|
288
|
-
if (this.animationState == DudeSpriteTags.Idle) {
|
|
289
|
-
this.setAnimationState(DudeSpriteTags.Run);
|
|
290
|
-
} else if (this.animationState == DudeSpriteTags.Run) {
|
|
291
|
-
this.setAnimationState(DudeSpriteTags.Idle);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (this.animationState == DudeSpriteTags.Run) {
|
|
297
|
-
const speed = this.runSpeed * this.state.direction;
|
|
298
|
-
this.velocity.x = speed * FIXED_DELTA_TIME;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
this.velocity.y = this.velocity.y + this.gravity;
|
|
302
|
-
|
|
303
|
-
position.x += this.velocity.x;
|
|
304
|
-
position.y += this.velocity.y;
|
|
305
|
-
|
|
306
|
-
if (this.isOnGround(position.y)) {
|
|
307
|
-
this.velocity.y = 0;
|
|
308
|
-
this.velocity.x = 0;
|
|
309
|
-
|
|
310
|
-
position.y = app.renderer.height;
|
|
311
|
-
|
|
312
|
-
if (this.animationState == DudeSpriteTags.Fall) {
|
|
313
|
-
this.setAnimationState(DudeSpriteTags.Land);
|
|
314
|
-
this.landTimer = new Timer(200, () => {
|
|
315
|
-
this.setAnimationState(DudeSpriteTags.Idle);
|
|
316
|
-
this.isJumping = false;
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (this.velocity.y > 0) {
|
|
322
|
-
this.setAnimationState(DudeSpriteTags.Fall);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if (this.animationState != DudeSpriteTags.Idle || this.isDashing) {
|
|
327
|
-
const halfSpriteWidth = (collider.w / 2) * this.state.scale;
|
|
328
|
-
|
|
329
|
-
const left = this.container.x - halfSpriteWidth < 0;
|
|
330
|
-
const right = this.container.x + halfSpriteWidth > app.renderer.width;
|
|
331
|
-
|
|
332
|
-
if (left || right) {
|
|
333
|
-
this.state.direction = -this.state.direction;
|
|
334
|
-
this.velocity.x = -this.velocity.x;
|
|
335
|
-
|
|
336
|
-
if (left) {
|
|
337
|
-
position.x = halfSpriteWidth;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (right) {
|
|
341
|
-
position.x = app.renderer.width - halfSpriteWidth;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
this.container.position.set(position.x, position.y);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
update(): void {
|
|
350
|
-
if (this.isDespawned) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
this.landTimer?.tick();
|
|
355
|
-
this.stateTimer?.tick();
|
|
356
|
-
this.scaleTimer?.tick();
|
|
357
|
-
|
|
358
|
-
this.fadeTween?.update();
|
|
359
|
-
this.spawnTween?.update();
|
|
360
|
-
this.scaleTween?.update();
|
|
361
|
-
|
|
362
|
-
this.container.zIndex = this.state.zIndex;
|
|
363
|
-
|
|
364
|
-
const collider = this.state.sprite.collider;
|
|
365
|
-
|
|
366
|
-
this.name.update({
|
|
367
|
-
name: this.state.name,
|
|
368
|
-
isVisible: !this.state.isAnonymous,
|
|
369
|
-
position: {
|
|
370
|
-
y:
|
|
371
|
-
-(this.state.sprite.h / 2 - collider.y + this.state.sprite.pivot.y) *
|
|
372
|
-
this.state.scale,
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
this.message.update({
|
|
377
|
-
position: {
|
|
378
|
-
y: this.name.text.position.y - this.name.text.height - 6,
|
|
379
|
-
},
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
this.emoteSpitter.update({
|
|
383
|
-
position: {
|
|
384
|
-
y: this.message.container.position.y - this.message.container.height,
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
this.move();
|
|
389
|
-
|
|
390
|
-
if (this.sprite) {
|
|
391
|
-
this.sprite.update({
|
|
392
|
-
color: {
|
|
393
|
-
[DudeSpriteLayers.Body]: this.userState.color
|
|
394
|
-
? this.userState.color
|
|
395
|
-
: this.state.color,
|
|
396
|
-
},
|
|
397
|
-
scale: {
|
|
398
|
-
x: this.state.direction * this.state.scale,
|
|
399
|
-
y: this.state.scale,
|
|
400
|
-
},
|
|
401
|
-
play: !this.isDashing,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
this.trail.update({
|
|
406
|
-
play: this.isDashing,
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
isOnGround(y: number): boolean {
|
|
411
|
-
return y > app.renderer.height;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
addMessage(message: string): void {
|
|
415
|
-
this.message.add(message);
|
|
416
|
-
this.state.isAnonymous = false;
|
|
417
|
-
this.fadeTween?.stop();
|
|
418
|
-
this.fadeTween = undefined; // https://github.com/tweenjs/tween.js/issues/665
|
|
419
|
-
this.container.alpha = 1;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
spitEmotes(emotes: string[]): void {
|
|
423
|
-
for (const emote of emotes) {
|
|
424
|
-
this.emoteSpitter.add(emote);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
async setAnimationState(state: DudeSpriteTags, force = false): Promise<void> {
|
|
429
|
-
if (this.animationState == state && !force) {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
this.animationState = state;
|
|
434
|
-
|
|
435
|
-
if (this.sprite) {
|
|
436
|
-
this.container.removeChild(this.sprite.container);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// TODO: Refactor sprite initializing, move logic to separate file
|
|
440
|
-
const layerAnimatedSprites = this.tagSprites[this.animationState];
|
|
441
|
-
|
|
442
|
-
this.sprite = new DudeSpriteContainer(layerAnimatedSprites);
|
|
443
|
-
|
|
444
|
-
this.trail.setSprite(this.sprite);
|
|
445
|
-
|
|
446
|
-
this.sprite.container.pivot.set(
|
|
447
|
-
this.state.sprite.pivot.x,
|
|
448
|
-
this.state.sprite.pivot.y,
|
|
449
|
-
);
|
|
450
|
-
|
|
451
|
-
this.container.addChild(this.sprite.container);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import * as PIXI from 'pixi.js';
|
|
2
|
-
import { Point } from '../helpers/types';
|
|
3
|
-
import { Timer } from '../helpers/timer';
|
|
4
|
-
import { FIXED_DELTA_TIME } from '../config/constants';
|
|
5
|
-
|
|
6
|
-
export type DudeEmoteSpitterProps = {
|
|
7
|
-
position: Point;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class DudeEmoteSpitter {
|
|
11
|
-
public container: PIXI.Container = new PIXI.Container();
|
|
12
|
-
|
|
13
|
-
private emotes: PIXI.Sprite[] = [];
|
|
14
|
-
|
|
15
|
-
private moveSpeed = 50;
|
|
16
|
-
private alphaSpeed = 1;
|
|
17
|
-
private scaleSpeed = 0.5;
|
|
18
|
-
|
|
19
|
-
private timer?: Timer;
|
|
20
|
-
|
|
21
|
-
public add(url: string): void {
|
|
22
|
-
const sprite = PIXI.Sprite.from(url);
|
|
23
|
-
sprite.anchor.set(0.5, 0.5);
|
|
24
|
-
sprite.scale.set(0, 0);
|
|
25
|
-
this.emotes.push(sprite);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public update(props: DudeEmoteSpitterProps): void {
|
|
29
|
-
this.timer?.tick();
|
|
30
|
-
|
|
31
|
-
if (!this.timer || this.timer.isCompleted) {
|
|
32
|
-
if (this.emotes.length > 0) {
|
|
33
|
-
this.timer = new Timer(2000, () => {
|
|
34
|
-
const sprite = this.emotes.shift();
|
|
35
|
-
|
|
36
|
-
if (sprite) {
|
|
37
|
-
this.container.addChild(sprite);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.container.position.x = props.position.x ?? this.container.position.x;
|
|
44
|
-
this.container.position.y = props.position.y ?? this.container.position.y;
|
|
45
|
-
|
|
46
|
-
for (const child of this.container.children) {
|
|
47
|
-
child.position.y -= (FIXED_DELTA_TIME * this.moveSpeed) / 1000;
|
|
48
|
-
child.scale.x += (FIXED_DELTA_TIME * this.scaleSpeed) / 1000;
|
|
49
|
-
child.scale.y += (FIXED_DELTA_TIME * this.scaleSpeed) / 1000;
|
|
50
|
-
|
|
51
|
-
if (child.scale.x > 1) {
|
|
52
|
-
child.alpha -= (FIXED_DELTA_TIME * this.alphaSpeed) / 1000;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (child.alpha <= 0) {
|
|
56
|
-
this.container.removeChild(child);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Timer } from '../helpers/timer';
|
|
2
|
-
import { Point } from '../helpers/types';
|
|
3
|
-
import { Tween } from '@tweenjs/tween.js';
|
|
4
|
-
import * as PIXI from 'pixi.js';
|
|
5
|
-
|
|
6
|
-
export type DudeMesageProps = {
|
|
7
|
-
position: Point;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class DudeMessage {
|
|
11
|
-
public container: PIXI.Container = new PIXI.Container();
|
|
12
|
-
public animated: PIXI.Container = new PIXI.Container();
|
|
13
|
-
|
|
14
|
-
private text: PIXI.Text = new PIXI.Text(undefined, {
|
|
15
|
-
fontFamily: 'Rubik',
|
|
16
|
-
fontSize: 20,
|
|
17
|
-
fill: 0x222222,
|
|
18
|
-
align: 'left',
|
|
19
|
-
breakWords: true,
|
|
20
|
-
wordWrap: true,
|
|
21
|
-
wordWrapWidth: 200,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
private padding = 10;
|
|
25
|
-
private borderRadius = 10;
|
|
26
|
-
private boxColor = 0xeeeeee;
|
|
27
|
-
|
|
28
|
-
private fadeShift = 10;
|
|
29
|
-
|
|
30
|
-
private isChecking = true;
|
|
31
|
-
|
|
32
|
-
private messageQueue: string[] = [];
|
|
33
|
-
|
|
34
|
-
private showTween?: Tween<PIXI.Container>;
|
|
35
|
-
private hideTween?: Tween<PIXI.Container>;
|
|
36
|
-
|
|
37
|
-
private timer?: Timer;
|
|
38
|
-
|
|
39
|
-
constructor(private beforeShow: () => void) {
|
|
40
|
-
this.container.addChild(this.animated);
|
|
41
|
-
|
|
42
|
-
this.text.anchor.set(0.5, 1);
|
|
43
|
-
this.text.position.set(0, -this.padding);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private trim(text: PIXI.Text): string {
|
|
47
|
-
const metrics = PIXI.TextMetrics.measureText(text.text, text.style);
|
|
48
|
-
|
|
49
|
-
return metrics.lines.length > 4
|
|
50
|
-
? metrics.lines.slice(0, 4).join(' ').slice(0, -3) + '...'
|
|
51
|
-
: text.text;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public update(props: DudeMesageProps): void {
|
|
55
|
-
this.timer?.tick();
|
|
56
|
-
|
|
57
|
-
this.showTween?.update();
|
|
58
|
-
this.hideTween?.update();
|
|
59
|
-
|
|
60
|
-
if (this.isChecking && this.messageQueue.length > 0) {
|
|
61
|
-
this.isChecking = false;
|
|
62
|
-
|
|
63
|
-
const message = this.messageQueue.shift();
|
|
64
|
-
|
|
65
|
-
if (message) {
|
|
66
|
-
this.beforeShow();
|
|
67
|
-
this.show(message);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
this.container.position.x = props.position.x ?? this.container.position.x;
|
|
72
|
-
this.container.position.y = props.position.y ?? this.container.position.y;
|
|
73
|
-
|
|
74
|
-
const isAnimationPlaying =
|
|
75
|
-
this.showTween?.isPlaying() || this.hideTween?.isPlaying();
|
|
76
|
-
|
|
77
|
-
if (!this.isChecking && !isAnimationPlaying && this.timer) {
|
|
78
|
-
this.animated.position.y = Math.sin(this.timer.current * 0.0025) * 4 - 2;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public add(message: string): void {
|
|
83
|
-
this.messageQueue.push(message);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private drawBox(text: PIXI.Text) {
|
|
87
|
-
const roundedRect = {
|
|
88
|
-
x: text.x - this.padding - text.width * text.anchor.x,
|
|
89
|
-
y: text.y - this.padding - text.height * text.anchor.y,
|
|
90
|
-
w: text.width + this.padding * 2,
|
|
91
|
-
h: text.height + this.padding * 2,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const box = new PIXI.Graphics();
|
|
95
|
-
box.beginFill(this.boxColor);
|
|
96
|
-
|
|
97
|
-
box.drawRoundedRect(
|
|
98
|
-
roundedRect.x,
|
|
99
|
-
roundedRect.y,
|
|
100
|
-
roundedRect.w,
|
|
101
|
-
roundedRect.h,
|
|
102
|
-
this.borderRadius
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
box.drawPolygon(
|
|
106
|
-
{
|
|
107
|
-
x: roundedRect.x + roundedRect.w / 2 - 10,
|
|
108
|
-
y: roundedRect.y + roundedRect.h,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
x: roundedRect.x + roundedRect.w / 2 + 10,
|
|
112
|
-
y: roundedRect.y + roundedRect.h,
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
x: roundedRect.x + roundedRect.w / 2,
|
|
116
|
-
y: roundedRect.y + roundedRect.h + 10 - 4,
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
box.endFill();
|
|
121
|
-
|
|
122
|
-
return box;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private show(message: string): void {
|
|
126
|
-
this.text.text = message;
|
|
127
|
-
this.text.text = this.trim(this.text);
|
|
128
|
-
|
|
129
|
-
this.animated.alpha = 0;
|
|
130
|
-
this.animated.position.y = this.fadeShift;
|
|
131
|
-
|
|
132
|
-
const box = this.drawBox(this.text);
|
|
133
|
-
|
|
134
|
-
this.animated.removeChildren();
|
|
135
|
-
this.animated.addChild(box, this.text);
|
|
136
|
-
|
|
137
|
-
const showProps = {
|
|
138
|
-
alpha: 1,
|
|
139
|
-
y: this.animated.y - this.fadeShift,
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const hideProps = {
|
|
143
|
-
alpha: 0,
|
|
144
|
-
y: this.animated.y + this.fadeShift,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
this.hideTween = new Tween(this.animated)
|
|
148
|
-
.to(hideProps, 500)
|
|
149
|
-
.onComplete(() => {
|
|
150
|
-
this.isChecking = true;
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
this.showTween = new Tween(this.animated)
|
|
154
|
-
.to(showProps, 500)
|
|
155
|
-
.onComplete(() => {
|
|
156
|
-
this.timer = new Timer(10000, () => {
|
|
157
|
-
this.hideTween?.start();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
this.showTween.start();
|
|
162
|
-
}
|
|
163
|
-
}
|
package/src/entities/DudeName.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Point, Rect } from '../helpers/types';
|
|
2
|
-
import * as PIXI from 'pixi.js';
|
|
3
|
-
|
|
4
|
-
export type DudeNameProps = {
|
|
5
|
-
name: string;
|
|
6
|
-
position: Point;
|
|
7
|
-
isVisible: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class DudeName {
|
|
11
|
-
public text: PIXI.Text = new PIXI.Text(undefined, {
|
|
12
|
-
fontFamily: 'Rubik',
|
|
13
|
-
fontSize: 18,
|
|
14
|
-
fill: 0xffffff,
|
|
15
|
-
align: 'center',
|
|
16
|
-
lineJoin: 'round',
|
|
17
|
-
strokeThickness: 4,
|
|
18
|
-
stroke: 'black',
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
this.text.anchor.set(0.5, 1);
|
|
23
|
-
this.text.zIndex = 100;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
update(props: DudeNameProps) {
|
|
27
|
-
this.text.text = props.name ?? '';
|
|
28
|
-
this.text.visible = props.isVisible;
|
|
29
|
-
this.text.position.x = props.position.x ?? this.text.position.x;
|
|
30
|
-
this.text.position.y = props.position.y ?? this.text.position.y;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
rect = (): Rect => ({
|
|
34
|
-
x: this.text.x,
|
|
35
|
-
y: this.text.y,
|
|
36
|
-
w: this.text.width,
|
|
37
|
-
h: this.text.height,
|
|
38
|
-
});
|
|
39
|
-
}
|