Skip to content

Commit

Permalink
Merge branch 'LudwikJaniuk-dino' into dino
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lim committed Jul 22, 2017
2 parents 513b10c + de0e6b3 commit 970e4ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Install on macOS with the following commands:
```bash
curl -L https://github.com/arcticmatt/dino-brick/releases/download/0.1.0/dino-`uname -s`-`uname -m` -o dino
chmod +x dino
sudo mv dino /usr/local/dino/
sudo mv dino /usr/local/bin/
```

#### install from source
Expand Down
6 changes: 4 additions & 2 deletions src/Controls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

module Controls where

import Dino (Game(..), Direction(..), dir, paused)
import Dino (Game(..), Direction(..), dir, duckCountdown, duckFrames, paused)

import Lens.Micro ((&), (.~), (^.), (%~))

handleUp :: Game -> Game
handleUp g = if g^.dir == Still || g^.dir == Duck then changeDir Up g else g

handleDown :: Game -> Game
handleDown g = if g^.dir == Still || g^.dir == Down then changeDir Duck g else g
handleDown g = if g^.dir == Still || g^.dir == Down
then changeDir Duck g & duckCountdown .~ duckFrames
else g

changeDir :: Direction -> Game -> Game
changeDir d g = g & dir .~ d
Expand Down
25 changes: 21 additions & 4 deletions src/Dino.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data Game = Game
, _scoreMod :: Int -- ^ controls how often we update the score
, _score :: Score -- ^ score
, _highscore :: Score -- ^ highscore of current sesh
, _duckCountdown :: Int -- ^ countdown for standing up after ducking
} deriving (Show)

type Score = Int
Expand Down Expand Up @@ -111,6 +112,10 @@ constScoreMod = 2
levelAmount :: Score
levelAmount = 100

-- "Duck" direction frame longevity
duckFrames :: Int
duckFrames = 8

scoreMap :: M.Map Int Difficulty
scoreMap = M.fromList $ zip [0 ..] [D0 ..]

Expand All @@ -124,7 +129,17 @@ step g = fromMaybe g $ do

-- | What to do if we are not dead.
step' :: Game -> Game
step' = incDifficulty . setHighScore . incScore . move . spawnBarrier . deleteBarrier . adjustStanding
step' = incDifficulty . setHighScore . incScore . move . spawnBarrier .
deleteBarrier . adjustStanding . adjustDuckCountdown

adjustDuckCountdown :: Game -> Game
adjustDuckCountdown = setDirectionFromDuckCountdown . decreaseDuckCountdown

setDirectionFromDuckCountdown :: Game -> Game
setDirectionFromDuckCountdown g = if (g^.duckCountdown <= 0) && (g^.dir == Duck) then g & dir .~ Still else g

decreaseDuckCountdown :: Game -> Game
decreaseDuckCountdown g = if g^.duckCountdown > 0 then g & duckCountdown %~ subtract 1 else g

incScore :: Game -> Game
incScore g = case g^.scoreMod of
Expand Down Expand Up @@ -359,6 +374,7 @@ initGame hs = do
, _scoreMod = 0
, _score = 0
, _highscore = hs
, _duckCountdown = -1
}
return g

Expand All @@ -367,16 +383,17 @@ difficultyMap = do
dists0 <- randomRs (20, 25) <$> newStdGen
dists1 <- randomRs (17, 22) <$> newStdGen
dists2 <- randomRs (16, 20) <$> newStdGen
dists3 <- randomRs (15, 18) <$> newStdGen
dists4 <- randomRs (12, 16) <$> newStdGen
dists3 <- randomRs (15, 20) <$> newStdGen
dists4 <- randomRs (12, 18) <$> newStdGen
distsHardest <- randomRs (12, 16) <$> newStdGen
return $ DifficultyMap
(DiffMod 1 1 dists0)
(DiffMod 1 2 dists1)
(DiffMod 2 2 dists2)
(DiffMod 2 3 dists3)
(DiffMod 3 3 dists4) -- same dists, different widths/heights
(DiffMod 3 4 dists4)
(DiffMod 4 4 dists4)
(DiffMod 3 4 distsHardest)

weightedList :: RandomGen g => g -> [(a, Rational)] -> [a]
weightedList gen weights = evalRand m gen
Expand Down

0 comments on commit 970e4ae

Please sign in to comment.