Cloning DEBRIS32 game

Advanced game related topics
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

it's a cool project!
but for now a little overkill, i'm also trying to make everything look the same,
a 3D look effect is not going to be accurate and why install a complete render engine if the sprites are already at hand :)
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cloning DEBRIS32 game

Post by infratec »

Have you seen my additions to
viewtopic.php?f=7&t=76636
:?:

Now you should have all pictures of the game.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

infratec wrote:Have you seen my additions to
viewtopic.php?f=7&t=76636
:?:

Now you should have all pictures of the game.
Oh i didn't notice (was on a second page), i replied over there with a little code :p
I'm gonna extract everything today and update the drive folder and description! :)
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cloning DEBRIS32 game

Post by infratec »

I use png because in png is already transparency included.
You don't need set a transparence color.

I use IrfanView and save the images as png with 'save transparent color' enabled,
but disabled 'save transparence as alpha-channel'.

Then I can simply use DisplayTransparentSprite() (after LoadSprite() of course)
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

infratec wrote:I use png because in png is already transparency included.
You don't need to set a transparency color.
I noticed you don't even have to set that color with bmp's if you leave it black like the original graphics :)
PNG uses an extra decoder so maybe it's a little slower, not sure..
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

@ricardo_sdl

I looked at your code today and noticed the actual angle was not snapped to the 11.25° angles but the sprite number was correct.
If the ship would need to fly forward it would need to do so in exactly the snapped angle that the sprite displays.
In the original debris game the ship also fly's in exactly that snapped angle.

If I use your code without modifications this would be a problem, for example:
The ship looks like it's at an angle of exactly 90°, but if you fly forward it doesn't always fly in a straight horizontal line.
why? Under the hood you still work with a 360° system, so the ship could look like it's in a 90° angle but in reality it's for example 92°.

If I want to implement delta time with the angle system that is needed for this project than I have no idea yet how to implement this..

Using ElapsedMilliseconds() like you did instead of SetFrameRate() gives me strange results...
Use an interval for ElapsedMilliseconds() at 31 or 32 milliseconds and it looks like it's exactly the same speed, use 33 and suddenly it's way slower??

So for now i use setframerate(),
The only thing that bothers me is that if you pressed the left or right to quickly, the ship it doesn't react..
The original game still reacts if you quickly press and release a button.

@STARGÅTE

I used your angle difference function and with some fiddling around (still a bit new to game graphics math) I found out how to use it properly! ..kinda :p
The main problem is that the ship wiggles when it's almost locked at it's target in AI-mode, it's also because of the angle snap system i'm afraid.
I think I managed to solve this with dif > 0.1 and dif < -0.1, but if you know a better way feel free to correct me :)

For everyone reading this:

I updated my code and also fully updated the folders in google drive.
All the graphics, all the sounds, everything is uploaded, updated and renamed to organize everything a little better.
To test my code you can download the new files from the link :)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Cloning DEBRIS32 game

Post by Mijikai »

Angle to Sprite Index:

Code: Select all

Procedure.i AngleToSpriteIndex(Angle.f)
  Protected index.i
  index = ((Angle - 5.625) / 11.25)
  If index = 32
    index = 0
  EndIf
  ProcedureReturn index
EndProcedure
If the ship sprites are composed into a single sprite-/tilemap (with a height of one)
Simply extract the correct sprite with ClipSprite()

Code: Select all

ClipSprite(sprite,AngleToSpriteIndex(Angle) * 32,0,32,32)
If each sprite loaded seperately into an array (srsly why would u do that?...) use it as the array index.

Code: Select all

AngleToSpriteIndex(Angle)
A more complete Example (only missing the sprite-/tilemap):

Code: Select all

EnableExplicit

UsePNGImageDecoder()

Procedure.i AngleToSpriteIndex(Angle.f)
  Protected index.i
  index = ((Angle - 5.625) / 11.25)
  If index = 32
    index = 0
  EndIf
  ProcedureReturn index
EndProcedure

