Permalink
Browse files

Further cleaning, see previous commit

  • Loading branch information...
Crysikrend committed Apr 13, 2018
1 parent fb3bebb commit cbfef5323c8da3c9ec0fc0f9f9ea844db765eda9
Showing with 31 additions and 57 deletions.
  1. +4 −4 src/AnimationLoader.hs
  2. +1 −1 src/Common.hs
  3. +2 −16 src/Game.hs
  4. +2 −10 src/GameSetup.hs
  5. +17 −19 src/Guy.hs
  6. +1 −1 src/InputModule.hs
  7. +0 −3 src/Main.hs
  8. +4 −3 src/SDLAnimations.hs
@@ -8,10 +8,10 @@
{-# LANGUAGE DeriveGeneric #-}

module AnimationLoader
( AnimationSetData(AnimationSetData)
, AnimationData(AnimationData)
, Frame(Frame)
, JSONFile(JSONFile)
( AnimationSetData(..)
, AnimationData(..)
, Frame(..)
, JSONFile(..)
, getAnimationDataFromJSON
, spitOutJSON
) where
@@ -2,7 +2,7 @@
-- that may need to be used anywhere
-------------------------------------------------

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleContexts #-}

module Common
( Layer
@@ -5,8 +5,7 @@
{-# LANGUAGE FlexibleContexts #-}

module Game
( GameSetup(GameSetup)
, game
( game
, beginGame
) where

@@ -20,26 +19,13 @@ import qualified SDL.Image
import Reflex
import Reflex.SDL2

import Common
import GameSetup
import SDLAnimations
import InputModule

import Guy

-- A type representing one layer in our app.
type Layer m = Performable m ()


-- Commit a layer stack that changes over time.
commitLayers :: (ReflexSDL2 r t m, MonadDynamicWriter t [Layer m] m) => Dynamic t [Layer m] -> m ()
commitLayers = tellDyn


-- Commit one layer that changes over time.
commitLayer :: (ReflexSDL2 r t m, MonadDynamicWriter t [Layer m] m) => Dynamic t (Layer m) -> m ()
commitLayer = tellDyn . fmap pure


-- The main game loop
game :: (ReflexSDL2 r t m, MonadDynamicWriter t [Layer m] m) => GameSetup -> m ()
game gamestate = do
@@ -3,18 +3,10 @@
-------------------------------------------------

module GameSetup
( GameSetup(GameSetup)
, Options(Options)
, KeyBindings
( GameSetup (..)
, Options (..)
, initialSetup
, renderer
, options
, window
, texmex
, initialOptions
, screenRes
, frameLimit
, keybindings
) where

import Foreign.C.Types
@@ -2,20 +2,16 @@
---------------------------

module Guy
( Guy()
( Guy (..)
, createGuy
, position
, velocity
, texture
, animation
, render
, updateGuy
) where

import Foreign.C.Types
import SDL.Vect
import qualified SDL

import Common
import SDLAnimations

-- The fundamental structures of all our objects in the game
@@ -28,25 +24,27 @@ data Guy =
, render :: SDL.Renderer -> IO ()
}

-- Creates a guy out of simple data
createGuy :: CDouble -> CDouble -> SDL.Texture -> AnimationState -> Guy
createGuy x y tex anim =
Guy
{ position = P $ V2 x y
, velocity = V2 0 0
, texture = tex
, animation = anim
, render = renderGuy $ createGuy x y tex anim
}
Guy
{ position = P $ V2 x y
, velocity = V2 0 0
, texture = tex
, animation = anim
, render = renderGuy $ createGuy x y tex anim
}

-- Update the guy's position and location
updateGuy :: Guy -> CDouble -> Guy
updateGuy g dt =
g
updateGuy guy dt =
guy
{ position =
let (P pos) = position g
(V2 newPosX newPosY) = pos + velocity g * V2 dt dt
let (P pos) = position guy
(V2 newPosX newPosY) = pos + velocity guy * V2 dt dt
in P $ V2 newPosX newPosY
, animation = updateAnimationState dt 0.1 (animation g)
, render = renderGuy g
, animation = updateAnimationState dt 0.1 (animation guy)
, render = renderGuy guy
}

-- Render the guy
@@ -3,7 +3,7 @@
---------------------------------------------------------

module InputModule
( KeyBindings(KeyBindings)
( KeyBindings (..)
, addBinding
, addBatchBindings
, getBoundInput
@@ -42,9 +42,6 @@ main = do
initAnimationState =
AnimationState animationSet animation [] "idle" 0 0

-- Create the player and add it to the entitylist
-- player = createGuy 0 0 playerTexture initAnimationState

-- Create the initial state and put the player in
let setup = initialSetup window renderer background

@@ -1,10 +1,11 @@
-- This module is responsible for taking animationData
-- and applying it into an SDL context
------------------------------------------------------

module SDLAnimations
( AnimationSet()
, Animation()
, AnimationState(AnimationState, currentAnimation, frameNumber, tickCount)
( AnimationSet(..)
, Animation(..)
, AnimationState(..)
, loadAnimations
, getAnimationSet
, getAnimation

0 comments on commit cbfef53

Please sign in to comment.