Created
July 28, 2011 23:27
-
-
Save jdoig/1112808 to your computer and use it in GitHub Desktop.
sdl demo using F#
This file contains hidden or 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
#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() |
Unfotunatly SdlDotNet is not supported and is not crossplatform (( There already is a https://github.com/dotnet/Silk.NET package, which supports multiplatforms and still supported
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one! The next step for me will be try to fuse ploting with SDL. Thanks for help!!!