Author Topic: GdiPlus last chance  (Read 7873 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
GdiPlus last chance
« on: March 16, 2013, 01:33:29 AM »
Deleted
« Last Edit: April 14, 2015, 04:40:20 AM by Peter »

JRS

  • Guest
Re: GdiPlus last chance
« Reply #1 on: March 16, 2013, 06:46:53 AM »
Hi Peter,

Your GDIPlus include file looks very much like sw.inc. Would it be worth converting the SB SokoMouse game to GDIPlus or is this a one time experiment and there will be no further updates to this library?

John

JRS

  • Guest
Re: GdiPlus last chance
« Reply #2 on: March 16, 2013, 07:37:27 AM »
I will wait until you give the green light.

Thanks!

JRS

  • Guest
Re: GdiPlus last chance
« Reply #3 on: March 16, 2013, 10:58:20 AM »
Quote
Sadly, we cannot use GdiPlus for games, is too slow.

Why am I not surprised?

Thanks for posting this game. I will convert it to SB. Maybe more Basic programmers will use ScriptBasic if they can easily create simple games.

BTW: Do you have any more level maps for SokoMouse beyond the 9 that were provided?


JRS

  • Guest
Re: GdiPlus last chance
« Reply #4 on: March 16, 2013, 11:13:59 AM »
My error. There are 30 maps. Sorry.

JRS

  • Guest
Re: GdiPlus last chance
« Reply #5 on: March 16, 2013, 09:29:49 PM »
Here is your Bird Shooter game running in ScriptBasic.

@Peter: Other than trying to dodge the turds, how does the plane fight back (shoot, ...) You have a couple lines of code that checks for the Key() to be two different values at the same time. ???



Code: OxygenBasic
  1. INCLUDE "sw.inc"
  2.  
  3.  
  4. '        *************
  5. FUNCTION CircleCollide(x1, y1, r1, x2, y2, r2)
  6. '        *************
  7.  IF SQR((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) <  r1 + r2 THEN
  8.     CircleCollide = 1
  9.   END IF
  10. END FUNCTION
  11.  
  12. '   ******
  13. SUB Timer1
  14. '   ******
  15.  dv = dv + 0.1
  16.   IF dv >= 1 THEN
  17.     dv = 0
  18.     zFrame = zFrame + 1
  19.     IF zFrame = 8 THEN zFrame = 0
  20.   END IF
  21. END SUB
  22.  
  23. '   ******
  24. SUB Timer2
  25. '   ******
  26.  jv = jv + 1
  27.   IF jv = 50 THEN
  28.     jv = 0
  29.     jx = jx + 1
  30.     IF jx = 21 THEN jx = 0
  31.   END IF
  32. END SUB
  33.  
  34. '   ******
  35. SUB Timer3
  36. '   ******
  37.  Drop = SW_Rnd(0,40)
  38. END SUB
  39.  
  40. '   ******
  41. SUB Timer4
  42. '   ******
  43.  IF Ok = 1 THEN EXIT SUB
  44.   za += .2
  45.   IF za >= 5 THEN
  46.     za = 0
  47.     count = count - 1
  48.     IF count <= 0 THEN count = 0
  49.   END IF
  50. END SUB
  51.  
  52. '   *********
  53. SUB SetExplos(xx, yy, ii)
  54. '   *********
  55.  FOR iDx = 0 TO 39
  56.     IF yBum[iDx] = 0 THEN
  57.       xBum[iDx] = xx
  58.       yBum[iDx] = yy
  59.       iBum[iDx] = ii
  60.       EXIT SUB
  61.     END IF
  62.   NEXT
  63. END SUB
  64.  
  65. '   **********
  66. SUB ShowExplos
  67. '   **********
  68.  FOR iDx = 0 TO 39
  69.   IF iBum[iDx] = 1 THEN
  70.     SW_DrawTile bmap, xBum[iDx], yBum[iDx], 64, 64, zBum[iDx], 1
  71.     vBum[iDx] = vBum[iDx] + 0.1
  72.     IF vBum[iDx] >= 1 THEN
  73.       vBum[iDx] = 0
  74.       zBum[iDx] = zBum[iDx] + 1
  75.     END IF
  76.     IF zBum[iDx] = 8 THEN
  77.       zBum[iDx] = 0
  78.       yBum[iDx] = 0
  79.       iBum[iDx] = 0
  80.       vBum[iDx] = 0
  81.     END IF
  82.   END IF
  83.   NEXT
  84. END SUB
  85.  
  86. '   *********
  87. SUB SetRocket(xx, yy)
  88. '   *********
  89.  FOR iAx = 0 TO 39
  90.   IF yRok[iAx] = 0 THEN
  91.     xRok[iAx] = xx
  92.     yRok[iAx] = yy
  93.     rRok[iAx] = 1
  94.     EXIT SUB
  95.   END IF
  96.   NEXT
  97. END SUB
  98.  
  99. '   **********
  100. SUB ScanRocket
  101. '   **********
  102.  FOR iAx = 0 TO 39
  103.   IF rRok[iAx] = 1 AND yRok[iAx] <= -32 THEN
  104.     rRok[iAx] = 0
  105.     yRok[iAx] = 0
  106.   END IF
  107.   NEXT
  108. END SUB
  109.  
  110. '   **********
  111. SUB ShowRocket
  112. '   **********
  113.  FOR iAx = 0 TO 39
  114.   IF rRok[iAx] = 1 THEN
  115.     SW_DrawTile bmap, xRok[iAx], yRok[iAx], 64, 64, zFrame, 0
  116.     yRok[iAx] = yRok[iAx] - 4
  117.     IF yRok[iAx] = 400 THEN zRak = 0
  118.   END IF
  119.   NEXT
  120. END SUB
  121.  
  122. '   **********
  123. SUB ScanRakete
  124. '   **********
  125.  IF rRak = 5 THEN EXIT SUB
  126.   IF SW_Key(32) AND SW_Key(39) AND zRak = 0 THEN
  127.     SetRocket(xRak, yRak)
  128.     rRak = 1
  129.     zRak = 1
  130.     SW_PlayWav w1
  131.   ELSE IF SW_Key(32) AND SW_Key(37) AND zRak = 0 THEN
  132.     SetRocket(xRak, yRak)
  133.     rRak = 2
  134.     zRak =1
  135.     SW_PlayWav w1
  136.   ELSE IF SW_Key(32) AND zRak = 0 THEN
  137.     SetRocket(xRak, yRak)
  138.     zRak = 1
  139.     SW_PlayWav w1
  140.   ELSE IF SW_Key(39) AND xRak < 736 THEN
  141.     rRak = 1
  142.   ELSE IF SW_Key(37) AND xRak > 0 THEN
  143.     rRak = 2
  144.   ELSE
  145.     rRak = 0
  146.   END IF
  147. END SUB
  148.  
  149. '   **********
  150. SUB ShowRakete
  151. '   **********
  152.  IF rRak = 0 THEN
  153.     SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
  154.   ELSE IF rRak = 1 THEN
  155.     SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
  156.     xRak = xRak + 1
  157.   ELSE IF rRak = 2 THEN
  158.     SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
  159.     xRak = xRak - 1
  160.   END IF
  161. END SUB
  162.  
  163. '   ***************
  164. SUB RocketCollision
  165. '   ***************
  166.  FOR iBx = 0 TO uz
  167.     FOR iCx = 0 TO 39
  168.       IF rRok[iCx] > 0 AND rUfo[iBx] > 0 THEN
  169.         IF CircleCollide(xRok[iCx] + 32, yRok[iCx] + 32, 16, xUfo[iBx] + 32, yUfo[iBx] + 32, 16) = 1 THEN
  170.           SetExplos(xUfo[iBx], yUfo[iBx], 1)
  171.           rRok[iCx] = 0
  172.           yRok[iCx] = 0
  173.           rUfo[iBx] = 0
  174.           yUfo[iBx] = 0
  175.           SW_PlayWav w2
  176.           sc = sc + 25
  177.           EXIT SUB
  178.         END IF
  179.       END IF
  180.     NEXT
  181.   NEXT
  182. END SUB
  183.  
  184. '   ***************
  185. SUB RaketeCollision
  186. '   ***************
  187.  IF Ok = 1 THEN EXIT SUB
  188.   FOR iAx = 0 TO 40
  189.     IF yMeg[iAx] > 0 THEN
  190.       IF CircleCollide(xRak, yRak, 16, xMeg[iAx], yMeg[iAx], 16) = 1 THEN
  191.         SetExplos(xRak, yRak, 1)
  192.         rRak = 5
  193.         Ok = 1
  194.         SW_PlayWav w3
  195.         EXIT SUB
  196.       END IF
  197.     END IF
  198.   NEXT
  199. END SUB
  200.  
  201. '   *******
  202. SUB SetUfos
  203. '   *******
  204.  FOR iAx = 0 TO uz
  205.     xUfo[iAx] = SW_Rnd(16,736)
  206.     yUfo[iAx] = SW_Rnd(16,300)
  207.     rUfo[iAx] = SW_Rnd(1,4)
  208.     zUfo[iAx] = 0
  209.     nUfo[iAX] = 0
  210.   NEXT
  211. END SUB
  212.  
  213. '   ********
  214. SUB ScanUfos
  215. '   ********
  216.  FOR iBx = 0 TO uz
  217.     IF rUfo[iBx] = 1 AND xUfo[iBx] >= 736 THEN
  218.       rUfo[iBx] = 2
  219.     ELSE IF rUfo[iBx] = 2 AND xUfo[iBx] <= 0 THEN
  220.       rUfo[iBx] = 1
  221.     ELSE IF rUfo[iBx] = 3 AND yUfo[iBx] <= 0 THEN
  222.       rUfo[iBx] = 4
  223.     ELSE IF rUfo[iBx] = 4 AND yUfo[iBx] >= 350 THEN
  224.       rUfo[iBx] = 3
  225.     ELSE IF jx = 5 AND rUfo[iBx] = 4 THEN
  226.       rUfo[iBx] = SW_Rnd(1,4)
  227.     ELSE IF jx = 10 AND rUfo[iBx] = 3 THEN
  228.       rUfo[iBx] = SW_Rnd(1,4)
  229.     ELSE IF jx = 15 AND rUfo[iBx] = 2 THEN
  230.       rUfo[iBx] = SW_Rnd(1,4)
  231.     ELSE IF jx = 20 AND rUfo[iBx] = 1 THEN
  232.       rUfo[iBx] = SW_Rnd(1,4)
  233.     END IF
  234.   NEXT
  235. END SUB
  236.  
  237. '   ********
  238. SUB ShowUfos
  239. '   ********
  240.  FOR iBx = 0 TO uz
  241.     IF rUfo[iBx] = 1 THEN
  242.       SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
  243.       xUfo[iBx] = xUfo[iBx] + 1
  244.     ELSE IF rUfo[iBx] = 2 THEN
  245.       SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
  246.       xUfo[iBx] = xUfo[iBx] - 1
  247.     ELSE IF rUfo[iBx] = 3 THEN
  248.       SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
  249.       yUfo[iBx] = yUfo[iBx] - 1
  250.     ELSE IF rUfo[iBx] = 4 THEN
  251.       SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
  252.       yUfo[iBx] = yUfo[iBx] + 1
  253.     END IF
  254.   NEXT
  255. END SUB
  256.  
  257. '   *******
  258. SUB SetData
  259. '   *******
  260.  xRak = 384
  261.   yRak = 536
  262.   rRak = 0
  263.   za = 0
  264.   uz = 40
  265.   sc = 0
  266.   Ok = 0
  267.   zFrame = 0
  268.   count = 300
  269.   SetUfos
  270.   FOR iBx = 0 TO 40
  271.     yMeg[iBx] = 0
  272.     xMeg[iBx] = 0
  273.   NEXT
  274. END SUB
  275.  
  276. '   ********
  277. SUB TestUfos
  278. '   ********
  279.  FOR iAx = 0 TO 40
  280.     IF yUfo[iAx] > 0 OR Ok = 1 THEN EXIT SUB
  281.   NEXT
  282.   Ok = 1
  283.   sc += count
  284. END SUB
  285.  
  286. '   ************
  287. SUB ScanUfoBombs
  288. '   ************
  289.  FOR iAx = 0 TO drop STEP 2
  290.     IF rUfo[iAx] > 0 THEN
  291.       IF yMeg[iAx] = 0 THEN
  292.         xMeg[iAx] = xUfo[iAx]
  293.         yMeg[iAx] = yUfo[iAx] + 32
  294.       END IF
  295.     END IF
  296.   NEXT
  297. END SUB
  298.  
  299. '   ********
  300. SUB UfoBombs
  301. '   ********
  302.  FOR iDx = 0 TO 40
  303.     IF yMeg[iDx] > 0 THEN
  304.       IF iDx < 20 THEN
  305.         SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
  306.       ELSE IF iDx >= 20 THEN
  307.         SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
  308.       END IF
  309.       yMeg[iDx] = yMeg[iDx] + 1
  310.       IF yMeg[iDx] >= 600 THEN yMeg[iDx] = 0
  311.     END IF
  312.   NEXT
  313. END SUB
  314.  
  315. ' *******
  316. '  MAIN *
  317. ' *******  
  318.  
  319. SW_Window 800, 600, 1
  320. SW_SetFPS 60
  321. SW_SetFont 28, 48, 0, ""
  322. bmap = SW_LoadTile("bmp/bitmap.bmp", 8, 5)
  323. w1 = "bmp/shoot.wav"
  324. w2 = "bmp/explo.wav"
  325. w3 = "bmp/xship.wav"
  326. SW_ShowMouse 0
  327. SetData
  328.  
  329. WHILE SW_Key(27) = 0
  330.   SW_Cls 0
  331.   SW_SetCaption "Frames " & SW_ShowFPS()
  332.   IF Ok = 1 THEN
  333.     SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
  334.   ELSE IF Ok = 0 THEN
  335.     SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
  336.   END IF
  337.   ScanUfos
  338.   ShowUfos
  339.   ScanRocket
  340.   ShowRocket
  341.   ScanRakete
  342.   ShowRakete
  343.   ScanUfoBombs
  344.   UfoBombs
  345.   ShowExplos
  346.   RocketCollision
  347.   RaketeCollision
  348.   TestUfos
  349.   Timer1
  350.   Timer2
  351.   Timer3
  352.   Timer4
  353.   IF Ok = 1 THEN
  354.     SW_SetText 240, 300, "ONCE AGAIN?", SW_RGB(255,255,255)
  355.     SW_SetText 240, 344, "HIT [c] KEY", SW_RGB(255,255,255)
  356.     IF SW_Key(67) THEN SetData
  357.   END IF
  358.   SW_SetText 16, 0, "BONUS " & count, SW_RGB(255,255,255)
  359.   SW_Sync
  360. WEND
  361. SW_Quit
  362.  
« Last Edit: March 17, 2013, 07:52:32 PM by JRS »

JRS

  • Guest
Re: GdiPlus last chance
« Reply #6 on: March 17, 2013, 07:54:51 AM »
That is what I thought as well looking at the code and being a natural key to use. I only have left and right arrow key functionality. My guess is that your IF statements checking the Key() function for two different values is the problem. (guess)

Code: OxygenBasic
  1. ELSE IF SW_Key(32) AND SW_Key(37) AND zRak = 0 THEN
  2.  

How can the return of your Key() function be equal to 32 & 37 at the same time?


JRS

  • Guest
Re: GdiPlus last chance
« Reply #7 on: March 17, 2013, 09:55:02 AM »
Here is the code for the game in ScriptBasic if you want to give it a try and maybe figure out why I only have left and right arrow keyboard support.

I had mentioned this with the SokoMouse game and I see you didn't get the hint. The CPU takes a big hit if you do a SetFps() call in the WHILE/WEND loop. It only needs to be set ONCE to keep the frame rate at the desired value.

FYI If I remark out the SetFps(), SB is runs at 150+ FPS in a XP VirtualBox. (on top of Ubuntu 64)

« Last Edit: March 17, 2013, 03:16:48 PM by JRS »

JRS

  • Guest
Re: GdiPlus last chance
« Reply #8 on: March 17, 2013, 11:03:14 AM »
Once again, DO NOT use scribaw.exe with anything other than IUP GUI scripts. PLEASE use scriba.exe from the console command line. Make sure the path to the SB bin directory is set and DLLC.dll is in the modules directory.

This updated attachment reflects the changes I made to BS.sbx (main game script) and includes the most recent dllc.dll file.

Update

Like SokoMouse, using SetFPS(60) outside the WHILE/WEND loop and using Sync() rather than Redraw() gives me the best game play. (Frames average around 90 in the title bar) It reduces CPU usage by 75% without changing the anything with the game.

X
« Last Edit: March 17, 2013, 03:16:32 PM by JRS »

JRS

  • Guest
Re: GdiPlus last chance
« Reply #9 on: March 17, 2013, 01:53:06 PM »
Peter,

I think you will find the root of our problems if you realize all variables return undef until assigned. I had to add zFrame = 0 to SetData as it was calling Simple Windows with it set as undef causing a GPF. If you can look at the code and determine what absolutely must be initialized prior to use we may find the problem. In the O2 version DIMing the arrarys must initialize them to zero.

Quote
Another thing is SW_RAND, dosn't work like Simple Window RND.

SW_Rnd is a wrapper for your Simple Windows API function and used in both SokoMouse and Angry Birds II. The ScriptBasic version of RND() isn't compatible with yours but is a SB keyword and SW_Rnd() is what your random generator function is calling in the games.

John

P.S. Hope you're not living in a Starbucks if you weren't kidding about the house burning down.

 
« Last Edit: March 17, 2013, 02:06:55 PM by JRS »

JRS

  • Guest
Re: GdiPlus last chance
« Reply #10 on: March 17, 2013, 03:14:36 PM »
I put the following in the WHILE/WEND loop and it printed fine when pressing the space bar.

Code: [Select]
 IF SW_Key(32) THEN PRINT "Space Key\n"


JRS

  • Guest
Re: GdiPlus last chance
« Reply #11 on: March 17, 2013, 08:34:19 PM »
Quote
It seems, there is a bug in ScriptBasic! I changed (zFrame = zFrame +1) in (zFrame +=1) and then there was animation!

Your observation made me curious so I wrote a little program to test your theory.

Code: [Select]
a += 1
PRINT "A: ",a,"\n"

b = b + 1
PRINT "B: ",b,"\n"

c = 0
c += 1
PRINT "C: ",c,"\n"

d = 0
d = d + 1
PRINT "D: ",d,"\n"

C:\SB22\test>scriba plusone.sb
A: 1
B: undef
C: 1
D: 1

C:\SB22\test>

It seems your right about there is a different result if referencing an uninitialized variable and then incrementing it. It seems to work correctly either way if the variable is assigned (initialized)  before hand.

Thanks for pointing this out!


JRS

  • Guest
Re: GdiPlus last chance
« Reply #12 on: March 17, 2013, 09:05:05 PM »
Peter,

I was right about the initialization of variables for this game. Add this SUB to the top of the program and call it in Main before starting. Everything seems to be working except using the Windows MM API for playing the wave is causing delays. I'm assuming the Bass call lets the game continue and plays the sound in another thread?

John

Code: OxygenBasic
  1. SUB InitVars
  2.  
  3.   SPLITA STRING(40,"0") BY "" TO xMeg
  4.   SPLITA STRING(40,"0") BY "" TO yMeg
  5.   SPLITA STRING(40,"0") BY "" TO zMeg
  6.   SPLITA STRING(40,"0") BY "" TO xUfo
  7.   SPLITA STRING(40,"0") BY "" TO yUfo
  8.   SPLITA STRING(40,"0") BY "" TO zUfo
  9.   SPLITA STRING(40,"0") BY "" TO rUfo
  10.   SPLITA STRING(40,"0") BY "" TO iUfo
  11.   SPLITA STRING(40,"0") BY "" TO nUfo
  12.   SPLITA STRING(40,"0") BY "" TO xRok
  13.   SPLITA STRING(40,"0") BY "" TO yRok
  14.   SPLITA STRING(40,"0") BY "" TO rRok
  15.   SPLITA STRING(40,"0") BY "" TO xBum
  16.   SPLITA STRING(40,"0") BY "" TO yBum
  17.   SPLITA STRING(40,"0") BY "" TO iBum
  18.   SPLITA STRING(40,"0") BY "" TO zBum
  19.   SPLITA STRING(40,"0") BY "" TO vBum
  20.  
  21.   xRak = 0
  22.   yRak = 0
  23.   rRak = 0
  24.   zRak = 0
  25.   iBx = 0
  26.   iDx = 0
  27.   iCx = 0
  28.   iAx = 0
  29.   zFrame = 0
  30.   z1 = 0
  31.   z2 = 0
  32.   z3 = 0
  33.   z4 = 0
  34.   bmap = 0
  35.   w1 = 0
  36.   w2 = 0
  37.   w3 = 0
  38.   s = 0
  39.   y = 0
  40.   sc = 0
  41.   uz = 0
  42.   jx = 0
  43.   drop = 0
  44.   Ok = 0
  45.   count = 0
  46.   px = 0
  47.  
  48.   jv = 0.0
  49.   zv = 0.0
  50.   dv = 0.0
  51.   za = 0.0
  52.  
  53. END SUB
  54.  
« Last Edit: March 17, 2013, 09:10:34 PM by JRS »

JRS

  • Guest
Re: GdiPlus last chance
« Reply #13 on: March 17, 2013, 09:43:00 PM »
Peter,

I remarked out the call to the Windows wave API and the game worked as expected. I was even able to clear the screen of birds.  :o

John

X

JRS

  • Guest
Re: GdiPlus last chance
« Reply #14 on: March 17, 2013, 10:38:38 PM »
ScriptBasic may be doing exactly as its told. There is a difference between incrementing an uninitialized variable and adding 1 to it.

Code: OxygenBasic
  1. a += 1
  2. PRINT "A: ",a,"\n"
  3.  
  4. b = b + 1
  5. PRINT "B: ",b,"\n"
  6.  
  7. c = 0
  8. c += 1
  9. PRINT "C: ",c,"\n"
  10.  
  11. d = 0
  12. d = d + 1
  13. PRINT "D: ",d,"\n"
  14.  
  15. undef u
  16. PRINT "U: ",u + 1,"\n"
  17.  

C:\SB22\test>scriba plusone.sb
A: 1
B: undef
C: 1
D: 1
U: undef

C:\SB22\test>

ScriptBasic defaults to careful but lazy programmer mode as default.  8)

You have the option to tell SB that you want some warning (errors) that you forgot an assignment and how you want SB to react to undef in expressions.  Setting Options

Quote from: SB Docs
BASIC languages generally do not require variable declaration to be programmer friendly. ScriptBasic is no exception for compatibility reasons: you can write huge programs without declaring any variable. Although this is possible this is not a good practice. Programmers can easily mistype a variable name and end up getting a new variable with undef value instead of getting compilation error. This may cost a lot of debugging time.

Forcing Variable Declaration

Another cool SB feature is switching between TEXT or BINARY mode on the fly with STDIN/OUT operations.

Switching between binary and text mode
« Last Edit: March 17, 2013, 11:45:39 PM by JRS »