Author Topic: QB64 coding challenge  (Read 8337 times)

0 Members and 1 Guest are viewing this topic.

Offline fatman2021

  • Newbie
  • Posts: 11
    • View Profile
QB64 coding challenge
« on: July 25, 2017, 06:20:23 pm »
Rewrite the following program in QB64:

Code: QB64: [Select]
  1. '
  2. '              The Mad Robot Demo
  3. '
  4. '                By Nick Harper
  5. '
  6. ' (c) Copyright Europress / VooDoo Software  1991
  7. '
  8. '
  9. '
  10. Curs Off: Flash Off
  11. Screen Open 0,320,200,16,Lowres
  12. Cls 0
  13. Td Screen Height 200
  14. Td Dir "amsopro_system:AMOS_3d_demos:/objects"
  15. Td Load "torso"
  16. Td Load "leg"
  17. Td Load "arm"
  18. Td Load "head"
  19. Td Load "stool"
  20. Td Load "animcube"
  21. Fade 1 : Wait 20
  22. Td Object 1,"torso",0,900,5000,0,0,0
  23. Td Object 2,"leg",-200,700,5000,0,0,0
  24. Td Object 3,"leg",200,700,5000,0,0,0
  25. Td Object 4,"arm",-300,1200,5000,0,0,-5000
  26. Td Object 5,"arm",330,1350,5000,0,0,0
  27. Td Object 6,"Head",0,1400,5000,0,0,0
  28. Td Object 7,"stool",1000,-300,4500,0,0,0
  29. Td Object 8,"stool",-700,-300,6500,0,0,0
  30. Td Move 0,1500,1000,500
  31. Td Face 0,1
  32. Double Buffer : Autoback 0
  33. Td Cls
  34. Td Redraw
  35. Hide On
  36. Fade 1,$F38,$FFF,,,,,,,$FB9,$7F,$F,$BF,$A00,$500
  37. HEAD=160
  38. LLEG=200 : LLEGS=0
  39. RLEG=-250 : RLEGS=1
  40. USX-150 : USZ=150
  41. BOUNCE=200
  42. Set Rainbow 0,0,250,"(15,1,2)","(6,1,2)","(9,1,2)"
  43. Rainbow 0,0,156,94
  44. BODY=0 : BODYI=1
  45.   Td Face 0,1
  46.   Gosub SHIFTEM
  47.   Td Cls
  48.   Td Redraw
  49.   Wait Vbl
  50.   Gosub LEFT_ARM
  51.   Gosub RIGHT_ARM
  52.   Gosub LEFT_LEG
  53.   Gosub RIGHT_LEG
  54.   Gosub HEAD
  55.   Gosub BODY
  56.   If BNC=1 Then Gosub BOUNCES
  57. HEAD:
  58. Td Move Rel 6,0,HEAD,0
  59. Td Angle Rel 6,0,0,1927
  60. HEAD=HEAD-20
  61. If HEAD>-260 Then Return
  62. HEAD=160
  63. ANG=Td Attitude C(6)
  64. If Abs(ANG)<2000 Then Angle 6,0,0,0
  65. LEFT_ARM:
  66. Td Angle Rel 5,0,2000,0
  67. Td Anim Rel 5,4,0,HEAD,0,1
  68. Td Move Rel 5,0,-HEAD,0
  69. RIGHT_ARM:
  70. Td Angle Rel 4,3854,0,0
  71. ANG=Td Attitude C(4)
  72. If Abs(ANG)<2000 Then Td Angle 4,0,0,0
  73. LEFT_LEG:
  74. If LEGS=0 Then Td Move Rel 3,0,LLEG,0
  75. If LEGS=0 Then Td Anim Rel 3,4,0,-LLEG,0,1
  76. If LLEG=-250 and LLEGS=1 Then BNC=1 : Boom
  77. If LLEG=-250 Then Inc LLEGS
  78. IF LLEGS=9 Then LLEGS=0 : LLEG=200
  79. RIGHT_LEG:
  80. If RLEGS=0 Then Td Move Rel 2,0,RLEG,0
  81. If RLEGS=0 Then Id Anim Rel 2,4,0,-RLEG,0,1
  82. If RLEGS=0 Then RLEG=RLEG-50
  83. If RLEG=250 and RLEGS=1 BNC=1 : Boom
  84. If RLEGS=9 Then RLEGS=0 : RLEG=200
  85. SHIFTEM:
  86. Td Move Rel 0,USX,0,USZ
  87. if Td Position X(0)-Td Position X(1)>4000 Then Add USX,-10
  88. If Td Position X(1)-Td Position X(0)>4000 Then Add USX,10
  89. If Td Position Z(0)-Td Position Z(1)>4000 Then Add USZ,-10
  90. If Td Position Z(1)-Td Position Z(0)>4000 Then Add USZ,10
  91. BOUNCES:
  92. Td Move Rel,7,0,BOUNCE,0
  93. Td Move Rel,8,0,BOUNCE,0
  94. Add BOUNCE,-100
  95. If BOUNCE=-300 Then BOUNCE=200 : BNC=0
  96. BODY:
  97. Td Surface "animcube",0,BODY To 1,0,0,2
  98. Add BODY,BODYI
  99. If BODY=3 Then BODYI=-1
  100. if BODY=0 Then BODYI=1


Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: QB64 coding challenge
« Reply #1 on: July 26, 2017, 05:34:12 am »
Hi Fatman2021

