@@ -23,7 +23,7 @@ type Fish = {
2323 TopLeft: Point
2424 Type: int
2525 /// The current velocity the fish will be moving in the designated direction.
26- AbsoluteVelocity : int
26+ HorizontalVelocity : int
2727 HorizontalDirection: HorizontalDirection
2828 VerticalDirection: VerticalDirection
2929} with
@@ -34,7 +34,7 @@ type Fish = {
3434 Array.append [| fishEnv.PlayerCollider|] fishEnv.BulletColliders
3535 match CheckCollision fishEnv.Level this.Box entities with
3636 | Collision.None ->
37- let newFish = this.WithNextPosition fishEnv.Level
37+ let newFish = this.WithNextPosition fishEnv.Level fishEnv.Random
3838 EnemyEffect.Update newFish
3939 | Collision.OutOfBounds ->
4040 EnemyEffect.Despawn
@@ -44,7 +44,7 @@ type Fish = {
4444 | Collision.CollidesObject _ ->
4545 EnemyEffect.PlayerHit this.Id
4646
47- member private this.WithNextPosition level : Fish =
47+ member private this.WithNextPosition level random : Fish =
4848 // TODO[#27]: Stick to the wall if there's any space (so that we should move as close to it as possible).
4949 let checkState ( state : Fish ) =
5050 match CheckCollision level state.Box Array.empty with
@@ -55,14 +55,14 @@ type Fish = {
5555 let newDirection = if keepDirection then this.HorizontalDirection else this.HorizontalDirection.Invert()
5656 let newState = {
5757 this with
58- TopLeft = this.TopLeft.Move( newDirection, this.AbsoluteVelocity )
58+ TopLeft = this.TopLeft.Move( newDirection, this.HorizontalVelocity )
5959 HorizontalDirection = newDirection
6060 }
6161 checkState newState
6262
6363 let moveVertically ( dir : VerticalDirection ) =
6464 { this with
65- TopLeft = this.TopLeft.Move( dir, this.AbsoluteVelocity )
65+ TopLeft = this.TopLeft.Move( dir, GameRules.FishVerticalVelocity )
6666 VerticalDirection = dir } |> checkState
6767
6868 // Returns length of the wall ahead and whether there's an open path
@@ -73,14 +73,14 @@ type Fish = {
7373 match CheckCollision level { fish.Box with TopLeft = nextPoint } Array.empty with
7474 | Collision.CollidesBrick ->
7575 let beforeBrick =
76- nextPoint.Move( fish.HorizontalDirection.Invert(), fish.AbsoluteVelocity )
76+ nextPoint.Move( fish.HorizontalDirection.Invert(), fish.HorizontalVelocity )
7777 match CheckCollision level { fish.Box with TopLeft = beforeBrick } Array.empty with
7878 | Collision.None -> count ( n + 1 ) nextPoint
7979 | _ -> struct ( n, false )
8080 | Collision.None ->
8181 struct ( n, true )
8282 | _ -> struct ( n, false )
83- count 0 ( fish.TopLeft.Move( fish.HorizontalDirection, fish.AbsoluteVelocity ))
83+ count 0 ( fish.TopLeft.Move( fish.HorizontalDirection, fish.HorizontalVelocity ))
8484
8585 let chooseDirectionOnWallCollision () =
8686 let struct ( lengthUp , isOpenPathUp ) = wallAheadInfo this level VerticalDirection.Up
@@ -99,6 +99,10 @@ type Fish = {
9999 moveVertically VerticalDirection.Down
100100 | _ -> None // Short wall (barrier), the next functions handle it
101101
102+ let updateVelocityOnDirectionChange ( fish : Fish ) =
103+ if fish.HorizontalDirection = this.HorizontalDirection then fish
104+ else { fish with HorizontalVelocity = random.RandomChoice GameRules.FishHorizontalVelocity }
105+
102106 moveHorizontally true
103107 |> Option.orElseWith( fun () ->
104108 chooseDirectionOnWallCollision())
@@ -107,13 +111,14 @@ type Fish = {
107111 |> Option.orElseWith( fun () ->
108112 moveVertically ( this.VerticalDirection.Invert()))
109113 |> Option.defaultValue this
114+ |> updateVelocityOnDirectionChange
110115
111116
112117 static member Default = {
113118 Id = Guid.Empty
114119 TopLeft = Point( 0 , 0 )
115120 Type = 0
116- AbsoluteVelocity = GameRules.FishBaseVelocity
121+ HorizontalVelocity = Array.head GameRules.FishHorizontalVelocity
117122 HorizontalDirection = HorizontalDirection.Right
118123 VerticalDirection = VerticalDirection.Up
119124 }
@@ -125,7 +130,7 @@ type Fish = {
125130 Id = Guid.NewGuid()
126131 TopLeft = position
127132 Type = random.NextExcluding GameRules.FishKinds
128- AbsoluteVelocity = GameRules.FishBaseVelocity
133+ HorizontalVelocity = random.RandomChoice GameRules.FishHorizontalVelocity
129134 HorizontalDirection = direction
130135 }
131136
@@ -134,7 +139,7 @@ type Fish = {
134139 Id = Guid.NewGuid()
135140 TopLeft = topLeft
136141 Type = `` type ``
137- AbsoluteVelocity = velocity
142+ HorizontalVelocity = velocity
138143 HorizontalDirection = direction
139144 }
140145
0 commit comments