Recent

Author Topic: [Bomberman] Making a solid object  (Read 443 times)

Pascal Van de Bergh

  • Newbie
  • Posts: 1
[Bomberman] Making a solid object
« on: January 23, 2020, 09:44:14 am »
Hello, my friend and i have to make bomberman in lazarus pascal for a school project. What we already have done is that we have made that the character can't go out of the picture. There are solid objects in bomberman that you can't walk through. Can anyone share their code with us? If you have a final game of bomberman in lazarus pascal we would love to have it!
 :)

this is the code for walking and border detection
if key = VK_UP then
   Image136.Top := Image136.Top -64;
if key = VK_DOWN then
   Image136.Top := Image136.Top +64;
if key = VK_LEFT then
      Image136.Left := Image136.Left -64;
if key = VK_RIGHT then
      Image136.Left := Image136.Left +64;
if key = VK_SPACE then
      Image136.Left := Image136.Left +64;

if Image136.Left = 0 then Image136.Left := Image136.Left +64;
if Image136.Top = 0 then Image136.Top := Image136.Top +64;
if Image136.Left = 1216 then Image136.Left := Image136.Left -64;
if Image136.Top = 704 then Image136.Top := Image136.Top -64;
« Last Edit: January 23, 2020, 09:46:21 am by Pascal Van de Bergh »

Handoko

  • Hero Member
  • *****
  • Posts: 3354
  • My goal: build my own game engine using Lazarus
Re: [Bomberman] Making a solid object
« Reply #1 on: January 23, 2020, 01:42:58 pm »
Hello Pascal Van de Bergh,
Welcome to the forum.

Good to see you've already understand how to read keyboard input and limit the movement.

Can anyone share their code with us? If you have a final game of bomberman in lazarus pascal we would love to have it!
 :)

 :) So, you want a shortcut ?!

Unfortunately, writing a bombarman game isn't simple and I doubt they will share you the code.

If you want a simpler-to-create game, I recommend you Pong. I wrote one and it's only 113 line of code:
https://forum.lazarus.freepascal.org/index.php/topic,42439.msg297949.html#msg297949

After looking your code, here is my advice for you:
Don't manipulate objects directly on the screen. For many reasons it is better and easier to manipulate your objects in the game world. And then you write a procedure to draw the objects in your game world to the screen.

Here is a snake game tutorial, it's long and boring, maybe you can learn something from it:
https://forum.lazarus.freepascal.org/index.php/topic,38136.msg258381.html#msg258381
« Last Edit: January 23, 2020, 01:45:04 pm by Handoko »

soerensen3

  • Full Member
  • ***
  • Posts: 183
Re: [Bomberman] Making a solid object
« Reply #2 on: January 23, 2020, 01:48:25 pm »
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

Mr.Madguy

  • Sr. Member
  • ****
  • Posts: 473
Re: [Bomberman] Making a solid object
« Reply #3 on: January 23, 2020, 02:09:07 pm »
Basically, you need map.
Code: Pascal  [Select]
  1. type
  2.   TCell = <some type, that holds info about game field cell, starting from enumeration and ending with some object>;
  3. //Example TCell = (clEmpty, clWall, clBomb, clBonus);
  4. var
  5.   Map:array[0..MaxX, 0..MaxY] of TCell;
  6.  
  7. //Some code
  8.   CellCoord := CharacterCoordToCellCoord(Character);
  9.   if Map[CellCoord.X, CellCoord.Y] = something then begin
  10.     ...
  11.   end;
  12.  
DynamicData 3.0 is released!
Since now development is frozen - only optimization passes will be made at some point.
Lack of multiple inheritance turns it into abomination.

Handoko

  • Hero Member
  • *****
  • Posts: 3354
  • My goal: build my own game engine using Lazarus
Re: [Bomberman] Making a solid object
« Reply #4 on: January 23, 2020, 02:44:52 pm »
I don't mean to discourage the OP. But to be able to write a bomberman game, the programmer need to be able to solve:

---  The explosion issues
- Bomb only explodes after some seconds (need to calculate the delay time)
- Explosion power can be improved if the player eat some power ups
- Explosion will trigger other bombs to explode immediately
- Explosion can't penetrate walls.

--- The wall issues
- Not all walls are breakable
- Some power ups are hidden beneath the wall

--- Also
- Need simple AI to make the monsters moving
- May need to create a level editor

Students submit a bomberman game for a school project?! If the teacher is 'smart' enough, he will think it must be copy-pasted from somewhere.
« Last Edit: January 23, 2020, 03:47:36 pm by Handoko »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5962
    • wiki
Re: [Bomberman] Making a solid object
« Reply #5 on: January 23, 2020, 02:57:23 pm »
To be honest, if you are at "Image136", then you are far away from a bomberman game.

But anyway....

1) Do not use the IDE's form editor to create the level. (I.e. do not place walls, and objects)
2) Improve naming => Image136 => PlayerImage (or if Player is a structure Player.Image)
3) Store your level as a 2 dimensional array.
3a) That means, you do not store pixel coordinates (like 64 or 128, ....), but simply 1,2,3....
3b) To display an image according to your 2-dim-array, multiply the coordinate.

Now with walls, and other objects stored in the 2 dim array, you should be able to check if the player is allowed on a field or not....



I know some of my hints are somewhat vague.
You set yourself a high goal. If you want any chance of archiving it (and of your teacher believing that you actually did it yourself), then you need to be able to figure some stuff out by yourself.