1- import { Container , Graphics , Point , Ticker } from "pixi.js" ;
1+ import {
2+ Container ,
3+ Graphics ,
4+ HTMLText ,
5+ Point ,
6+ TextStyle ,
7+ Ticker ,
8+ } from "pixi.js" ;
29import QubitPiece from "./QubitPiece" ;
310import {
411 BOARD_HEIGHT ,
512 BOARD_WIDTH ,
613 CELL_SIZE ,
714 PIECE_RADIUS ,
15+ TEXT_FONT ,
816} from "../constants" ;
917import { range , uniqWith } from "lodash-es" ;
1018import type { Piece } from "./Deck" ;
@@ -17,6 +25,7 @@ import MeasurementPiece from "./MeasurementPiece";
1725import { playScoreSound , playSound } from "../audio" ;
1826import QubitPair from "./QubitPair" ;
1927import GatePiece from "./GatePiece" ;
28+ import { animate } from "motion" ;
2029
2130export const startingCell = new Point ( Math . floor ( BOARD_WIDTH / 2 - 1 ) , 0 ) ;
2231const RECT_MARGIN = PIECE_RADIUS / 2 ;
@@ -202,6 +211,7 @@ export default class Board extends GameNode {
202211 this . drawLine ( point , nbr , current . base ) ;
203212 qubit . bounce ( ) ;
204213 measuredQubits . push ( nbr ) ;
214+ this . pingScore ( nbr , measuredQubits . length ) ;
205215 scoreToAdd += measuredQubits . length ;
206216 newQueue . push ( nbr ) ;
207217 } else {
@@ -264,6 +274,33 @@ export default class Board extends GameNode {
264274 await delay ( 150 ) ;
265275 } while ( anyFalling ) ;
266276 }
277+
278+ async pingScore ( position : Point , score : number ) {
279+ if ( ! ( this . current instanceof MeasurementPiece ) ) {
280+ return ;
281+ }
282+ const coords = getBlochCoords ( this . current . base ) ;
283+ const text = new HTMLText ( {
284+ text : `${ score * 100 } ` ,
285+ style : new TextStyle ( {
286+ fontSize : 24 + 2 * score ,
287+ fontFamily : TEXT_FONT ,
288+ fontWeight : "bold" ,
289+ fill : getColor ( coords ) ,
290+ stroke : { color : getSecondaryColor ( coords ) , width : 4 } ,
291+ } ) ,
292+ } ) ;
293+ text . anchor = { x : 0.5 , y : 0.5 } ;
294+ text . position = this . gridToLocal ( position ) ;
295+ text . alpha = 0 ;
296+ this . view . addChild ( text ) ;
297+ await animate ( [
298+ [ text . position , { y : text . position . y - CELL_SIZE / 2 } ] ,
299+ [ text , { alpha : 1 } , { at : 0 } ] ,
300+ [ text , { alpha : 0 } , { delay : 0.25 } ] ,
301+ ] ) ;
302+ this . view . removeChild ( text ) ;
303+ }
267304}
268305
269306export function inBounds ( p : Point ) {
0 commit comments