Author Topic: GdiPlus last chance  (Read 7865 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Re: GdiPlus last chance
« Reply #15 on: March 18, 2013, 01:53:52 AM »
Hi John,

Glad to hear that we come nearer to a super Basic language.
A good way to declare variables is the LUA way, a variabe is always NIL when  no value is  assigned.
This forces  programmer to think in another direction.

I think I have an idea.

Maxim

  • Guest
Re: GdiPlus last chance
« Reply #16 on: March 18, 2013, 02:21:18 AM »
Sadly, we cannot use GdiPlus for games, is too slow.
I got 6 frames/sec in a small game. Is only good for Graphic.

This was only a test,  here is this game with Simple Window.
Hi Peter,

What about GDI+ optimisation?
http://forums.codeguru.com/showthread.php?523273-GDI-and-double-buffering

Game return error with OxygenBasic line 1: include "sw.inc"



Peter

  • Guest
Re: GdiPlus last chance
« Reply #17 on: March 18, 2013, 04:47:32 AM »
Hi Maxim,

I use double buffer!
This GDIPLUS thing is really slow, I think that the Engineers were drunken!  :D

Check it for fun! Look at the frames, I have adjusted 200 frames!
Wait a little bit to see the shock wave!
Code: [Select]
include "gp.inc"

Window 640,480,1
int x, y, a=255, d=1
worm = LoadImage "img/worm.png",1

while Key(27)=0
  
Cls ARGB(255,255,255,255)
SetCaption "FRAMES  " + GetFPS  
  for y=0 to 480 step 16
     for x=0 to 640 step 16
        'Line x, y, x+10, y+10, 2, ARGB(a,255,0,0)
        Line x, y, -x+10, -y+10, 2, ARGB(a,0,0,255)
     next
  next      
  SpriteZoom worm,40,0,512,512
  if d=1
     a -=4
     if a <=1 Then d=2
  end if  
  if d=2
     a +=2
     if a >=255 Then d=2
  end if  
  Redraw  
  SetFPS 200

wend
Quit

X

Charles Pegge

  • Guest
Re: GdiPlus last chance
« Reply #18 on: March 18, 2013, 04:52:04 AM »
Some of my neighbours do the bird shoot for real, though with less powerful weapons, and no lethal feathers from the birds - (I think pheasants and partridges should be able to fight back :) )

Peter

  • Guest
Re: GdiPlus last chance
« Reply #19 on: March 18, 2013, 05:02:49 AM »
Quote
Game return error with OxygenBasic line 1: include "sw.inc"

only for fun  ;D

X

Peter

  • Guest
Re: GdiPlus last chance
« Reply #20 on: March 18, 2013, 05:32:37 AM »
If I want to pack into a DLL Opengl.  what is the call condition?
STDCALL CDECL FASTCALL, or so!

The Dll is already there, but OxygenBasic cannot  localize it.
Everything is in the same directory!

I struggle now two days with this crap.
I think, it gets time  for a better user help !
But that isn't your thing, I think, no time for kids games.  :D

Maxim

  • Guest
Re: GdiPlus last chance
« Reply #21 on: March 18, 2013, 07:02:06 AM »
I use double buffer!
This GDIPLUS thing is really slow, I think that the Engineers were drunken!  :D
Thanks for sw.inc, but this is use sw.dll (gp.inc - gp.dll). Can you do pure GDI+ example?

Perhaps for images it is not good choice, but vector functions with path work enought fast, I use this for game editor.

Peter

  • Guest
Re: GdiPlus last chance
« Reply #22 on: March 18, 2013, 07:27:58 AM »
Quote
Thanks for sw.inc, but this is use sw.dll (gp.inc - gp.dll). Can you do pure GDI+ example?

Code: [Select]
include "gp.inc"
def Escape 27

gdiPlus = LoadLibrary "gdiplus.dll"

Bind gdiPlus
(
  GdipDrawImageRect GdipDrawImageRect
  GdipGetImageDimension GdipGetImageDimension
  GdipResetWorldTransform GdipResetWorldTransform
  GdipRotateWorldTransform GdipRotateWorldTransform
  GdipTranslateWorldTransform GdipTranslateWorldTransform
)

