1- import { Engine , World , Bodies , Vector , Composite , Body , Events } from "matter-js" ;
1+ import { Engine , World , Bodies , Vector , Body , Events } from "matter-js" ;
22import { throwReturn } from "../../core/common" ;
33import { GameAI } from "../gameAi/GameAi" ;
44import { createSensorExecutor , SensorExecutor } from "./sensors" ;
@@ -41,15 +41,15 @@ export type GameInput = {
4141
4242
4343export enum EGameStateObjectType {
44- player , bullet , wall
44+ player , bullet , wall ,
4545}
4646
4747export type GameStateObject = {
4848 /** engine body */
4949 body : Body ,
5050 type : EGameStateObjectType ,
5151 health : number ,
52- }
52+ } ;
5353
5454export type GameStatePlayer = GameStateObject & {
5555 type : EGameStateObjectType . player ,
@@ -176,11 +176,11 @@ export class Game {
176176 let vec = Vector . rotate ( Vector . create ( 1 , 0 ) , body . angle ) ;
177177 vec = Vector . mult ( vec , 5 ) ;
178178 Body . setVelocity ( body , vec ) ;
179- player . health -= .0005
179+ player . health -= .0005 ;
180180 }
181181 if ( x . rotate !== 0 ) {
182182 Body . setAngularVelocity ( body , x . rotate * .3 ) ;
183- player . health -= Math . abs ( x . rotate ) * .005
183+ player . health -= Math . abs ( x . rotate ) * .005 ;
184184 }
185185 if ( x . use ) {
186186 this . use ( player ) ;
@@ -211,14 +211,14 @@ export class Game {
211211 } else if ( alivePlayers . length === 0 ) {
212212 this . gameState . winner = - 2 ;
213213 }
214- } ;
214+ }
215215
216216 private processBullets ( ) {
217217 const { gameState : { bullets } } = this ;
218218 // todo: based on current step delta
219- bullets . forEach ( x => { x . health -= .01 } ) ;
219+ bullets . forEach ( x => { x . health -= .01 ; } ) ;
220220
221- bullets . map ( x => {
221+ bullets . forEach ( x => {
222222 const { body, health } = x ;
223223 const { speed, velocity } = body ;
224224
@@ -233,12 +233,14 @@ export class Game {
233233 const bulletSize = 5 ;
234234 const itemCooldown = 2000 ;
235235
236- // todo: check ammo
236+ // todo: check ammo
237237 const { body : { position, angle } , item } = player ;
238238 const { gameState : { bullets } , settings : { game : { playerSize } } } = this ;
239239
240- if ( item . cooldown !== 0 )
240+ if ( item . cooldown !== 0 ) {
241+ player . health -= .2 ;
241242 return ;
243+ }
242244 item . cooldown = itemCooldown ;
243245
244246 const distance = playerSize + bulletSize + 1 ;
@@ -257,9 +259,7 @@ export class Game {
257259 type : EGameStateObjectType . bullet ,
258260 health : 1 ,
259261 body,
260- } )
261-
262- player . health -= .1 ;
262+ } ) ;
263263 }
264264
265265 // todo: move all sensor related things into GameAI folder
@@ -294,17 +294,17 @@ export class Game {
294294 player . health -= damage ;
295295 bullet . health -= damage ;
296296 } else if ( objects [ 1 ] . type === EGameStateObjectType . bullet ) {
297- objects . forEach ( x => x . health /= 2 )
297+ objects . forEach ( x => x . health /= 2 ) ;
298298 }
299299 }
300- }
300+ } ;
301301
302302 pairs . forEach ( processColisionPair ) ;
303303 }
304304
305305 constructor ( userSettings : Partial < GameSettings > = { } ) {
306306 const settings = this . settings = mergeSettings ( Game . SETTINGS_DEFAULT , userSettings ) ;
307- // create engine (as any for ignoring deprecated warning
307+ // create engine (as any for ignoring deprecated warning
308308 // - no other function to create engine known)
309309 this . engine = ( Engine as any ) . create ( ) ;
310310 const world = this . world ;
@@ -345,7 +345,7 @@ export class Game {
345345 timeRemaining : settings . game . maxGameLength ,
346346 } ;
347347
348- Events . on ( this . engine , "collisionStart" , this . onCollision . bind ( this ) )
348+ Events . on ( this . engine , "collisionStart" , this . onCollision . bind ( this ) ) ;
349349
350350 this . sensorExecutor = createSensorExecutor ( this ) ;
351351 }
0 commit comments