flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > Simple game engine with SDL2

Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 22 Apr 2018, 10:46
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.


Description: A simple game engine made with SDL2, assembled with fasmg
Download
Filename: prahorda.zip
Filesize: 5.96 MB
Downloaded: 2155 Time(s)

Post 22 Apr 2018, 10:46
View user's profile Send private message Visit poster's website Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 195
Location: N 5.43564° E 100.3091°
yeohhs 22 Apr 2018, 12:48
Very Happy Nice! Thank you very much.
Post 22 Apr 2018, 12:48
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 24 Apr 2018, 14:05
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.
Post 24 Apr 2018, 14:05
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1398
Location: Piraeus, Greece
Picnic 17 Aug 2018, 08:26
Nice to sharing the source Tomasz.

The road.def level looks like the 2nd level of the game Bad Dudes Vs. DragonNinja, very cool Smile

Image

Image
Post 17 Aug 2018, 08:26
View user's profile Send private message Visit poster's website Reply with quote
TheRaven



Joined: 22 Apr 2008
Posts: 91
Location: U.S.A.
TheRaven 09 Mar 2019, 08:06
I do remember Bad Dudes --played many Data East and SNK rumblers & shmups.
Didn't think T.G. had the Fist of the North Star in him -nice.
Post 09 Mar 2019, 08:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.