Skip to content

Instantly share code, notes, and snippets.

@jdoig
Created July 28, 2011 23:27
Show Gist options
  • Save jdoig/1112808 to your computer and use it in GitHub Desktop.
Save jdoig/1112808 to your computer and use it in GitHub Desktop.
sdl demo using F#
#light
open SdlDotNet.Core;
open SdlDotNet.Graphics;
open SdlDotNet.Graphics.Sprites;
open SdlDotNet.Input;
open System.Drawing;
open System;
type StuperGario = class
val mutable location : Point
new () = {location = new Point(10,185)}
end
let screen = Video.SetVideoMode(512, 256) (* Drawing Surface *)
let man = new StuperGario()
let bg = new Surface(@"..\Imgs\bg.png") (* Background image *)
let manSprite = new Sprite(new Surface(@"..\Imgs\gario.png"),man.location)
let Update (args : TickEventArgs) =
screen.Blit(bg) |> ignore (* Draw Background *)
screen.Blit(manSprite,man.location) |> ignore (* Draw man *)
screen.Update() (* Render Screen *)
if Keyboard.IsKeyPressed(Key.LeftArrow) then man.location.X <- man.location.X + -3
if Keyboard.IsKeyPressed(Key.RightArrow) then man.location.X <- man.location.X + 3
let HandleInputDown(args : KeyboardEventArgs) =
match args.Key with
| Key.Escape ->Events.QuitApplication() (* Escape -> Quit *)
| _ -> ignore|>ignore
Video.WindowCaption <- "FSharp Game" (* Set the SDL Window Title *)
Events.KeyboardDown.Add(HandleInputDown)
Events.Tick.Add(Update) (* Update screen and player position *)
Events.Run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment