Recent

Author Topic: Trying my hand at a 2d game  (Read 1554 times)

TBMan

  • Full Member
  • ***
  • Posts: 188
Trying my hand at a 2d game
« on: March 06, 2025, 12:56:24 am »
I'm doing a 2d "dungeon" type game. I'll have a hero battling different sorts of opponents on a scrolling game screen. I'm keeping the first version to a 50x50 world until I feel confident with the game play and animation, then I'll up it to a larger size. I'm using 32x32 sprites, which are just arrays of bytes. Today I finished up on a working map editor, so now I have to add more sprites for the background and then design the characters which should be fun. I plan on creating my own music for the game as well, which will be fun to do as well.  This is a non-commercial game and I'll be happy to distribute it when it is "finished."

I have attached a photo of the game in development with it's preliminary "fog of war" and one of the map editor also. Both are being coded using PTCGraph. I had made a simple GUI OOP interface which has made things so much easier.
« Last Edit: March 07, 2025, 05:52:02 pm by TBMan »

Handoko

  • Hero Member
  • *****
  • Posts: 5458
  • My goal: build my own game engine using Lazarus
Re: Trying my had at a 2d game
« Reply #1 on: March 06, 2025, 02:28:28 am »
Interesting.
I rarely see people use Lazarus to create games. Please keep us informed.

flowCRANE

  • Hero Member
  • *****
  • Posts: 927
Re: Trying my had at a 2d game
« Reply #2 on: March 07, 2025, 02:15:45 pm »
Why does anyone who decides to make a game in Free Pascal (Lazarus) notoriously avoid game development libraries? There's powerful and highly efficient SDL or Allegro with open sourced headers on GitHub, and the entire Castle Game Engine, but I still see pseudo-games based on LCL, BGRAControls, and now PTCGraph — all that hardly use GPUs for rendering, nor have a sound mixer and other things that are mandatory for game development.

People spend a lot of time creating and maintaining solutions that give Free Pascal users the ability to create serious productions, but no one gives a shit and prefer to use libraries for creating GUIs rather than those dedicated to creating games. Why? Why are you so afraid of multimedia libraries and game engines?

It's high time to change this mentality and start creating more serious projects that will not only look serious, but will also show everyone that Free Pascal is suitable for creating sensible games, not just database tools. Time to say goodbye to consoles and VGA mode when you have full GPU support, sound mixers, gamepads and all that goodness at your fingertips for free, all cross-platform and easy to use. No matter if you want to make retro-console-like dungeons, platformers, point-and-click adventures, or something more advanced — don't waste time and use dedicated solutions.



I made this mistake myself and did my hobby platformer project in LCL, called Deep Platformer (it's unfinished, abandoned). If I had used SDL2, I would have learned a lot of new things, but I would also have had much greater capabilities and 100x better rendering performance. I suggest you learn from other people's mistakes (including mine in this case) and not go down that path.
Lazarus 4.0 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL3.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Trying my had at a 2d game
« Reply #3 on: March 07, 2025, 03:49:56 pm »
@flowCRANE:
fwiw I fully agree with you to use a tailored gaming engine for writing games/demo's. It makes things much easier (and quite frankly as intended)

However, consider that it might have been done so because of the learning experience e.g. learning the basics (whether or not they are the correct basics according to our personal standards does not matter).

More importantly, please note that PTC is not as stated. Yes, PTC is not a fully implemented engine and the units that are based on it do have to meet the compatibility requirements (so those will not ever see any improvement). PTC itself however is a fast graphics engine making use of threads and which you can use to render gl scenes. Please have a look at it before judging the book by only its cover.

And also yes, I am also aware that OP most probably does not make use of the possible potential.
Today is tomorrow's yesterday.

TBMan

  • Full Member
  • ***
  • Posts: 188
Re: Trying my had at a 2d game
« Reply #4 on: March 07, 2025, 05:35:55 pm »
I was just reviewing some of the 2d games on Steam and my graphics are obviously way off the mark. I'm not a graphics designer, lol.

As far as using someone else's game engine...

Who am I? A senior citizen who's has time to return to coding as a hobby. My games are not commercial, nor will more than a handful of people ever see them.

Why don't I use a game engine?:

Look at all the posts in the general section by people who are '"scratching their heads" over windows programming i.e. "How can I change the color of this control", "Why doesn't this control do this or that"., etc., etc.

It's because they didn't code the libraries. They have to try to immerse themselves into someone else's code to understand how it all works and interacts. That takes a lot of time and if there isn't enough documentation, it won't be fully realized.

Sure, I don't have the skills to do graphics at the state of the art, neither 2d or 3d, I'm not even close, but at least I know what my screen controls do, because I coded them. I don't have to figure out how to change a color in a bitmap, because I designed the simple bitmap format that I use.

What's a 2d dungeon game do?
1 - explore the world
2 - gather inventory
3 - fight bad guys
4 - get points
5 - achieve some sort of win scenario without getting killed first.

What I learned how to do so far:
1. Move and display a 2d world in a defined area of the screen. This involves scrolling the map when a boundary is met, and not going out of range.
2. Fog of war - simple for now - displaying it being removed around the movement character.
3. Translate a mouse click on the map and determine the position in the scrolling world map
4. Move the main character with keyboard and mouse
4. Develop a game world that is expandable.
5. Develop a map editor for the game(s)
6. Sprite/tile editor
7. Palette editor.

To be learned:
1. FPS management for limited animations
2 and other things that will come up.

I'd rather spend my time writing my code than learning someone else's at this point. I'm not ruling out a game engine, but I'm having fun rolling my own.

I've also been a guitar player since 1963 and I'm fairly good at writing, playing and recording music. I have decent DAW (Reaper) and various other tools at my disposal to create sound effects and music.
« Last Edit: March 07, 2025, 05:51:40 pm by TBMan »

Roland57

  • Hero Member
  • *****
  • Posts: 505
    • msegui.net
Re: Trying my hand at a 2d game
« Reply #5 on: March 07, 2025, 07:06:54 pm »
I like games made with ptcGraph.  :)

