Message board for the users of flat assembler.
> Examples and Tutorials > Simple game engine with SDL2
This is a very simple groundwork for a game that I've been making a few years ago with my friends, purely for fun. As it has been abandoned then, they gave me a permission to share it and now I release this code as a public domain.
It was originally created with fasm 1 and later converted to fasmg. But a few minor tweaks should suffice to make it assemble with fasm 1 once more. Assembling it with fasmg requires the fasm 1 compatibility macros.
It uses 32-bit SDL2 library. For Windows the required DLLs are included, on Linux 32-bit version of libSDL2 needs to be installed with all components.
You may notice that it shares some similarities with my much older engine for DOS, except this one has been abandoned at even earlier stage. There are no "lemmings" to decimate here, they were never added. The player is left with nothing more than punching and kicking the air.
To start the game, a .DEF file needs to be provided as an argument from command line or by dropping the file onto the program. There are two .DEF files included.
|22 Apr 2018, 10:46||
Nice! Thank you very much.
“It’s not that we have a short time to live, but that we waste a lot of it.”
-Lucius Annaeus Seneca
|22 Apr 2018, 12:48||
For those not eager to read the entire source to find out what the keyboard commands are, basic instructions below.
Left/right arrow - move around
Up arrow - jump
P - punch, K - kick (corresponding animations are defined only in PARTY.DEF)
Enter - switch full screen / windowed
Space - turn on "party mode" (blinking effect visible only on transparent background)
There are also some additional commands to further test the graphics engine:
W/S/A/D - move the viewport around
-/= - resize the viewport
The .DEF files are a simple text, you can easily edit them or create additional ones. Background/terrain should be provided in form of a PNG with alpha channel, the boundaries of terrain to walk on are taken from alpha.
The planes are defined in .DEF file with a "plan" command, followed by the name of the file and then either "=" to define the terrain plane or a parallax proportion, like "1:2" for a background parallax and "2:1" for a foreground parallax. The planes are drawn in the order in which they are defined in file, so the backgrounds need to be defined first, then the terrain, and then foregrounds. If there is another number after the parallax definition, it defines the speed at which the plane is moving relative to the terrain.
The definitions of character animations contain sets of parameters that look like:
X Y WxH[N/M] (DX DY)
X and Y are coordinates of the first frame (in the image that contains all of them), W and H define dimensions of a single frame (all frames need to be of the same size and adjacent to each other), N is the number of frames, M is at how many frames per second the animation plays (so the N/M fraction does at the same time define how long the animation is in seconds). DX and DY allow to offset the animation relative to the actual coordinates of the animated character.
There are several additional parameters defined as assembly-time constants on top of CODE.INC, like the strength of jump etc. One could easily change them into run-time parameters (perhaps read from .DEF) if needed.
|24 Apr 2018, 14:05||
< Last Thread | Next Thread >
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.