thank's to show me what was AMOS BASIC in Amiga 500
 I must googlize to find these information  https://en.wikipedia.org/wiki/AMOS_(programming_language)  http://www.powerprograms.nl/amiga/amiga-all-about-amos.html

thinking in general
AICU  Amos = oldBasic  16bit plus libraries to direct access to hardware
IMHO to develop this kind of libraries can lead to 2 issues
 1. some hardware resources in the modern OSes are usable through OSes's functions.... see how now if you use INT 33h in DOS is OK in Windows 7 or over is going to find troubles...
2.  PC (desktop + notebook) have so many different hardwares plugged into.... let to  think about CPU, GPU, Soundcard, Wifi component.... and then there are different OSes running  (Windowses,  FreeDos, Unix/Linux universe, Mac universe....)
but if it is possible to  use  interface libraries like that of JavaMachine or SDL or GL to get results like AMOS Basic....

thinking in topic
someone that has time and will to spent in this conversion must create libraries that emulate those functions using an AMOS manual to understand what he must create before translating this your posted code.

Good Luck
Programming isn't difficult, only it's  consuming time and coffee

Offline fatman2021

  • Newbie
  • Posts: 11
    • View Profile
Re: QB64 coding challenge
« Reply #2 on: July 26, 2017, 09:22:53 am »
thinking in general
AICU  Amos = oldBasic  16bit plus libraries to direct access to hardware
IMHO to develop this kind of libraries can lead to 2 issues
 1. some hardware resources in the modern OSes are usable through OSes's functions.... see how now if you use INT 33h in DOS is OK in Windows 7 or over is going to find troubles...
2.  PC (desktop + notebook) have so many different hardwares plugged into.... let to  think about CPU, GPU, Soundcard, Wifi component.... and then there are different OSes running  (Windowses,  FreeDos, Unix/Linux universe, Mac universe....)
but if it is possible to  use  interface libraries like that of JavaMachine or SDL or GL to get results like AMOS Basic....

