Recent

Author Topic: The plumps - a small RTS game in Lazarus  (Read 4768 times)

Tomi

  • Full Member
  • ***
  • Posts: 102
The plumps - a small RTS game in Lazarus
« on: March 06, 2022, 11:27:26 am »
Hello everybody!

I have started to make a small RTS game in Lazarus. It is not finished yet, but I can present some stuff about it for you. For example a picture at least, but I will publish the source code soon.
Its title is "The plumps" (maybe "Puffancsok" in hungarian) and you can control the little cute creatures of an alien planet in its fight against enemy.
So, what I completed till now with the game?
- Scrollable game field,
- A simple own algorithm to move units and avoid obstacles,
- Player can build some basic buildings.
I make the game purely in Lazarus, so nothing special like game engines or similar tools. Graphics made with Anim8or.
Now, I would like present you my first steps with this topic. If you can recommend me similar Lazarus games, so don't hesitate because I need all kinds of knowledge.

Tomi

  • Full Member
  • ***
  • Posts: 102
Re: The plumps - a small RTS game in Lazarus
« Reply #1 on: March 19, 2022, 05:14:48 pm »
And ladies and gentelmen, here is the source code from my website:
http://www.programozzunk.ucoz.hu/lazjatekok/puffancsok.zip

Note that this game are in very early version, so this is a beta version. But try it; I hope, you will like my work and I hope, I can inspire you if you plan to make similar games.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: The plumps - a small RTS game in Lazarus
« Reply #2 on: March 19, 2022, 05:49:33 pm »
Great! It works, even on Linux too.
Many things are still missing, but you made a good step.

I can move the creatures and create buildings. Unfortunately it run too fast on my PC. You can use a TTimer or run some codes to check the computer speed and do necessary delay. Also, I guess you have a large monitor. All the sprites seemed very large on my 1600x900 resolution monitor.

Just to warn you, using TCanvas to create games ... you will have performance issue later.

furious programming

  • Hero Member
  • *****
  • Posts: 853
Re: The plumps - a small RTS game in Lazarus
« Reply #3 on: March 19, 2022, 06:59:30 pm »
Use SDL — it is super simple to use and quite powerful. Dealing with LCL limitations in the terms of creating game is a waste of time.
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

Tomi

  • Full Member
  • ***
  • Posts: 102
Re: The plumps - a small RTS game in Lazarus
« Reply #4 on: March 20, 2022, 09:27:49 am »
"it run too fast on my PC. You can use a TTimer or run some codes to check the computer speed and do necessary delay."

Hello Handoko!

Setting of correct game speed is always a big problem for me if there is no basic tools for this. But in this game I used TTimer at lines 1374-1376:
Code: Pascal  [Select][+][-]
  1. palyafrissito:=TTimer.Create(nil);
  2.   palyafrissito.interval:=10;
  3.   palyafrissito.ontimer:=@palyafrissites;
Maybe value 10 for interval is too small and the game is too fast because of it? Is there an optimal value to correct speed at all computers?

Tomi

  • Full Member
  • ***
  • Posts: 102
Re: The plumps - a small RTS game in Lazarus
« Reply #5 on: March 20, 2022, 09:34:09 am »
Use SDL — it is super simple to use and quite powerful. Dealing with LCL limitations in the terms of creating game is a waste of time.
Hello Furious!

Yes, SDL and similar tools makes game developing easier, but I'm still too green for this and I just use basic Lazarus possibilities for games in first times. Then I will try Allegro and Castle Game Engine if necessary.

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: The plumps - a small RTS game in Lazarus
« Reply #6 on: March 20, 2022, 11:35:26 am »
Is there an optimal value to correct speed at all computers?
Для этого каждый "шаг" основного процесса проводят соответственно прошедшего времени. Вычисляют deltaTime прошедшего времени данного цикла и герой (и всё окружение) двигаются соответственно данного deltaTime. И тогда на разных компьютерах это будет работать примерно одинаково.
google translate:
To do this, each "step" of the main process is carried out according to the elapsed time. The deltaTime of the elapsed time of the given cycle is calculated and the hero (and the whole environment) move according to the given deltaTime. And then on different computers it will work approximately the same.
Code: Pascal  [Select][+][-]
  1. prcedure proc(dt: double);
  2. begin
  3.   Heroes.X :=  Heroes.X + Heroes.Speed * dt / 1000;    // 1000 ms
  4. end;
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

