locked
Collision problem RRS feed

  • Question

  • Hello everyone,

    I am working on a collision snippet at the moment. But I got some problems.

    Importcode: VLJ457

    I am using Array.GetItemCount to count my objects. If everything is right, it should give back 4. I am writing this result in the textwindow.

    But if I run the program, it writes "4" endless and the program crashes. If I comment the textwndow task out, it crashes too.

    But if I divide Array.GetItemCount with 3, I get 1.33333333 and the program never crashes. But, of course, it doesn't work like it should.

    Anyone see the problem?


    Mit freundlichen Grüßen Timo Greetings Timo

    Wednesday, October 9, 2013 6:59 AM

Answers

  • Timo,

    The move/collisioncheck should be done as follows:

    from Xpos and Ypos together with dx/dy from the keypress: calculate newX newY.

    then check for collision,

    if NO collision then move to newX,newY ; else do not move.


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Timo Sö Saturday, November 2, 2013 9:42 AM
    Thursday, October 17, 2013 5:42 PM
    Answerer
  • Timo

    http://en.wikipedia.org/wiki/Z-order

    I think it's origins come from the field of animation.

    Is useful in programming when adding AND removing shapes.

    So you could create an effect by adding shapes on top/partially overlapping each other and as well by the order in which they are hidden/removed.

    indices = Array.GetAllIndices(F)  'index shapes Z-order w/integers 

    Sub DataTable
      GW["big"][1]     = "W=500;H=500;PW=0;BGC=black;RS=0;BC=Crimson"
      GW["big"][2]     = "T=Songline Software - Big Black Window"
      GW["small"][1]   = "W=380;H=300;PW=0;BGC=white;RS=0;BC=black"
      GW["small"][2]   = "T=Songline Software - Small White Window"
      '                                                                                                                                                                        --  Z --
      F["leftEar"]     = "W=20;H=50;C=SpringGreen;Op=0;X=162;Y=120;R=0"           '1
      F["rightEar"]    = "W=20;H=50;C=SpringGreen;Op=0;X=318;Y=120;R=0"           '2
      F["face"]        = "W=150;H=200;C=Green;Op=0;X=175;Y=50;R=0"                '3
      F["headTopCovr"] = "W=350;H=110;C=black;Op=0;X=75;Y=50;R=0"                 '4  
      F["headTop"]     = "W=150;H=60;C=Green;Op=0;X=175;Y=129;R=0"                '5
      F["leftEye"]     = "W=40;H=30;C=DarkMagenta;Op=0;X=190;Y=145;R=10;bY=0.1"   '6  
      F["rightEye"]    = "W=40;H=30;C=DarkMagenta;Op=0;X=270;Y=145;R=-10;bY=0.1"  '7
      F["leftPupil"]   = "W=35;H=30;C=Yellow;Op=0;X=193;Y=145;R=0;bX=0.8"         '8  
      F["rightPupil"]  = "W=35;H=30;C=Yellow;Op=0;X=272;Y=145;R=0;bX=0.8"         '9
    EndSub

    Sample:  JRP437


    • Edited by Jibba j Sunday, October 20, 2013 10:02 AM get all
    • Marked as answer by Timo Sö Saturday, November 2, 2013 9:42 AM
    Sunday, October 20, 2013 9:58 AM
  • Timo    ,   this works well.        KHH822-1( This is for  right wall collision. )

     
    • Marked as answer by Timo Sö Saturday, November 2, 2013 9:42 AM
    Monday, October 21, 2013 1:54 PM
    Answerer

