-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.fs
85 lines (69 loc) · 2.44 KB
/
Game.fs
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
(*
MonoGame game class overrides
*)
module Game
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Content
open Microsoft.Xna.Framework.Graphics
open Media
open Rendering
open Networking
open Logic
type PlutusGame () as context =
inherit Game ()
let mutable graphics = new GraphicsDeviceManager (context)
let mutable viewport = Unchecked.defaultof<Viewport>
let mutable spriteBatch = Unchecked.defaultof<SpriteBatch>
let mutable state = State.Zero
override context.Initialize () =
do context.Content.RootDirectory <- "Content"
do graphics.GraphicsProfile <- GraphicsProfile.HiDef
do viewport <- graphics.GraphicsDevice.Viewport
do spriteBatch <- new SpriteBatch (context.GraphicsDevice)
//Disable window resizing
do base.Window.AllowUserResizing <- false
//Initialize networking
do state <- State.StartNetworking state
base.Initialize ()
()
override context.LoadContent () =
//Load the textures
do state <- State.LoadAssets context.Content state
base.LoadContent ()
()
override context.Update gameTime =
let dt = (float gameTime.ElapsedGameTime.TotalSeconds) * 1.0
base.Update gameTime
//Update the game state
state <- State.Update state dt
//Check if the user has requested to quit
if state.ExitFlag then
do State.StopNetworking state
base.Exit ()
()
override context.Draw gameTime =
context.GraphicsDevice.Clear Color.Black
spriteBatch.Begin()
renderBackground
"Space"
state.Textures
viewport
spriteBatch
//Render everything in the state's render collection
List.iter
(fun rd ->
match rd with
| EntityRD (textureName, position, orientation, radius, frame) ->
renderEntity
textureName
position
orientation
radius
frame
state.Textures
spriteBatch
viewport
| _ -> printfn "Unhandled render data: %A" rd ) state.RenderCollection
spriteBatch.End()
base.Draw gameTime
()