Skip to content

Commit d4998de

Browse files
authored
Merge pull request #15 from keera-studios/zuriHac2018
Merging and readjustment of repo after ZuriHac2018
2 parents 9bb4e9f + 6ca6a81 commit d4998de

17 files changed

+1892
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ or select a section below:
1515
* [Books](http://github.com/keera-studios/haskell-game-programming/wiki/Books)
1616

1717

18-
Please, donate to this project using flatter: [![Flattr this awesome project](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ivanperez-keera&url=https://github.com/keera-studios/haskell-game-programming&title=HaskellGameProgramming&language=&tags=github&category=software)
18+
Please, donate to this project using flatter: [![Flattr this awesome project](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=ivanperez-keera&url=https://github.com/keera-studios/haskell-game-programming&title=HaskellGameProgramming&language=&tags=github&category=software)
1919

2020
If you would like to use another donation method, please get in touch with Keera Studios.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for keera-board-game-scaffold
2+
3+
## 0.1.0.0 -- 2018-06-04
4+
5+
* First version. Released on an unsuspecting world.

examples/board-game-scaffold/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# keera-board-game-scaffold
2+
3+
This is a Haskell board game scaffold.
4+
5+
Table of Contents:
6+
* [Installation](#installation)
7+
* [Documentation](#documentation)
8+
* [Related projects](#related-projects)
9+
* [Curious?](#curious)
10+
11+
## Installation
12+
13+
For installing the game you need the following packages:
14+
* [GHC](https://www.haskell.org/ghc/)
15+
* [command-line interface for cabal](https://github.com/haskell/cabal/tree/master/cabal-install)
16+
* SDL2, SDL2-gfx
17+
18+
On debian/ubuntu, you can install them with:
19+
20+
```
21+
$ sudo apt-get install ghc cabal-install
22+
$ sudo apt-get install libsdl2-dev libsdl2-gfx-dev
23+
```
24+
I recommend using a [cabal sandbox](https://www.haskell.org/cabal/users-guide/installing-packages.html#developing-with-sandboxes) for installing the game.
25+
26+
Here are the instructions:
27+
28+
```
29+
$ git clone https://github.com/keera-studios/haskell-game-programming
30+
$ cd examples/game-board-scaffold
31+
$ cabal update
32+
$ cabal sandbox init
33+
$ cabal install --only-dependencies
34+
$ cabal run
35+
```
36+
37+
If any of these instructions do not work for you, please let me know via [issue](https://github.com/keera-studios/haskell-game-programming/issues) or [mail](chriz@keera.co.uk).
38+
39+
## Documentation
40+
41+
To try and make things as clear as possible, the code includes as much haddock
42+
documentation and comments as we could reasonably fit. You can compile
43+
those with:
44+
45+
```
46+
$ git clone https://github.com/keera-studios/haskell-game-programming
47+
$ cd examples/game-board-scaffold
48+
$ cabal update
49+
$ cabal sandbox init
50+
$ cabal install --only-dependencies
51+
$ cabal configure && cabal haddock --executables --internal
52+
```
53+
54+
## Related projects
55+
* [Magic Cookies](https://github.com/keera-studios/magic-cookies), a commercial FRP game written in Haskell using Yampa that's available on iTunes and Google Play.
56+
* [Haskanoid](https://github.com/ivanperez-haskell/haskanoid) a Haskell breakout game implemented using the Functional Reactive Programming library Yampa.
57+
* [Pang a Lambda](https://github.com/keera-studios/games-pang-a-lambda) a Haskell game implemented using the Functional Reactive Programming library Yampa.
58+
59+
## Curious?
60+
61+
It seems that I catched your attention. If so let's get in contact ([issue](https://github.com/keera-studios/haskell-game-programming/issues) or [mail](chriz@keera.co.uk))! Some (but none exclusive) examples: Are you interested in ...
62+
* ... improving this game? Like:
63+
* Improving the documentation.
64+
* Improving the code.
65+
* Adding new features.
66+
* ... ?
67+
* ... using this Haskell game for educational or other purposes?
68+
* ... letting me know what you think about this Haskell game?
69+
* ... writing your own Haskell game?
70+
* ...?

examples/board-game-scaffold/Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Introduction to the Basic Game Structure Used by Keera Studios Ltd
2+
Work in progress by Christina Zeller
3+
4+
## Goal of this document:
5+
- We (Keera Studios) want to introduce (parts of) our recent basic game structure.
6+
- Using this basic game structure as a skeleton in mind shall help you to easier and faster find your way in our games.
7+
- Besides, if you are developing your own games, it might help you to structure your games.
8+
9+
## Reading advices and content of this document:
10+
- [Warning](#warning)
11+
- Obviously everybody should read warnings.
12+
Here you find some limitations of the document.
13+
- [Game Structure](#game-structure---the-modules)
14+
- If you want to know about our game structure, this is the place to look.
15+
- [Why is a basic game structure helpful?](#why-is-a-basic-game-structure-helpful)
16+
- If you wonder whether you should know something about game structures, here you find some reasons why we think it is helpful.
17+
- [Curious?](#curious)
18+
- If you want to get involved or use our material, take a look at this section.
19+
20+
## Warning
21+
- This document describes parts of a theoretical (ideal) game structure. We are working hard to reach it, however sometimes reality clashes with theory. Our solution is either to work harder to get closer to the ideal or sometimes we are figuring out that our ideal is not ideal and we adapt the game structure.
22+
- So don't be surprised if not all our games show the complete basic game structure or if in the future we change our mind and state another. That's called development.
23+
24+
## Game Structure - The Modules
25+
- Basically all our games have the following modules.
26+
- However, sometimes module names vary slightly. That's because we haven't found a consent regarding several names yet. Hopefully, this will become more stable someday in the near future.
27+
- Therefore, if you have any suggestions to improve names or the structure, let us know!
28+
29+
```
30+
Game
31+
----> Main
32+
----> Constants
33+
----> UserInput
34+
----> DeviceOutput
35+
----> InputOutputMatcher
36+
----> Play
37+
----> State
38+
----> Objects
39+
----> Levels
40+
```
41+
42+
```
43+
-------------------------------------------------------------------------------
44+
45+
Constants
46+
Main
47+
|
48+
|___ init:
49+
| UserInput
50+
| DeviceOutput
51+
|
52+
|___ game loop:
53+
sense (UserInput) ---\ Input / State (of Game)
54+
process input (Play) ------------> Output---> Levels
55+
create output (DeviceOutput) ---/ Matcher \ Objects
56+
57+
-------------------------------------------------------------------------------
58+
```
59+
60+
### Main.hs
61+
- Catch and print exceptions.
62+
- Create handler for initializing input and output and allocate resources.
63+
- Start the game loop. That is, sense input, process input, create output.
64+
65+
### Constants
66+
Define magic numbers at one place with one name.
67+
68+
### DeviceOutput.hs
69+
Handle output related aspects, that is
70+
- Initialize device output related aspects like a rendering context, runtime context, window and sound.
71+
- Render (visual and audio).
72+
73+
### UserInput.hs
74+
Provide controller for storing and recognizing user input.
75+
76+
### InputOutputMatcher
77+
Match the user input with the displayed screen.
78+
79+
### State.hs
80+
Provide the structure for game states.
81+
82+
### Play.hs
83+
Provide the game logic/flow.
84+
85+
### Objects.hs
86+
All objects of the game with specific properties and functions.
87+
88+
### Levels.hs
89+
Define every level with its characteristics.
90+
91+
## Why is a basic game structure helpful?
92+
- The game structure helps to find your way in our games even if you are not familiar with the implementation details.
93+
- If you handle many games you can change things in all games at the same time.
94+
- Skeletons reduce needed brain capacity for maintenance.
95+
- It helps you to start to write your first game.
96+
- You can reuse code or outsource parts that are always handled in the same way.
97+
- Once well known, you can focus on the game specific parts not on the technical and maybe boring parts that need to be done in every game.
98+
- Introducing new features will hopefully result in only minor changes of your game structure.
99+
- ...
100+
101+
## Curious?
102+
103+
It seems that I caught your attention. If so let's get in contact ([issue](https://github.com/keera-studios/haskell-game-programming/issues) or [mail](chriz@keera.co.uk))! Some (but none exclusive) examples: Are you interested in ...
104+
* ... improving this document? Like:
105+
* Improving spelling and grammar.
106+
* Improving the comprehensibility of the document.
107+
* Improving the structure of the document.
108+
* ... ?
109+
* ... using this source for educational or other purpose?
110+
* ... letting me know what you think about this document?
111+
* ... writing your own Haskell game?
112+
* ...?
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# ZuriHac 2018 --- Game Programming --- Some Tasks
2+
by Christina Zeller
3+
4+
- This document gives an unsorted overview of suggested tasks in Haskell game programming.
5+
- The unsorted tasks vary in complexity. Don't get (too) frustrated but ask me for hints.
6+
7+
Table of Contents:
8+
* [Hands on tasks (playing with the code)](#hands-on-tasks-playing-with-the-code)
9+
* [Hands on tasks (createing a board game)](#hands-on-tasks-creating-a-board-game)
10+
* [Exploring the game structure](#exploring-the-game-structure)
11+
* [Haskanoid: SDL FRP (Yampa) Wiimote](#haskanoid-sdl1-sdl2-frp-yampa-wiimote)
12+
* [Confused?](#confused)
13+
14+
## Hands on tasks (playing with the [code](https://github.com/keera-studios/haskell-game-programming/tree/zuriHac2018/examples/board-game-scaffold/src))
15+
### Constants
16+
- Change the title of the window.
17+
- Change the default screen size.
18+
- Change the screen margin.
19+
### Levels
20+
- Change the background colour.
21+
- Change the fields colour.
22+
- Change the number of fields of a grid.
23+
- Change the shape of the grid.
24+
- Add a new level.
25+
- Add a level solved definition for each level.
26+
- Add a maximal number of moves in a level.
27+
### GameState
28+
- Add a field to count moves.
29+
- Add a pause game state.
30+
### DeviceOutput
31+
- Do not render/display empty fields.
32+
- Do render/display empty fields as small filled pies or ellipses.
33+
- Draw fields as triangles.
34+
- Add rendering/displaying of a level solved status.
35+
- Add rendering/displaying of a paused game status.
36+
- Add a button (rectangle, circle, ...) next to the game board.
37+
- Add the level number next to the game board.
38+
- Render images/assets instead of circles/triangles/rectangles ([one source of free assets](http://www.kenney.nl/)).
39+
- Add audio.
40+
### UserInput
41+
- Close the window if the close button of a window was clicked.
42+
- Handle/Store a keyboard pressed key 'P' event.
43+
### InputOutputMatch
44+
- Add a function to check whether the background was clicked.
45+
- Add a function to check whether a specific area was clicked (e.g., a restart button).
46+
### Objects
47+
- Add a new field kind.
48+
### GameLogic
49+
- Change the allowed moves.
50+
- Change the result of a move.
51+
- Count the number of moves.
52+
- Restart the level if the background or a button on the screen was clicked.
53+
- Add a level solved behaviour.
54+
- Add a pause game behaviour.
55+
- React on a keyboard pressed key 'P' event with changing to the paused game status.
56+
57+
## Hands on tasks (creating a board game)
58+
- Reimplement an existing board game (4 in a line, solitaire, find the pairs, Mensch \"argere dich nicht, ...).
59+
- Create your own board game (maybe using the [board game scaffold](https://github.com/keera-studios/haskell-game-programming/tree/zuriHac2018/examples/board-game-scaffold)) with your own logic and rules.
60+
61+
## Exploring the game structure
62+
- Create the haddock documentation (see [README](https://github.com/keera-studios/haskell-game-programming/blob/zuriHac2018/examples/board-game-scaffold/README.md)) and get an overview of the game.
63+
- Where do you expect:
64+
- The handling of mouse and key board events?
65+
- The definition of the game board and its elements in general?
66+
- The definition of a solved game board?
67+
- The handling of the game flow?
68+
- The rendering of a game board?
69+
- The background colour?
70+
- The colour of fields of the board?
71+
- The logical board size?
72+
- The board size used for rendering?
73+
- The definition of a valid move?
74+
- The result of a move?
75+
- The detection of clicked fields?
76+
- Read about our [basic game structure](https://github.com/keera-studios/haskell-game-programming/blob/zuriHac2018/examples/board-game-scaffold/docs/game-structure.md). Why you should read it? The document will tell you.
77+
- Take a look at the following import examples. Can you associate them with the specific modules of the [game](https://github.com/keera-studios/haskell-game-programming/tree/zuriHac2018/examples/board-game-scaffold/src)?
78+
- Example 1:
79+
80+
```haskell
81+
-- External imports
82+
import Control.Monad (void)
83+
import Data.Int (Int16, Int32)
84+
import Data.List (transpose)
85+
import qualified Data.Text as T (pack)
86+
import Foreign.C.Types (CInt (CInt))
87+
import SDL (InitFlag (InitVideo), Renderer, V2 (V2),
88+
V4 (V4), Window, createSoftwareRenderer,
89+
createWindow, defaultWindow, getWindowSurface,
90+
getWindowSurface, initialize, showWindow,
91+
surfaceFillRect, updateWindowSurface,
92+
windowInitialSize)
93+
import SDL.Primitive (fillCircle)
94+
95+
-- Internal imports
96+
import Constants (Color, caption, defaultBG, screenMarginWH, screenWH)
97+
import GameState (GameState, GameStatus (LevelPlaying), gameGrid, gameInfo,
98+
gameLevel, gameStatus)
99+
import Levels (LevelSpec, background, fieldColor, levels)
100+
import Objects (Field, Grid, fieldId, findPosition)
101+
```
102+
103+
- Example 2:
104+
105+
```haskell
106+
-- External imports
107+
108+
-- Internal imports
109+
import GameState (GameState, GameStatus (LevelPlaying), gameGrid,
110+
gameInfo, gameStatus)
111+
import InputOutputMatch (clickedFields)
112+
import Objects (Field, FieldKind (Empty, Tile), Grid, fieldKind,
113+
swapFields)
114+
import UserInput (Controller, controllerDragPoss)
115+
```
116+
117+
- Example 3:
118+
119+
```haskell
120+
-- External imports
121+
import Data.Ix (inRange)
122+
123+
-- Internal imports
124+
import DeviceOutput (absFieldsPositions, calcFieldSize)
125+
import Objects (Field, Grid)
126+
```
127+
128+
- Example 4:
129+
130+
```haskell
131+
-- External imports
132+
import Data.Ix (inRange)
133+
import Data.List (find)
134+
135+
-- Internal imports
136+
import DeviceOutput (ScreenPosition, gridFieldSize, gridFieldsAbsPositions)
137+
import Objects (Field, Grid)
138+
```
139+
140+
- Example 5:
141+
142+
```haskell
143+
-- External imports
144+
145+
-- Internal imports
146+
import DeviceOutput (RenderingCtx, initializeGUI, render)
147+
import GameLogic (gameLogic)
148+
import GameState (GameState, defaultState)
149+
import UserInput (Controller, defaultController, updateController)
150+
```
151+
152+
- Example 6:
153+
154+
```haskell
155+
-- External imports
156+
import Data.Int (Int32)
157+
import SDL (EventPayload (MouseButtonEvent, MouseMotionEvent),
158+
InputMotion (Pressed, Released), Point (P), V2 (V2),
159+
eventPayload, mouseButtonEventMotion, mouseMotionEventPos,
160+
pollEvent)
161+
162+
-- Internal imports
163+
```
164+
165+
- Create a list for commonly used variables and abbreviations in the code. If you see irregularities you are very welcome to fix them.
166+
- What makes it easy or hard to understand the code? If you want try to fix it and/or give us feedback regarding the difficulty of understanding our documents and our code.
167+
- Compare the board game scaffold with the game structure of [haskanoid](https://github.com/ivanperez-keera/haskanoid) and/or [Pang a Lambda](https://github.com/keera-studios/games-pang-a-lambda).
168+
- Structure [raindrops](https://github.com/keera-studios/haskell-game-programming/tree/master/examples/raindrops) using our [basic game structure](https://github.com/keera-studios/haskell-game-programming/blob/zuriHac2018/examples/board-game-scaffold/docs/game-structure.md).
169+
170+
## Haskanoid: SDL1 SDL2 FRP (Yampa) Wiimote
171+
- Take a look at the [issues](https://github.com/ivanperez-keera/haskanoid/issues) that we added and tagged with ZuriHac2018 of [haskanoid](https://github.com/ivanperez-keera/haskanoid) our breakout game in Haskell. It uses functional reactive programming, can be played with various input devices (mouse, wiimote, ...) and can be compiled with SDL1 or SDL2.
172+
173+
## Confused?
174+
Don't panic! Let's talk and find a solution. ;-)

0 commit comments

Comments
 (0)