Procedure.i RenderShip(X.f,Y.f,Sprite.i,Angle.f)
  ClipSprite(sprite,AngleToSpriteIndex(Angle) * 32,0,32,32)
  ZoomSprite(sprite,128,128)
  DisplayTransparentSprite(sprite,X - 64,Y - 64)
  ProcedureReturn
EndProcedure

Procedure.i Main()
  Protected sprite.i
  Protected rotation.f
  If InitSprite()
    If OpenWindow(0,0,0,640,480,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
      If OpenWindowedScreen(WindowID(0),0,0,640,480)
        SetFrameRate(60)
        sprite = CatchSprite(#PB_Any,?ship,#PB_Sprite_AlphaBlending);<- load sprite-/tilemap!
        Repeat
          Repeat
            Select WindowEvent()
              Case #PB_Event_CloseWindow
                Break 2
              Case #Null
                Break
            EndSelect
          ForEver
          ClearScreen(#Null)
          RenderShip(320,240,sprite,rotation)
          rotation + 1
          If rotation > 360
            rotation = 0
          EndIf
          FlipBuffers()
        ForEver
      EndIf
      CloseWindow(0)  
    EndIf  
  EndIf
  ProcedureReturn #Null
EndProcedure

Main()

End

DataSection
ship:
;include ship sprite-/timemap
EndDataSection
Angle and direction:
I dont know what debris does but if its not locked at those angles it most likely just adjusts the closest sprite to the direction.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

Angle and direction:
I dont know what debris does but if its not locked at those angles it most likely just adjusts the closest sprite to the direction.
it never is rotated out of those angles @Mijikai.
gonna view your example now, thanks :)

about the loading into an array or constantly snipping into one big sprite, isn't the second option way slower and harder for a computer? i never used that tool for sprites because of that, it makes managing sprites a lot easier though.
Last edited by TheAutomator on Tue Feb 09, 2021 7:19 pm, edited 1 time in total.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Cloning DEBRIS32 game

Post by Mijikai »

TheAutomator wrote:
...about the loading into an array or constantly snipping into one big sprite, isn't the second option way slower and harder for a computer? i never used that tool for sprites because of that, it makes managing sprites a lot easier though.
Uploading one vs. multiple texture to the gpu is faster.
Ideally you want to have as few of those transfers as possible.
For a small games this might not matter but it is good practise and often makes things easier anyway.

Some paper:
http://download.nvidia.com/developer/NV ... epaper.pdf
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

So i better merge the sprites into long rows or grids in a single picture then, okay, thanks for the tip!

@Mijikai, worked like a charm, using your sprite render function now. (made a long image from the ships, it's in the drive folder)
Going to update the code soon, busy days here unfortunately so i don't have much free time right now..
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

UPDATE: move the mouse to the ship :p
Next step: bullets!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cloning DEBRIS32 game

Post by infratec »

Use

Code: Select all

EnableExplicit
as your first instruction.
Since the program is growing, you will run into trouble without it. :wink:
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Cloning DEBRIS32 game

Post by infratec »

Also use Enumerations / constants for your sprites and sounds.

It is easier to read

Code: Select all

DisplaySprite(#Ship, ...)
instead of

Code: Select all

DisplaySprite(0, ...)
And for me (personally) it looks horrible if procedures are directly inside of the main code.
I place them above of the code.
Behind constants/enumerations and structures

Code: Select all

EnableExplicit

#bla = 1
#blu = 2

Structure xyz
EndStructure

XIncludeFile "file.pbi"

Procedure X1()
  Protected.i Va1

EndProcedure


;-Main

Define.i X, Y, Exit

Init()

OpenWindow()

Repeat

Until Exit
But that's only my preferred coding.
User avatar
TheAutomator
Enthusiast
Enthusiast
Posts: 112
Joined: Tue Dec 01, 2020 8:33 pm

Re: Cloning DEBRIS32 game

Post by TheAutomator »

@infratec,

I will, it's only in it's early testing state :)
Post Reply