aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-07 15:12:02 +0100
committerJoris Guyonvarch2015-03-07 15:12:02 +0100
commit17a58e0c4c67f27d87635bf1b2ca50fb11795ad3 (patch)
tree8de99cdf0b4021ca6db6920537e7d0fa250e90bc /src
parent336816d2e8ab4afff1562123dfde61bf3a68e61c (diff)
Organizing source code with subdirectories
Diffstat (limited to 'src')
-rw-r--r--src/Board.elm15
-rw-r--r--src/Input.elm2
-rw-r--r--src/Main.elm21
-rw-r--r--src/Model/Board.elm17
-rw-r--r--src/Model/Cloud.elm (renamed from src/Cloud.elm)16
-rw-r--r--src/Model/Config.elm (renamed from src/Config.elm)5
-rw-r--r--src/Model/Game.elm (renamed from src/Game.elm)15
-rw-r--r--src/Model/Player.elm (renamed from src/Player.elm)10
-rw-r--r--src/Model/Point.elm (renamed from src/Point.elm)13
-rw-r--r--src/Model/Vec2.elm (renamed from src/Vec2.elm)12
-rw-r--r--src/Update/CloudUpdate.elm (renamed from src/CloudStep.elm)25
-rw-r--r--src/Update/Update.elm (renamed from src/Step.elm)32
-rw-r--r--src/Utils/Geometry.elm (renamed from src/Geometry.elm)10
-rw-r--r--src/Utils/Physics.elm (renamed from src/Physics.elm)8
-rw-r--r--src/View/Page.elm (renamed from src/Display.elm)20
15 files changed, 140 insertions, 81 deletions
diff --git a/src/Board.elm b/src/Board.elm
deleted file mode 100644
index fa544d8..0000000
--- a/src/Board.elm
+++ /dev/null
@@ -1,15 +0,0 @@
-module Board where
-
-import Vec2 (Vec2)
-
-boardSize : Vec2
-boardSize =
- { x = 500
- , y = 500
- }
-
-boardDiagonal : Float
-boardDiagonal =
- let x = boardSize.x
- y = boardSize.y
- in sqrt(x^2 + y^2)
diff --git a/src/Input.elm b/src/Input.elm
index 3723ba3..28fb2d1 100644
--- a/src/Input.elm
+++ b/src/Input.elm
@@ -6,7 +6,7 @@ import Random
import Time (Time, fps)
import Signal (..)
-import Vec2 (Vec2)
+import Model.Vec2 (Vec2)
type alias Input =
{ dir : Vec2
diff --git a/src/Main.elm b/src/Main.elm
index 6be5766..329492a 100644
--- a/src/Main.elm
+++ b/src/Main.elm
@@ -5,18 +5,25 @@ import Random
import Graphics.Element (Element)
import Html (Html)
-import Game (Game, initialGame)
-import Display (display)
-import Step (step)
+import Model.Game (Game, initialGame)
+import Model.Vec2 (originVec)
+import Model.Config (Config(White))
+
+import Update.Update (update)
+
import Input (getInput)
-import Vec2 (originVec)
-import Config (Config(White))
+
+import View.Page (page)
main : Signal Html
-main = Signal.map display game
+main = Signal.map page game
game : Signal Game
-game = Signal.foldp step (initialGame initialSeed originVec White 0) getInput
+game =
+ Signal.foldp
+ update
+ (initialGame initialSeed originVec White 0)
+ getInput
port initialTime : Int
diff --git a/src/Model/Board.elm b/src/Model/Board.elm
new file mode 100644
index 0000000..1361cfb
--- /dev/null
+++ b/src/Model/Board.elm
@@ -0,0 +1,17 @@
+module Model.Board
+ ( boardSize
+ , boardDiagonal
+ ) where
+
+import Model.Vec2 (Vec2)
+
+boardSize : Vec2
+boardSize =
+ { x = 500
+ , y = 500
+ }
+
+boardDiagonal : Float
+boardDiagonal =
+ boardSize.x ^ 2 + boardSize.y ^ 2
+ |> sqrt
diff --git a/src/Cloud.elm b/src/Model/Cloud.elm
index 45a1dcb..11f6311 100644
--- a/src/Cloud.elm
+++ b/src/Model/Cloud.elm
@@ -1,11 +1,17 @@
-module Cloud where
+module Model.Cloud
+ ( Cloud
+ , initCloud
+ , playerPointsCollision
+ , playerPointCollision
+ ) where
import List
-import Point (..)
-import Player (..)
-import Config (..)
-import Geometry (distance)
+import Model.Point (..)
+import Model.Player (..)
+import Model.Config (..)
+
+import Utils.Geometry (distance)
type alias Cloud =
{ points : Config -> List Point
diff --git a/src/Config.elm b/src/Model/Config.elm
index e02cf3f..2973dc7 100644
--- a/src/Config.elm
+++ b/src/Model/Config.elm
@@ -1,4 +1,7 @@
-module Config where
+module Model.Config
+ ( Config(..)
+ , otherConfig
+ ) where
type Config =
White
diff --git a/src/Game.elm b/src/Model/Game.elm
index e294942..4ef5d89 100644
--- a/src/Game.elm
+++ b/src/Model/Game.elm
@@ -1,13 +1,16 @@
-module Game where
+module Model.Game
+ ( Game
+ , initialGame
+ ) where
import Random (..)
-
-import Player (..)
-import Cloud (..)
-import Vec2 (Vec2)
-import Config (..)
import Keyboard (KeyCode)
+import Model.Player (..)
+import Model.Cloud (..)
+import Model.Vec2 (Vec2)
+import Model.Config (..)
+
type alias Game =
{ time : Float
, keysDown : List KeyCode
diff --git a/src/Player.elm b/src/Model/Player.elm
index d1c10e0..c6aac21 100644
--- a/src/Player.elm
+++ b/src/Model/Player.elm
@@ -1,7 +1,11 @@
-module Player where
+module Model.Player
+ ( Player
+ , playerSize
+ , playerSpeed
+ ) where
-import Vec2 (..)
-import Config (Config)
+import Model.Vec2 (..)
+import Model.Config (Config)
type alias Player =
{ pos : Vec2
diff --git a/src/Point.elm b/src/Model/Point.elm
index e66a5f7..41967b6 100644
--- a/src/Point.elm
+++ b/src/Model/Point.elm
@@ -1,7 +1,14 @@
-module Point where
+module Model.Point
+ ( Point
+ , pointMove
+ , pointSize
+ , pointSpeed
+ , pointSpawnDist
+ , pointAwayDist
+ ) where
-import Vec2 (..)
-import Board (boardDiagonal)
+import Model.Vec2 (..)
+import Model.Board (boardDiagonal)
type alias Point =
{ initTime : Float
diff --git a/src/Vec2.elm b/src/Model/Vec2.elm
index c980e1a..85ff008 100644
--- a/src/Vec2.elm
+++ b/src/Model/Vec2.elm
@@ -1,4 +1,14 @@
-module Vec2 where
+module Model.Vec2
+ ( Vec2
+ , add
+ , sub
+ , mul
+ , div
+ , norm
+ , clockwiseRotate90
+ , isNull
+ , originVec
+ ) where
type alias Vec2 =
{ x : Float
diff --git a/src/CloudStep.elm b/src/Update/CloudUpdate.elm
index e6bfc96..86f7e13 100644
--- a/src/CloudStep.elm
+++ b/src/Update/CloudUpdate.elm
@@ -1,19 +1,22 @@
-module CloudStep where
+module Update.CloudUpdate
+ ( cloudUpdate
+ ) where
import List
import Random (..)
-import Vec2 (..)
-import Geometry (..)
-import Player (..)
-import Board (boardSize, boardDiagonal)
-import Point (..)
-import Physics (getMove, getWaveMove)
-import Cloud (..)
-import Config (..)
+import Model.Vec2 (..)
+import Model.Player (..)
+import Model.Board (boardSize, boardDiagonal)
+import Model.Point (..)
+import Model.Cloud (..)
+import Model.Config (..)
-cloudStep : Float -> Seed -> Player -> Cloud -> (Cloud, Int, Seed)
-cloudStep time seed player {points, spawn, lastSpawn} =
+import Utils.Geometry (..)
+import Utils.Physics (getMove, getWaveMove)
+
+cloudUpdate : Float -> Seed -> Player -> Cloud -> (Cloud, Int, Seed)
+cloudUpdate time seed player {points, spawn, lastSpawn} =
let pointsToCatch = presentPoints time (points player.config)
presentAndNotCaughtPoints = List.filter (not << (playerPointCollision time player)) pointsToCatch
addScore = (List.length pointsToCatch) - (List.length presentAndNotCaughtPoints)
diff --git a/src/Step.elm b/src/Update/Update.elm
index dd340a5..0187dcf 100644
--- a/src/Step.elm
+++ b/src/Update/Update.elm
@@ -1,23 +1,27 @@
-module Step where
+module Update.Update
+ ( update
+ ) where
import List
import Keyboard (KeyCode)
import Char (fromCode, toCode)
-import Vec2 (..)
-import Game (..)
-import Player (..)
-import Cloud (..)
-import Geometry (..)
-import Player (playerSpeed)
-import Point (pointSpeed, pointMove, pointAwayDist)
-import Physics (getNewPosAndSpeed)
-import CloudStep (cloudStep)
-import Config (otherConfig)
+import Model.Player (..)
+import Model.Point (pointSpeed, pointMove, pointAwayDist)
+import Model.Vec2 (..)
+import Model.Config (otherConfig)
+import Model.Cloud (..)
+import Model.Game (..)
+
+import Utils.Geometry (..)
+import Utils.Physics (getNewPosAndSpeed)
+
+import Update.CloudUpdate (cloudUpdate)
+
import Input (Input)
-step : Input -> Game -> Game
-step {dir, inputKeysDown, delta} {time, keysDown, score, player, cloud, bestScore, seed} =
+update : Input -> Game -> Game
+update {dir, inputKeysDown, delta} {time, keysDown, score, player, cloud, bestScore, seed} =
let hostilePoints = cloud.points (otherConfig player.config)
in if(playerPointsCollision time player hostilePoints) then
let newBestScore = if(score > bestScore) then score else bestScore
@@ -25,7 +29,7 @@ step {dir, inputKeysDown, delta} {time, keysDown, score, player, cloud, bestScor
else
let newTime = time + delta
newPlayer = playerStep delta dir (newKeyCode keysDown inputKeysDown) player
- (newCloud, addScore, newSeed) = cloudStep time seed newPlayer cloud
+ (newCloud, addScore, newSeed) = cloudUpdate time seed newPlayer cloud
in { time = newTime
, keysDown = inputKeysDown
, score = score + addScore
diff --git a/src/Geometry.elm b/src/Utils/Geometry.elm
index 73e8d1f..085026f 100644
--- a/src/Geometry.elm
+++ b/src/Utils/Geometry.elm
@@ -1,7 +1,11 @@
-module Geometry where
+module Utils.Geometry
+ ( polarToCartesian
+ , distance
+ , inBoard
+ ) where
-import Vec2 (..)
-import Board (boardSize)
+import Model.Vec2 (..)
+import Model.Board (boardSize)
polarToCartesian : Float -> Float -> Vec2
polarToCartesian angle dist =
diff --git a/src/Physics.elm b/src/Utils/Physics.elm
index c68ab58..751af6c 100644
--- a/src/Physics.elm
+++ b/src/Utils/Physics.elm
@@ -1,6 +1,10 @@
-module Physics where
+module Utils.Physics
+ ( getNewPosAndSpeed
+ , getMove
+ , getWaveMove
+ ) where
-import Vec2 (..)
+import Model.Vec2 (..)
getNewPosAndSpeed : Float -> Vec2 -> (Float -> Float) -> (Vec2, Vec2) -> (Vec2, Vec2)
getNewPosAndSpeed dt dir computeSpeed (pos, speed) =
diff --git a/src/Display.elm b/src/View/Page.elm
index 48e6cd6..ed0dceb 100644
--- a/src/Display.elm
+++ b/src/View/Page.elm
@@ -1,4 +1,6 @@
-module Display where
+module View.Page
+ ( page
+ ) where
import List
@@ -12,15 +14,15 @@ import Html.Attributes (..)
import Html.Attributes as A
import Json.Encode (string)
-import Vec2 (Vec2)
-import Player (..)
-import Game (Game)
-import Point (..)
-import Board (boardSize)
-import Config (..)
+import Model.Vec2 (Vec2)
+import Model.Player (..)
+import Model.Game (Game)
+import Model.Point (..)
+import Model.Board (boardSize)
+import Model.Config (..)
-display : Game -> Html
-display game =
+page : Game -> Html
+page game =
div
[]
[ h1 [] [ text "cAtchVoid" ]