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

    Movement using the DoMove (not really a question) comments welcome if this is wrong

    Hi,

    I was playing a bit further with my program, and modified so I do the movement in the SpriteEngine.DoMove procedure , and it works fine regardles if velocity is 80, 95, or whatever... what I modified compared to my older source is :

    TForm1.OnIDLE

    Here is one obvious problem, which I did not even tried to solve... for now, somehow my Figure moves faster then the
    screen is scroll. ( I was hoping the speed would be the same...but there is a slight difference... will play with it later... was not
    the object here to solve that ... but rather to implement the movement more properly)

    Code:
        ActTime := ActTime + AdPerCounter.TimeGap;
        if ActTime > 25 then
        begin
          Blurp.vx:=0;
          Blurp.vy:=0;
              if GetKeyState(VK_LEFT) < 0 then
                begin
                      Blurp.vx:=-95;
                      AdSpriteEngine.X:=AdSpriteEngine.X-Blurp.vx*(AdPerCounter.TimeGap/1000);
                end;
              if GetKeyState(VK_RIGHT) < 0 then
                begin
                      Blurp.vx:=95;
                      AdSpriteEngine.X:=AdSpriteEngine.X-Blurp.vx*(AdPerCounter.TimeGap/1000);
                end;
              if GetKeyState(VK_UP) < 0 then
                begin
                      Blurp.vy:=-95;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y-Blurp.vy*(AdPerCounter.TimeGap/1000);
                end;
              if GetKeyState(VK_DOWN) < 0 then
                begin
                      Blurp.vy:=95;
                      AdSpriteEngine.Y:=AdSpriteEngine.Y-Blurp.vy*(AdPerCounter.TimeGap/1000);
                end;
          ActTime := 0;
        end;
    Here Is my modified DoMove , for now works great, been playing with it , using different velocity... always stops where it should yippeee

    Code:
    procedure TBlurp.DoMove(TimeGap: Double);
    begin
      inherited;
      // left
      if vx < 0 then
        begin
          if not testForWall(X+vx*TimeGap,Y,Image.Width,Image.Height-1,'left') then
            begin
              X:=X+round(vx*TimeGap) ;
            end;
        end;
      // right
      if vx > 0 then
        begin
         if not testForWall(X,Y,Image.Width,Image.Height-1,'right') then
           begin
             X:=X+round(vx*TimeGap);
           end;
        end;
      // up
      if vy < 0 then
        begin
          if not testForWall(X,Y+vy*TimeGap,Image.Width-1,Image.Height,'up') then
            begin
              Y:=Y+round(vy*TimeGap);
            end;
        end;
      // down
      if vy > 0 then
        begin
          if not testForWall(X,Y,Image.Width-1,Image.Height,'down') then
            begin
              Y:=Y+round(vy*TimeGap);
            end;
        end;
    
      Collision;
    end;
    Also one unexpected sidefect is ... before it was important where my Start position for my character was... now it's not , X can be 128,139,131 ... it works the same.

    Anyway I'll continue now with implementing gravity And checking the scrolling part.

    Greetings
    Rob

  2. #2

    Scrolling works now , ... and unfortunatelly gotta go get some sleep... :(

    Code:
        if ActTime > 10 then
        begin
          Blurp.vx:=0;
          Blurp.vy:=0;
              if GetKeyState(VK_LEFT) < 0 then
                begin
                      Blurp.vx:=-80;
                      if (Blurp.X > 320) and (Blurp.X < (40*64)-320) then
                        begin
                          AdSpriteEngine.X:=(Blurp.X*-1)+320;
                        end;
                end;
              if GetKeyState(VK_RIGHT) < 0 then
                begin
                      Blurp.vx:=80;
                      if (Blurp.X > 320) and (Blurp.X < (40*64)-320) then
                        begin
                          AdSpriteEngine.X:=(Blurp.X*-1)+320;
                        end;
                end;
              if GetKeyState(VK_UP) < 0 then
                begin
                      Blurp.vy:=-80;
                      if (Blurp.Y > 240) and (Blurp.Y < (29*64)-240) then
                        begin
                          AdSpriteEngine.Y:=(Blurp.Y*-1)+240;
                        end;
                end;
              if GetKeyState(VK_DOWN) < 0 then
                begin
                      Blurp.vy:=80;
                      if (Blurp.Y > 240) and (Blurp.Y < (29*64)-240) then
                        begin
                          AdSpriteEngine.Y:=(Blurp.Y*-1)+240;
                        end;
                end;
          ActTime := 0;
        end;
    Due to the fact that I use 60 FPS limit... had to decrease ACT TIME to 10... I don't know what to call this effect but when ACT TIME was 60... the screen was moving... I dunnot a bit erm... tear effect ... the outer lines of my character seemed to be jumping in and out of the character when it was redrawn...

    Anyway now it works great , and was pretty simple to do to. Only thing, gravity...tomorrow.

    Greetings
    Rob

    ps. : once I'm finished with my experiments...I'll use const and more variables instead of manually putting in numbers....
    Last edited by robert83; 21-08-2011 at 12:56 AM. Reason: changed source

  3. #3
    Hi Rob, glad to hear that it is now working for you

    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
  •