Created
February 10, 2015 12:14
-
-
Save MangelMaxime/e299504535e71b4fefea to your computer and use it in GitHub Desktop.
OutlinedContainer
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
import Color (..) | |
import Graphics.Collage (..) | |
import Graphics.Element (..) | |
import Keyboard | |
import Signal | |
import Text | |
import Time (..) | |
import Window | |
{-- Part 1: Model the user input ---------------------------------------------- | |
What information do you need to represent all relevant user input? | |
Task: Redefine `UserInput` to include all of the information you need. | |
Redefine `userInput` to be a signal that correctly models the user | |
input as described by `UserInput`. | |
------------------------------------------------------------------------------} | |
type alias UserInput = {} | |
userInput : Signal UserInput | |
userInput = | |
Signal.constant {} | |
type alias Input = | |
{ timeDelta : Float | |
, userInput : UserInput | |
} | |
{-- Part 2: Model the game ---------------------------------------------------- | |
What information do you need to represent the entire game? | |
Tasks: Redefine `GameState` to represent your particular game. | |
Redefine `defaultGame` to represent your initial game state. | |
For example, if you want to represent many objects that just have a position, | |
your GameState might just be a list of coordinates and your default game might | |
be an empty list (no objects at the start): | |
type GameState = { objects : [(Float,Float)] } | |
defaultGame = { objects = [] } | |
------------------------------------------------------------------------------} | |
(gameWidth, gameHeight) = (600,400) | |
(halfWidth, halfHeight) = (300,200) | |
type alias Object a = { a | x:Float, y:Float } | |
type alias ObjectMoving = Object { vx:Float, vy:Float } | |
type alias GameState = {} | |
defaultGame : GameState | |
defaultGame = | |
{} | |
{-- Part 3: Update the game --------------------------------------------------- | |
How does the game step from one state to another based on user input? | |
Task: redefine `stepGame` to use the UserInput and GameState | |
you defined in parts 1 and 2. Maybe use some helper functions | |
to break up the work, stepping smaller parts of the game. | |
------------------------------------------------------------------------------} | |
stepGame : Input -> GameState -> GameState | |
stepGame {timeDelta,userInput} gameState = | |
gameState | |
{-- Part 4: Display the game -------------------------------------------------- | |
How should the GameState be displayed to the user? | |
Task: redefine `display` to use the GameState you defined in part 2. | |
------------------------------------------------------------------------------} | |
-- helpers values | |
groundColor = rgb 74 163 41 | |
skyColor = rgb 174 238 238 | |
txt f = Text.fromString >> Text.color purple >> Text.monospace >> f >> Text.leftAligned | |
msg = "Just some text to bereplace by score value later" | |
-- | |
-- shared functions for rendering objects | |
displayObj : Object a -> Color -> Shape -> Form | |
displayObj obj color shape = | |
move (obj.x, obj.y) (filled color shape) | |
-- | |
display : (Int,Int) -> GameState -> Element | |
display (w,h) gameState = | |
--Text.asText gameState | |
-- I want to outlined this container | |
container w h middle <| | |
collage gameWidth gameHeight | |
[ | |
filled skyColor ( rect gameWidth gameHeight ), | |
move (0,50-halfHeight) (filled groundColor ( rect gameWidth 50 )) | |
] | |
{-- That's all folks! --------------------------------------------------------- | |
The following code puts it all together and shows it on screen. | |
------------------------------------------------------------------------------} | |
delta : Signal Float | |
delta = | |
Signal.map inSeconds (fps 35) | |
input : Signal Input | |
input = | |
Signal.sampleOn delta (Signal.map2 Input delta userInput) | |
gameState : Signal GameState | |
gameState = | |
Signal.foldp stepGame defaultGame input | |
main : Signal Element | |
main = | |
Signal.map2 display Window.dimensions gameState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment