Giter Club home page Giter Club logo

poc_gtk4_2d_action_game's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.