Created
September 8, 2020 01:50
-
-
Save Tombert/562030af55582bc6b8d0f0ad3aa78ed0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open Microsoft.Xna.Framework | |
open Microsoft.Xna.Framework.Input | |
open Microsoft.Xna.Framework.Graphics | |
type FNAGame() as self = | |
inherit Game() | |
let mutable gdm = new GraphicsDeviceManager(self) | |
let mutable keyboardPrev = new KeyboardState() | |
let mutable mousePrev = new MouseState() | |
let mutable gpPrev = new GamePadState() | |
let mutable batch: SpriteBatch option = None | |
let mutable texture : Texture2D option = None | |
do | |
self.Content.RootDirectory <- "Content" | |
gdm.PreferredBackBufferWidth <- 1280; | |
gdm.PreferredBackBufferHeight <- 720; | |
gdm.IsFullScreen <-false; | |
gdm.SynchronizeWithVerticalRetrace <- true | |
override this.Initialize() = base.Initialize(); | |
override this.LoadContent() = | |
batch <- Some (new SpriteBatch(self.GraphicsDevice)) | |
texture <- Some (self.Content.Load<Texture2D>("FNATexture")) | |
base.LoadContent() | |
override this.UnloadContent() = | |
match batch with | |
| Some x -> x.Dispose() | |
| None -> () | |
match texture with | |
| Some x -> x.Dispose() | |
| None -> () | |
base.UnloadContent() | |
override this.Update gameTime = | |
let keyboardCur = Keyboard.GetState() | |
let mouseCur = Mouse.GetState(); | |
let gpCur = GamePad.GetState(PlayerIndex.One); | |
if (keyboardCur.IsKeyDown(Keys.Space) && keyboardPrev.IsKeyUp(Keys.Space)) then | |
System.Console.WriteLine "Space bar was pressed!" | |
if (mouseCur.RightButton = ButtonState.Released && mousePrev.RightButton = ButtonState.Pressed) then | |
System.Console.WriteLine "Right mouse button was released!" | |
if (gpCur.Buttons.A = ButtonState.Pressed && gpPrev.Buttons.A = ButtonState.Pressed) then | |
System.Console.WriteLine "A button is being held!" | |
keyboardPrev <- keyboardCur; | |
mousePrev <- mouseCur; | |
gpPrev <- gpCur; | |
base.Update(gameTime); | |
override this.Draw gameTime = | |
self.GraphicsDevice.Clear(Color.CornflowerBlue) | |
(Option.map2 (fun (batch : SpriteBatch) (texture: Texture2D) -> | |
batch.Begin(); | |
batch.Draw(texture, Vector2.Zero, Color.White) | |
batch.End(); | |
) batch texture) | |
|> ignore | |
base.Draw(gameTime); | |
[<EntryPoint>] | |
let main argv = | |
printfn "Hello World from F#!" | |
use g = new FNAGame() | |
g.Run(); | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment