Fix reveal mechanic
This commit is contained in:
parent
4639c22025
commit
76875e8ee1
4 changed files with 19 additions and 14 deletions
11
src/area.ts
11
src/area.ts
|
|
@ -1,7 +1,18 @@
|
||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
import { mp5 } from '../main';
|
||||||
|
|
||||||
export const revealedArea$ = new BehaviorSubject<{ x: number; y: number; w: number }>({
|
export const revealedArea$ = new BehaviorSubject<{ x: number; y: number; w: number }>({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
w: 0,
|
w: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export function pointIsRevealed(
|
||||||
|
point: { x: number; y: number },
|
||||||
|
revealedArea: { x: number; y: number; w: number }
|
||||||
|
): boolean {
|
||||||
|
const distanceBetweenPoints = mp5.dist(point.x, point.y, revealedArea.x, revealedArea.y);
|
||||||
|
console.log(distanceBetweenPoints, revealedArea.w);
|
||||||
|
|
||||||
|
return distanceBetweenPoints < revealedArea.w / 2;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,6 @@ export function isColliding(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shapeCollision(
|
|
||||||
firstShape: { x: number; y: number; w: number },
|
|
||||||
secondShape: { x: number; y: number; w: number }
|
|
||||||
) {
|
|
||||||
return mp5.dist(firstShape.x, firstShape.y, secondShape.x, secondShape.y) < secondShape.w - 150;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateEdgeCoords(existingEdges: Edge[]): Coordinates {
|
export function generateEdgeCoords(existingEdges: Edge[]): Coordinates {
|
||||||
let newCoords: Coordinates;
|
let newCoords: Coordinates;
|
||||||
const existingCoordinates = existingEdges.map(({ x, y }) => ({ x, y }));
|
const existingCoordinates = existingEdges.map(({ x, y }) => ({ x, y }));
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { asyncScheduler, distinct, distinctUntilKeyChanged, throttleTime } from 'rxjs';
|
import { map } from 'rxjs';
|
||||||
import { mp5 } from '../../main';
|
import { mp5 } from '../../main';
|
||||||
import { revealedArea$ } from '../area';
|
import { pointIsRevealed, revealedArea$ } from '../area';
|
||||||
import { colors } from '../constants/colors';
|
import { colors } from '../constants/colors';
|
||||||
import { shapeCollision } from '../helpers';
|
|
||||||
|
|
||||||
export class Package {
|
export class Package {
|
||||||
x: number;
|
x: number;
|
||||||
|
|
@ -16,8 +15,10 @@ export class Package {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
|
|
||||||
revealedArea$.subscribe((revealedArea) => {
|
revealedArea$
|
||||||
this.revealed = shapeCollision({ x: this.x, y: this.y, w: 10 }, revealedArea);
|
.pipe(map((revealedArea) => pointIsRevealed({ x: this.x, y: this.y }, revealedArea)))
|
||||||
|
.subscribe((isRevealed) => {
|
||||||
|
this.revealed = isRevealed;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export class Player {
|
||||||
if (this.showRevealEl) {
|
if (this.showRevealEl) {
|
||||||
const x = this.cursorOnRevealClick.x;
|
const x = this.cursorOnRevealClick.x;
|
||||||
const y = this.cursorOnRevealClick.y;
|
const y = this.cursorOnRevealClick.y;
|
||||||
const w = Math.floor(timeElapsedSinceRevealClick * 0.4);
|
const w = timeElapsedSinceRevealClick * 0.4;
|
||||||
|
|
||||||
mp5.fill(mp5.color(colors.greyLighter));
|
mp5.fill(mp5.color(colors.greyLighter));
|
||||||
mp5.strokeWeight(5);
|
mp5.strokeWeight(5);
|
||||||
|
|
|
||||||
Reference in a new issue