I attach here the "lines" version of my snake game. The "bitmap" version is here.

See also Ghost Invasion.
My projects are on Gitlab and on Codeberg.

flowCRANE

  • Hero Member
  • *****
  • Posts: 927
Re: Trying my hand at a 2d game
« Reply #6 on: March 07, 2025, 07:40:33 pm »
Please have a look at it before judging the book by only its cover.

I didn't — I quickly looked through the source code and it doesn't look like something that would be used for creating games. More for creating typical applications, because there is rendering, keyboard and mouse support, but I didn't find a sound mixer or gamepad support. I know that not every game should support gamepads, but without sounds it's a bit weak.



Why don't I use a game engine?:

Look at all the posts in the general section by people who are '"scratching their heads" over windows programming i.e. "How can I change the color of this control", "Why doesn't this control do this or that"., etc., etc.

I do not suggest anyone to use big tools to create games, when what they do is ultimately simple and small. Such suggestions would be inappropriate, also in my opinion. What I suggest is to use a library that contains what the games require, is easy to use, and is actively being developed. And when I say a library (like SDL), it's not an engine, just a multimedia API. With it, you can create anything, a game and game content editors, but also, for example, a music or video player. So you can still make a whole game from scratch (with a completely custom engine).

Take SDL for example, the current version is SDL3 (which I use in my game project). It supports everything needed to create any game, including simple projects — windowing, mouse, keyboard and gamepad support, rendering (software or hardware), sound mixer allowing to play any number of sounds at once, and much much more features which you don't have to use if you don't need them.

All these features are easy to use, limited to calls to a few simple functions. 2D rendering is as trivial as using TCanvas — just pass rect and texture to the function call. Want to play a sound? Call one function. Don't be afraid, just try. All with simple, structural-procedural code, instead of a bunch of bulky classes and all of these huge, complicated codebases. In addition, great documentation, where you will find everything you need, in a short and accessible form.



I thought the same as you — since I'm doing a hobby project, for myself and a few people, I don't need any library. And then I decided to try, I downloaded SDL and made a Tetris clone (Fairtris, then Fairtris 2) and then I realized what a big mistake I made to avoid such libraries.

Do whatever you want, after all it's your project, but don't limit yourself unnecessarily. Programming always requires learning new things.
Lazarus 4.0 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on a retro-style action/adventure game (pixel art), programming the engine from scratch, using Free Pascal and SDL3.

TBMan

  • Full Member
  • ***
  • Posts: 188
Re: Trying my hand at a 2d game
« Reply #7 on: March 07, 2025, 08:03:01 pm »
Please have a look at it before judging the book by only its cover.

I didn't — I quickly looked through the source code and it doesn't look like something that would be used for creating games. More for creating typical applications, because there is rendering, keyboard and mouse support, but I didn't find a sound mixer or gamepad support. I know that not every game should support gamepads, but without sounds it's a bit weak.



Why don't I use a game engine?:

Look at all the posts in the general section by people who are '"scratching their heads" over windows programming i.e. "How can I change the color of this control", "Why doesn't this control do this or that"., etc., etc.