Window 640,480,1
font= LoadFont "arial",32,2
Cls ARGB(155,0,0,255)
gdc = GetScreenDC()
single angle=180, width, height

image= LoadImage "img/toy.gif",1
iHdc = GetImageDC(image)
GdipGetImageDimension(iHdc, &width, &height)

while Key(Escape)=0
  Cls ARGB(255,0,0,255)
  GdipRotateWorldTransform (gdc, angle, MatrixOrderPrepend)
  GdipTranslateWorldTransform(gdc, width, height, MatrixOrderAppend)
  GdipDrawImageRect(gdc, iHdc, 0.0,0.0, 200.0,200.0) 'width, height)
  GdipResetWorldTransform (gdc)                                        
  Text font,0,0,"ImageWidth " + width + "  ImageHeight " + height,ARGB(255,0,255,0)

  Redraw
  SetFPS 80
  angle +=1
  if angle =540 then angle=180
wend

Quit

X

Maxim

  • Guest
Re: GdiPlus last chance
« Reply #23 on: March 18, 2013, 07:38:36 AM »
Code: [Select]
include "gp.inc"
def Escape 27

gdiPlus = LoadLibrary "gdiplus.dll"

Bind gdiPlus
(
  GdipDrawImageRect GdipDrawImageRect
  GdipGetImageDimension GdipGetImageDimension
  GdipResetWorldTransform GdipResetWorldTransform
  GdipRotateWorldTransform GdipRotateWorldTransform
  GdipTranslateWorldTransform GdipTranslateWorldTransform
)

Window 640,480,1
font= LoadFont "arial",32,2
Cls ARGB(155,0,0,255)
gdc = GetScreenDC()
single angle=180, width, height

image= LoadImage "img/toy.gif",1
iHdc = GetImageDC(image)
GdipGetImageDimension(iHdc, &width, &height)

while Key(Escape)=0
  Cls ARGB(255,0,0,255)
  GdipRotateWorldTransform (gdc, angle, MatrixOrderPrepend)
  GdipTranslateWorldTransform(gdc, width, height, MatrixOrderAppend)
  GdipDrawImageRect(gdc, iHdc, 0.0,0.0, 200.0,200.0) 'width, height)
  GdipResetWorldTransform (gdc)                                        
  Text font,0,0,"ImageWidth " + width + "  ImageHeight " + height,ARGB(255,0,255,0)

  Redraw
  SetFPS 80
  angle +=1
  if angle =540 then angle=180
wend

Quit
this is not pure
you can not do some optimisation with this code

Aurel

  • Guest
Re: GdiPlus last chance
« Reply #24 on: March 18, 2013, 08:00:03 AM »
oxymap editor use sw.inc only and i made few maps with this Peter program
and seems to me that work very fine.
I think that Peter says that he create sw.dll because he need more speed but i
simply don't see almost any important difference...maybe i am completely wrong... :-\

Maxim

  • Guest
Re: GdiPlus last chance
« Reply #25 on: March 18, 2013, 08:13:10 AM »
game builder
short video
example source for editor
I use GdipSetClipRectI also, but this is not in main loop, it is in MouseMove event, and in addition path functional is enought fast width vector primitives

Aurel

  • Guest
Re: GdiPlus last chance
« Reply #26 on: March 18, 2013, 08:27:17 AM »
 :o
u use python + windows api for your program, uff i dont like python but
this look very cool... ;)

JRS

  • Guest
Re: GdiPlus last chance
« Reply #27 on: March 18, 2013, 01:41:37 PM »
Good News!

I didn't have to use Bass after all and just changing the last parameter to 1 for the SW_PlayWav call allowed ASYNC operation and smooth game play. Attached is my current working version of the game.

X
« Last Edit: March 18, 2013, 02:10:51 PM by JRS »

Peter

  • Guest
