Commit 17a58e0c authored by Joris Guyonvarch's avatar Joris Guyonvarch

Organizing source code with subdirectories

parent 336816d2
......@@ -6,7 +6,7 @@ import Random
import Time (Time, fps)
import Signal (..)
import Vec2 (Vec2)
import Model.Vec2 (Vec2)
type alias Input =
{ dir : Vec2
......
......@@ -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
......
module Board where
module Model.Board
( boardSize
, boardDiagonal
) where
import Vec2 (Vec2)
import Model.Vec2 (Vec2)
boardSize : Vec2
boardSize =
......@@ -10,6 +13,5 @@ boardSize =
boardDiagonal : Float
boardDiagonal =
let x = boardSize.x
y = boardSize.y
in sqrt(x^2 + y^2)
boardSize.x ^ 2 + boardSize.y ^ 2
|> sqrt
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
......
module Config where
module Model.Config
( Config(..)
, otherConfig
) where
type Config =
White
......
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
......
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
......
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
......
module Vec2 where
module Model.Vec2
( Vec2
, add
, sub
, mul
, div
, norm
, clockwiseRotate90
, isNull
, originVec
) where
type alias Vec2 =
{ x : Float
......
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)
......
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
......
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 =
......
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) =
......
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" ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment