Blitz Basic to GLBasic

Previous topic - Next topic

johngood


Sorry PeeJay there is nothing in my inbox here!  :O

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

Kitty Hello

Do I understand that command correctly?

It's does a "loop" to tile the specified sprite all over the screen, with a given offset?

Like:
Code (glbasic) Select

x  =xstart
WHILE x < screenwidth
   y = ystart
   while y< screenheight
      DRAWANIM id, frame, x,y
      INC x, tileheight
    wend
    inc y, tilewidth
wend

Ian Price

Yes, the above Blitz tile commands cover the whole screen - if a tile goes off any side it returns on the opposite side, so there are never any gaps. One of the Blitz commands does not include masking, the other does.

Another tile command (I remember especially from PlayBasic) repeats a specified tile across a given area - not necessarily the whole screen eg it could just put a repeating tilestrip across the bottom of the screen that loops left to right. etc.

Both are easy to replicate in code/functions however, as you have demonstrated above and as I did in B'lox!
I came. I saw. I played.

Kitty Hello

I see. I added it to my todo list. It's not hard to do and might be slightly faster when you draw the lot in one batch.

codegit

Agree. This is a valuable command to have. I used it alot with BlitzBasic. I have replicated my own version, but if it can be coded internally and run faster, that will be good news.  :good:
------------------------------------------
1 X Acer TravelMate 4270, laptop, XP PRO
1 X Dell Studio 17 laptop, Windows 7
1 X MacBook Pro 2,2 GHz Core 2 Duo, 2 GB RAM, 160 GB HDD, 9400M
2 X iTouch
1 X HTC Desire (Android 2.1)
iPad soon to be added

johngood

Hi Guys its me again   ;/

Still can't get my head around converting BlitzBasic programs, I think I am
just too old now or very thick...

I have dropped my sites to a very small conversion of Spider.bb

What does this statement do as it is never used in the program and it generates an Error in GLBasic?

Global Enemy.SpiderData

How would the following be written in GLBasic

Enemy = New SpiderData  //  in Function InitEnemy()  I have tried LOCAL Enemy AS SpiderData followed by DIMPUSH spiderdata[], Enemy


For Enemy = Each SpiderData   // in Function DrawEnemies() I have tried FOREACH Enemy IN  SpiderData generates wrong argument type


Any further help would be great thanks.

Regards,
johngood.


Code (glbasic) Select

Global Enemy.SpiderData


Function InitEnemy()
Enemy                   = New SpiderData
Enemy\xpos              = Rnd(32,620)
Enemy\ypos              = Enemy_Ypos_Start
Enemy\speed             = 1
Enemy\animframe         = 0
Enemy\animcount         = 1
Enemy\animpause         = 4
Enemy\hit               = False
End Function


Function DrawEnemies()
For Enemy = Each SpiderData
DrawImage spiders,Enemy\xpos,Enemy\ypos,Enemy\animframe
Enemy\animcount = Enemy\animcount + 1
If Enemy\animcount > Enemy_Anim_Pause Then
Enemy\animcount = 1
If Enemy\hit = False Then
Enemy\animframe = 1 - Enemy\animframe
Else
Enemy\animframe = Enemy\animframe + 1
If Enemy\animframe >7 Then
Delete Enemy
EndIf
EndIf
EndIf
If Enemy <> Null Then
Enemy\ypos = Enemy\ypos - Enemy\speed
If Enemy\ypos <15 Then
GameOver = True
Delete Each SpiderData
EndIf
EndIf
Next
End Function

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

MrTAToad

QuoteGlobal Enemy.SpiderData
Would be something like :

TYPE SpiderData
ENDTYPE

GLOBAL enemy[] as SpiderData

QuoteEnemy = New SpiderData  //  in Function InitEnemy()  I have tried LOCAL Enemy AS SpiderData followed by DIMPUSH spiderdata[], Enemy
Technically, its not needed.  What you do is just define a type and then put data in it and then use DIMPUSH to put the type in the array.  For example :

FUNCTION add:
local dummy as SpiderData

// Put stuff in dummy
DIMPUSH enemy[],dummy
ENDFUNCTION

QuoteFor Enemy = Each SpiderData   // in Function DrawEnemies() I have tried FOREACH Enemy IN  SpiderData generates wrong argument type
FOREACH enemy in enemy[]
NEXT

All \ are placed by .

There is no NULL is GLBasic, so that part isn't needed really

johngood

Thanks for your quick response MrTAToad  =D

With your help I have the following:

LOADANIM "gfx/spider_shapes.bmp",1,16,16

TYPE SpiderData
   xpos
   ypos
   animframe
   animcount
   animpause
   speed
   hit
ENDTYPE

GLOBAL spiderdata[] AS spiderdata

GLOBAL Enemy[] AS SpiderData

bla bla

FUNCTION InitEnemy:
   LOCAL dummy AS SpiderData   
   dummy.xpos              = RND(100)
   dummy.ypos              = Enemy_Ypos_Start
   dummy.speed             = 1
   dummy.animframe         = 0
   dummy.animcount         = 1
   dummy.animpause         = 4
   dummy.hit               = FALSE
   DIMPUSH Enemy[], dummy
ENDFUNCTION