Re: GdiPlus last chance
« Reply #28 on: March 18, 2013, 02:51:49 PM »
John,

Why don't you use PlayWav and LoadWav from the sw library? Is the same Api!
If you had asked me, then I had said, set the last parameter on 1!
I know about 800 Api's invocations.

JRS

  • Guest
Re: GdiPlus last chance
« Reply #29 on: March 18, 2013, 04:21:55 PM »
Thanks for the info Peter about now using the MS MM API call with SW.

Here is an updated version of the Soko Mouse game with a new background and 30 levels. I almost had level three solve but got screwed in the final few moves. If you have solved level 3 or beyond, send me a screen shot showing the level completed and the number of moves. You will hold the Big Cheese for that level unless someone can solve the level in fewer moves. (results posted on All Basic)



Code: [Select]
' ScriptBasic SokoMouse

INCLUDE "sbsw.inc"

SUB Initialize
  SW_DrawBmp p1, 0, 0, 640, 480, 0
' SW_BmpText fo, 200, 8, "SokoMouse", 24, 24
  zA = 0
  Notified = FALSE
  CALL ShowLevel
  FOR bc = 0 TO 299
    xBox[bc] = 0
    yBox[bc] = 0
    rBox[bc] = 0
    zBox[bc] = 0
    iBox[bc] = 0
  NEXT
  zR = 0
  vR = 0
  pHead = 3
  Ready = 0
  sl = 0
  cV = 0
  cR = 0
  Steps = 0
  RasReg = 0
  KeyR = 0
  KeyL = 0
  KeyU = 0
  KeyD = 0
  BoxRas = 0
  Turn = 1
  zTurn = 0
END SUB

SUB LoadMaps
  SW_LoadBytes "Maps/Map" & lev & "-1.bin", Map1
  SW_LoadBytes "Maps/Map" & lev & "-2.bin", Map2
  SW_LoadBytes "Maps/Map" & lev & "-3.bin", Map3
END SUB  
  
SUB ShowLevel
  SW_Sprite s8, 480, 450, zA
  SW_Sprite s9, 576, 450, zA
  SW_BmpText fo, 520, 450, FORMAT("%~00~",lev), 24, 24
  vA += 1
  IF vA = 8 THEN
    vA = 0
    zA = zA + 1
    IF zA = 4 THEN zA = 0
  END IF
END SUB

SUB ShowMaps
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map1[ibx]) = 3 THEN SW_Sprite s1, idx * 32, icx * 32, 3
      IF ASC(Map3[ibx]) = 2 THEN SW_Sprite s1, idx * 32, icx * 32, 2
      IF ASC(Map2[ibx]) = 5 THEN SW_Sprite s2, idx * 32, icx * 32, zR
    NEXT
  NEXT
  vR += 1
  IF vR = 10 THEN
    vR = 0
    zR += 1
  END IF
  IF zR = 4 THEN zR = 0
END SUB

SUB FindHead
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 6 THEN
        xHead = idx * 32
        yHead = icx * 32
        rHead = 0
        zHead = 0
        EXIT SUB
      END IF
    NEXT
  NEXT
END SUB

SUB AllDone
  IF Ready >= 1 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) <> 4 THEN
        EXIT SUB
      END IF
    NEXT
  NEXT
  Ready = 2
  RasReg = 1
  Turn = 0
  pHead = 0
  rTurn = SW_Rnd(1, 2)
  xTurn = xHead
  yTurn = yHead
END SUB

SUB TurnHead
  IF Turn > 0 THEN EXIT SUB
  IF rTurn = 1 THEN
    SW_Sprite s6, xTurn, yTurn, zTurn
  ELSE IF rTurn = 2 THEN
    SW_Sprite s7, xTurn, yTurn, zTurn
  END IF
  zTurn = zTurn + 1
  IF zTurn = 64 THEN zTurn = 0
END SUB

SUB FlashBox
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) = 4 THEN
        SW_Sprite s4, idx * 32, icx * 32, cR
      END IF
    NEXT
  NEXT
  cV += 1
  IF cV = 10 THEN
    cV = 0
    cR += 1
  END IF
  IF cR = 4 THEN cR = 0