furious programming

  • Hero Member
  • *****
  • Posts: 853
Re: The plumps - a small RTS game in Lazarus
« Reply #7 on: March 20, 2022, 11:44:41 am »
Yes, SDL and similar tools makes game developing easier, but I'm still too green for this and I just use basic Lazarus possibilities for games in first times.

You will always be ”to green” for this until you finally try — nobody was born with such knowledge and skill.

When I decided to make a game using SDL myself, I didn't really know how to use this library either. However, it is so easy to use that I had no problems programming other things. At most once in a while, by trial and error, I slowly came to a solution. I suggest not to waste your time on LCL to build games, because it is not suitable for creating games for many reasons, including the most important:
  • no Direct3D and OpenGL support
  • unable to use GPU for rendering textures
  • no exclusive video mode support and available screen resolutions
  • absolutely no support for sound mixer and playing multiple sounds at the same time
  • lack of support for game controllers and their full functionality
  • lack o V-Sync support
What I mentioned above are the basics, without which creating even a simple game will be inconvenient, the game itself will be very limited, and its performance will be very low (software rendering is horribly slow in compare to GPU rendering). As you can see, it doesn't make much sense.

Whether you want to make a tiny game or a bigger one, use the library dedicated to their creation. It does not have to be SDL, but it is important that it has all the functionality to create full-fledged video games. However, if you are interested in creating a 2D game, I strongly advise you not to use 3D engines for this purpose, because it will significantly complicate the implementation, and you will get discouraged very quickly.

Use something small, light, functional and, above all, supported at all times. I suggest SDL because it meets all the requirements and is great, but it can also be Allegro, because it's the same shelf. In case you ever get tempted by SDL and have questions, I will be happy to help. I've learned a lot over the last year so I'll be able to help a bit, especially when it comes to basic (key) issues.

Is there an optimal value to correct speed at all computers?

You have several solutions.

The first is to use delta to calculate motion using interpolation. Thanks to this, the game will run at the same speed on every computer, but the very big downside is that it will eat up all the available power of the CPU core. In the case of small games that do not have complicated logic and long-lasting frame rendering, this solution is weak.

The second way is a constant framerate and pauses between generating frames. The current time is taken, the frame is generated along with the rendering, and the time is retrieved again. Based on the two times, the number of milliseconds it took to generate the frame is calculated, the waiting time for the next frame is calculated and the function is called, which freezes the thread (Windows.Sleep, FPNanoSleep, SDL_Delay, etc.). This allows you to easily handle logic (no delta), frames are generated at regular intervals, and the process only uses as much power as it needs. It is a simple, energy-saving solution, but not very precise.

The third solution is V-Sync support, i.e. generating and displaying frames in accordance with the screen refresh rate. In this case, you also need to use delta-time, but timing and waiting for the generation of next frames is implemented on the API side of the GPU, so you do not have to program anything yourself — the intervals will be performed automatically. The solution is easy to implement (e.g. using SDL) and energy-saving and solves the screen tearing problem.

The fourth solution is a constant framerate (independent of the screen refresh rate), no delta-time, but precise measurement of the time between generating frames. Similar to the first one given, but the difference is that the intervals should be performed with more precision than the millisecond. After measuring the waiting time between frames, a larger portion is waited first using eg SDL_Delay (milliseconds) and the remainder waited using busy waiting. Thanks to this, the framerate will always be what we want (super-precise), no matter how little time you have to wait between frames. If you need inspiration, I implemented such a clock in my game called Fairtris (unit Fairtris.Clock.pp). This solution is also simple and energy-saving.

Of course, there are more ways and it all depends on what we really care about.


It should be noted that no matter if we want a constant framerate or a variable (matched to screen refresh rate or completely dynamic), using delta is a good idea if we want to use the slow motion (or accelerated motion) effect in the game. Without delta, it cannot be done other than changing the game framerate or doing strenge things with game logic, which is a very poor solution. The playback speed of the game should be independent of the framerate and programmed in such a way that it is easy to manipulate it.
« Last Edit: March 20, 2022, 12:12:03 pm by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: The plumps - a small RTS game in Lazarus
« Reply #8 on: March 20, 2022, 01:11:43 pm »

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: The plumps - a small RTS game in Lazarus
« Reply #9 on: March 20, 2022, 01:17:40 pm »
I suggest not to waste your time on LCL to build games, because it is not suitable for creating games for many reasons, including the most important:
  • no Direct3D and OpenGL support
  • unable to use GPU for rendering textures
  • no exclusive video mode support and available screen resolutions
  • absolutely no support for sound mixer and playing multiple sounds at the same time
  • lack of support for game controllers and their full functionality
  • lack o V-Sync support
