mirror of
https://github.com/z0w0/helm.git
synced 2024-08-15 15:20:25 +03:00
flappy: add bird images
This commit is contained in:
parent
916d71380f
commit
cabfc36960
@ -4,11 +4,13 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.List (find)
|
import Data.List (find)
|
||||||
|
import qualified Data.Map as M
|
||||||
import Data.Maybe (isJust)
|
import Data.Maybe (isJust)
|
||||||
import Debug.Trace (traceShow)
|
import Debug.Trace (traceShow)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
|
|
||||||
import Linear.V2 (V2(V2))
|
import Linear.V2 (V2(V2))
|
||||||
|
import System.FilePath ((</>))
|
||||||
import qualified System.Random as Rand
|
import qualified System.Random as Rand
|
||||||
|
|
||||||
import Helm
|
import Helm
|
||||||
@ -24,6 +26,8 @@ import qualified Helm.Sub as Sub
|
|||||||
import qualified Helm.Time as Time
|
import qualified Helm.Time as Time
|
||||||
import Helm.Time (Time)
|
import Helm.Time (Time)
|
||||||
|
|
||||||
|
import qualified Paths_helm as Paths
|
||||||
|
|
||||||
-- | Represents the game actions for our game.
|
-- | Represents the game actions for our game.
|
||||||
data Action
|
data Action
|
||||||
= DoNothing -- ^ Do nothing.
|
= DoNothing -- ^ Do nothing.
|
||||||
@ -55,10 +59,12 @@ data Model = Model
|
|||||||
, obstacles :: [Obstacle]
|
, obstacles :: [Obstacle]
|
||||||
, timeScore :: Time
|
, timeScore :: Time
|
||||||
, timeSpeed :: Double
|
, timeSpeed :: Double
|
||||||
|
-- not really part of game state, but most convenient to stuff it here
|
||||||
|
, assets :: M.Map String (Image SDLEngine)
|
||||||
}
|
}
|
||||||
|
|
||||||
initial :: (Model, Cmd SDLEngine Action)
|
initial :: M.Map String (Image SDLEngine) -> (Model, Cmd SDLEngine Action)
|
||||||
initial =
|
initial assets =
|
||||||
( Model
|
( Model
|
||||||
{ flapperPos = V2 0 0
|
{ flapperPos = V2 0 0
|
||||||
, flapperVel = V2 0 0
|
, flapperVel = V2 0 0
|
||||||
@ -66,6 +72,7 @@ initial =
|
|||||||
, obstacles = []
|
, obstacles = []
|
||||||
, timeScore = 0
|
, timeScore = 0
|
||||||
, timeSpeed = 1
|
, timeSpeed = 1
|
||||||
|
, assets = assets
|
||||||
}
|
}
|
||||||
, Cmd.execute Rand.newStdGen SetupObstacles
|
, Cmd.execute Rand.newStdGen SetupObstacles
|
||||||
)
|
)
|
||||||
@ -377,7 +384,11 @@ view model@Model { .. } = Graphics2D $
|
|||||||
overlay Waiting _ = waitingOverlay overlayColor
|
overlay Waiting _ = waitingOverlay overlayColor
|
||||||
overlay Dead model = deadOverlay overlayColor model
|
overlay Dead model = deadOverlay overlayColor model
|
||||||
overlay Playing model = playingOverlay overlayColor model
|
overlay Playing model = playingOverlay overlayColor model
|
||||||
flapper = filled (rgb 0.36 0.25 0.22) $ rect flapperDims
|
--flapper = filled (rgb 0.36 0.25 0.22) $ rect flapperDims
|
||||||
|
flapper | playerStatus == Dead = image flapperDims (assets M.! "birdDead")
|
||||||
|
| dy < -10 = image flapperDims (assets M.! "birdFlap")
|
||||||
|
| otherwise = image flapperDims (assets M.! "bird")
|
||||||
|
where V2 _ dy = flapperVel
|
||||||
backdrop = filled (rgb 0.13 0.13 0.13) $ rect dims
|
backdrop = filled (rgb 0.13 0.13 0.13) $ rect dims
|
||||||
lava = move (V2 0 (h / 2 - lavaHeight / 2)) $ filled (rgb 0.72 0.11 0.11) $ rect $ V2 w lavaHeight
|
lava = move (V2 0 (h / 2 - lavaHeight / 2)) $ filled (rgb 0.72 0.11 0.11) $ rect $ V2 w lavaHeight
|
||||||
structure NoObstacle = blank
|
structure NoObstacle = blank
|
||||||
@ -395,9 +406,21 @@ main = do
|
|||||||
, SDL.windowDimensions = windowDims
|
, SDL.windowDimensions = windowDims
|
||||||
}
|
}
|
||||||
|
|
||||||
run engine defaultConfig GameLifecycle
|
imageDir <- (</> "images") <$> Paths.getDataDir
|
||||||
{ initialFn = initial
|
let assetList = [("bird.png", "bird"),
|
||||||
, updateFn = update
|
("bird-flap.png", "birdFlap"),
|
||||||
, subscriptionsFn = subscriptions
|
("bird-dead.png", "birdDead")
|
||||||
, viewFn = view
|
]
|
||||||
}
|
loadAssets' [] game loaded = game loaded
|
||||||
|
loadAssets' ((file, id):files) game loaded = do
|
||||||
|
SDL.withImage engine (imageDir </> file) $ \image ->
|
||||||
|
loadAssets' files game (M.insert id image loaded)
|
||||||
|
loadAssets files game = loadAssets' files game M.empty
|
||||||
|
|
||||||
|
loadAssets assetList $ \allAssets ->
|
||||||
|
run engine defaultConfig GameLifecycle
|
||||||
|
{ initialFn = initial allAssets
|
||||||
|
, updateFn = update
|
||||||
|
, subscriptionsFn = subscriptions
|
||||||
|
, viewFn = view
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ license: MIT
|
|||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
tested-with: GHC == 8.0.2
|
tested-with: GHC == 8.0.2
|
||||||
extra-source-files: LICENSE, README.md
|
extra-source-files: LICENSE, README.md
|
||||||
|
data-files: images/bird.png images/bird-dead.png images/bird-flap.png
|
||||||
author: Zack Corr
|
author: Zack Corr
|
||||||
maintainer: Zack Corr <zack@z0w0.me>
|
maintainer: Zack Corr <zack@z0w0.me>
|
||||||
copyright: (c) 2013-2017, Zack Corr
|
copyright: (c) 2013-2017, Zack Corr
|
||||||
@ -67,10 +68,15 @@ executable helm-example-flappy
|
|||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
hs-source-dirs: examples/flappy
|
hs-source-dirs: examples/flappy
|
||||||
|
|
||||||
|
other-modules:
|
||||||
|
Paths_helm
|
||||||
|
|
||||||
build-depends:
|
build-depends:
|
||||||
base >= 4 && < 5,
|
base >= 4 && < 5,
|
||||||
linear >= 1 && < 2,
|
linear >= 1 && < 2,
|
||||||
random == 1.*,
|
random == 1.*,
|
||||||
|
containers >= 0.5,
|
||||||
|
filepath >= 1,
|
||||||
helm
|
helm
|
||||||
|
|
||||||
executable helm-example-hello
|
executable helm-example-hello
|
||||||
|
BIN
images/bird-dead.png
Normal file
BIN
images/bird-dead.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
images/bird-flap.png
Normal file
BIN
images/bird-flap.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
BIN
images/bird.png
Normal file
BIN
images/bird.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
Loading…
Reference in New Issue
Block a user