END SUB

SUB ScanBoxes
  IF BoxRas > 0 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 4 THEN
        iBox[ibx] = 1
        xBox[ibx] = idx * 32
        yBox[ibx] = icx * 32
        rBox[ibx] = 0
      END IF
    NEXT
  NEXT
END SUB

SUB ShowBoxes
  FOR ibx = 20 TO 280
    IF iBox[ibx] = 1 AND rBox[ibx] = 0 THEN
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 1 THEN
      xBox[ibx] = xBox[ibx] + 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 2 THEN
      xBox[ibx] = xBox[ibx] - 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 3 THEN
      yBox[ibx] = yBox[ibx] - 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 4 THEN
      yBox[ibx] = yBox[ibx] + 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    END IF
  NEXT
END SUB

SUB ScanHead
  IF RasReg > 0 THEN EXIT SUB
  idx = xHead / 32
  icx = yHead / 32
  ibx = icx * 20 + idx
  IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_right) AND ASC(Map3[ibx + 1]) = 4 AND ASC(Map3[ibx + 2]) = 0 AND KeyR = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    rHead = 1
    pHead = 1
    BoxRas = 0
    xBox[ibx + 1] = xHead + 32
    yBox[ibx + 1] = yHead
    rBox[ibx + 1] = 1
    iBox[ibx + 1] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_left) AND ASC(Map3[ibx - 1]) = 4 AND ASC(Map3[ibx - 2]) = 0 AND KeyL = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    rHead = 2
    pHead = 2
    BoxRas = 0
    xBox[ibx - 1] = xHead - 32
    yBox[ibx - 1] = yHead
    rBox[ibx - 1] = 2
    iBox[ibx - 1] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_up) AND ASC(Map3[ibx - 20]) = 4 AND ASC(Map3[ibx - 40]) = 0 AND KeyU = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    rHead = 3
    pHead = 3
    BoxRas = 0
    xBox[ibx - 20] = xHead
    yBox[ibx - 20] = yHead - 32
    rBox[ibx - 20] = 3
    iBox[ibx - 20] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_down) AND ASC(Map3[ibx + 20]) = 4 AND ASC(Map3[ibx + 40]) = 0 AND KeyD = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    rHead = 4
    pHead = 4
    BoxRas = 0
    xBox[ibx + 20] = xHead
    yBox[ibx + 20] = yHead + 32
    rBox[ibx + 20] = 4
    iBox[ibx + 20] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_right) AND ASC(Map3[ibx + 1]) = 0 AND KeyR = 0 THEN
    rHead = 1
    pHead = 1
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_left) AND ASC(Map3[ibx - 1]) = 0 AND KeyL = 0 THEN
    rHead = 2
    pHead = 2
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_up) AND ASC(Map3[ibx - 20]) = 0 AND KeyU = 0 THEN
    rHead = 3
    pHead = 3
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_down) AND ASC(Map3[ibx + 20]) = 0 AND KeyD = 0 THEN
    rHead = 4
    pHead = 4
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE
    rHead = 0
  END IF
END SUB

SUB ShowHead
  IF rHead = 0 AND pHead = 1 THEN
    SW_Sprite s3, xHead, yHead, 3
  ELSE IF rHead = 0 AND pHead = 2 THEN
    SW_Sprite s3, xHead, yHead, 1
  ELSE IF rHead = 0 AND pHead = 3 THEN
    SW_Sprite s3, xHead, yHead, 0
  ELSE IF rHead = 0 AND pHead = 4 THEN
    SW_Sprite s3, xHead, yHead, 2
  ELSE IF rHead = 1 THEN
    xHead += 2
    SW_Sprite s3, xHead, yHead, 3
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 2 THEN
    xHead -= 2
    SW_Sprite s3, xHead, yHead, 1
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 3 THEN
    yHead -= 2
    SW_Sprite s3, xHead, yHead, 0
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 4 THEN
    yHead += 2
    SW_Sprite s3, xHead, yHead, 2
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  END IF
END SUB

