diff options
Diffstat (limited to 'src/LivingVillage.Desktop')
| -rw-r--r-- | src/LivingVillage.Desktop/Game.fs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs index 960a8c6..6e0feb6 100644 --- a/src/LivingVillage.Desktop/Game.fs +++ b/src/LivingVillage.Desktop/Game.fs @@ -66,12 +66,15 @@ module Atlas = type LivingVillageGame() as this = inherit Game() + let autoplay = Environment.GetEnvironmentVariable("LV_AUTOPLAY") = "1" + let titleSuffix = if autoplay then " [AUTOPLAY]" else "" + let modeName = if autoplay then "autoplay" else "keyboard" let graphics = new GraphicsDeviceManager(this) let mutable spriteBatch = Unchecked.defaultof<SpriteBatch> let mutable atlas = Unchecked.defaultof<Texture2D> let mutable pixel = Unchecked.defaultof<Texture2D> let mutable map = MapGen.generate Sim.mapWidthTiles Sim.mapHeightTiles - let mutable world = Sim.initialWorld () + let mutable world = Sim.initialWorld 42UL let mutable camera = Vector2.Zero let mutable fpsFrames = 0 let mutable fpsSeconds = 0.0 @@ -82,8 +85,8 @@ type LivingVillageGame() as this = graphics.SynchronizeWithVerticalRetrace <- true this.IsFixedTimeStep <- true this.TargetElapsedTime <- TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60L) - this.Window.Title <- "Living Village M0" - + this.Window.Title <- if autoplay then "Living Village M1 [AUTOPLAY]" else "Living Village M1" + printfn $"mode={modeName} seed=42" member private this.CenterCamera() = let viewport = this.GraphicsDevice.Viewport let vw = float32 viewport.Width @@ -105,17 +108,20 @@ type LivingVillageGame() as this = let kb = Keyboard.GetState() if kb.IsKeyDown(Keys.Escape) then this.Exit() let input = - { MoveX = - (if kb.IsKeyDown(Keys.D) then 1.0f - elif kb.IsKeyDown(Keys.A) then -1.0f - else 0.0f) - MoveY = - (if kb.IsKeyDown(Keys.S) then 1.0f - elif kb.IsKeyDown(Keys.W) then -1.0f - else 0.0f) } - let ts = - { Dt = float32 gameTime.ElapsedGameTime.TotalSeconds - Input = input } + if autoplay then + let t = float32 world.Tick + { MoveX = MathF.Sin(t / 60.0f) * 0.8f + MoveY = MathF.Cos(t / 90.0f) * 0.6f } + else + { MoveX = + (if kb.IsKeyDown(Keys.D) then 1.0f + elif kb.IsKeyDown(Keys.A) then -1.0f + else 0.0f) + MoveY = + (if kb.IsKeyDown(Keys.S) then 1.0f + elif kb.IsKeyDown(Keys.W) then -1.0f + else 0.0f) } + let ts = { Input = input } world <- Sim.step ts world this.CenterCamera() fpsFrames <- fpsFrames + 1 @@ -124,7 +130,7 @@ type LivingVillageGame() as this = let fps = float fpsFrames / fpsSeconds fpsFrames <- 0 fpsSeconds <- 0.0 - this.Window.Title <- $"Living Village M0 | fps {fps:F1} | tick {world.Tick}" + this.Window.Title <- $"Living Village M1{titleSuffix} | fps {fps:F1} | tick {world.Tick}" printfn $"fps={fps:F1} tick={world.Tick} pos=({world.Avatar.Pos.X:F0},{world.Avatar.Pos.Y:F0})" override this.Draw(gameTime: GameTime) = |
