The MASM Forum

Projects => Game Development => Topic started by: caballero on July 10, 2022, 08:26:36 AM

Title: Birds game
Post by: caballero on July 10, 2022, 08:26:36 AM
The game is done.

Full Masm 32 bits + GDI source code. No external dll or lib used. Everything used is in my web page freely downloable.

Some birds flying here and there shit in your garden. You have a ball to convince them to do it in the neighbor's garden.

You have a score account and a seconds counter. When this counter reaches zero it should be game over, it's on the to-do list.

The ball describes a parabola. If it hits a bird, it will increase the marker by more the farther away the bird is.

Known bug: After a few shots, the motion of the ball speeds up. [Fixed]
Title: Re: Birds game
Post by: jj2007 on July 10, 2022, 10:22:42 AM
Looks lovely :thumbsup:

Wouldn't sky.png (4415 bytes) instead of sky.bmp (921654 bytes) be a better choice? Same for the birds, they could be one gif file...
Title: Re: Birds game
Post by: Biterider on July 10, 2022, 03:06:14 PM
Hi Caballero
Looks very good!
I'm looking forward to the finished game.  :thumbsup:

Biterider
Title: Re: Birds game
Post by: caballero on July 10, 2022, 05:50:29 PM
Hi, thank you for testing it.  :thumbsup:

I don't use any external routine to read image files, I read them "by hand" and bmp files are one of the easiest to read, that's why I use them. I think I could avoid to use the sky.bmp painting the cloudy sky with my own routines but, since the original challenge was reading these two files, I'll leave it at that.
Title: Re: Birds game
Post by: jj2007 on July 10, 2022, 09:13:07 PM
For inspiration - with source ;-)

Code: [Select]
GuiParas equ "Birds", w500, h320, b none
include \masm32\MasmBasic\Res\MbGui.asm
  SetGlobals SDWORD bird1X, bird1Y, bird2X, bird2Y, d1y, d2y
  mov eax, GuiHeight
  sar eax, 1
  sub eax, 30
  mov bird1Y, eax
  add eax, 60
  mov bird2Y, eax
Event Paint
  GuiImage "sky.png", fit
  GuiImage "tweety.gif", bird1X, bird1Y, 60, 60
  GuiImage "tweety.gif", bird2X, bird2Y
Event Timer
  sub bird1X, 5
  .if bird1X<-60
m2m bird1X, GuiWidth
  .endif
  sub bird2X, 4
  .if bird2X<-60
m2m bird2X, GuiWidth
  .endif
  sub Rand(11), 5
  add eax, d1y
  add bird1Y, eax
  .if bird1Y<20
dec d1y
  .elseif bird1Y>250
inc d1y
  .endif
  sar eax, 1
  inc eax
  .if bird2Y<20
dec d2y
  .elseif bird2Y>250
inc d2y
  .endif
  add eax, d2y
  sub bird2Y, eax
  GuiCls
GuiEnd
Title: Re: Birds game
Post by: caballero on July 10, 2022, 09:31:14 PM
I have fixed some issues:

   - The birds in the background are always slower than the ones in the foreground. This gives a greater sense of depth.

   - When it came to regenerating the birds that were lost, it was not done well because I had to multiply the x-dim of the sprite by 10 because stretching generated decimals.
   
   x The ordering of the three layers of birds does not seem to be working well in all cases. It cannot be that a smaller bird passes in front of a larger one. In to-do list.
Title: Re: Birds game
Post by: caballero on July 10, 2022, 09:41:23 PM
jj, where is the source? There's an include that I don't have. Do you use for reading/stretching images?
Title: Re: Birds game
Post by: jj2007 on July 10, 2022, 10:23:20 PM
jj, where is the source? There's an include that I don't have.
Part of MasmBasic (http://masm32.com/board/index.php?topic=94.0)

Quote
Do you use for reading/stretching images?

For reading, I use mostly GdipCreateBitmapFromStream
For zooming, I use GdipDrawImageRectRectI

I really posted it just for inspiration. Yours looks better :thumbsup:
Title: Re: Birds game
Post by: caballero on July 10, 2022, 11:10:07 PM
Nah, yours is nice too.  :thumbsup:

I don't use any external routine to read/zooming an image, I like to code it by myself.
Title: Re: Birds game
Post by: caballero on July 11, 2022, 05:41:04 AM
The sorting method seems to be working now. None smaller bird should appear before a bigger one.
Title: Re: Birds game
Post by: Greenhorn on July 13, 2022, 08:26:28 AM
Great stuff, caballero !  :thumbsup:

> The next step would be to draw a ball that would take a parabolic shot to the bottom to hit the bird, adding a score counter to it.
Reminds me a little bit on "Moorhuhn" game.  :biggrin:
Title: Re: Birds game
Post by: caballero on July 13, 2022, 07:39:13 PM
Thanks, Greenhorn  :thumbsup:. Moorhuhn reminds me Super Mario.
Title: Re: Birds game
Post by: jj2007 on July 13, 2022, 10:45:56 PM
Version 2, playing around with some new features, mainly zoom and RotateFlip (https://docs.microsoft.com/en-us/windows/win32/api/gdiplusimaging/ne-gdiplusimaging-rotatefliptype) :tongue:

Event Paint
  GuiImage 97, fit                             ; sky.png
  GuiImage 98, bird1X, bird1Y, size1, size1    ; tweety.gif
  GuiImage 98, bird2X, bird2Y                  ; tweety again
  GuiImageSet z=zoom3, rf=b3RF                 ; RotateNoneFlipX when going out of the screen
  GuiImage "https://jj2007.eu/pics/eagle.gif", bird3X, bird3Y, 200, 200


That was the "simple" part - the logic of the movements is trickier, see attached source :cool:

97+98 are resource IDs. The eagle was too fat to be included, so I put it on my page.
Title: Re: Birds game
Post by: caballero on July 14, 2022, 09:10:09 AM
Balls with clipping tests. The ball is not from any image file, but made on the fly using math algos, this way we get a smaller exe. Since I don't use any external routine to draw the sprites, I have to do the clipping by myself, the same for the birds.
Title: Re: Birds game
Post by: caballero on July 17, 2022, 02:21:04 AM
Now, you may move the ball around the screen with the mouse cursor, yet still cannot be shooted. Since the ball is at the user level, I have to add another layer for it. The ball, when shooted, will cross several layers, hence some birds must appear before and other behind it.

When finished, with the m'left button you'll shoot and with the m'right increase the angle.
Title: Re: Birds game
Post by: caballero on July 25, 2022, 10:53:31 PM
Hi. Another step:

I have reduced the ball by several percentages to simulate its distance when we throw it. The path followed by the ball is a parabolic shot, with an initial speed of 20m/s and an angle of 60ยบ. The result is that it initially goes up slightly and then goes down until it reaches a certain point, where it disappears.

Only one ball can be thrown at a time. At the moment, the ball does not hit any bird. That will be the next step.

A pending task would be to discolor the bitmap when we reduce it to give a better sense of depth. Although it wouldn't be difficult to do, I don't know I will do it, because I'm starting to get bored of this game.

Each time the ball crosses a layer a rearrangement should be made so that the birds and the ball appear in front or behind, where appropriate. But the ordering method that I have implemented is somewhat slow and perhaps not worth it, considering that every time a new bird is created a sort is executed.
Title: Re: Birds game
Post by: caballero on July 27, 2022, 12:02:49 AM
I have added a few things:

- A little scoring system at the top left, that I don't like much, so I will change it for another.
- Sounds for throwing the ball and when hit a bird.
- The collision test is not working very well yet.