#12 Fix rendering of zones
This commit is contained in:
parent
d0b708db62
commit
0825c64da0
2 changed files with 121 additions and 0 deletions
|
@ -9,6 +9,10 @@ module PatienceBoard
|
|||
|
||||
, handleInputs
|
||||
, initGame
|
||||
|
||||
, isInGame
|
||||
, isInEnding
|
||||
, isInPile
|
||||
) where
|
||||
|
||||
import CardDeck
|
||||
|
|
117
lib/PatienceRenderer.hs
Normal file
117
lib/PatienceRenderer.hs
Normal file
|
@ -0,0 +1,117 @@
|
|||
module PatienceRenderer
|
||||
( render
|
||||
, getWindow
|
||||
) where
|
||||
|
||||
import PatienceBoard
|
||||
import Selector
|
||||
|
||||
import CardRenderer
|
||||
import PNGRenderer
|
||||
import SelectorRenderer
|
||||
|
||||
import InputHandler
|
||||
|
||||
import Graphics.Gloss(
|
||||
Display(..)
|
||||
, green
|
||||
, play
|
||||
)
|
||||
|
||||
----------------------------- Constants ------------------------------
|
||||
|
||||
-- Distance between cards that are on top of each other
|
||||
cardDistance :: Float
|
||||
cardDistance = 20
|
||||
|
||||
-- Distance between neighbouring stacks
|
||||
stackDistance :: Float
|
||||
stackDistance = 10
|
||||
|
||||
-- Distance between different zones of the board
|
||||
zoneDistance :: Float
|
||||
zoneDistance = 25
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
-- Render the GameStacks zone.
|
||||
renderGS :: Board -> Picture
|
||||
renderGS = renderStacks stackDistance (negate cardDistance) . gameStacks
|
||||
|
||||
-- Render the EndingStacks zone.
|
||||
renderES :: Board -> Picture
|
||||
renderES = renderStacks stackDistance 0 . endingStacks
|
||||
|
||||
-- X axis render difference for EndingStacks
|
||||
esXDiff :: Float
|
||||
esXDiff = fromIntegral esX * cardDistance
|
||||
where cardDistance = cardWidth + stackDistance
|
||||
(esX, _) = endingStacksCoord
|
||||
|
||||
-- Y axis render difference for EndingStacks
|
||||
esYDiff :: Float
|
||||
esYDiff = fromIntegral esY * (zoneDistance + cardHeight)
|
||||
where (_, esY) = endingStacksCoord
|
||||
|
||||
-- Render the Pile zone.
|
||||
renderPile :: Board -> Picture
|
||||
renderPile = renderStack 0 . pile
|
||||
|
||||
-- X axis render difference for Pile
|
||||
pileXDiff :: Float
|
||||
pileXDiff = 0
|
||||
|
||||
-- Y axis render difference for Pile
|
||||
pileYDiff :: Float
|
||||
pileYDiff = esYDiff
|
||||
|
||||
-- Get the diff based on a coordinate because different 'zones' have
|
||||
-- different offsets.
|
||||
getDiff :: Coordinate -> (Float, Float)
|
||||
getDiff coord
|
||||
| isInEnding coord = (width, esYDiff)
|
||||
| isInPile coord = (pileXDiff, pileYDiff)
|
||||
| otherwise = (width, cardDistance)
|
||||
where width = cardWidth + stackDistance
|
||||
|
||||
-- The board consists of three parts:
|
||||
-- the gamestacks, the endingstacks and the pile.
|
||||
-- Pile is located at (0,1).
|
||||
-- EndingStacks are located at (n,1) - see calculations.
|
||||
-- GameStacks are located at (0,0).
|
||||
renderBoard :: Board -> Picture
|
||||
renderBoard board = compose [
|
||||
pile,
|
||||
endingStacks,
|
||||
gameStacks
|
||||
]
|
||||
where pile = translate pileXDiff pileYDiff $ renderPile board
|
||||
endingStacks = translate esXDiff esYDiff $ renderES board
|
||||
gameStacks = renderGS board
|
||||
|
||||
-- Render the PatienceGameSelector.
|
||||
renderPSelector :: Selector -> Picture
|
||||
renderPSelector ps = compose [
|
||||
selector,
|
||||
selected
|
||||
]
|
||||
where selector = renderSelector xd1 yd1 ps
|
||||
selected = renderSelected xd2 yd2 ps
|
||||
(xd1, yd1) = getDiff (position ps)
|
||||
(xd2, yd2) = getDiff $ getSelected ps
|
||||
|
||||
getSelected :: Selector -> Coordinate
|
||||
getSelected s@Selector{ selected = Just c } = c
|
||||
getSelected s@Selector{ selected = Nothing } = (0,0)
|
||||
|
||||
render :: Game -> Picture
|
||||
render game = translate centerX centerY $ compose [
|
||||
renderBoard $ board game,
|
||||
renderPSelector $ selector game
|
||||
]
|
||||
where centerX = negate $ (cardWidth + stackDistance) * (fromIntegral amountOfGameStacks - 1) / 2
|
||||
centerY = 0 -- TODO Different center
|
||||
|
||||
-- The default window to play patience.
|
||||
getWindow :: Display
|
||||
getWindow = InWindow "Patience" (1200,800) (50,50)
|
Reference in a new issue