Set up overview screen with click handlers
This commit is contained in:
parent
a4bb1655d0
commit
954cc1fe72
7 changed files with 93 additions and 8 deletions
42
src/scenes/OverviewScene.ts
Normal file
42
src/scenes/OverviewScene.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { mp5 } from '../../main';
|
||||
import { Player } from '../Player';
|
||||
import { colors } from '../constants/colors';
|
||||
import { Edge } from '../Edge';
|
||||
|
||||
export class OverviewScene {
|
||||
player: Player;
|
||||
edgeData: Array<{ x: number; y: number; r: number }>;
|
||||
edges: Edge[];
|
||||
|
||||
constructor() {
|
||||
this.edgeData = [
|
||||
{ x: 100, y: 100, r: 50 },
|
||||
{ x: 900, y: 400, r: 100 },
|
||||
{ x: 300, y: 600, r: 75 },
|
||||
];
|
||||
this.edges = this.edgeData.map((edge) => new Edge(edge.x, edge.y, edge.r));
|
||||
this.player = new Player();
|
||||
}
|
||||
|
||||
public draw() {
|
||||
mp5.background(mp5.color(colors.greyLighter));
|
||||
|
||||
this.player.follow();
|
||||
this.drawLocations();
|
||||
this.player.move();
|
||||
}
|
||||
|
||||
public onSceneClick() {
|
||||
console.log('Click on scene');
|
||||
this.edges.forEach((edgeShape, i) => {
|
||||
const dist = mp5.dist(mp5.mouseX, mp5.mouseY, edgeShape.x, edgeShape.y);
|
||||
if (dist < edgeShape.r) {
|
||||
console.log(`Click on edge ${i}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private drawLocations() {
|
||||
this.edges.forEach((edgeShape) => edgeShape.draw());
|
||||
}
|
||||
}
|
||||
Reference in a new issue