Sadly, we cannot use GdiPlus for games, is too slow.
Another thing is SW_RAND, dosn't work like Simple Window RND.
IF SW_Key(32) THEN PRINT "Space Key\n"
It seems, there is a bug in ScriptBasic! I changed (zFrame = zFrame +1) in (zFrame +=1) and then there was animation!
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"
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.
Sadly, we cannot use GdiPlus for games, is too slow.Hi Peter,
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.
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
Game return error with OxygenBasic line 1: include "sw.inc"
I use double buffer!Thanks for sw.inc, but this is use sw.dll (gp.inc - gp.dll). Can you do pure GDI+ example?
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?
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 pureCode: [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
' 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
IF SW_Key(vk_right) = 0 THEN KeyR = 1
IF SW_Key(vk_right)THEN
KeyR = 0
SW_Wait(10)
END IF
IF SW_Key(vk_left) = 0 THEN KeyL = 1
IF SW_Key(vk_left) THEN
KeyL = 0
SW_Wait(10)
END IF
IF SW_Key(vk_up) = 0 THEN KeyU = 1
IF SW_Key(vk_up) THEN
KeyU = 0
SW_Wait(10)
END IF
IF SW_Key(vk_down) = 0 THEN KeyD = 1
IF SW_Key(vk_down) THEN
KeyD = 0
SW_Wait(10)
END IF
:oThanks, but I only want say - gdiplusflat can be used for game programming, for example: tetris, lines, chess and other not massive count sprites or used only vector graphics with good effects. Also gdi+ have good distinction from gdi - internal mechanism like garbage collection, therefore memory use is optimal.
u use python + windows api for your program, uff i dont like python but
this look very cool... ;)
You will hold the Big Cheese
I solved some Levels and i needed 30 minutes for ten Levels.