Java 2D Platformer Tutorial #8 - Fixing Up the Collision Problems

Поділитися
Вставка
  • Опубліковано 3 жов 2024
  • Check out my new Kotlin tutorial series: • Video Hey guys! In this video we fix up all of the collision bugs. Thanks for watching!

КОМЕНТАРІ • 21

  • @rajivnarayan5214
    @rajivnarayan5214 8 років тому

    Wow man I cant stop commenting on your vids. Good job once again despite this being 2+ years ago

  • @theYouTubeClipsR
    @theYouTubeClipsR Рік тому

    There is still a bug. I noticed that when you jump near a block and move into it, it teleports the player to the top and messes up the screen. Any fixes?
    Ill post my code below.
    ```
    public class Player extends Rectangle {
    public static final long serialVerionUID= 1L;
    private boolean topCollision = false;
    private double moveSpeed = 5;
    private double x,y;
    private int width,height;
    public boolean right = false, left = false, jumping = false, falling = false;
    private double jumpSpeed = 15;
    private double currentJumpSpeed = jumpSpeed;
    private double maxFallSpeed= 5;
    private double currentFallSpeed = 0.5;
    public Player(int width, int height){
    x = GamePanel.WIDTH / 2;
    y = GamePanel.WIDTH / 2;
    this.width = width;
    this.height = height;
    }
    public void tick(Block[] b){
    int iX = (int)x;
    int iY = (int)y;
    for(int i= 0; i < b.length; i ++) {
    // right
    if (Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset, iY + (int) GameState.yOffset + 2 ) , b[i])
    || Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset, iY + height + (int)GameState.yOffset - 1), b[i])) {
    right = false;
    }
    //left
    if (Collision.playerBlock(new Point(iX + (int)GameState.xOffset - 1, iY + (int) GameState.yOffset + 2) , b[i])
    || Collision.playerBlock(new Point(iX + (int)GameState.xOffset - 1, iY + height + (int)GameState.yOffset - 1), b[i])) {
    left = false;
    }
    //top
    if (Collision.playerBlock(new Point(iX + (int)GameState.xOffset+1, iY + (int) GameState.yOffset) , b[i])
    || Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset-1, iY + (int)GameState.yOffset), b[i])) {
    jumping = false;
    falling = true;
    }
    //bottom
    if (Collision.playerBlock(new Point(iX + (int)GameState.xOffset + 2, iY + height + (int) GameState.yOffset - 1) , b[i])
    || Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset - 1, iY + height + (int)GameState.yOffset+ 1), b[i])) {
    y = b[i].getY()- height - GameState.yOffset;
    falling = false;
    topCollision = true;
    }else{
    if(!topCollision && !jumping){
    falling = true;
    }
    }
    }
    topCollision = false;
    if(right){
    GameState.xOffset+= moveSpeed;
    }
    if(left){
    GameState.xOffset-= moveSpeed ;
    }
    if(jumping){
    GameState.yOffset-=currentJumpSpeed;
    currentJumpSpeed -= 1;
    }
    if(currentJumpSpeed

  • @TekkitWizard
    @TekkitWizard 10 років тому +1

    Can u post a place were we can get the src code because i can't figure out this bug i have and i just really want to compare side by side view of mine to yours to see what is wrong. thanks so much---TekkitWizard

  • @danielherreragonzalez4311
    @danielherreragonzalez4311 10 років тому

    can you post the gamepanel class and the main one, finish the tutorial but i cant seem to make to work, also on your page you dont have those 2 clases uploaded :P

  • @davidhenricson8699
    @davidhenricson8699 10 років тому

    Hey! Great tutorial! For how long time have you been programming in Java?

    • @PatrickFeltes
      @PatrickFeltes  10 років тому

      I started about 1.5 years ago during the summer. Once you figure out the basics, you can move onto the more challenging topics like game programming without much difficulty.

  • @kozzymoto8994
    @kozzymoto8994 8 років тому

    My code is exactly like yours but my block still doesn't move on the blocks. I can't figure out what is happening please help!

    • @kozzymoto8994
      @kozzymoto8994 8 років тому

      +KozzyMoto Never mind I just increased the amount added to the offset and it works fine now

    • @Frost-cq7sq
      @Frost-cq7sq 8 років тому

      +KozzyMoto Hey i have the same problem did you add to all the offsets?

    • @kozzymoto8994
      @kozzymoto8994 8 років тому

      just to the last two y offsets

  • @Frost-cq7sq
    @Frost-cq7sq 8 років тому +1

    Hey man i have added to the padding just like you did but my player still doesn't move right on the blocks. Should i just add to all the offsets? What should i do?

    • @fisherjunior6903
      @fisherjunior6903 3 роки тому

      I realize Im pretty off topic but does anybody know of a good site to stream new tv shows online?

    • @jamalconor4225
      @jamalconor4225 3 роки тому

      @Fisher Junior I watch on Flixzone. You can find it on google =)

    • @sageconrad8665
      @sageconrad8665 3 роки тому

      @Jamal Conor Yea, have been watching on Flixzone for since march myself :)

    • @fisherjunior6903
      @fisherjunior6903 3 роки тому

      @Jamal Conor Thank you, signed up and it seems like a nice service =) I really appreciate it!

    • @jamalconor4225
      @jamalconor4225 3 роки тому

      @Fisher Junior you are welcome xD

  • @LucaGAFFE
    @LucaGAFFE 10 років тому

    Make More!

    • @PatrickFeltes
      @PatrickFeltes  10 років тому

      More should be coming this weekend!