forked from ForNeVeR/O21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameRules.fs
More file actions
165 lines (117 loc) · 4.23 KB
/
GameRules.fs
File metadata and controls
165 lines (117 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// SPDX-FileCopyrightText: 2025 O21 contributors <https://github.com/ForNeVeR/O21>
//
// SPDX-License-Identifier: MIT
module O21.Game.Engine.GameRules
open System
open O21.Game
open O21.Game.U95
// ----------------------- Screen Constants -----------------------
[<Literal>]
let GameScreenWidth = 600
[<Literal>]
let GameScreenHeight = 400
// ----------------------- Player Constants -----------------------
[<Literal>]
let ShotCooldownTicks = 15
[<Literal>]
let ShotCooldownTicksWithZeroCooldownAbility = 3
[<Literal>]
let MaxPlayerLives = 9
[<Literal>]
let InitialPlayerLives = 5
[<Literal>]
let MaxPlayerVelocity = 3
[<Literal>]
let MaxOxygenUnits = 100
// ----------------------- Level Constants -----------------------
[<Literal>]
let LevelWidth = GameScreenWidth
[<Literal>]
let LevelHeight = 300
// ----------------------- Time Constants -----------------------
[<Literal>]
let TicksPerSecond = 10.0
[<Literal>]
let PostDeathFreezeTicks = 6
[<Literal>]
let OxygenUnitPeriod = 22
[<Literal>]
let BulletLifetime = 10
[<Literal>]
let BulletFromExplosiveLifetime = 15
/// 7 Min
[<Literal>]
let AbilityLifetime = 4200
// ----------------------- Score Constants -----------------------
[<Literal>]
let GivePointsForStaticBonus = 25
[<Literal>]
let GivePointsForLifebuoy = 50
[<Literal>]
let GivePointsForBomb = 20
[<Literal>]
let GivePointsForFish = 10
[<Literal>]
let SubtractPointsForShotBonus = 10
[<Literal>]
let SubtractPointsForShot = 1
[<Literal>]
let SubtractPointsForShotByExplosiveBullet = 5
// ----------------------- Physics Constants -----------------------
[<Literal>]
let BulletVelocity = 5 // TODO[#131]: Compare with the original
[<Literal>]
let ExplosiveBulletVelocity = 7 // TODO[#131]: Compare with the original
let BulletVerticalSpread = Vector(0, 3) // TODO[#236]: Compare with the original
[<Literal>]
let BombVelocity = -5
[<Literal>]
let ParticleSpeed = 3
let ParticlesPeriodRange = [|7..10|]
let ParticlesOffsetRange = [|-2..2|]
// ----------------------- Object Sizes -----------------------
let BrickSize = Vector(12, 12)
let PlayerSize = Vector(46, 27)
let BulletSize = Vector(6, 6)
let ParticleSize = Vector(5, 5)
let FishSizes = [|Vector(25, 25); Vector(25, 25); Vector(25, 25); Vector(25, 25); Vector(25, 25)|]
let BombSize = Vector(20, 20)
let BonusSize = Vector(30, 30)
// ------------------------------ Enemy Constants ------------------------------
let FishKinds: int = FishSizes.Length
let LevelEntryFishSpawnProbability: float = 0.00363 // 0.363%
let FishHorizontalVelocity = [| 3; 4; 5 |]
let FishVerticalVelocity = 5
let BombKinds: int = 5
// ----------------------- Functions -----------------------
/// Relative position of the bullet sprite's top left corner to the player sprite's top corner (from the shooting side)
/// when the bullet appears.
let NewBulletPosition(playerTopForwardCorner: Point, playerDirection: HorizontalDirection) =
match playerDirection with
| HorizontalDirection.Left -> playerTopForwardCorner + Vector(-4 - BulletSize.X, 14)
| HorizontalDirection.Right -> playerTopForwardCorner + Vector(4, 14)
let NewParticlePosition(playerTopForwardCorner: Point, playerDirection: HorizontalDirection) =
match playerDirection with
| HorizontalDirection.Left -> playerTopForwardCorner + Vector(28, -ParticleSize.Y)
| HorizontalDirection.Right -> playerTopForwardCorner + Vector(-28, -ParticleSize.Y)
let ClampVelocity(Vector(x, y)): Vector =
Vector(
Math.Clamp(x, -MaxPlayerVelocity, MaxPlayerVelocity),
Math.Clamp(y, -MaxPlayerVelocity, MaxPlayerVelocity)
)
let GetLevelPosition level (coordinates: int * int) =
Point(LevelWidth / level.LevelMap[0].Length * fst coordinates,
LevelHeight / level.LevelMap.Length * snd coordinates)
// ----------------------- Other Game Constants -----------------------
let StartingLevel = LevelCoordinates(1, 1)
let PlayerStartingPosition = Point(200, 140)
let LevelSizeInTiles = Vector(50, 25)
let BombTriggerOffset = -15
let LifebuoySpawnProbability = 0.2 // TODO[#237]: Compare with the original
let LifeBonusSpawnProbability = seq {
yield 0.
yield! [|0.25; 0.125;|]
yield! Array.create 7 0.0625
while true do yield 0.
} // TODO[#238]: Compare with the original
let StaticBonusKinds = 10