|
Post by B+ on Apr 1, 2018 14:13:07 GMT
Hello, Last night I setup JB v2.0 on my laptop (Windows 10) and everything seems to be working well (that I've tested so far) except this sample program: COLLIDES.bas I am wondering if anyone else is also having a problem with this sample?
|
|
|
Post by Stefan Pendl on Apr 1, 2018 18:07:25 GMT
Issue a down command before using the graphics box, this also helps with invisible sprites.
|
|
|
Post by B+ on Apr 1, 2018 21:01:17 GMT
Well COLLIDES.bas needed allot more than just down command. Here is an improvement:
'COLLIDES.bas fixed up for more interesting and educational Sample
'demonstrate sprite backgropund, cycling, moving and collision in Just BASIC
Global H$ 'trapclose use quit which needs handle H$ H$ = "w" 'for this sample
'this sample should have loaded these smiley files not smiley4.bmp (different size?) loadbmp "smiley1", "sprites\smiley.bmp" loadbmp "smiley2", "sprites\smiley1.bmp" loadbmp "smiley3", "sprites\smiley2.bmp" loadbmp "smiley4", "sprites\smiley3.bmp" loadbmp "landscape", "sprites\bg1.bmp"
'move window for sprites off of mainwin showing stuff going on UpperLeftX = 800 UpperLeftY = 300 WindowHeight = 300 WindowWidth = 400 graphicbox #w.g, 0, 0, 400, 300 open "COLLIDES.bas Sprite Test" for window_nf as #w
'these were missing from sample #w "trapclose quit" #w.g "down"
#w.g "background landscape";
' alternate the order for a more interesting display #w.g "addsprite smiley smiley1 smiley2 smiley3 smiley4" #w.g "addsprite smiler smiley2 smiley3 smiley4 smiley1" #w.g "addsprite smiled smiley3 smiley4 smiley1 smiley2" #w.g "addsprite smiles smiley4 smiley1 smiley2 smiley3"
' this cycles through smileys #w.g "cyclesprite smiley 1" #w.g "cyclesprite smiler 1" #w.g "cyclesprite smiled 1" #w.g "cyclesprite smiles 1"
'take a good look at different? sprites #w.g "spritexy smiley 50 10" #w.g "spritexy smiler 100 10" #w.g "spritexy smiled 50 60" #w.g "spritexy smiles 100 60" for i = 1 to 8 #w.g, "drawsprites" call pause 1000 'take a good look at different? sprites next
'now move them for x = 1 to 200 step 5 #w.g "spritexy smiley "; x; " "; x #w.g "spritexy smiler "; 300-x; " "; x #w.g "spritexy smiled "; 300-x; " "; 200-x #w.g "spritexy smiles "; x; " "; 200-x #w.g "drawsprites" #w.g "spritecollides smiley list$" if list$ > "" then print list$ call pause 500 next x print "That's all folks!" wait 'done, wait for quit
sub quit H$ close #H$ '<=== this needs Global H$ = ... as needed end 'Thanks Facundo, close graphic wo error end sub sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
|
|
|
Post by Stefan Pendl on Apr 2, 2018 9:30:10 GMT
If you use a sub as a event handler, the handle of the object sending this event will be included in the first string parameter of the sub. This parameter must not be global, a local one will just be as good, since handles on there own are already global. The parameter will contain "#w", which is what JB expects for the handle variable. I also added checking all four sprites and used "not equal" instead of "greater than" to check the collision list. Attachments:COLLIDES.bas (2.63 KB)
|
|
|
Post by B+ on Apr 2, 2018 17:48:41 GMT
I think I should have cleared list after each print of it or is it cleared after every print?
Stephan, in your code:
'COLLIDES.bas fixed up for more interesting and educational Sample
'demonstrate sprite backgropund, cycling, moving and collision in Just BASIC
'this sample should have loaded these smiley files not smiley4.bmp (different size?) loadbmp "smiley1", "sprites\smiley.bmp" loadbmp "smiley2", "sprites\smiley1.bmp" loadbmp "smiley3", "sprites\smiley2.bmp" loadbmp "smiley4", "sprites\smiley3.bmp" loadbmp "landscape", "sprites\bg1.bmp"
'move window for sprites off of mainwin showing stuff going on UpperLeftX = 800 UpperLeftY = 300 WindowHeight = 300 WindowWidth = 400 graphicbox #w.g, 0, 0, 400, 300 open "COLLIDES.bas Sprite Test" for window_nf as #w
'these were missing from sample #w "trapclose quit" #w.g "down"
#w.g "background landscape";
' alternate the order for a more interesting display #w.g "addsprite smiley smiley1 smiley2 smiley3 smiley4" #w.g "addsprite smiler smiley2 smiley3 smiley4 smiley1" #w.g "addsprite smiled smiley3 smiley4 smiley1 smiley2" #w.g "addsprite smiles smiley4 smiley1 smiley2 smiley3"
' this cycles through smileys #w.g "cyclesprite smiley 1" #w.g "cyclesprite smiler 1" #w.g "cyclesprite smiled 1" #w.g "cyclesprite smiles 1"
'take a good look at different? sprites #w.g "spritexy smiley 50 10" #w.g "spritexy smiler 100 10" #w.g "spritexy smiled 50 60" #w.g "spritexy smiles 100 60" for i = 1 to 8 #w.g, "drawsprites" call pause 1000 'take a good look at different? sprites next
'now move them for x = 1 to 200 step 5 #w.g "spritexy smiley "; x; " "; x #w.g "spritexy smiler "; 300-x; " "; x #w.g "spritexy smiled "; 300-x; " "; 200-x #w.g "spritexy smiles "; x; " "; 200-x #w.g "drawsprites" #w.g "spritecollides smiley list$" if list$ <> "" then print "smiley collides with: "; list$ #w.g "spritecollides smiler list$" if list$ <> "" then print "smiler collides with: "; list$ #w.g "spritecollides smiled list$" if list$ <> "" then print "smiled collides with: "; list$ #w.g "spritecollides smiles list$" if list$ <> "" then print "smiles collides with: "; list$ call pause 500 next x print "That's all folks!" wait 'done, wait for quit
sub quit H$ close #H$ print "window "; H$; " closed" end 'Thanks Facundo, close graphic wo error end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
If I had used following (in my example) would that be OK? I mean it WAS working allot better than original sample!:
sub quit Handle$ close #Handle$ end 'Thanks Facundo, close graphic wo error end sub
Well I guess I can try it myself. These window handle thingys are very confusing.
|
|
|
Post by Stefan Pendl on Apr 2, 2018 22:17:32 GMT
The variable receiving the collision list will be empty if there are no collisions, so there is no need for clearing it manually. The variable name doesn't make any difference, there should be an example included in the handle variables section of the JB help file.
|
|
edsa
New Member
Posts: 2
|
Post by edsa on Apr 15, 2018 17:50:07 GMT
I have just joined, thanks to a reminder from Stefan. I had programmed in Basic years ago and have forgotten everything. How can I see some sample programs please with some explanation?
|
|
|
Post by B+ on Apr 15, 2018 19:14:11 GMT
I have just joined, thanks to a reminder from Stefan. I had programmed in Basic years ago and have forgotten everything. How can I see some sample programs please with some explanation? Have you checked out the Tutorial in new JB v2.0 ? Look under Help. Attachments:
|
|
edsa
New Member
Posts: 2
|
Post by edsa on Apr 15, 2018 20:06:39 GMT
Thank you, B+ I downloaded the Tutorial and looked at the Mayhem program AND tried it. Now I have better idea what it's all about. I'll studying the basics and hope to progress..
Thank you. (Good to know it works with Windows 10)
|
|