Blitz Basic to GLBasic

Previous topic - Next topic

johngood

I am trying to convert a Blitz Basic game for GLBasic

Blitz Basic      GLBasic

Type Boss1      TYPE Boss1
   Field X          X
   Field Y          Y
   Field S          S
   Field L          L
   Field D          D
   Field F          F
End Type         ENDTYPE

That part was easy but this part?

For h.Boss1 = Each Boss1
   Delete h
Next


Tried this but does not work!

LOCAL h[] AS Boss1
FOREACH h IN Boss1
   DELETE h
NEXT


Any help would be great thanks.

johngood.
Dell Dimension 9200: Core 2 Duo 2.40GHz, 2GB Ram, ATI Radeon X1300Pro, Windows XP Pro SP3
Intel Mac SnowLeopard 10.6.4 Core 2 Duo 2.4GHz 2GB Ram
iPod Touch 2G 4.0 16 GB, iPod Touch 4G 4.1 32 GB

Schranz0r

here we go:

Code (glbasic) Select
TYPE TBoss1
X
Y
S
L
D
F
ENDTYPE

// set this global if you want to use it in a function!
GLOBAL _TBoss1[] AS TBoss1


// create some bosses
FOR i = 0 TO 9
LOCAL b AS TBoss1

b.X = i*20
b.Y = 10
b.S = i

DIMPUSH _TBoss1[], b // set this boss in the "bossarray"!
NEXT







WHILE TRUE

// Show all bosses
FOREACH b IN _TBoss1[]
PRINT b.S, b.X, b.Y
NEXT

// if SPACE-Key hit then delete all bosses!
IF KEY(57)
FOREACH b IN _TBoss1[]
DELETE b
NEXT
ENDIF

SHOWSCREEN
WEND
END
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

johngood


Thanks Schranz0r for a quick and very helpfull reply.  :good:

As usual the people on this site are always very helpfull, its not surprising
that more and more prople are choosing GLBasic as their Programming language.


Thanks again.
Best Regards
johngood.
Dell Dimension 9200: Core 2 Duo 2.40GHz, 2GB Ram, ATI Radeon X1300Pro, Windows XP Pro SP3
Intel Mac SnowLeopard 10.6.4 Core 2 Duo 2.4GHz 2GB Ram
iPod Touch 2G 4.0 16 GB, iPod Touch 4G 4.1 32 GB

PeeJay

There is an even easier way of deleting all entries of a type - using the above example, simply doing
Code (glbasic) Select
DIM _TBoss1[0]
will save all that messing about with the FOR...NEXT loop
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Kitty Hello

and REDIM _TBoss1[0] will do the same thing as DIM _TBoss1[0], except it will not free the memory, thus allowing you to use the memory for new allocations much faster. (Use that for bullets, e.g.)

johngood

Hi its me again, oh NO I hear you say: :S

Thanks to PeeJay and Kitty Hello for additional input. :good:

The first game I wanted to convert was Galax2.bb it was
quite large so I settled for SpaceInvaders.bb which is
the code below, never having used Blitz Basic my only
reason for choosing it was that you seem to have users
who have used it and also use GLBasic.


Blitz Basic                                                                      GLBasic

Global player.playerdata                = New playerdata      >   ? Lost
Global bullet.bulletdata                 = New bulletdata        >   ? Lost
Global alienbullet.alienbulletdata     = New alienbulletdata  >   ? Lost

; Game types
Type playerdata
  Field x
  Field y
  Field speed
End Type

Type bulletdata
  Field x
  Field y
  Field speed
  Field state
End Type

Type aliendata
  Field x
  Field y
  Field image
  Field state 
End Type

Type alienbulletdata
  Field x
  Field y
End Type


As you can see their is no TYPE declaration
for player or bullet other that below?

; Define variables                                                  ;Define variables
player\x     = 10                    >                              player.x   = 10
player\y     = 420                  >                              player.y   = 420
player\speed = 2                   >                              player.speed  = 2
bullet\speed = 8                    >                              bullet.speed  = 8
                                                                         Error: TYPE is not declared
this is used later in the code                                   even if I declare it!
                                                                         so this will not compile

DrawImage playerbullet, bullet\x, bullet\y       >          DRAWSPRITE 0, bullet.x, bullet.y             
DrawImage playership, player\x, player\y       >           DRAWSPRITE 1, player.x, player.y

Do any of you have a lookup sheet of Blitz Statements and GLBasic equivalents?

Regards
johngood.
Dell Dimension 9200: Core 2 Duo 2.40GHz, 2GB Ram, ATI Radeon X1300Pro, Windows XP Pro SP3
Intel Mac SnowLeopard 10.6.4 Core 2 Duo 2.4GHz 2GB Ram
iPod Touch 2G 4.0 16 GB, iPod Touch 4G 4.1 32 GB

Ian Price

#6
Here's a simple way of displaying Type data

Code (glbasic) Select


SETSCREEN 640,480,0

// Player Type data
TYPE Tplayer
 x=100
 y=100
 speed=50