I do not suggest anyone to use big tools to create games, when what they do is ultimately simple and small. Such suggestions would be inappropriate, also in my opinion. What I suggest is to use a library that contains what the games require, is easy to use, and is actively being developed. And when I say a library (like SDL), it's not an engine, just a multimedia API. With it, you can create anything, a game and game content editors, but also, for example, a music or video player. So you can still make a whole game from scratch (with a completely custom engine).

Take SDL for example, the current version is SDL3 (which I use in my game project). It supports everything needed to create any game, including simple projects — windowing, mouse, keyboard and gamepad support, rendering (software or hardware), sound mixer allowing to play any number of sounds at once, and much much more features which you don't have to use if you don't need them.

All these features are easy to use, limited to calls to a few simple functions. 2D rendering is as trivial as using TCanvas — just pass rect and texture to the function call. Want to play a sound? Call one function. Don't be afraid, just try. All with simple, structural-procedural code, instead of a bunch of bulky classes and all of these huge, complicated codebases. In addition, great documentation, where you will find everything you need, in a short and accessible form.



I thought the same as you — since I'm doing a hobby project, for myself and a few people, I don't need any library. And then I decided to try, I downloaded SDL and made a Tetris clone (Fairtris, then Fairtris 2) and then I realized what a big mistake I made to avoid such libraries.

Do whatever you want, after all it's your project, but don't limit yourself unnecessarily. Programming always requires learning new things.

I'll try SDL. Thanks.

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: Trying my hand at a 2d game
« Reply #8 on: March 07, 2025, 10:59:20 pm »
Прежде чем выбрать какой-то движок/фреймворк, заглянитена эту страницу.
Выбор движков/фреймворков достаточно не мал и в некоторых случаях даже уходить от LCL не надо. И возможно вам что-то своё приглянется.
Заметьте, многие движки идут с примерами внутри, на Паскале!


--------------------------------------
Google translate:
Before choosing any engine/framework, take a lookat this page.
The choice of engines/frameworks is quite large and in some cases you don't even need to move away from LCL. And maybe you'll like something of your own.
Note that many engines come with examples inside, in Pascal!
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

hukka

  • New Member
  • *
  • Posts: 45
    • Github
Re: Trying my hand at a 2d game
« Reply #9 on: March 07, 2025, 11:59:59 pm »
For something simple that's event based and runs in a window, like a Minesweeper or Sokoban style game, VCL or PTCGraph is probably enough (unless you want smooth scrolling). But if you want smooth 60 FPS movement with vsync, not to mention game controller support, that's going to be basically impossible without using one of the numerous modern libraries built for that purpose. Here's another vote for SDL2/3. It's a very popular library so there's plenty of reference material around.

Attached is a screenshot of a little SDL3 thing I made that simulates the look of a CRT display. It does a bunch of blits each frame with alpha blending, subpixel accurate scaling etc., all hardware accelerated in just a couple hundred lines of code. It only takes about one tenth of a millisecond per frame to do this! Doing this on the CPU would require many times more code and only achieve a fraction of the speed.
« Last Edit: March 08, 2025, 12:02:08 am by hukka »

TBMan

  • Full Member
  • ***
  • Posts: 188
Re: Trying my hand at a 2d game
« Reply #10 on: March 08, 2025, 01:38:35 am »
I downloaded SDL3 and I'll see if I can make sense of it. There seems to be a lot of examples.

Seenkao

  • Hero Member
  • *****
  • Posts: 711
    • New ZenGL.
Re: Trying my hand at a 2d game
« Reply #11 on: March 08, 2025, 07:39:48 am »
For something simple that's event based and runs in a window, like a Minesweeper or Sokoban style game, VCL or PTCGraph is probably enough (unless you want smooth scrolling). But if you want smooth 60 FPS movement with vsync
Проблема LCL/VCL приложений явно не в том, на что вы ссылаетесь. Достаточно посмотреть соседние топики, где показана демонстрация работы в LCL приложении и скроллинг там нормальный (примеры можно собрать и на OpenGL).
Можно заглянуть в Castle Game Engine и там тоже достаточно много примеров использующих LCL.

Потому не надо принижать возможностей LCL приложений, при том, что такие приложения могут работать с большинством игровых движков/библиотек. А новичкам это может быть будет даже удобнее.
 :)

Единственно с чем сейчас не справится LCL - это с мобильными устройствами (или какими-то подобными).

---------------------------------------------------------
Google translate:
The problem with LCL/VCL applications is clearly not what you are referring to. Just look at adjacent topics, where a demonstration of working in an LCL application is shown and scrolling is normal there (examples can be compiled on OpenGL).
You can look at Castle Game Engine and there are also quite a lot of examples using LCL.

