Results 1 to 10 of 10

Thread: Popped

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Popped

    I know it's a very last minute thing, but I've started my entry for the compo...it's called "Popped". It's going to be a tilt the world game to guide a bubble around the world past hazards and stuff trying not to get popped.

    cheers,
    Paul

  2. #2
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    sound's like a fun game Paul

  3. #3
    Thanks
    I have done bugger all so far, so we will see! haha

  4. #4
    I have a collision question for in my game if anyone can help?

    I want to stop the circle (bubble) when it hits a sloped tile (45 degrees) moving either up / down / left / right. I can do square tiles, but not sure how to do sloped:

    Code:
    |\       __
    |_\      \ |
              \|
    ___
    | /       /|
    |/       /_|
    Here is a screenshot (includes gravity vector when tilting world) which shows the sloped tiles as well as the square tiles:



    This is my collision code for square tiles which I hope to add sloped tiles to:

    Code:
    var
      Corners: SpriteCorners := new SpriteCorners;
    
    method PoppedApp.GetBubbleCorners(aOfsX,aOfsY: Single): SpriteCorners;
    begin
      // calculate tile index for each object corner
      Corners.Left   := FLevel.getTileX(FBubble.pos.x - FBubble.radius + aOfsX);
      Corners.Right  := FLevel.getTileX(FBubble.pos.x + FBubble.radius - 0.001 + aOfsX);
      Corners.Up     := FLevel.getTileY(FBubble.pos.y - FBubble.radius + aOfsY);
      Corners.Down   := FLevel.getTileY(FBubble.pos.y + FBubble.radius - 0.001 + aOfsY);
    
      // if true then there is a wall there
      Corners.WallUL    := FLevel.wallAt(Corners.Left  ,Corners.Up);
      Corners.WallUR    := FLevel.wallAt(Corners.Right ,Corners.Up);
      Corners.WallDL    := FLevel.wallAt(Corners.Left  ,Corners.Down);
      Corners.WallDR    := FLevel.wallAt(Corners.Right ,Corners.Down);
    
      Result := Corners;
    end;
    
    method PoppedApp.MoveBubble(aTimeSlice: Single);
    var
      cnr: SpriteCorners;
    begin
      cnr := GetBubbleCorners(0,FBubble.vel.y*aTimeSlice);
    
      if FBubble.vel.y < 0 then
      // moving up
      begin
        if not cnr.WallUL and not cnr.WallUR then
        // not obstructed so move normally
          FBubble.pos.y := FBubble.pos.y + FBubble.vel.y * aTimeSlice
        else
        // hit tile so move to edge of tile and stop
        begin
          FBubble.vel.y := 0;
          FBubble.pos.y  := cnr.Up * cTileSize + cTileSize + FBubble.radius;
        end;
      end
      else
      if FBubble.vel.y > 0 then
      // moving down
      begin
        if not cnr.WallDL and not cnr.WallDR then
        // not obstructed so move normally
          FBubble.pos.y := FBubble.pos.y + FBubble.vel.y * aTimeSlice
        else
        // hit tile so move to edge of tile and stop
        begin
          FBubble.vel.y := 0;
          FBubble.pos.y  := cnr.Down * cTileSize - FBubble.radius;
        end;
      end;
    
      cnr := GetBubbleCorners(FBubble.vel.x*aTimeSlice,0);
    
      if FBubble.vel.x < 0 then
      // moving left
      begin
        if not cnr.WallUL and not cnr.WallDL then
        // not obstructed so move normally
          FBubble.pos.x := FBubble.pos.x + FBubble.vel.x * aTimeSlice
        else
        // hit tile so move to edge of tile and stop
        begin
          FBubble.vel.x := 0;
          FBubble.pos.x  := cnr.Left * cTileSize + cTileSize + FBubble.radius;
        end;
      end
      else
      if FBubble.vel.x > 0 then
      // moving right
      begin
        if not cnr.WallUR and not cnr.WallDR then
        // not obstructed so move normally
          FBubble.pos.x := FBubble.pos.x + FBubble.vel.x * aTimeSlice
        else
        // hit tile so move to edge of tile and stop
        begin
          FBubble.vel.x := 0;
          FBubble.pos.x  := cnr.Right * cTileSize - FBubble.radius;
        end;
      end;
    
      // apply gravity
      FBubble.vel.x := FBubble.vel.x + FGravityX * aTimeSlice;
      FBubble.vel.y := FBubble.vel.y + FGravityY * aTimeSlice;
    
      // don't allow bubble to move faster than maximum velocity
      if FBubble.vel.VecLen > cMaxVel then 
      begin
        var m   : Single := FBubble.vel.VecLen;
        FBubble.vel.SetValue(FBubble.vel.x * cMaxVel / m,FBubble.vel.y * cMaxVel / m);
      end;
    end;
    cheers,
    Paul

  5. #5
    You should do line to circle colision detection for this. http://stackoverflow.com/a/1079478

  6. #6
    Quote Originally Posted by SilverWarior View Post
    You should do line to circle colision detection for this. http://stackoverflow.com/a/1079478
    Thanks mate, I will take a look at it

    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
  •