FUNCTION DrawEnemies:
   FOREACH Enemy IN  Enemy[]
      DRAWANIM 1,Enemy.animframe,Enemy.xpos,Enemy.ypos
      Enemy.animcount = Enemy.animcount + 1   
      IF Enemy.animcount > Enemy_Anim_Pause
         Enemy.animcount = 1
         IF Enemy.hit = FALSE
            Enemy.animframe = 1 - Enemy.animframe
         ELSE
            Enemy.animframe = Enemy.animframe + 1
            IF Enemy.animframe >7
               DELETE Enemy
            ENDIF//Enemy.animframe
         ENDIF
      ENDIF
      IF Enemy
         Enemy.ypos = Enemy.ypos - Enemy.speed
         IF Enemy.ypos <15
            GameOver = TRUE
            DELETE Enemy
         ENDIF
      ENDIF
   NEXT
ENDFUNCTION

This is what the compiler produces!    :'(

Regards,
johngood.


Code (glbasic) Select

In file included from C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:2:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: `spiderdata' was not declared in this scope
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: template argument 1 is invalid
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: ISO C++ forbids declaration of `spiderdata' with no type
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:6: error: type/value mismatch at argument 1 in template parameter list for`template<class T> class __GLBASIC__::DGArray'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:6: error:   expected a type, got `__GLBASIC__::spiderdata'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:6: error: invalid type in declaration before ';' token
In file included from C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:1:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: `spiderdata' was not declared in this scope
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: template argument 1 is invalid
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp.h:17: error: ISO C++ forbids declaration of `spiderdata' with no type
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:242: error: no match for call to `(__GLBASIC__::SpiderData) (int)'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:268: error: no matching function for call to `DIMDEL(__GLBASIC__::SpiderData&, int&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:788: note: candidates are: void __GLBASIC__::DIMDEL(__GLBASIC__::DGIntArray&, int)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:798: note:                 void __GLBASIC__::DIMDEL(__GLBASIC__::DGNatArray&, int)
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:279: error: could not convert `Enemy' to `bool'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::CheckCollision()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:313: error: no match for call to `(__GLBASIC__::SpiderData) (int)'
*** FATAL ERROR - Please post this output in the forum
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

MrTAToad

Quoteerror: `spiderdata' was not declared in this scope
Variables are case-sensitive.  You define the TYPE as
Code (glbasic) Select
TYPE SpiderDatabut try and use it as
Code (glbasic) Select
GLOBAL spiderdata[] AS spiderdata

codegit

This was one of the first things that caught me as well when I moved from Blitz. Try remmember that GLBASIC is case sensitive.  =D
------------------------------------------
1 X Acer TravelMate 4270, laptop, XP PRO
1 X Dell Studio 17 laptop, Windows 7
1 X MacBook Pro 2,2 GHz Core 2 Duo, 2 GB RAM, 160 GB HDD, 9400M
2 X iTouch
1 X HTC Desire (Android 2.1)
iPad soon to be added

Ian Price

Quote from: codegit on 2009-Oct-02
Try remmember that GLBASIC is case sensitive.  =D

That'll be GLBasic then :P
I came. I saw. I played.

johngood

Sorry guys I keep forgetting how case sensitive GLBasic is, it does no have a Case switch! :whistle:

I have been commenting all the routines out and debugging them one at a time.
I am learning a lot from you guys thanks. :good:

I am stuck at the FUNCTION DrawEnemies.

I have not called DrawEnemies in the code but I have un-commented the Function and it generates
the Errors below

FUNCTION DrawEnemies:
   FOREACH Enemy IN  Enemy[]
      DRAWANIM 8,Enemy.animframe,Enemy.xpos,Enemy.ypos
      Enemy.animcount = Enemy.animcount + 1
      IF Enemy.animcount > Enemy_Anim_Pause
         Enemy.animcount = 1
         IF Enemy.hit = FALSE
            Enemy.animframe = 1 - Enemy.animframe
         ELSE
            Enemy.animframe = Enemy.animframe + 1
            IF Enemy.animframe >7
               DELETE Enemy
            ENDIF
         ENDIF
      ENDIF
      IF Enemy
         Enemy.ypos = Enemy.ypos - Enemy.speed
         IF Enemy.ypos <15
            GameOver = TRUE
            DELETE Enemy
         ENDIF
      ENDIF
   NEXT
   
ENDFUNCTION


Regards,
johngood.

Code (glbasic) Select

compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:221: error: no match for call to `(__GLBASIC__::SpiderData) (int)'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:247: error: no matching function for call to `DIMDEL(__GLBASIC__::SpiderData&, int&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:788: note: candidates are: void __GLBASIC__::DIMDEL(__GLBASIC__::DGIntArray&, int)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:798: note:                 void __GLBASIC__::DIMDEL(__GLBASIC__::DGNatArray&, int)
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:255: error: could not convert `Enemy' to `bool'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:266: error: no matching function for call to `DIMDEL(__GLBASIC__::SpiderData&, int&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:788: note: candidates are: void __GLBASIC__::DIMDEL(__GLBASIC__::DGIntArray&, int)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:798: note:                 void __GLBASIC__::DIMDEL(__GLBASIC__::DGNatArray&, int)
*** FATAL ERROR - Please post this output in the forum
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

MrTAToad

Try
Code (glbasic) Select
FOREACH enm IN  Enemy[], and replace all enemy.xxx statements with enm.xxxx

You are trying to use a variable that has already been defined as an array

johngood

#28

The Errors are getting smaller or is it that I am getting older. ;/
Why was I getting Enemy bool  Error in my earlier posts
The Error is still there enm bool Error because I replaced Enemy with enm?

Regards,
johngood.




Code (glbasic) Select

compiling:
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DrawEnemies()':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:255: error: could not convert `Enm' to `bool'
*** FATAL ERROR - Please post this output in the forum
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

Kitty Hello