Не надо путать людей. Есть очень немало решений для одновременного использования и LCL и OpenGL/DX. Их можно увидеть в соседних топиках и на вики Freepascal. На немецком форуме почти все уроки по OpenGL сделаны под LCL. dglOpenGL.pas - позволяет работать с LCL в Windows без особых знаний создания окна/контекста OpenGL.
google translate:
Don't confuse people. There are quite a few solutions for using both LCL and OpenGL/DX at the same time. They can be seen in neighboring topics and on the Freepascal wiki. In the German forum, almost all OpenGL tutorials are made under LCL. dglOpenGL.pas - allows you to work with LCL on Windows without much knowledge of creating an OpenGL window/context.
Думаю я даже не смогу полностью осветить эту тему. И большой шанс, что я что-нибудь упущу. LCL так же можно использовать и с SDL, Castle Game Engine, PGF, Apus Game Engine, ZenGL и многими другими движками.
Подключение контроллеров, вообще не зависит от того что мы используем. Для этого надо просто использовать нужные библиотеки. Зачастую, которые уже идут с игровыми движками. И так же можно использовать в LCL.
Со звуком так же, ни кто не запрещает использовать одноканальный/многоканальный звук. Всё это предоставлено в соответствующих библиотеках. И так же можно использовать в LCL.
Вы очень сильно вводите в заблуждение людей!!!

google translate:
I don't even think I can fully cover this topic. And there's a good chance I'll miss something. LCL can also be used with SDL, Castle Game Engine, PGF, Apus Game Engine, ZenGL and many other engines.
Connecting controllers does not depend at all on what we use. To do this, you just need to use the necessary libraries. Often that already come with game engines. And it can also be used in LCL.
With sound, no one forbids the use of single-channel / multi-channel sound. All this is provided in the respective libraries. And it can also be used in LCL.
You are very misleading people!!!

