Java 2D Platformer Tutorial #7 - Adding Blocks

Поділитися
Вставка
  • Опубліковано 19 лют 2014
  • Check out my new Kotlin tutorial series: • Video Hey guys! In this video we add blocks to the game!

КОМЕНТАРІ • 18

  • @up4life108
    @up4life108 7 років тому

    im trying to make a mario clone in ruby using gosu. when i want to make the blocks hitable, i also loop thru the array just like in the video but it will always take the hitbox for the last block in the array.

  • @rhyse302
    @rhyse302 9 років тому

    Whenever I add the collision it won't let me use "Or" statements.

  • @epromes7175
    @epromes7175 5 років тому

    what is the shortcut key to import liberaries?

  • @quexatt
    @quexatt 6 років тому

    Is it just me but it's super laggy :( how do I fix this? Also thanks so much!!!

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

    whenever i move one way, it won't stop moving, and i have the controls down correctly

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

      well now that i did the x-gamestate.xoffset and such u can stop moving, but then i cannot start again

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

    at about 15 mins i start to get this error
    Exception in thread "Thread-1" java.lang.ArrayIndexOutOfBoundsException: 3
    at com.kody.game.entities.Player.tick(Player.java:50)
    at com.kody.game.gamestate.Level1State.tick(Level1State.java:36)
    at com.kody.game.gamestate.GameStateManager.tick(GameStateManager.java:17)
    at com.kody.game.main.GamePanel.tick(GamePanel.java:70)
    at com.kody.game.main.GamePanel.run(GamePanel.java:50)
    at java.lang.Thread.run(Unknown Source)
    pressing enter at the main screen will not bring me into the game, and i also cannot navigate the home menu.. i thaught i copies yours exactly but i guess not.

  • @excellent147
    @excellent147 5 років тому

    Buttomn collision doesnt work :\

  • @iPodTouchhelper2207
    @iPodTouchhelper2207 9 років тому +1

    When I press the a or d, it stars to move then doesnt stop, HELP
    package stockman.entities;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Rectangle;
    import com.sun.glass.events.KeyEvent;
    import stockman.gamestate.GameState;
    import stockman.main.GamePanel;
    import stockman.phyics.Collision;
    import stocman.objects.Block;
    public class Player extends Rectangle{
    private static final long serialVersionUID = 1L;
    //movement booleans
    private boolean right = false, left = false, jumping = false, falling = false;
    private double moveSpeed = 2.5;
    //bounds
    private double x, y;
    private int width, height;
    //jumpspeed
    private double jumpSpeed = 5;
    private double currentJumpSpeed = jumpSpeed;
    //fallspeed
    private double fallSpeed = 5;
    private double currentFallSpeed = fallSpeed;
    public Player(int width, int height){
    x = GamePanel.WIDTH /2;
    y = GamePanel.HEIGHT / 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, iY), b[i]) ||
    Collision.playerBlock(new Point(iX + width, iY + height), b[i]))
    {
    right = false;
    }
    }
    if(right) {GameState.xOffset += moveSpeed;}
    if(left) {GameState.yOffset += moveSpeed;}
    if(jumping) {
    y -= currentJumpSpeed;
    currentJumpSpeed -= 1;
    if(currentJumpSpeed

    • @SmashStory
      @SmashStory 9 років тому +1

      Stockman If you keep moving, that means something's not making right and left = false. Make sure in GameState Manager, game panel, and level 1 state, you have Keypressed under the Keypressed methods, and keyReleased under the keyReleased methods.
      Example:
      public void keyPressed(int e)

    • @iPodTouchhelper2207
      @iPodTouchhelper2207 9 років тому +1

      Thanks for that !!!! I realised that I had keypressed on both and it's working now :)

  • @bigpool5071
    @bigpool5071 7 років тому

    at like 15 minutes in the video I get this error
    Exception in thread "Thread-1" java.lang.ArrayIndexOutOfBoundsException: 3
    at com.patrickfeltes.game.gamestate.Level1State.tick(Level1State.java:33)
    at com.patrickfeltes.game.gamestate.GameStateManager.tick(GameStateManager.java:16)
    at com.patrickfeltes.game.main.GamePanel.tick(GamePanel.java:69)
    at com.patrickfeltes.game.main.GamePanel.run(GamePanel.java:50)
    at java.lang.Thread.run(Unknown Source)
    when trying to run the game. any help or advice?

  • @Levisss3
    @Levisss3 9 років тому

    why now left arrow is up
    and right arrow is still right? what i did wrong? :\
    package me.Bamba.game.entities;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.event.KeyEvent;
    import me.Bamba.game.gamestate.GameState;
    import me.Bamba.game.objects.Block;
    import me.Bamba.game.physics.Collision;
    import me.alon.game.main.GamePanel;
    public class Player {
    // movement booleans
    private boolean right = false, left = false, jumping = false, falling = false;
    // bounds
    private double x, y;
    private int width, height;
    // move speed
    private double moveSpeed = 2.5;
    // jump speed
    private double jumpSpeed = 5;
    private double currentJumpSpeed = jumpSpeed;
    // fall speed
    public double maxFallSpeed = 5;
    public double currentFallSpeed = 0.1;
    public Player (int width, int height) {
    x = GamePanel.WIDTH / 2;
    y = GamePanel.HEIGHT / 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, iY), b[i])
    || Collision.playerBlock(new Point(iX + width, iY + height), b[i])) {
    }
    }

    if (right) {
    GameState.xOffset += moveSpeed;
    }
    if (left) {
    GameState.yOffset -= moveSpeed;
    }
    if (jumping) {
    GameState.yOffset -= currentJumpSpeed;
    currentJumpSpeed -= .1;
    if(currentJumpSpeed

    • @SmashStory
      @SmashStory 9 років тому

      FaZe Bamba if left is press, we want to go left. So we have to move the xOffset, not the yOffset.
      if (left) gameState.xOffset -= movespeed;
      I have no idea why he put yOffset, and it's even more confusing of why it works for him lol.

  • @Monkexxx
    @Monkexxx 7 років тому

    at 17 minutes, when i press a or d I go always left :[

    • @danieladriaenssen936
      @danieladriaenssen936 6 років тому

      I had the same problem, in the collision class I had return b.contains(b); it should be return b.contains(p);

  • @AndrewisGaming
    @AndrewisGaming 8 років тому +2

    In this tutorial you barely explain anything. Why would you say "Tutorial", and not teach us anything? copying the code doesn't do anything for us. Rename these to "Showing you how to make a platformer #".... Instead of lying to us.

    • @justadeveloper709
      @justadeveloper709 10 місяців тому

      if you have difficulty to learn this, go study java.