Therefore, there is no need to belittle the capabilities of LCL applications, given that such applications can work with most game engines/libraries. And for beginners, this may even be more convenient.
 :)

The only thing LCL can't handle right now is mobile devices (or anything similar).
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

hukka

  • New Member
  • *
  • Posts: 45
    • Github
Re: Trying my hand at a 2d game
« Reply #12 on: March 08, 2025, 10:11:31 am »
The problem with LCL/VCL applications is clearly not what you are referring to. Just look at adjacent topics, where a demonstration of working in an LCL application is shown and scrolling is normal there (examples can be compiled on OpenGL).
You can look at Castle Game Engine and there are also quite a lot of examples using LCL.

Therefore, there is no need to belittle the capabilities of LCL applications, given that such applications can work with most game engines/libraries. And for beginners, this may even be more convenient.
 :)

The only thing LCL can't handle right now is mobile devices (or anything similar).

Your examples were not plain LCL (whoops I said VCL in my post), but using hardware accelerated libraries such as OpenGL and Castle. You can also host a SDL2/3 context inside an LCL app, but that was not the point. You can't do vsync in plain LCL, unless your underlying window manager forces vsync globally. Scrolling, sure, but not hardware accelerated without use of external libraries.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Trying my hand at a 2d game
« Reply #13 on: March 08, 2025, 03:05:45 pm »
Attached is a screenshot of a little SDL3 thing I made ...
Now, /there/ is a blast from the past :)
Today is tomorrow's yesterday.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Trying my hand at a 2d game
« Reply #14 on: March 08, 2025, 03:18:47 pm »
I didn't — I quickly looked through the source code and it doesn't look like something that would be used for creating games.
In basics PTC is a framebuffer library (based on openPTC), so ...

Your typical application  :-X
Code: Pascal  [Select][+][-]
  1.  
  2.  PTC OpenGL example for PTCPas
  3.  Copyright (c) Nikolay Nikolov (nickysn@users.sourceforge.net)
  4.  This source code is in the public domain
  5. }
  6.  
  7. program PtcGL2Example;
  8.  
  9. {$MODE objfpc}
  10.  
  11. uses
  12.   ptc, gl, SysUtils;
  13.  
  14. var
  15.   Console: IPTCConsole;
  16.   Event: IPTCEvent;
  17.   Done: Boolean = False;
  18. begin
  19.   try
  20.     try
  21.       { create console }
  22.       Console := TPTCConsoleFactory.CreateNew;
  23.  
  24.       { tell PTC we want OpenGL }
  25.       Console.OpenGL_Enabled := True;
  26.  
  27.       { use OpenGL single buffering }
  28.       Console.OpenGL_Attributes.DoubleBuffer := False;
  29.  
  30.       { open the console }
  31.       Console.Open('PTC OpenGL single buffering example');
  32.  
  33.       glClearColor(0.0, 0.0, 0.0, 0.0);
  34.  
  35.       glMatrixMode(GL_PROJECTION);
  36.       glLoadIdentity;
  37.       glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
  38.  
  39.       { loop until the key 'q' is pressed }
  40.       repeat
  41.         { draw scene }
  42.         glClear(GL_COLOR_BUFFER_BIT);
  43.  
  44.         glBegin(GL_POLYGON);
  45.           glColor3f(1.0, 0.0, 0.0);
  46.           glVertex3f(0.25, 0.25, 0.0);
  47.           glColor3f(1.0, 1.0, 0.0);
  48.           glVertex3f(0.75, 0.25, 0.0);
  49.           glColor3f(0.5, 0.0, 1.0);
  50.           glVertex3f(0.75, 0.75, 0.0);
  51.           glColor3f(0.0, 1.0, 0.0);
  52.           glVertex3f(0.25, 0.75, 0.0);
  53.         glEnd;
  54.  
  55.         glFlush;
  56.  
  57.         { check for events }
  58.         if Console.NextEvent(Event, False, PTCAnyEvent) then
  59.         begin
  60.           { handle keyboard events }
  61.           if Supports(event, IPTCKeyEvent) and (event as IPTCKeyEvent).Press then
  62.           begin
  63.             case (event as IPTCKeyEvent).Code of
  64.               PTCKEY_Q: Done := True;
  65.             end;
  66.           end;
  67.         end;
  68.       until Done;
  69.     finally
  70.       if Assigned(Console) then
  71.         Console.Close;
  72.     end;
  73.   except
  74.     on Error: TPTCError do
  75.       { report error }
  76.       Error.Report;
  77.   end;
  78. end.
  79.  

... it is not a gaming engine with frivolous things like audio and input-methods  :)
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018