Skip to content

Commit 1e1f2bd

Browse files
committed
lighting trail and interval
1 parent 1a933e7 commit 1e1f2bd

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

base/battle/BattleAnimation.ts

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
random_normal,
5252
get_distance,
5353
cumsum,
54+
promised_wait,
5455
} from "../utils";
5556
import {BattleStage, DEFAULT_POS_ANGLE} from "./BattleStage";
5657
import * as _ from "lodash";
@@ -305,13 +306,16 @@ export class BattleAnimation {
305306
};
306307
roughness: number;
307308
count: number;
309+
interval_time: number | number[];
308310
render_position: battle_positions;
309311
ignore_if_dodge?: boolean;
312+
trail: boolean;
313+
trail_factor: number;
310314
duration: number;
311315
}[] = [];
312316
public particles_sequence: ParticlesInfo;
313317
public running: boolean;
314-
public sprites: (Phaser.Sprite | Phaser.Graphics | Phaser.TileSprite | PlayerSprite)[];
318+
public sprites: (Phaser.Sprite | Phaser.Graphics | Phaser.TileSprite | PlayerSprite | Phaser.Image)[];
315319
public sprites_prev_properties: {
316320
[key: string]: {
317321
[property: string]: any;
@@ -1349,13 +1353,25 @@ export class BattleAnimation {
13491353
const thickness_base_value = lighting_seq.thickness?.base_value ?? 1;
13501354
const thickness_range_delta = lighting_seq.thickness?.range_delta ?? 0;
13511355
const count = lighting_seq.count ?? 1;
1352-
for (let i = 0; i < count; ++i) {
1356+
const trail = lighting_seq.trail ?? true;
1357+
const trail_factor = lighting_seq.trail_factor ?? 0.5;
1358+
const duration = _.clamp(lighting_seq.duration, 30, Infinity);
1359+
for (let j = 0; j < count; ++j) {
13531360
let resolve_function;
13541361
const this_promise = new Promise(resolve => {
13551362
resolve_function = resolve;
13561363
});
13571364
this.promises.push(this_promise);
1365+
let interval_time = 0;
1366+
if (lighting_seq.count > 1 && lighting_seq.interval_time) {
1367+
interval_time = Array.isArray(lighting_seq.interval_time)
1368+
? lighting_seq.interval_time[j]
1369+
: lighting_seq.interval_time * j;
1370+
}
13581371
const cast_lighting = async () => {
1372+
if (interval_time > 30) {
1373+
await promised_wait(this.game, interval_time);
1374+
}
13591375
const calcualted_from = {
13601376
x: from.x + _.random(-pos_range_delta.x, pos_range_delta.x, true),
13611377
y: from.y + _.random(-pos_range_delta.y, pos_range_delta.y, true),
@@ -1375,17 +1391,33 @@ export class BattleAnimation {
13751391
const dist = get_distance(calcualted_from.x, calcualted_to.x, calcualted_from.y, calcualted_to.y);
13761392
const data_size = dist | 0;
13771393

1378-
const group = this.ability_sprites_groups[lighting_seq.render_position ?? battle_positions.BETWEEN];
1394+
const group_pos = lighting_seq.render_position ?? battle_positions.BETWEEN;
1395+
const group = this.ability_sprites_groups[group_pos];
13791396
const img = this.game.add.image(0, 0, undefined, undefined, group);
13801397
const bmp = this.game.add.bitmapData(numbers.GAME_WIDTH, numbers.GAME_HEIGHT);
13811398
bmp.smoothed = false;
13821399
bmp.add(img);
13831400
bmp.clear();
1401+
this.sprites.push(img);
1402+
1403+
if (trail) {
1404+
const trail_bitmap_data = this.game.make.bitmapData(numbers.GAME_WIDTH, numbers.GAME_HEIGHT);
1405+
trail_bitmap_data.smoothed = false;
1406+
trail_bitmap_data.fill(0, 0, 0, 1);
1407+
trail_bitmap_data.trail_factor = trail_factor;
1408+
const trail_image = this.game.make.image(0, 0, trail_bitmap_data);
1409+
trail_image.blendMode = Phaser.blendModes.SCREEN;
1410+
this.trails_bmps.push(trail_bitmap_data);
1411+
this.trails_objs.push(trail_image);
1412+
this.ability_sprites_groups[group_pos].addChild(trail_image);
1413+
img.data.trail_image = trail_image;
1414+
img.data.trail_enabled = true;
1415+
}
13841416

13851417
const y_data = cumsum(random_normal(data_size, lighting_seq.roughness ?? 0.01, 0));
1386-
for (let i = 0; i < data_size; ++i) {
1387-
const x = calcualted_from.x + (dist * i) / data_size;
1388-
const y = calcualted_from.y + dist * y_data[i];
1418+
for (let k = 0; k < data_size; ++k) {
1419+
const x = calcualted_from.x + (dist * k) / data_size;
1420+
const y = calcualted_from.y + dist * y_data[k];
13891421
const rot_x =
13901422
(x - calcualted_from.x) * cast_angle_cos -
13911423
(y - calcualted_from.y) * cast_angle_sin +
@@ -1399,7 +1431,6 @@ export class BattleAnimation {
13991431

14001432
bmp.context.putImageData(bmp.imageData, 0, 0);
14011433

1402-
const duration = _.clamp(lighting_seq.duration, 30, Infinity);
14031434
this.game.time.events.add(duration, () => {
14041435
bmp.destroy();
14051436
img.destroy();
@@ -1410,7 +1441,7 @@ export class BattleAnimation {
14101441
if (!Array.isArray(start_delay) && typeof start_delay === "object") {
14111442
start_delay = this.get_expanded_values(start_delay as CompactValuesSpecifier, count);
14121443
}
1413-
start_delay = Array.isArray(start_delay) ? start_delay[i] : (start_delay as number) ?? 0;
1444+
start_delay = Array.isArray(start_delay) ? start_delay[j] : (start_delay as number) ?? 0;
14141445
if (start_delay < 30) {
14151446
cast_lighting();
14161447
} else {

base/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export function random_normal(n = 1, sigma = 1, mu = 0) {
505505
const u2 = Math.random();
506506
const r = Math.sqrt(-2 * Math.log(u1));
507507
const theta = 2 * Math.PI * u2;
508-
const rnd = mu + sigma * r * Math.cos(theta);
508+
const rnd = mu + sigma * r * (i % 0 ? Math.cos(theta) : Math.sin(theta));
509509
out[i] = rnd;
510510
}
511511
return out;

0 commit comments

Comments
 (0)