Skip to content

Instantly share code, notes, and snippets.

@meganehouser
Last active December 19, 2015 00:28
Show Gist options
  • Save meganehouser/5868530 to your computer and use it in GitHub Desktop.
Save meganehouser/5868530 to your computer and use it in GitHub Desktop.
Delta Engine の Sample/EmptyGame を F# で無理やり mutable をなくして実装。
open DeltaEngine.Core
open DeltaEngine.Datatypes
open DeltaEngine.Platforms
type LerpColor = { Current: Color; Next: Color; Percentage:float32 }
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module LerpColor =
let initialState = {Current=Color.Black; Next=Color.Black; Percentage=0.0f}
let update state =
match (state.Percentage + Time.Current.Delta) with
| t when t >= 1.0f -> {Current=state.Next; Next=Color.GetRandomColor(); Percentage=0.0f}
| t -> {state with Percentage=t}
let draw (state:LerpColor) (window:Window) =
window.BackgroundColor <- Color.Lerp(state.Current, state.Next, state.Percentage)
module EmptyGame =
let subscribe window =
Observable.scan(fun state source -> LerpColor.update state) LerpColor.initialState
>> Observable.subscribe(fun state -> LerpColor.draw state window)
>> ignore
type EmptyGame (window:Window) =
let runEvent = new Event<_>()
let run() = runEvent.Trigger()
do runEvent.Publish |> subscribe window
interface Runner with
member this.Run() = run()
member this.Run() = run()
[<CompiledName("Main")>]
let run () =
let app = new App()
app.Start<EmptyGame>();
module Program =
[<EntryPoint>]
let run args =
EmptyGame.run()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment