Results 1 to 10 of 31

Thread: Collission detection on level ( source Travels doc + some other examples)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    @Robert: hmm...I tried running your test program to take a look, but it doesn't run for me

    I get the dialog box error below:
    ---------------------------
    Dreamworld: DreamWorld.exe - Unable To Locate Component
    ---------------------------
    This application has failed to start because d3dx9_33.dll was not found. Re-installing the application may fix this problem.
    ---------------------------
    OK
    ---------------------------
    cheers,
    Paul

  2. #2
    you can download those dll files manually.

  3. #3
    ok, thanks

    cheers,
    Paul

  4. #4
    Hello,

    I've changed the movement from 3 to 4 now, so that it can be divided correctly... since my level is made of 64x64 tiles ...

    I think the problem is here but don't know how to fix....

    Left and Top works always on my level everywhere... it stops right there when it reaches the wall (no pixel left out...) , and I can continue to move in any other direction ...

    Left = works
    Top = works
    Right = stops 4 pixels sooner then it should...always
    Bottom = stops 4 pixels sooner then it should...always

    meanwhile I've also found out that it's important where my character starts... so I've set the starting position to

    X (3x64)-32
    Y (3x64)-32

    I hope I'm not wrong here, but currently my tiles are 64x64, whereas my character is 32x32.

    I've checked the Right and Bottom testwall functions... it works as it should because it is right that if it lets another +4 to x or +4 to y ... it is true... only thing is I can't seem to firugre it out... how the heck does it work correctly for Left and Top...
    Code:
     
     
               if GetKeyState(VK_LEFT) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X-4,Blurp.Y,Blurp.Image.Width,Blurp.Image.Height) then
                    begin
                      Blurp.X:=Blurp.X-4;
                      AdSpriteEngine.X:=AdSpriteEngine.X+4;
                    end;
                end;
              if GetKeyState(VK_RIGHT) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X+4,Blurp.Y,Blurp.Image.Width,Blurp.Image.Height) then
                    begin
                      Blurp.X:=Blurp.X+4;
                      AdSpriteEngine.X:=AdSpriteEngine.X-4;
                    end;
                end;
              if GetKeyState(VK_UP) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X,Blurp.Y-4,Blurp.Image.Width,Blurp.Image.Height) then
                    begin
                      Blurp.Y:=Blurp.Y-4;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y+4;
                    end;
                end;
              if GetKeyState(VK_DOWN) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X,Blurp.Y+4,Blurp.Image.Width,Blurp.Image.Height) then
                    begin
                      Blurp.Y:=Blurp.Y+4;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y-4;
                    end;
    Code:
    function TBlurp.testForWall(spriteXpos,spriteYpos:single;spriteWidth,spriteHeight:integer):boolean;
    begin
      testForWall := false;
      if not (TileInfo[round(spriteXpos) div 64, round(spriteYpos) div 64].tilenr in [2]) or not
      (TileInfo[(round(spriteXpos)+spriteWidth) div 64, round(spriteYpos) div 64].tilenr in [2]) or not
      (TileInfo[round(spriteXpos)div 64, (round(spriteYpos)+spriteHeight) div 64].tilenr in [2]) or not
      (TileInfo[(round(spriteXpos)+spriteWidth) div 64, (round(spriteYpos)+spriteHeight) div 64].tilenr in [2]) then testForWall :=true;
    end;
    Greetings
    Rob

  5. #5
    I'll throw out this kind of suggestion:
    Code:
              if GetKeyState(VK_LEFT) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X-4,Blurp.Y) then
                    begin
                      Blurp.X:=Blurp.X-4;
                      AdSpriteEngine.X:=AdSpriteEngine.X+4;
                    end;
                end;
              if GetKeyState(VK_RIGHT) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X+4+Blurp.Image.Width,Blurp.Y) then
                    begin
                      Blurp.X:=Blurp.X+4;
                      AdSpriteEngine.X:=AdSpriteEngine.X-4;
                    end;
                end;
              if GetKeyState(VK_UP) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X,Blurp.Y-4) then
                    begin
                      Blurp.Y:=Blurp.Y-4;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y+4;
                    end;
                end;
              if GetKeyState(VK_DOWN) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X,Blurp.Y+4+Blurp.Image.Height) then
                    begin
                      Blurp.Y:=Blurp.Y+4;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y-4;
                    end;
                end;
    Code:
    function TBlurp.testForWall(pointX,pointY:single):boolean;
    var tilenr: integer;
    begin
      tilenr:=TileInfo[trunc(pointX) div 64, trunc(pointY) div 64].tilenr;
      case tilenr of
        2: result:=true;
        else result:=false;
      end;
    end;
    Last edited by User137; 16-08-2011 at 03:58 PM. Reason: trunc

  6. #6
    Thank you! It's so simple and works wonderfully... I had to modify it a bit :

    Right :

    Code:
              if GetKeyState(VK_RIGHT) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X+Blurp.Image.Width,Blurp.Y) then
                    begin
                      Blurp.testForWall(Blurp.X+4+Blurp.Image.Width,Blurp.Y);
                      Blurp.X:=Blurp.X+4;
                      AdSpriteEngine.X:=AdSpriteEngine.X-4;
                    end;
                end;
    Down

    Code:
              if GetKeyState(VK_DOWN) < 0 then
                begin
                  if not Blurp.testForWall(Blurp.X,Blurp.Y+Blurp.Image.Height) then
                    begin
                      Blurp.testForWall(Blurp.X,Blurp.Y+4+Blurp.Image.Height);
                      Blurp.Y:=Blurp.Y+4;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y-4;
                    end;
                end;
    removed +4 otherwise it stopped 4 pixels sooner as before to the right and bottom, now it stops when it hits the wall and I can move in any other direction ... GREAT!

    Only thing is there are two bugs, which I'll look into tonight for some reason the following is possible :

    Attachment 557


    If I approach the tile from bellow, and hit it... keep pressing UP...and start moving to the
    left... the moment a small part of my character sprite is "free" it allows me to go up and
    down inside the wall ( I'm still happy tough, this is a better BUG atleast )
    Right side is not affected by this... if I find another wall sprite, and keep pressing top
    and try to go right...I can only go up once my character is completely free.


    Attachment 556

    Same here, if I approach a Wall sprite from left or right, and my Character is a bit Higher ... it can go trough...and move Left and Right... if I do the same with my character being lover then the Wall sprite it is not happening...

    Think this has something to do with only using X,Y maybe... anyway I'll play with it tonight.

    Attached is my modified "demo" thing.

    Thank you again for "spoon feeding" this to me, thank you VERY VERY much!!!
    Attachment 555

    Greetings
    Robert

  7. #7
    Hey Robert, have you looked at that tile game tutorial site I posted earlier? That might really help you get this all working

    Maybe this site can help?
    http://www.tonypa.pri.ee/tbw/tut05.html

    It is using action script (Flash) but I managed to folow the tutorials, especially "Hit the Wall" and "Jumping" to make a simple platform game with collision that worked quite well
    cheers,
    Paul

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •