Skip to content

Commit c86718e

Browse files
committed
Merge: gamnit: simple 2D API, input events and the game Asteronits
You should probably read this PR commit by commit, it is a bit long but it's mostly due to the sample game, a big XML file and changes to indentation. The new API provided by `simple_2d` is meant to replace mnit for writing 2D games. Client modules only have to create instances of `Sprite` which will be displayed as long as they are in `App::sprites`. At this point, the `simple_2d` API is not optimized and you may see a slowdown at the insertion of new sprites. However, we could improve the performance by preallocating buffer space for more sprites, and by caching sprites state on the GPU to avoid unnecessary updates. This PR also adds support for input events for Linux and Android. It uses the existing services from `mnit::input`, `sdl` and `android::input_events`. Finally, the game Asteronits is an example for the `simple_2d` API. In this game, the player controls a ship, avoids asteroids and destroys them. The gameplay and UI is limited by design to be a simple example. Note that the `touch_ui` variant is used on Android only but it also works on Linux. The tool texture_atlas_parser reads XML TextureAtlas files and produces Nit classes with one attribute per subtexture. We could move this tool if it is useful for any other projects. Pull-Request: #1894 Reviewed-by: Jean Privat <jean@pryen.org> Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
2 parents fb71985 + 6765cc9 commit c86718e

32 files changed

+5845
-119
lines changed

contrib/asteronits/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
NITC=../../bin/nitc
2+
NITLS=../../bin/nitls
3+
4+
all: bin/asteronits
5+
6+
bin/asteronits: $(shell ${NITLS} -M src/asteronits.nit linux) ${NITC} pre-build
7+
${NITC} src/asteronits.nit -m linux -o $@
8+
9+
bin/texture_atlas_parser: src/texture_atlas_parser.nit
10+
${NITC} src/texture_atlas_parser.nit -o $@
11+
12+
src/controls.nit: art/controls.svg
13+
make -C ../inkscape_tools/
14+
../inkscape_tools/bin/svg_to_png_and_nit art/controls.svg -a assets/ -s src/ -x 2.0 -g
15+
16+
src/spritesheet_city.nit: bin/texture_atlas_parser
17+
bin/texture_atlas_parser art/sheet.xml --dir src/ -n spritesheet
18+
19+
pre-build: src/controls.nit src/spritesheet_city.nit
20+
21+
check: bin/asteronits
22+
NIT_TESTING=true bin/asteronits
23+
24+
# ---
25+
# Android
26+
27+
android: bin/asteronits.apk
28+
bin/asteronits.apk: $(shell ${NITLS} -M src/asteronits.nit android) ${NITC} res/drawable-hdpi/icon.png pre-build
29+
${NITC} src/touch_ui.nit -m android -o $@
30+
31+
android-release: $(shell ${NITLS} -M src/asteronits.nit android) ${NITC} res/drawable-hdpi/icon.png pre-build
32+
${NITC} src/touch_ui.nit -m android -o bin/asteronits.apk --release
33+
34+
res/drawable-hdpi/icon.png: art/icon.svg
35+
make -C ../inkscape_tools/
36+
../inkscape_tools/bin/svg_to_icons --out res --android art/icon.svg

contrib/asteronits/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Sample portable 2D game implemented with the `simple_2d` API of gamnit
2+
3+
This projects is organized in 3 modules, one per concern:
4+
5+
* `game_logic` defines the pure game logic without any of the display details.
6+
7+
* `asteronits` implements the display logic with support for keyboard input events.
8+
9+
* `touch_ui` adds an interface for touchscreen devices with buttons to open fire and control the ship.
10+
11+
# Art
12+
13+
Artwork created by Kenney.nl under CC0

0 commit comments

Comments
 (0)