All replies

  • Subroutine Rechts(), Links(), Runter(), and Hoch() call Kollisionscheck() again.  So I think this causes endless loop.

    Nonki Takahashi

    Wednesday, October 9, 2013 11:09 AM
  • Timo,  does this help:

    line 54      For i = 1 To Array.GetItemCount(Shape)-1

    VLJ457-0

    Wednesday, October 9, 2013 11:13 AM
  •  

    You used samename array.   You must change the name.

    Shape[2][1][0] = Shapes.AddRectangle(60, 70)
      Shape[2][1][1] = 60 'Breite
      Shape[2][1][2] = 70 'Höhe
     

    for example,  see  KHH822-0




    • Edited by NaochanONEditor Wednesday, October 9, 2013 12:23 PM changed code number
    Wednesday, October 9, 2013 12:10 PM
    Answerer
  • @Nonki

    No, I do not think so. I call the movement subroutines to move the player in the opposite direction. After this, I check if the player hits a another shape. This should be not so and that is why it will not do it again.

    @Jibba Jabba

    Yes, the loop is fixed now.

    @NoachanON

    Thanks. I will call it different. Now there is no loop, and the snippet works better.

    But I still have some trouble with the collision position. To see what I mean, use NoachanON's example and move the player to the shape at the bottom right. If the player hits the shape, it should mobe upwards.But the player moves down and right. I think I have a logic mistake in my code, but I can't find it.

    Thanks so far.


    Mit freundlichen Grüßen Timo Greetings Timo

    Thursday, October 10, 2013 8:59 PM
  • In Sub TasteGedrueckt you move at any rate and THEN do the CollisionCheck. Try it the other way round.

    First detect if there is (Edit: or will be) a collision and if none, then you can move.


    • Edited by Pappa LapubEditor Thursday, October 10, 2013 10:23 PM
    • Proposed as answer by litdev Monday, October 14, 2013 5:39 PM
    Thursday, October 10, 2013 10:20 PM
    Answerer
  • I am sorry for my late answer.

    Pappa Lapub, I can't figure out what you mean exactly. I moved the collision check to different positions of my code, but it won't work.


    Mit freundlichen Grüßen Timo Greetings Timo

    Thursday, October 17, 2013 9:39 AM
  • Timo, I think you should redesign your collision check.

    If you look at the brown shape at down right, there is a region on the top and on the left with a width of 25 (diameter of your player), which is forbidden for the top/left coordinate of the player. To the right and on the bottom there is no boundary region.

    You only have to calculate this region once, and can check if the top/left of your player is coming into this region (or into the shape e.g. from below)

    Given the dimensions in your program this forbidden region is 285 <= x <= 440 and 405 <= y <= 450

    For the other shapes you can also calculate such regions.

    In the image you see the brown shape, the yellow forbidden region, two positions of the player touching the shape.

    The black dot is the coordinate of the top/left corner of the player.



    Jan [ WhTurner ] The Netherlands


    Thursday, October 17, 2013 12:28 PM
    Answerer
  • Sorry, war Blödsinn, funzt ohnehin auch nicht. Hatte mir den Code eigentlich gar nicht so sehr durchgesehen. Dachte nur, den SubAufruf Kollisionscheck() ev. im Ablauf VOR den jeweiligen Shapes.Move(..  zu stellen.

    Aber nebenbei würde ich einfach GraphicsWindow.PenWidth = 0   ganz zu Beginn definieren, dann ersparts Du Dir gleich alle GraphicsWindow.PenColor = Farbe  und Deine Shapes haben erst gar keinen Rand mehr.

    Außerdem ev. den roten Ball zuerst definieren, dann liegt er ganz zuoberst und über allen anderen Shapes und ist leichter zu verfolgen beim Testen.

    Noch was anderes: Läuft die SBIDE++ bei Dir (DE-de) ??? Liegt's ev an der Sprache?  Hab nämlich arge Schwierigkeiten und werd mich wohl an gungan wenden müssen.

    Thursday, October 17, 2013 5:25 PM
    Answerer
  • Timo,

    The move/collisioncheck should be done as follows:

    from Xpos and Ypos together with dx/dy from the keypress: calculate newX newY.

    then check for collision,

    if NO collision then move to newX,newY ; else do not move.


    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Timo Sö Saturday, November 2, 2013 9:42 AM
    Thursday, October 17, 2013 5:42 PM
    Answerer
  • Außerdem ev. den roten Ball zuerst definieren, dann liegt er ganz zuoberst und über allen anderen Shapes und ist leichter zu verfolgen beim Testen.

    No, you should define the red ball last. The shapes are stacked in sequence of creation, the last is on top.


    Jan [ WhTurner ] The Netherlands

    Friday, October 18, 2013 5:47 PM
    Answerer
  • Z-ordering?
    • Edited by Jibba j Friday, October 18, 2013 10:45 PM zzzzz
    Friday, October 18, 2013 10:44 PM
  • Yes of course, Timos' is on 1st place and i put it underneath Shape() for testing, which is definitely on last place then. Sorry, had a mistake in thinking.

    Friday, October 18, 2013 11:36 PM
    Answerer
  • Thanks for your tips.

    If I understood WhTurner33 right I must edit my calculation of the new player position. I will try this out.

    @Jibba Jabba

    What do you mean with "Z-ordering?"

    @Pappa Lapub

    Of course, the pen width. This makes it more easy. Thanks.

    Where can I get the DE-de version of gungan's SBIDE+++?

    I can not find it.


    Mit freundlichen Grüßen Timo Greetings Timo

    Sunday, October 20, 2013 9:14 AM
  • Timo

    http://en.wikipedia.org/wiki/Z-order

    I think it's origins come from the field of animation.

    Is useful in programming when adding AND removing shapes.

    So you could create an effect by adding shapes on top/partially overlapping each other and as well by the order in which they are hidden/removed.

    indices = Array.GetAllIndices(F)  'index shapes Z-order w/integers 

    Sub DataTable
      GW["big"][1]     = "W=500;H=500;PW=0;BGC=black;RS=0;BC=Crimson"
      GW["big"][2]     = "T=Songline Software - Big Black Window"
      GW["small"][1]   = "W=380;H=300;PW=0;BGC=white;RS=0;BC=black"
      GW["small"][2]   = "T=Songline Software - Small White Window"
      '                                                                                                                                                                        --  Z --
      F["leftEar"]     = "W=20;H=50;C=SpringGreen;Op=0;X=162;Y=120;R=0"           '1
      F["rightEar"]    = "W=20;H=50;C=SpringGreen;Op=0;X=318;Y=120;R=0"           '2
      F["face"]        = "W=150;H=200;C=Green;Op=0;X=175;Y=50;R=0"                '3
      F["headTopCovr"] = "W=350;H=110;C=black;Op=0;X=75;Y=50;R=0"                 '4  
      F["headTop"]     = "W=150;H=60;C=Green;Op=0;X=175;Y=129;R=0"                '5
      F["leftEye"]     = "W=40;H=30;C=DarkMagenta;Op=0;X=190;Y=145;R=10;bY=0.1"   '6  
      F["rightEye"]    = "W=40;H=30;C=DarkMagenta;Op=0;X=270;Y=145;R=-10;bY=0.1"  '7
      F["leftPupil"]   = "W=35;H=30;C=Yellow;Op=0;X=193;Y=145;R=0;bX=0.8"         '8  
      F["rightPupil"]  = "W=35;H=30;C=Yellow;Op=0;X=272;Y=145;R=0;bX=0.8"         '9
    EndSub

    Sample:  JRP437


    • Edited by Jibba j Sunday, October 20, 2013 10:02 AM get all
    • Marked as answer by Timo Sö Saturday, November 2, 2013 9:42 AM
    Sunday, October 20, 2013 9:58 AM
  • Hallo Timo,

    Edit: (War wohl die falsche Anwort zuvor, seh's jetzt erst):

    Lies SB IDE++: It's Here! (Update: 32 bit issues fixed!

    Richtige Antwort: Es gibt keine DE-de Version, wenn Du die Benutzeroberfläche (Menüs usw.) meinst.

    Allerdings kannst Du die SmallBasicLibrary.De.xml aus dem MS SB-Hauptordner oder die hier SmallBasicLibraryDe.zip (erweiterte .xml mit Zusatzinfos, wie Standardwerte von Eigenschaften usw. in IntelliSense) nehmen und jeweils in den "SBIDE++ -Hauptordner" und den nach "SBIDE++ Hauptordner\lib"  hineinkopieren, neben die beiden dort bereits liegenden engl. SmallBasicLibrary.xml.

    Dann ist die IntelliSense Hilfe größtenteils deutsch (SBIDE++ erst neustarten), bis auf die Keywords wie If, Then, Else, For, While, Sub usw. und die Fehlermeldungen in der unteren Leiste.

    Ansonsten die deutschen .xml für Plugins wie gehabt in den lib-Ordner zur jeweiligen .dll hinzufügen.


    Sunday, October 20, 2013 5:22 PM
    Answerer
  • Timo    ,   this works well.        KHH822-1( This is for  right wall collision. )

     
    • Marked as answer by Timo Sö Saturday, November 2, 2013 9:42 AM
    Monday, October 21, 2013 1:54 PM
    Answerer
  • Thanks for all your answers, examples and everything else.

    I am sorry that I answer so late. But the school is very hard at the moment. I need to learn a lot at the moment (300 new Spanish vocabulary for example) and that's why I have no time for programming at the moment.

    I tested NoachanON's example and it works better than my own (but not completly well ;) ). I will take a look on this again if I have more time.

    Thanks for your time.

    Timo


    Mit freundlichen Grüßen Timo Greetings Timo

    Saturday, November 2, 2013 9:39 AM