What I mentioned above are the basics, without which creating even a simple game will be inconvenient, the game itself will be very limited, and its performance will be very low (software rendering is horribly slow in compare to GPU rendering).
Единственно по какой причине это не подходящий вариант, это если у вас высоконагруженное приложение. Тут я частично согласен!
На простых играх это практически ни как не скажется.
google translate:
The only reason this is not a suitable option is if you have a highly loaded application. Here I partly agree!
In simple games, this has almost no effect.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: The plumps - a small RTS game in Lazarus
« Reply #10 on: March 20, 2022, 01:20:16 pm »
Copied the good comment to the Wiki, https://wiki.freepascal.org/Game_framework#Using_LCL_for_game_development
Вы зря это сделали. По большей части заходят смотреть такие вещи новички. А LCL намного удобнее и быстрее для понимания, чем разбор каких-либо движков.
И, увы, не соответствует действительности. Выше всё описал.
google translate:
You did it in vain. For the most part, beginners come to see such things. And LCL is much more convenient and faster to understand than parsing any engines. :)
And, alas, it is not true. :( All described above.
« Last Edit: March 20, 2022, 01:22:37 pm by Seenkao »
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: The plumps - a small RTS game in Lazarus
« Reply #11 on: March 20, 2022, 01:44:17 pm »
@Seenkao, please point me to your detailed answer, and I will add it to the same wiki part.

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: The plumps - a small RTS game in Lazarus
« Reply #12 on: March 20, 2022, 02:02:56 pm »
@Seenkao, please point me to your detailed answer, and I will add it to the same wiki part.
Пост №9. Я не думаю, что это нужно вообще выкладывать на вики. Это обсуждения. Но думаю на вики были бы полезны именно ссылки на эти обсуждения.
google translate:
Post number 9. I don't think this should be posted on the wiki at all. These are discussions. But I think links to these discussions would be useful on the wiki.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

furious programming

  • Hero Member
  • *****
  • Posts: 853
Re: The plumps - a small RTS game in Lazarus
« Reply #13 on: March 20, 2022, 03:55:48 pm »
Don't confuse people. There are quite a few solutions for using both LCL and OpenGL/DX at the same time.

There are several solutions, but they all require a lot of knowledge and writing a lot of code, and besides, they only slightly cover what libraries such as SDL or Allegro offer. So what if you can create an OpenGL context, since rendering anything will require in-depth knowledge of this API? In addition, it will require writing code that someone has already written and tested on many operating systems and millions of devices. For the same reason, we use LCL to create window applications, rather than writing millions of lines of code in WinAPI.

Also, even if you write a rendering code, it will still be a fraction of what is expected for game development. Where's the multiple displays and resolutions support? Where is the exclusive video mode support? Where is the sound mixer support? Where is the support for the keyboard, mouse, as well as controllers and their mapping? Do you want to write it yourself? Good luck. SDL has 300k+ LoC, I wonder how long it will take someone to do the same, who is just starting their adventure with game development.

In short, if you are recommending anyone to use LCL to build a full-fledged game, then you have no idea what you are talking about. By doing this, you only do harm to others.

Quote
Connecting controllers does not depend at all on what we use. To do this, you just need to use the necessary libraries. Often that already come with game engines. And it can also be used in LCL.

What libraries? Why should I use separate libraries since SDL covers everything?

Quote
With sound, no one forbids the use of single-channel / multi-channel sound. All this is provided in the respective libraries. And it can also be used in LCL.

More libraries? How many more will you need to search for and include in the project? Are you trolling or are you drunk?

Quote
You are very misleading people!!!

You have no idea what you are writing about, your arguments are full of nonsense. I bet you have never created any more serious game, and you base your entire opinion on randomly found information in Google. You are the best teacher I have ever met.

Coming back to the seriousness, without irony, everything that @Seenkao wrote is suitable for the trash and I advise everyone not to take his statements seriously. I advise against using LCL to create games, let alone looking for multiple libraries that support various aspects, since everything, absolutely EVERYTHING is supported by one meaningful library, such as SDL or Allegro (or entire engine like ZenGL or CGE). Not only is everything supported, but we also have one documentation describing everything, as well as one license (because the library is one). In this way, writing code for the game will be convenient, we will save a lot of time and we will not be limited in any way.

And, at best, window applications and LCL with embedded OpenGL controls should be used to create editors and other tools for creating game content. Absolutely NOT for the game itself.

Quote
In simple games, this has almost no effect.

I suggest you wake up, look at your calendar and understand that it's 2022, not 1980. We have great tools and libraries with powerful functionality that make game development very easy, and we have these tools for free. If you want to waste your time on LCL and millions of additional libraries, waste your time, but don't persuade others to do so.
« Last Edit: March 20, 2022, 03:58:22 pm by furious programming »
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: The plumps - a small RTS game in Lazarus
« Reply #14 on: March 20, 2022, 04:31:15 pm »
furious programming, как много эмоций...  %) Спокойнее молодой человек.
Всё что вам нужно знать, это то, что рекламируемая вами библиотека SDL просто подключается к LCL и используется. Но видимо вам это невдомёк...

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

google translate:
how many emotions...%) Calm down the young man.
All you need to know is that the SDL library you advertise is simply connected to the LCL and used. But apparently you don't know...

And everything that you wrote just collapses into collapse, about your own statements. And the fact that other engines are just as easily connected to the LCL and used can not even be said. And somewhere it costs by default. :D

I bet you have never created any more serious game, and you base your entire opinion on randomly found information in Google. You are the best teacher I have ever met.
Для таких утверждений, надо сначала самому что-то стоящее написать, а не повторить очередной тетрис. ::)
google translate:
For such statements, you must first write something worthwhile yourself, and not repeat another Tetris. ::)

Ну и, ваши же эмоции вас и выдали. Я так понимаю что конкретного вам не чего сказать, просто очередная бравада. Думаю дальше спорить бесполезно, вы всё равно дальше своего носа не хотите видеть. Всего доброго!
Google translate:
Well, your own emotions betrayed you. I understand that there is nothing specific for you to say, just another bravado. I think it’s useless to argue further, you still don’t want to see beyond your nose. All the best! 8-)
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

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

 

TinyPortal © 2005-2018