a5
This commit is contained in:
parent
82b08e86eb
commit
ffdbbb5e3b
54
a5/.gitignore
vendored
54
a5/.gitignore
vendored
@ -1,54 +0,0 @@
|
||||
game
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
29
a5/LICENSE
29
a5/LICENSE
@ -1,29 +0,0 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2019, Daniel Hládek
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
78
a5/README.md
78
a5/README.md
@ -1,78 +0,0 @@
|
||||
# World Game Library
|
||||
|
||||
Learn asycnronous C programming by a game.
|
||||
|
||||
The library implements a game loop for a character-based ncurses game;
|
||||
|
||||
The library finds out the event types:
|
||||
|
||||
- start and end
|
||||
- mouse events
|
||||
- keyboard events
|
||||
- screen resize events
|
||||
|
||||
It can print colors and arbitrary characters on the screen.
|
||||
Running is interrupted when character is drawn out of the screen.
|
||||
|
||||
## Installation and Running
|
||||
|
||||
Make sure, that `ncurses` is installed.
|
||||
|
||||
Clone this repository.
|
||||
|
||||
Compile:
|
||||
|
||||
```c
|
||||
make
|
||||
```
|
||||
|
||||
Run:
|
||||
|
||||
```c
|
||||
./game
|
||||
```
|
||||
|
||||
## Make your own game
|
||||
|
||||
The game happens in a rectangular world of colorful characters.
|
||||
Your goal as a programmer is to modify the world according to the pressed keys and the internal game state.
|
||||
The library implements the game loop and draws the world to screen.
|
||||
|
||||
Your game in file `game.c` consists of two functions:
|
||||
|
||||
- `void* init_game()` is called in the beginning. Here you can initialize the internal state of the game.
|
||||
The function should return a pointer to an instance of the initial game state `game`.
|
||||
- `int game_event(struct event* event,void* game)`
|
||||
is called by the game loop in periodic interval or when a key was pressed. Non-zero return value or `Ctrl+C` key interrupts the game loop.
|
||||
|
||||
The world variable represents state of two-dimensional grid of characters on the screen. The screen matrix looks like this:
|
||||
|
||||
```
|
||||
origin
|
||||
[0,0] width
|
||||
+--------------------+
|
||||
h | |
|
||||
e | |
|
||||
i | |
|
||||
g | |
|
||||
h | |
|
||||
t | |
|
||||
+--------------------+
|
||||
```
|
||||
|
||||
The world has the following parameters:
|
||||
|
||||
- `int height`: y-dimension of the grid.
|
||||
- `int width`: x-dimension of the grid.
|
||||
- `int interval`: maximum time between steps in milliseconds.
|
||||
|
||||
### The Event Function
|
||||
|
||||
The `int game_event(struct event* event,void* game)`
|
||||
function should:
|
||||
|
||||
1. Read the game state (from the `void* game`) pointer.
|
||||
1. Examine the pressed key from event pointer. If the `key` variable is non-zero, a key was pressed. According to the pressed key, modify the game state `game`.
|
||||
1. Draw the game state. In the beginning of the step function the screen is empty.
|
||||
1. Returning non-zero value ends the game loop.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user