Skip to content

Instantly share code, notes, and snippets.

@dtchepak dtchepak/steps.md Secret
Last active Jan 1, 2016

Embed
What would you like to do?
Getting started with gloss-game and cabal sandbox

Create a project directory and a new cabal sandbox.

% mkdir glossTest
% cd glossTest
glossTest  % cabal sandbox init
Writing a default package environment file to
glossTest/cabal.sandbox.config
Creating a new sandbox at glossTest/.cabal-sandbox

Clone the gloss-game repository and add the source to the cabal sandbox:

glossTest  % mkdir deps
glossTest  % cd deps
glossTest/deps  % git clone https://github.com/mchakravarty/gloss-game.git
Cloning into 'gloss-game'...
remote: Counting objects: 38, done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 38 (delta 10), reused 28 (delta 4)
Unpacking objects: 100% (38/38), done.
Checking connectivity... done
glossTest/deps  % cd ..
glossTest  % cabal sandbox add-source deps/gloss-game
glossTest  % cabal install gloss-game
... snip ...
Installing library in
glossTest/.cabal-sandbox/lib/x86_64-osx-ghc-7.6.3/gloss-game-0.2.0.0

Now setup our own project.

glossTest% cabal init

I used the default values for everything, except "What does the package build:" where I selected "Executable", as I'll be running a UI. We then need to manually edit the glossTest.cabal file to include a main module and a reference to gloss-game, and remove some superfluous fields.

glossText$  vim glossTest.cabal

-- Initial glossTest.cabal generated by cabal init.  For further 
-- documentation, see http://haskell.org/cabal/users-guide/

name:                glossTest
version:             0.1.0.0
author:              You
maintainer:          your email
build-type:          Simple
cabal-version:       >=1.10

executable glossTest
  main-is:             Game.hs
  build-depends:       base >=4.6 && <4.7
                       , gloss >=4.6 && <4.7
                       , gloss-juicy >=0.1 && <0.2
                       , gloss-game >=0.2 && <0.3
  default-language:    Haskell2010

Almost there. Now to add Game.hs, from Manuel's lets-program repo. You'll also want the Slime.bmp image to be able to run the example program.

glossTest  % vim Game.hs
(... save https://github.com/mchakravarty/lets-program/blob/master/step1/Game.hs to Game.hs ...)
glossTest  % cp deps/gloss-game/examples/slime/Slime.bmp .

Now we can build and run:

glossTest  % cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring glossTest-0.1.0.0...
Building glossTest-0.1.0.0...
Preprocessing executable 'glossTest' for glossTest-0.1.0.0...
[1 of 1] Compiling Main             ( Game.hs, dist/build/glossTest/glossTest-tmp/Main.o )
Linking dist/build/glossTest/glossTest ...
glossTest  % ls
Game.hs              cabal.sandbox.config glossTest.cabal
Setup.hs             deps
Slime.bmp            dist
glossTest  % dist/build/glossTest/glossTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.