spice 0.3.2.0 → 0.3.2.1
raw patch · 2 files changed
+1/−88 lines, 2 filesdep −spicedep ~data-default
Dependencies removed: spice
Dependency ranges changed: data-default
Files
- spice.cabal +1/−10
- src/test/Main.hs +0/−78
spice.cabal view
@@ -1,5 +1,5 @@ name: spice -version: 0.3.2.0 +version: 0.3.2.1 synopsis: An FRP-based game engine written in Haskell. description: An FRP-based game engine written in Haskell. - See the homepage for more information. homepage: http://github.com/crockeo/spice @@ -48,12 +48,3 @@ , OpenGL default-language: Haskell2010 - -executable spice - ghc-options: -rtsopts - main-is: Main.hs - hs-source-dirs: src/test/ - build-depends: base == 4.7.* - , spice - , data-default - default-language: Haskell2010
− src/test/Main.hs
@@ -1,78 +0,0 @@-module Main where - -------------- --- Imports -- -import FRP.Spice.Graphics -import FRP.Spice.Math -import FRP.Spice - -import Data.Default - ----------- --- Code -- - --- Some directions -up, down, left, right :: Vector Float -up = Vector ( 0) ( 1) -down = Vector ( 0) (-1) -left = Vector (-1) ( 0) -right = Vector ( 1) ( 0) - --- The speed in which pos should move -speedCfg :: Float -speedCfg = 0.5 - --- The size rendered squares should take -size :: Float -size = 0.05 - --- Applying the speed to a vector -speed :: DeltaTime -> Vector Float -> Vector Float -speed dt vec = vec * Vector (speedCfg * dt) (speedCfg * dt) - --- A basic game type -data BasicGame = BasicGame { pos :: Vector Float - , mousePos :: Vector Float - } - --- Updating the game -updatePos :: DeltaTime -> Input -> BasicGame -> BasicGame -updatePos dt input game = - move dt game [ (keyboard input ! CharKey 'W', speed dt up ) - , (keyboard input ! CharKey 'S', speed dt down ) - , (keyboard input ! CharKey 'A', speed dt left ) - , (keyboard input ! CharKey 'D', speed dt right) - ] - where move :: DeltaTime -> BasicGame -> [(Bool, Vector Float)] -> BasicGame - move dt game [] = game - move dt game@(BasicGame pos _) ((True , d):xs) = move dt (game { pos = pos + d }) xs - move dt game ((False, _):xs) = move dt game xs - --- Updating the mouse position -updateMousePosition :: Input -> BasicGame -> BasicGame -updateMousePosition input game@(BasicGame _ mousePos) = - game { mousePos = mousePosition input } - -updateGame :: DeltaTime -> Input -> BasicGame -> BasicGame -updateGame dt input game = updateMousePosition input $ updatePos dt input game - --- Rendering the game -renderGame :: BasicGame -> Scene -renderGame (BasicGame pos mousePos) = do - bindColor $ color3i 0 0 255 - renderRectangle ((mousePos * Vector 0 1) - (Vector 1 0)) $ Vector 2 2 - - bindColor $ color3i 255 0 0 - renderSquare pos size - - bindColor $ color3i 0 255 0 - renderSquare mousePos size - --- Giving BasicGame a Game instance. -instance Game BasicGame where - update dt input game = updateGame dt input game - render game = renderGame game - --- Starting the game -main :: IO () -main = startEngine defaultWindowConfig $ BasicGame def def