|
Post by held12345 on Mar 14, 2023 12:23:53 GMT -5
Hi good afternoon. I would like to take out the for-next and go through a key control " t=t+1 : gosub gehe"
don't get it.
Thanks. greeting don't get it.
Thanks. greeting
nomainwin WindowWidth = 600 WindowHeight = 750 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.g, 50,50,500,300 graphicbox #1.h, 50,400,500,300 open "Blitter" for graphics_nf_nsb as #1 #1 "trapclose [quit]"
loadbmp "largebmp","sprites\large.bmp" #1.g "down ; drawbmp largebmp 0 0" #1.h "down ; fill red"
gDC=GetDC(hwnd(#1.g)) hDC=GetDC(hwnd(#1.h)) result=blit(hDC,0,0,500,300,gDC,1100,300)
mDC=CreateCompatibleDC(gDC) hBitmap=hbmp("largebmp") oldBmp=SelectObject(mDC,hBitmap) for x=0 to 50 t=t+1 gosub [gehe] next wait [quit] close#1 end [gehe] result=blit(hDC,0,0,500,300,mDC,t,0) return
Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As long,_ 'handle of object SelectObject As long 'returns previously selected object End Function
function blit(dDC,x,y,w,h,sDC,sx,sy) CallDll #gdi32, "BitBlt", _ dDC as ulong,_ 'The destination DC x as long,_ 'x location on destination y as long,_ 'y location on destination w as long,_ 'width to transfer h as long,_ 'height to transfer sDC as ulong,_ 'Th/code]e source DC sx as long,_ 'x location in source sy as long,_ 'y location in source _SRCCOPY as ulong,_ 'The operation to be performed blit as long 'nonzero if successful end function
|
|
|
Post by Rod on Mar 15, 2023 5:38:56 GMT -5
Have we moved away from rotation? You will need to better describe what you want to do. How big is the graphic resource? You want to see a small part of it in the destination DC? The keys do what? rotate pan, shrink enlarge?
|
|
|
Post by held12345 on Mar 16, 2023 3:21:03 GMT -5
Hello, I can't get any further with the rotate. I have a terrain in graphicbox #1.g and in graphicbox #1.h (large.bmp) , to copy graphicbox #1.h to graphicbox #1.g when the car is moved. #1.s , is the sprite (auto1.bmp). the sprite is transparent and is moved with the keys q/w/e/s. now i need help please how to rotate the sprite and bring it to #1.g. Thanks. greeting
nomainwin WindowWidth = 800 WindowHeight = 750 Open "msimg32.dll" for DLL as #m graphicbox #1.g, 50,50,500,300 graphicbox #1.h, 50,400,500,300 graphicbox #1.s, 560,50,128,128 open "Blitter" for graphics_nf_nsb as #1 #1 "trapclose [quit]"
loadbmp "largebmp","sprites\large.bmp" loadbmp "sprite","sprites\auto1.bmp" #1.g "down ; drawbmp largebmp 0 0" #1.s "down" gDC=GetDC(hwnd(#1.g)) hDC=GetDC(hwnd(#1.h)) mDC=CreateCompatibleDC(gDC) hBitmap=hbmp("largebmp") oldBmp=SelectObject(mDC,hBitmap) gDCs=GetDC(hwnd(#1.g)) hDCs=GetDC(hwnd(#1.s)) mDCs=CreateCompatibleDC(gDCs) hBitmaps=hbmp("sprite") oldBmps=SelectObject(mDCs,hBitmaps) gosub [sprite] x=x+5 y=100 result=blit(hDC,0,0,500,300,mDC,0,0) result=TransparentBlt(hDC, x, y, 128,128, mDCs, 0, 0,128, 128, 0) timer 10, [keyCheck] wait [quit] close#1 end [keyCheck] if keyState(81) then x=x-2 gosub [vordergrundsprite] end if if keyState(69) then x=x+2 gosub [vordergrundsprite] end if if keyState(83) then y=y+2 gosub [vordergrundsprite] end if if keyState(87) then y=y-2 gosub [vordergrundsprite] end if wait [vordergrundsprite] result=blit(hDC,0,0,500,300,mDC,0,0) result=TransparentBlt(hDC, x, y, 128,128, mDCs, 0, 0,128, 128, 0) return [sprite] results=blit(hDCs,0,0,128,128,mDCs,0,0) return function keyState(keycode) calldll #user32, "GetAsyncKeyState", _ keycode AS long, _ keyState AS long end function
Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As long,_ 'handle of object SelectObject As long 'returns previously selected object End Function
function blit(dDC,x,y,w,h,sDC,sx,sy) CallDll #gdi32, "BitBlt", _ dDC as ulong,_ 'The destination DC x as long,_ 'x location on destination y as long,_ 'y location on destination w as long,_ 'width to transfer h as long,_ 'height to transfer sDC as ulong,_ 'The source DC sx as long,_ 'x location in source sy as long,_ 'y location in source _SRCCOPY as ulong,_ 'The operation to be performed blit as long 'nonzero if successful end function function TransparentBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSource, xSource, ySource, wSource, hSource, clrTransp) calldll #m, "TransparentBlt", _ hdcDest as ulong, _ 'handle to destination DC xDest as long, _ 'x-coord of destination upper-left corner yDest as long, _ 'y-coord of destination upper-left corner wDest as long, _ 'width of destination rectangle hDest as long, _ 'height of destination rectangle hdcSource as ulong, _ 'handle to source DC xSource as long, _ 'x-coord of source upper-left corner ySource as long, _ 'y-coord of source upper-left corner wSource as long, _ 'width of source rectangle hSource as long, _ 'height of source rectangle clrTransp as ulong, _ 'color to make transparent TransparentBlt as long end function
Attachments:
|
|
|
Post by held12345 on Mar 16, 2023 3:38:53 GMT -5
this is the 2x bmp. greeting Attachments:bmp.zip (13.54 KB)
|
|
|
Post by Rod on Mar 17, 2023 9:02:15 GMT -5
THis is a quick demo of how you might use sprites to create a track and rotating car. You will need to learn how to scroll the background (it will wrap) and how to detect collisions. You probably need track sprites to collide with. Work the sprite tutorial on the LBPE. This is a zip file with the rotated sprite and a .bas example.This is the tutorial on LBPE
nomainwin
'load the bitmaps we'll use as sprites & background 'load smiley1.bmp to use as our sprite 'load bg1.bmp as our background loadbmp "track", "large.bmp"
'open a window and graphicbox WindowHeight = 600 WindowWidth = 800 graphicbox #w.g, 0, 0, 800, 600 open "Use keys l r u d s to move sprite" for window_nf as #w print #w, "trapclose [quit]"
'add the background and sprite to the sprite engine 'add background using large.bmp loadbmp "track", "large.bmp" #w.g "backgroundxy 400 0" 'start track centered #w.g "background track" for c= 0 to 31 loadbmp "c";c ,"car";c;".bmp" next #w.g "addsprite car c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31" #w.g "spritexy car 400 100"
rad=57.29577951 'liberty needs radians for trig 'set the car starting coordinates and movement x = 400 y = 100 dx=cos(angle/rad) dy=sin(angle/rad) sprite=0 speed =0
'start the keyboard checking event print #w.g, "when characterInput [keyboardinterrupt]" print #w.g, "setfocus"
' now start the timer to repeatedly call the drawing loop timer 17, [drawingloop]
'now sit and wait for the first event to trigger wait
[drawingloop] 'this loop gets called every 17ms by the timer event
'add the movement to x and y x=x+dx*speed y=y+dy*speed
'now redraw the sprites #w.g "spritexy car ";x;" ";y print #w.g, "drawsprites" wait
[keyboardinterrupt] 'this loop gets called every time a key is pressed 'set the movement depending on key pressed key$=Inkey$ select case key$ case "l" 'left angle=angle-11.25 sprite=sprite-1 if sprite<0 then sprite=sprite+32 : angle=angle+360 #w.g "spriteimage car c";sprite dx=cos(angle/rad) dy=sin(angle/rad) case "r" 'right angle=angle+11.25 sprite=sprite+1 if sprite>31 then sprite=sprite-32 : angle=angle-360 #w.g "spriteimage car c";sprite dx=cos(angle/rad) dy=sin(angle/rad) case "u" 'up speed=speed+1 case "d" 'down speed=speed-1 case "s" 'stop speed=0 end select wait
[quit] timer 0
close #w
|
|
|
Post by held12345 on Mar 17, 2023 12:26:17 GMT -5
Hello, thanks for the help.
I'm looking for a rotate for this dll : CallDll #gdi32, "PlgBlt" for my program.
|
|
|
Post by Rod on Mar 17, 2023 12:46:30 GMT -5
You can’t mix sprites and blitter. It is one or the other. Why do you prefer plgblt() ?
Anatoly already showed how to use plgblt() to rotate a bmp.
We come back to the fact that you are not describing your project on enough detail for folks to help. Take a step back from code and perceived solutions and tell us what the project is about and what you want to happen onscreen.
|
|
|
Post by held12345 on Mar 17, 2023 15:34:14 GMT -5
I will now turn the sprite and save it with the program.
I would now like to make c1 to c36 sprites with the program 0-360 degrees. how is it please what numerical values have to be changed and how.
Thanks greeting
nomainwin WindowWidth=1000 WindowHeight=600 UpperLeftX=(DisplayWidth-WindowWidth)/2 UpperLeftY=(DisplayHeight-WindowHeight)/2 menu #1, "&File", "&Open Sprite",[openSprite],_ "&Save As...",[saveAs],|,"E&xit",[quit] open "Rotate and Mask Sprite" for graphics_nsb as #1 #1 "down ; trapclose [quit]"
hWindow=hwnd(#1) CallDll #user32, "GetDC",_ hWindow as ulong,_ hDC as ulong wait
[quit] CallDll #user32, "ReleaseDC",_ hWindow as ulong,_ hDC as ulong,_ r as long close #1 end
[openSprite] if hBitmap<>0 then unloadbmp ("bm") #1 "cls" end if
filedialog "Open Sprite","*.bmp",bitmap$ if bitmap$="" then wait loadbmp "bm" , bitmap$ hBitmap=hbmp("bm") bmpheight=HeightBitmap(bitmap$) bmpwidth=WidthBitmap(bitmap$) midx=int(bmpwidth/2) midy=int(bmpheight/2)+bmpheight radi=int(bmpwidth/2) #1 "fill black" #1 "drawbmp bm 0 ";bmpheight for angle= 72 to 360 step 72 newx=newx+bmpwidth call rotate angle,newx,midx,midy,radi, hWindow, hDC next call MakeMask bmpwidth, bmpheight, hWindow, hDC wait
[saveAs] #1 "getbmp SpriteMask 0 0 ";bmpwidth;" ";2*bmpheight filedialog "Save As... ","*.bmp",savefile$ if savefile$="" then wait newx=0 for a=1 to 10 #1 "getbmp SpriteMask ";newx;" 0 ";bmpwidth;" ";2*bmpheight bmpsave "SpriteMask",left$(savefile$,len(savefile$)-4)+str$(a)+".bmp" newx=newx+bmpwidth next wait
'************FUNCTIONS****************** function WidthBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic WidthBitmap = asc(mid$(pic$,19,1)) + _ (asc(mid$(pic$,20,1)) * 256) end function
function HeightBitmap(name$)
open name$ for input as #pic pic$=input$(#pic,29) close #pic HeightBitmap = asc(mid$(pic$,23,1)) + _ (asc(mid$(pic$,24,1)) * 256) end function
sub rotate angle, newx, midx, midy, radi, hWindow, hDC for d = 0 to radi for n= 1 to 360 step .5 scan x=int(midx-(d*sin(n/57.29577951))) y=int(midy-(d*cos(n/57.29577951))) CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long a=n+angle mod 360 x=int(midx-(d*sin(a/57.29577951))) y=int(midy-(d*cos(a/57.29577951))) x=x+newx CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long,_ r as long next n next d end sub
sub MakeMask wide, high, hWnd,hDC white=(255*256*256)+(255*256)+255 black=0 for x = 0 to 12*wide-1 for y = high to 2*high-1 CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long if pColor=black then newColor=white else newColor=black end if j=y-high CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long, _ j as long, _ newColor as long, _ r as long next y next x end sub
thanks greeting
|
|
|
Post by Rod on Mar 18, 2023 2:35:11 GMT -5
Well 36 isn’t symmetrical it’s decimal. To split a circle evenly we go 180 90 45 22.5 11.25 giving us 32 angles or views. I will adjust the code later today.
|
|
|
Post by held12345 on Mar 18, 2023 3:14:36 GMT -5
hello thanks for help. I then wanted to use it in your program above, co to c31
greeting
|
|
|
Post by Rod on Mar 18, 2023 6:00:05 GMT -5
This will rotate a bmp and output 32 views, it rotates from 0o to 348.75o in 11.25o steps It takes a while because I oversample the initial image to get rid of moire patterns. If you give it car.bmp it will output car0.bmp car1.bmp ......
Be sure your bmp image is centered in a square bmp and contained within a circle within that square else you will lose the extremities. It works best on photo realistic images.
nomainwin WindowWidth=800 WindowHeight=600 UpperLeftX=(DisplayWidth-WindowWidth)/2 UpperLeftY=(DisplayHeight-WindowHeight)/2 menu #1, "&File", "&Open Sprite",[openSprite],_ "&Save As...",[saveAs],|,"E&xit",[quit] open "Rotate and Mask Sprite" for graphics_nsb as #1 #1 "down ; trapclose [quit]"
hWindow=hwnd(#1) CallDll #user32, "GetDC",_ hWindow as ulong,_ hDC as ulong wait
[openSprite] if hBitmap<>0 then unloadbmp ("bm") #1 "cls" end if
filedialog "Open Sprite","*.bmp",bitmap$ if bitmap$="" then wait loadbmp "bm" , bitmap$ hBitmap=hbmp("bm") bmpheight=HeightBitmap(bitmap$) bmpwidth=WidthBitmap(bitmap$) midx=int(bmpwidth/2) midy=int(bmpheight/2)+bmpheight radi=int(bmpwidth/2) #1 "fill black" #1 "drawbmp bm 0 ";bmpheight newx=bmpwidth s=0 for angle= 0 to 348.75 step 11.25 call rotate angle,newx,midx,midy,radi, hWindow, hDC call MakeMask bmpwidth, bmpheight, hWindow, hDC #1 "getbmp SpriteMask ";newx;" 0 ";bmpwidth;" ";2*bmpheight bmpsave "SpriteMask",left$(bitmap$,len(bitmap$)-4)+str$(s)+".bmp" s=s+1 next
[quit] CallDll #user32, "ReleaseDC",_ hWindow as ulong,_ hDC as ulong,_ r as long close #1 end
'************FUNCTIONS****************** function WidthBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic WidthBitmap = asc(mid$(pic$,19,1)) + _ (asc(mid$(pic$,20,1)) * 256) end function
function HeightBitmap(name$)
open name$ for input as #pic pic$=input$(#pic,29) close #pic HeightBitmap = asc(mid$(pic$,23,1)) + _ (asc(mid$(pic$,24,1)) * 256) end function
sub rotate angle, newx, midx, midy, radi, hWindow, hDC for d = 0 to radi for n= 1 to 360 step .5 scan x=int(midx-(d*sin(n/57.29577951))) y=int(midy-(d*cos(n/57.29577951))) CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long a=n+angle mod 360 x=int(midx-(d*sin(a/57.29577951))) y=int(midy-(d*cos(a/57.29577951))) x=x+newx CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long,_ r as long next n next d end sub
sub MakeMask wide, high, hWnd,hDC white=(255*256*256)+(255*256)+255 black=0 for x = wide to wide*2-1 for y = high to 2*high-1 CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long if pColor=black then newColor=white else newColor=black end if j=y-high CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long, _ j as long, _ newColor as long, _ r as long next y next x end sub
|
|
|
Post by held12345 on Mar 18, 2023 9:29:38 GMT -5
hello thanks for the help.
it works wonderfully with the 31 sprite. If I rotate the sprite with the program and it is supposed to follow the angle forwards, then the direction is not correct,
but it runs diagonally forwards and not according to the angle.
How do I have to put this into the program now to enlarge the sprite 3x:
SPRITESCALE sprite scale
thanks greeting
nomainwin
'load the bitmaps we'll use as sprites & background 'load smiley1.bmp to use as our sprite 'load bg1.bmp as our background loadbmp "track", "large.bmp"
'open a window and graphicbox WindowHeight = 600 WindowWidth = 800 graphicbox #w.g, 0, 0, 800, 600 open "Use keys l r u d s to move sprite" for window_nf as #w print #w, "trapclose [quit]"
'add the background and sprite to the sprite engine 'add background using large.bmp loadbmp "track", "large.bmp" #w.g "backgroundxy 400 0" 'start track centered #w.g "background track" for c= 0 to 31 loadbmp "c";c ,"car";c;".bmp" next #w.g "addsprite car c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31" #w.g "spritexy car 400 100"
rad=57.29577951 'liberty needs radians for trig 'set the car starting coordinates and movement x = 400 y = 100 dx=cos(angle/rad) dy=sin(angle/rad) sprite=0 speed =0
'start the keyboard checking event print #w.g, "when characterInput [keyboardinterrupt]" print #w.g, "setfocus"
' now start the timer to repeatedly call the drawing loop timer 17, [drawingloop]
'now sit and wait for the first event to trigger wait
[drawingloop] 'this loop gets called every 17ms by the timer event
'add the movement to x and y x=x+dx*speed y=y+dy*speed
'now redraw the sprites #w.g "spritexy car ";x;" ";y print #w.g, "drawsprites" wait
[keyboardinterrupt] 'this loop gets called every time a key is pressed 'set the movement depending on key pressed key$=Inkey$ select case key$ case "l" 'left angle=angle-11.25 sprite=sprite-1 if sprite<0 then sprite=sprite+32 : angle=angle+360 #w.g "spriteimage car c";sprite dx=cos(angle/rad) dy=sin(angle/rad) case "r" 'right angle=angle+11.25 sprite=sprite+1 if sprite>31 then sprite=sprite-32 : angle=angle-360 #w.g "spriteimage car c";sprite dx=cos(angle/rad) dy=sin(angle/rad) case "u" 'up speed=speed+1 case "d" 'down speed=speed-1 case "s" 'stop speed=0 end select wait
[quit] timer 0
close #w
Thanks. greeting Attachments:
|
|
|
Post by held12345 on Mar 18, 2023 12:28:31 GMT -5
this is correkt :
case "l" 'left angle=angle+11.25 <<<<<<<<<<<< this is ok sprite=sprite-1 if sprite<0 then sprite=sprite+32 : angle=angle+360 #w.g "spriteimage car c";sprite dx=cos(angle/rad) dy=sin(angle/rad)
case "r" 'right angle=angle-11.25 <<<<<<<<<<<<<< this is ok sprite=sprite+1 if sprite>31 then sprite=sprite-32 : angle=angle-360 #w.g "spriteimage car c";sprite dx=cos(angle/rad) dy=sin(angle/rad)
Attachments:
|
|
|
Post by Rod on Mar 18, 2023 13:27:56 GMT -5
Aha, you solved your first problem. That’s the best bit about BASIC. You can’t break it you just keep trying.
|
|
|
Post by Rod on Mar 18, 2023 14:44:39 GMT -5
Small point, it isn’t 31 sprites it is 32, named 0 to 31.
|
|