ENDTYPE

// Set the variable player to get data from the Tplayer Type
LOCAL player AS Tplayer

// Main loop

// Repeat until ESC pressed
WHILE TRUE

// Show Type data on screen
PRINT player.x+" "+player.y+" "+player.speed,10,10

SHOWSCREEN

// End loop when condition met (ESC pressed)
WEND


All that will do is take your data set up in the TYPE statement and show it to you. You can change the LOCAL variable name to whatever you want, but it'll still get the Type data for the Tplayer Type. You can update the TYPE data by simply using something like this in the main loop -
Code (glbasic) Select

IF KEY(205) THEN INC player.x, 2

to move the player position right by 2 pixels when pressing the RIGHT cursor. :)

One thing to remember is that GLBasic is case sensitive, so be careful when defining your variables etc.
I came. I saw. I played.

PeeJay

Hiya John

You might find it useful to have a quick look on my site - there are tutorials on there - you may find the Highway tutorial very useful, especially bearing in mind I wrote that shortly after switching from Blitz to GL myself.

Unfortunately, there isn't a direct translation type lookup table, as there are some things that there is no direct equivalent for (eg Blitz has TILEBLOCK, with no equivalent in GL ..... I miss that! GL has POLYVECTOR, with no equivalent in BB)

Hope that helps ....
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

johngood

Thanks PeeJay at this very moment I am going through your Highway tutorial. =D

Nice job and well documented, I dont know if you still have the original Blitz code as it would
be good to see just how the Blitz code was converted to your GLBasic code!

Regards
Johngood.

Dell Dimension 9200: Core 2 Duo 2.40GHz, 2GB Ram, ATI Radeon X1300Pro, Windows XP Pro SP3
Intel Mac SnowLeopard 10.6.4 Core 2 Duo 2.4GHz 2GB Ram
iPod Touch 2G 4.0 16 GB, iPod Touch 4G 4.1 32 GB

PeeJay

Check your inbox  :x
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Kitty Hello

TILEBLOCK is not LOADANIM?

Ian Price

QuoteTILEBLOCK is not LOADANIM?
Nope - totally separate commands.

Quote
TileBlock

Similar to TileImage but ignores transparency. Use this to tile an entire or portion of the screen with a single repetative image.

Blitx code -
Code (glbasic) Select

; TileBlock example
Graphics 800,600,16

; Load an image to tile (your location might vary)
gfxBall=LoadImage("C:Program FilesBlitz Basicsamplesall.bmp")

; Tile the graphic without transparency
TileBlock gfxBall

; Wait for ESC to hit
While Not KeyHit(1)
Wend

I came. I saw. I played.

Kitty Hello

is that of any use?

PeeJay

Extremely useful, yes, for repetitive tiled backgrounds, but also for parallax scrolls (as it fills the viewport, and the offset can be used for the scroll effect)

This is taken from the BB helpfile (as Ian explained, TileImage / TileBlock are basically the same command, just with the latter ignoring transparency)


Code (glbasic) Select
TileImage handle,[x],[y],[frames]
Definition
Tiles the screen with an image (or its frames) of your choice. 

Parameters
handle= variable holding the image's handle
x=starting x location of the tile; assumed 0
y=starting y location of the tile; assumed 0
frames=the frame of the image to tile; optional with imagestrip 

Description
If you want to make a starfield or other easy tiled background, this is YOUR command. All you have to do is specify the image handle (an image loaded with the LoadImage or LoadAnimImage command). Optionally, you can specify a starting x and y location, as well as an optional frame. You can milk some serious parallax effects with a simple imagestrip with a couple of various starfields and the TileImage command. 

Example
; CreateImage/TileImage/ImageBuffer example

; Again, we'll use globals even tho we don't need them here
; One variable for the graphic we'll create, one for a timer
Global gfxStarfield, tmrScreen

; Declare graphic mode
Graphics 640,480,16

; Create a blank image that is 320 pixels wide and 32 high with 10 frames of 32x32
gfxStarfield=CreateImage(32,32,10)

; loop through each frame of the graphic we just made
For t = 0 To 9
; Set the drawing buffer to the graphic frame so we can write on it
SetBuffer ImageBuffer(gfxStarfield,t)
; put 50 stars in the frame at random locations
For y = 1 To 50
Plot Rnd(32),Rnd(32)
Next
Next

; Double buffer mode for smooth screen drawing
SetBuffer BackBuffer()

; Loop until ESC is pressed
While Not KeyHit(1)

; Only update the screen every 300 milliseconds. Change 300 for faster or
; slower screen updates
If MilliSecs() > tmrScreen+300 Then
Cls ; clear the screen

; Tile the screen with a random frame from our new graphic starting at
; x=0 and y=0 location.
TileImage gfxStarfield,0,0,Rnd(9)
Flip ; Flip the screen into view
tmrScreen=MilliSecs() ; reset the time
End If
Wend


You thinking of adding it then, Gernot?  =D
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

Ian Price

I requested this over a year ago, so YES!
I came. I saw. I played.