SUB MousePos
  xPos = FIX(SW_xMouse() / 32)
  yPos = FIX(SW_yMouse() / 32)
  IF SW_MouseButton() = 1 THEN
    IF xPos = 15 AND yPos = 14 AND lev > 1 AND ButtonC = 0 THEN
      lev -= 1
      ButtonC = 1
      SW_PlayWav w4
      Initialize
      LoadMaps
      FindHead
      EXIT SUB
    END IF
  END IF
  IF SW_MouseButton() = 1 THEN
    IF xPos = 18 AND yPos = 14 AND lev < 30 AND ButtonC = 0 THEN
      lev += 1
      ButtonC = 1
      SW_PlayWav w4
      Initialize
      LoadMaps
      FindHead
    END IF
  END IF
  IF SW_MouseButton() = 0 THEN ButtonC = 0
END SUB


' MAIN

SW_Window 640, 480, 1
SW_SetCaption "ScriptBasic SokoMouse"

SW_SetFps(60)

Q  = SW_LoadBmp("SokoMedia/sokomouse.bmp", 1)
p1 = SW_LoadBmp("SokoMedia/smbg.bmp", 1)
Fo = SW_LoadBmp("SokoMedia/FontStrip.bmp", 96)
s1 = SW_LoadBmp("SokoMedia/SokoStrip.bmp", 5)
s2 = SW_LoadBmp("SokoMedia/RundStrip.bmp", 4)
s3 = SW_LoadBmp("SokoMedia/HeadStrip.bmp", 4)
s4 = SW_LoadBmp("SokoMedia/BoxsStrip.bmp", 4)
s6 = SW_LoadBmp("SokoMedia/HeadStripR.bmp", 64)
s7 = SW_LoadBmp("SokoMedia/HeadStripL.bmp", 64)
s8 = SW_LoadBmp("SokoMedia/ArroStripL.bmp", 4)
s9 = SW_LoadBmp("SokoMedia/ArroStripR.bmp", 4)

w1 = "SokoMedia/move.wav"
w2 = "SokoMedia/push.wav"
w3 = "SokoMedia/done.wav"
w4 = "SokoMedia/clic.wav"


SW_Cls  0xCCCCCC
SW_Sprite Q, 180, 60, 0
SW_BmpText fo, 205, 32, "SOKOMOUSE", 24, 24
SW_BmpText fo, 170, 428, "PRESS ANY KEY", 24, 24
SW_WaitKey

lev = 1
Initialize
LoadMaps
ShowLevel
FindHead

WHILE SW_Key(27) = 0
  ShowMaps
  IF sl THEN ShowLevel
  ScanBoxes
  ScanHead
  ShowBoxes
  ShowHead
  FlashBox
  AllDone
  MousePos
  TurnHead
  IF SW_Key(vk_space) THEN
    SW_BmpText fo, 64, 420, "Wait...", 24, 24
    Initialize
    LoadMaps
    FindHead
  END IF
  IF Ready = 2 AND NOT(Notified) THEN
    SW_BmpText fo, 64, 450, Steps & " moves to solve.", 20, 20
    SW_Sync
    SW_PlayWav w3
    sl = 1
    Notified = TRUE
  END IF
  BoxRas += 2
  IF BoxRas = 32 THEN BoxRas = 0
  IF SW_Key(vk_right) = 0 THEN KeyR = 1
  IF SW_Key(vk_right)THEN KeyR = 0
  IF SW_Key(vk_left) = 0 THEN KeyL = 1
  IF SW_Key(vk_left) THEN KeyL = 0
  IF SW_Key(vk_up) = 0 THEN KeyU = 1
  IF SW_Key(vk_up) THEN KeyU = 0
  IF SW_Key(vk_down) = 0 THEN KeyD = 1
  IF SW_Key(vk_down) THEN KeyD = 0
  SW_Sync
WEND
SW_CloseWindow



X
« Last Edit: March 18, 2013, 05:24:42 PM by JRS »