Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

lavalfils/poc_gtk4_2D_action_game

Open more actions menu

Repository files navigation

Proof of Concept for a Gtk4 2D action game

This is a Proof of Concept showing that it is possible to make a simple 2D action game using only Gtk4 widgets which are now GPU rendered. The game from the allegro vivace's 'gameplay' tutorial section was used and modified just enough to make it run using only gtk4 widgets instead of allegro.

How to play

  • Arrow keys to move ship
  • Space bar to shoot

Screenshot

Issues

  • No sound fx. I removed all codes related to sound effects as I am only testing the gtk4 widgets.

Solved issues

  • The problem with keyboard input not being fluid has been fixed. Actually the solution was already implemented in the original code but i inadvertently deleted the codes while converting keyboard processing from allegro to gtk4.

  • Was able to add tint effects via css. To test the tint effects, I tinted the alien ships to red when they get hit.

Implementation details

  • The game loop is implemented using the tick callback.

  • For game drawing, I preload GtkPictures inside a GtkFixed layout container then show or hide them as required and use gtk_fixed_move to reposition them.

  • For animations like the explosions, I use the same GtkPicture but change its texture at different times with the function gtk_picture_set_paintable.

  • I use a GtkOverlay to contain all the game's scene. You need to set the overlay's first child to a widget whose size corresponds to the screen size of your game. If not you will see the application window keeps resizing evertime that a GtkPicture is positioned at the border of the window. Also the advantage of using the GtkOverlay is that you can now create layers in your game like one for the background, one for the game's scene and one for the ui or something like that.

Building

I have only tested the game on Linux using Fedora 34. Most probably it will also compile and run on Windows using MSYS2.

Requirements

  • A C compiler. I am using gcc.
  • Gtk4 together with the dev packages installed. Tested with gtk4.2.1.

Compiling

Just compile the game.c file and then run.

compile

gcc -o game game.c `pkg-config --cflags --libs gtk4`

run

./game

Python version

  • pygtk4game is the python version which uses Python 3 and PyGObject.

About

Proof of Concept for a Gtk4 2D action game using only available gtk4 widgets

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.