|
| 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