-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import GoldTriangle from 'modules/GameEngine/Drawing/Particles/GoldTriangle'; | ||
import { randomInt } from 'modules/utils/randomValue'; | ||
import tinycolor from 'tinycolor2'; | ||
import ParticleManager from '../ParticleManager'; | ||
import Particle from '../interfaces'; | ||
import styles from '../styles'; | ||
|
||
export default class GoldNoteParticle implements Particle { | ||
public finished = true; | ||
|
||
constructor( | ||
x: number, | ||
y: number, | ||
width: number, | ||
playerNumber: 0 | 1 | 2 | 3, | ||
particleManager: typeof ParticleManager, | ||
) { | ||
const color = styles.colors.players[playerNumber].starPerfect.fill; | ||
|
||
const lightColor = tinycolor(color).lighten(15).toRgbString(); | ||
const darkColor = tinycolor(color).darken(15).toRgbString(); | ||
|
||
if (Math.random() > 0.85) { | ||
const position = randomInt(0, width / 8); | ||
|
||
const rand = Math.random(); | ||
let finalColor = color; | ||
if (rand > 0.66) finalColor = lightColor; | ||
else if (rand > 0.33) finalColor = darkColor; | ||
|
||
const finalY = y + 20 * (Math.random() - 0.5); | ||
|
||
particleManager.add(new GoldTriangle(x + position * 8, finalY, finalColor)); | ||
} | ||
} | ||
public tick = (ctx: CanvasRenderingContext2D, canvas: HTMLCanvasElement) => {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import debris from 'modules/GameEngine/Drawing/Elements/debris'; | ||
import spreadValue from 'modules/GameEngine/Drawing/Particles/utils'; | ||
import Particle from '../interfaces'; | ||
|
||
const baseTtlMs = 500; | ||
const ttlSpreadMs = 100; | ||
|
||
const velocityModifier = 0.2; | ||
|
||
export default class GoldTriangle implements Particle { | ||
public finished = false; | ||
|
||
private ttl; | ||
private startingTtl; | ||
private velocityX; | ||
private velocityY; | ||
private width; | ||
private initialAngle; | ||
private heightModifier; | ||
|
||
constructor( | ||
private x: number, | ||
private y: number, | ||
private color: string, | ||
) { | ||
this.startingTtl = this.ttl = spreadValue(baseTtlMs, ttlSpreadMs); | ||
this.velocityX = velocityModifier * Math.random() - velocityModifier / 2; | ||
this.velocityY = velocityModifier * Math.random() - velocityModifier / 2; | ||
this.width = 25; | ||
this.initialAngle = 180 - Math.random() * 360; | ||
this.heightModifier = 0.5 + Math.random() / 2; | ||
} | ||
public tick = (ctx: CanvasRenderingContext2D, canvas: HTMLCanvasElement, delta: number) => { | ||
const percentage = 1 - this.ttl / this.startingTtl; | ||
const ticksLeft = this.startingTtl - this.ttl; | ||
|
||
const width = this.width * percentage; | ||
const height = this.width * this.heightModifier * percentage; | ||
|
||
const x = this.x - width / 2 + ticksLeft * this.velocityX; | ||
const y = this.y + height / 2 + ticksLeft * this.velocityY; | ||
|
||
debris(canvas, ctx, x, y, width, height, this.initialAngle + ticksLeft, this.color, 0.5 * percentage); | ||
|
||
this.ttl = this.ttl - delta; | ||
this.finished = this.ttl <= 0; | ||
}; | ||
} |