XAMOS( https://sourceforge.net/projects/xamos/) uses SDL and jAMOS(https://sourceforge.net/projects/javaamos/?source=directory) uses JavaMachine, and you can use GL directly in your QB64 programs. So it can definitely be done.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: QB64 coding challenge
« Reply #3 on: July 26, 2017, 02:24:55 pm »
trying to figure out what the commands do is the, shall we say, interesting part. pulled up a copy of a refernece manual for AMOS and 90% of the commands in that program are there but not all of them. like what the hey does the Td on all those lines do? its not in the manual I found. nether is 'object' or 'face'. I guess it probably depends on just which version of AMOS, as the manual I found is for AMOS Professional written soumtime around 93'-94' and is 556 pages long.
Granted after becoming radioactive I only have a half-life!

Offline SkyCharger001

  • Newbie
  • Posts: 14
    • View Profile
Re: QB64 coding challenge
« Reply #4 on: July 26, 2017, 03:16:57 pm »
I've tried to look it up and all references I found focused on AMOS 3D, an extension to base-AMOS.

this suggests that "Td" means the command is intended for that extension and not base-AMOS.
It also suggest to me the "Td" is a variable-/function-naming-rules friendly rendition of "3D".


Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: QB64 coding challenge
« Reply #6 on: July 26, 2017, 07:14:32 pm »
Dear Fatman2021
I'm sorry  but your info about manuals are incomplete... I also like SkyCharger001 have had some intuitive ideas about Td command that is no in those two manual that you have linked....
following the idea of SkyCharger001 about AMOS3d I googlized and I have found this manual....https://ia802705.us.archive.org/8/items/amos-3d-manual/AMOS%203D%20-%20Manual-ENG.pdf
if you can see at  chapter 8.2. AMOS commands you can find all your Td command code..... well this is the first step to translate from AMOS to QB64 that code....

please, next time be more specific if it is possible

Programming isn't difficult, only it's  consuming time and coffee

Offline SkyCharger001

  • Newbie
  • Posts: 14
    • View Profile
Re: QB64 coding challenge
« Reply #7 on: July 27, 2017, 01:45:34 pm »
page 106 (108 according to the PDF-reader) confirms my suspicion: Td precedes all AMOS 3D specific commands.

Offline fatman2021

  • Newbie
  • Posts: 11
    • View Profile
Re: QB64 coding challenge
« Reply #8 on: July 27, 2017, 01:50:04 pm »
Information on the TD command can be found on pages 10,17,35,67,69-108 of the Amos 3D User Guide:
https://archive.org/details/amos-3d-manual

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: QB64 coding challenge
« Reply #9 on: July 27, 2017, 07:25:13 pm »
Hi Fatman2021

1
glad to get more info from you... here is the skeleton of AMOS instructions....
all but not Td position X(n)   and Td position Z(n) that I cannot find in AMOS 3D manual .....
 
Code: QB64: [Select]
  1.  
  2. '
  3. '              The Mad Robot Demo
  4. '
  5. '                By Nick Harper
  6. '
  7. ' (c) Copyright Europress / VooDoo Software  1991
  8. '
  9. '
  10. '
  11. Curs Off: Flash Off ' text cursor off, turn off the flashing colour sequence
  12. Screen Open 0,320,200,16,Lowres    'Screen Open number,width,height,colours,pixel mode
  13. ' Lowres = 320 pixels wide
  14. Cls 0 'Cls colour number--> paint alla screen with 0 (black as default)
  15. ' Td seems being like a metacommand for IDE AMOS to let execute only
  16. ' on running the command of IDE like setting path of files, loading files to use
  17.  
  18. Td Screen Height 200     '(Set the screen height to drawing)
  19. Td Dir "amsopro_system:AMOS_3d_demos:/objects" ' Set the object directory name)
  20. Td Load "torso"   ' Load the named object  -->load 6 object models_Images
  21. Td Load "leg"
  22. Td Load "arm"
  23. Td Load "head"
  24. Td Load "stool"
  25. Td Load "animcube"
  26. Fade 1 : Wait 20
  27. '   FADE blend colours to new values, Fade speed set the speed of the fade
  28. 'by choosing the number of vertical blank periods between each colour change
  29.  'Fade effects are executed using interrupts, so it is sensible to wait until the fade has ended before going on to the
  30. 'next program instruction. The length of wait required can be calculated with this formula:
  31. 'wait = fade speed * 15
  32. '
  33. Td Object 1,"torso",0,900,5000,0,0,0  ' Create an object
  34. Td Object 2,"leg",-200,700,5000,0,0,0 ' Object NumObject,"NameModel", x1,y1,z1,Ax,Ay,Az
  35. Td Object 3,"leg",200,700,5000,0,0,0  ' x1,y1,z1 are cohordinates
  36. Td Object 4,"arm",-300,1200,5000,0,0,-5000 'Ax Ay Az are angles of rotation along X Y and Z axises
  37. Td Object 5,"arm",330,1350,5000,0,0,0 ' these angles are expressed as VRU--->> Voodoo Rotation units
  38. Td Object 6,"Head",0,1400,5000,0,0,0  ' 360 celsius = 65536 VRU
  39. Td Object 7,"stool",1000,-300,4500,0,0,0    '  celsius = VRU / 182
  40. Td Object 8,"stool",-700,-300,6500,0,0,0  'VRU = celsius * 182
  41. Td Move 0,1500,1000,500 ' move objecte 0 at cohordinates x y z
  42. Td Face 0,1    ' Point an object 0 to object 1 calculating range between and angles A and B joining them
  43. Double Buffer : Autoback 0    'DOUBLE BUFFER Instruction activate the double buffering system
  44. 'creates an invisible copy of the current screen and stores it as a "logical screen". All graphics
  45. 'operations, including Bob movements, are now performed directly on this logical screen, without disturbing your
  46. 'existing display at all.
  47. ' Autoback 0 deactivates autoback system
  48. 'autoback 1 activates SEMI_AUTOMATIC mode, text and graphics operations are made on logic and phisical screen, No BOB action
  49. ' Autoback 2 FullyAutomatic, every graphic operation on the screen is synchronized with BOB active
  50. 'AUTOBACK is extremely intelligent and completely automatic, but it can only synchronise graphics and text
  51. 'commands
  52.  
  53.  
  54.  
  55. Td Cls  ' (Clear the 30 display area with extra speed) savind 2D graphics
  56. Td Redraw    'Draw al! current visible 30 objects
  57. Screen Swap  ' swap screen physical and logical
  58. Hide On       ' hide mouse cursor
  59. Fade 1,$F38,$FFF,,,,,,,$FB9,$7F,$F,$BF,$A00,$500
  60. ' fade 9 colours of original 15
  61. ' they seem variables
  62. HEAD=160
  63. LLEG=200 : LLEGS=0
  64. RLEG=-250 : RLEGS=1
  65. USX-150 : USZ=150     ' here USX = -150
  66. BOUNCE=200
  67. Set Rainbow 0,0,250,"(15,1,2)","(6,1,2)","(9,1,2)"   ' define a rainbow
  68. 'Set Rainbow number,index,height,red$,green$,blue$
  69. ' number of rainbow from 0 to 3
  70. ' index is the color index that is to be changed, and only colours 0 to 15
  71. ' can be affected. In practice,
  72. ' this colour can be assigned a different value for each horizontal screen
  73. '  scan line, if necessary.
  74. ' it sets the height of the rainbow in units,
  75. ' with each unit ready to hold one scan line of colour
  76. ' it can range from 16 to 65500, but only the first 280 can be displayed
  77.  'on screen at once
  78. ' the Red, Blue and Green components of the rainbow colours are set up as strings, each within their own
  79. ' brackets, their format comprises three values  (number,step,count)
  80.  ' the number of scan lines assigned to one colour value
  81.  ' Step is a value to be added to the colour, which controls the colour change
  82. ' Count is simply the number of times this whole process is performed.
  83.  
  84.  
  85. Rainbow 0,0,156,94
  86. 'display a rainbow
  87. 'Rainbow number,offset,vertical position,height
  88. ' The offset sets the value for the first colour in the table created with SET RAINBOW
  89. 'number 0-3 , The vertical position is a coordinate which must have a minimum value of 40, and it affects the starting point of the
  90. ' rainbow's vertical display on screen
  91. ' sets the rainbow's vertical height in screen scan lines
  92. '
  93. BODY=0 : BODYI=1
  94.   Td Face 0,1     ' Point an object 0 to object 1 calculating range between and angles A and B joining them
  95.   Gosub SHIFTEM
  96.   Td Cls     ' (Clear the 30 display area with extra speed) savind 2D graphics
  97.   Td Redraw      'Draw al! current visible 30 objects
  98.   Screen Swap       ' swap screen physical and logical
  99.   Wait Vbl   ' wait for the next vertical blank period
  100.   Gosub LEFT_ARM
  101.   Gosub RIGHT_ARM
  102.   Gosub LEFT_LEG
  103.   Gosub RIGHT_LEG
  104.   Gosub HEAD
  105.   Gosub BODY
  106.   If BNC=1 Then Gosub BOUNCES
  107.  
  108. HEAD:
  109. Td Move Rel 6,0,HEAD,0  'Move an object relative to its current position)
  110. Td Angle Rel 6,0,0,1927
  111. HEAD=HEAD-20
  112. If HEAD>-260 Then Return
  113. HEAD=160
  114. ANG=Td Attitude C(6)
  115. If Abs(ANG)<2000 Then Angle 6,0,0,0
  116.  
  117. LEFT_ARM:
  118. Td Angle Rel 5,0,2000,0   ' can make objects execute smooth turns
  119. 'simply by changing  the attitude gradually
  120. 'Set up an angle animation string  applies the changes specilied by
  121. 'the movement string angle$ to either A, B or C.
  122. Td Anim Rel 5,4,0,HEAD,0,1
  123. Td Move Rel 5,0,-HEAD,0 'Move an object relative to its current position)
  124.  
  125. RIGHT_ARM:
  126. Td Angle Rel 4,3854,0,0
  127. 'Set up an angle animation string  applies the changes specilied by
  128. 'the movement string angle$ to either A, B or C.
  129.  
  130. ANG=Td Attitude C(4)    '  (Return an object's attitude A or B or C
  131. If Abs(ANG)<2000 Then Td Angle 4,0,0,0   'Set up an angle animation string
  132. Return                   'Abs give an absolute value
  133.  
  134. LEFT_LEG:
  135. If LEGS=0 Then Td Move Rel 3,0,LLEG,0
  136. If LEGS=0 Then Td Anim Rel 3,4,0,-LLEG,0,1  'This command applies a change (called a delta) to point p of object n.
  137. If LLEG=-250 and LLEGS=1 Then BNC=1 : Boom    'generate explosive sound effect
  138. If LLEG=-250 Then Inc LLEGS    'increment an integer variable by one unit
  139. IF LLEGS=9 Then LLEGS=0 : LLEG=200
  140.  
  141. RIGHT_LEG:
  142. If RLEGS=0 Then Td Move Rel 2,0,RLEG,0  'Move an object relative to its current position)
  143. ' Td MOVE REL n,dx,dy,dz The movement it applies though, is relative
  144. '  to the object's current position.
  145.  
  146. If RLEGS=0 Then Id Anim Rel 2,4,0,-RLEG,0,1
  147. '(Apply change to a point - relative to the points position)
  148. 'This command applies a change (called a delta) to point p of object n.
  149. ' The change to be applied is specified by x, y and z.
  150. ' The change is applied to the object as it was saved under OM.
  151.  
  152.  
  153. If RLEGS=0 Then RLEG=RLEG-50
  154. If RLEG=250 and RLEGS=1 BNC=1 : Boom
  155. If RLEGS=9 Then RLEGS=0 : RLEG=200
  156.  
  157. SHIFTEM:
  158. Td Move Rel 0,USX,0,USZ  ' 'Move an object relative to its current position
  159. if Td Position X(0)-Td Position X(1)>4000 Then Add USX,-10      ' range x
  160. If Td Position X(1)-Td Position X(0)>4000 Then Add USX,10
  161. If Td Position Z(0)-Td Position Z(1)>4000 Then Add USZ,-10
  162. If Td Position Z(1)-Td Position Z(0)>4000 Then Add USZ,10
  163.  
  164. BOUNCES:
  165. Td Move Rel,7,0,BOUNCE,0  'Move an object relative to its current position)
  166. Td Move Rel,8,0,BOUNCE,0  'Move an object relative to its current position)
  167. Add BOUNCE,-100
  168. If BOUNCE=-300 Then BOUNCE=200 : BNC=0
  169.  
  170. BODY:
  171. Td Surface "animcube",0,BODY To 1,0,0,2
  172. '(Copy a surface)
  173. 'Td SURFACE name1 ,b1 ,f1 to n2,b2,f2,rt
  174. ' name1 = source object name, b1 block number within name1
  175. ' face number within b1
  176.  ' n2 number destination object  b2 block number within n2
  177.  ' f2 face number within b2 ,  rt rotation angle  (0-3)
  178. Add BODY,BODYI   ' ADD does sum of BODY and BODYI
  179. If BODY=3 Then BODYI=-1
  180. if BODY=0 Then BODYI=1
  181.  

there some video to see output of this kind of instruction on the web?

2
about the code I think that at line 64  in QB64 IDE we must correct as in comment
Quote
USX-150 : USZ=150     ' here USX = -150

so at line 150 is in original code Td Anim Rel and not Id Anim Rel
Quote
If RLEGS=0 Then Id Anim Rel 2,4,0,-RLEG,0,1 

3
it is fine to see Boom coded and I like to see result of Rainbow instruction

Is the challenge  about to create a like Amos3D library or to do the same operations o easily to get the same results?

See Again
Programming isn't difficult, only it's  consuming time and coffee

Offline fatman2021

  • Newbie
  • Posts: 11
    • View Profile
Re: QB64 coding challenge
« Reply #10 on: July 27, 2017, 07:38:51 pm »
The challange is to rewrite the program using existing QB64 commands/functions.

Offline fatman2021

  • Newbie
  • Posts: 11
    • View Profile
Re: QB64 coding challenge
« Reply #11 on: July 27, 2017, 09:28:47 pm »
Video of the AMOS Mad Robot Program: