1
1
import { getExnFromStrictNull } from "commonlib-ts/src/NullableUtils" ;
2
2
import { state as flyComponentState } from "./FlyComponentStateType"
3
- import { getPositionComponentExn , getVelocityComponentExn } from "../gameObject/GameObject" ;
3
+ import * as GameObject from "../gameObject/GameObject" ;
4
4
import { getGameObjectStateExn , setPositionComponentState } from "../utils/WorldUtils" ;
5
5
import { state as worldState } from "../world/WorldStateType" ;
6
- import { getVelocity } from "./VelocityComponent" ;
7
- import { getPosition , setPosition } from "./PositionComponent" ;
6
+ import * as VelocityComponent from "./VelocityComponent" ;
7
+ import * as PositionComponent from "./PositionComponent" ;
8
8
9
9
export let create = ( ) : flyComponentState => {
10
10
let flyComponentState : flyComponentState = {
@@ -27,20 +27,21 @@ export let setMaxVelocity = (flyComponentState: flyComponentState, maxVelocity)
27
27
}
28
28
29
29
export let fly = ( worldState : worldState , flyComponentState : flyComponentState ) : worldState => {
30
- let maxVelocity = flyComponentState . maxVelocity
31
-
30
+ //获得该组件的maxVelocity、gameObject
31
+ let maxVelocity = getMaxVelocity ( flyComponentState )
32
32
let gameObject = getExnFromStrictNull ( flyComponentState . gameObject )
33
- let gameObjectState = getGameObjectStateExn ( worldState , gameObject )
34
33
35
- //通过gameObject获得positionComponent,获得它的position
36
- let [ x , y , z ] = getPosition ( getPositionComponentExn ( gameObjectState ) )
34
+ //通过该组件的gameObject,获得挂载到该gameObject的positionComponent组件
35
+ //获得它的position
36
+ let [ x , y , z ] = PositionComponent . getPosition ( GameObject . getPositionComponentExn ( getGameObjectStateExn ( worldState , gameObject ) ) )
37
37
38
- //通过gameObject获得velocityComponent,获得它的velocity
39
- let velocity = getVelocity ( getVelocityComponentExn ( gameObjectState ) )
38
+ //通过该组件的gameObject,获得挂载到该gameObject的velocityComponent组件
39
+ //获得它的velocity
40
+ let velocity = VelocityComponent . getVelocity ( GameObject . getVelocityComponentExn ( getGameObjectStateExn ( worldState , gameObject ) ) )
40
41
42
+ //根据maxVelocity、velocity,更新positionComponent组件的position
41
43
velocity = velocity < maxVelocity ? ( velocity * 2.0 ) : maxVelocity
42
-
43
- let positionComponentState = setPosition ( getPositionComponentExn ( gameObjectState ) , [ x + velocity , y + velocity , z + velocity ] )
44
+ let positionComponentState = PositionComponent . setPosition ( GameObject . getPositionComponentExn ( getGameObjectStateExn ( worldState , gameObject ) ) , [ x + velocity , y + velocity , z + velocity ] )
44
45
45
46
return setPositionComponentState ( worldState , gameObject , positionComponentState )
46
47
}
0 commit comments