1- import {
2- World ,
3- Circle ,
4- Polygon ,
5- Vec2Value ,
6- Contact ,
7- Body ,
8- Settings ,
9- } from "planck" ;
1+ import { World , Circle , Polygon , Vec2Value , Contact , Body , Settings } from "planck" ;
102
113import { Dataset , Driver , Middleware } from "polymatic" ;
4+
125import { MainContext } from "./Main" ;
136import { FrameLoopEvent } from "./FrameLoop" ;
14-
15- export interface Ball {
16- type : "ball" ;
17- key : string ;
18- position : { x : number ; y : number } ;
19- radius : number ;
20- color : string ;
21- }
22-
23- export interface Rail {
24- type : "rail" ;
25- key : string ;
26- vertices : Vec2Value [ ] | undefined ;
27- }
28-
29- export interface Table {
30- type : "table" ;
31- key : string ;
32- width : number ;
33- height : number ;
34- }
35-
36- export interface Pocket {
37- type : "pocket" ;
38- key : string ;
39- position : { x : number ; y : number } ;
40- radius : number ;
41- }
7+ import { Ball , Pocket , Rail } from "./Data" ;
428
439export type Entity = Ball | Rail | Pocket ;
4410
@@ -73,11 +39,7 @@ export class Physics extends Middleware<MainContext> {
7339 }
7440
7541 handleFrameLoop ( ev : FrameLoopEvent ) {
76- this . dataset . data ( [
77- ...this . context . balls ,
78- ...this . context . rails ,
79- ...this . context . pockets ,
80- ] ) ;
42+ this . dataset . data ( [ ...this . context . balls , ...this . context . rails , ...this . context . pockets ] ) ;
8143 this . time += ev . dt ;
8244 while ( this . time >= this . timeStep ) {
8345 this . time -= this . timeStep ;
@@ -96,16 +58,12 @@ export class Physics extends Middleware<MainContext> {
9658
9759 if ( ! dataA || ! dataB ) return ;
9860
99- const ball =
100- dataA . type === "ball" ? dataA : dataB . type === "ball" ? dataB : null ;
101- const pocket =
102- dataA . type === "pocket" ? dataA : dataB . type === "pocket" ? dataB : null ;
61+ const ball = dataA . type === "ball" ? dataA : dataB . type === "ball" ? dataB : null ;
62+ const pocket = dataA . type === "pocket" ? dataA : dataB . type === "pocket" ? dataB : null ;
10363
10464 if ( ball && pocket ) {
10565 // do not change world immediately
106- this . world . queueUpdate ( ( ) =>
107- this . emit ( "ball-in-pocket" , { ball, pocket } )
108- ) ;
66+ this . world . queueUpdate ( ( ) => this . emit ( "ball-in-pocket" , { ball, pocket } ) ) ;
10967 }
11068 } ;
11169
0 commit comments