public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

    counter += delta;

    Input input = gc.getInput();

    float fdelta = delta * Player.speed;

    Player.setpdelta(fdelta);

    double rightlimit = (grassMap.getWidth() * SIZE) - (SIZE * 0.75);

    // System.out.println("Right limit: " + rightlimit);

    float projectedright = Player.x + fdelta + SIZE;

    boolean cangoright = projectedright < rightlimit;

    // there are two types of fixes. A kludge and a hack. This is a kludge.

    if (input.isKeyDown(Input.KEY_UP)) {

      sprite = up;

      float fdsc = (float) (fdelta - (SIZE * .15));

      if (!(isBlocked(Player.x, Player.y - fdelta)
          || isBlocked((float) (Player.x + SIZE + 1.5), Player.y - fdelta))) {

        sprite.update(delta);

        // The lower the delta the slower the sprite will animate.

        Player.y -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_DOWN)) {

      sprite = down;

      if (!isBlocked(Player.x, Player.y + SIZE + fdelta)
          || !isBlocked(Player.x + SIZE - 1, Player.y + SIZE + fdelta)) {

        sprite.update(delta);

        Player.y += fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_LEFT)) {

      sprite = left;

      if (!(isBlocked(Player.x - fdelta, Player.y)
          || isBlocked(Player.x - fdelta, Player.y + SIZE - 1))) {

        sprite.update(delta);

        Player.x -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_RIGHT)) {

      sprite = right;

      // the boolean-kludge-implementation

      if (cangoright
          && (!(isBlocked(Player.x + SIZE + fdelta, Player.y)
              || isBlocked(Player.x + SIZE + fdelta, Player.y + SIZE - 1)))) {

        sprite.update(delta);

        Player.x += fdelta;
      } // else { System.out.println("Right limit reached: " +
      // rightlimit);}

    }

    Player.rect.setLocation(Player.getplayershitboxX(), Player.getplayershitboxY());

    //		for (Item i : stuff) {
    //
    //			if (Player.rect.intersects(i.hitbox)) {
    //				//System.out.println("yay");
    //				if (i.isvisible) {

    //					Player.health += 10000;
    //					i.isvisible = false;
    //				}

    //			}
    //		}

    /*for (Ninja n : dojo) {

    	if (Player.rect.intersects(n.hitbox)) {
    		//System.out.println("yay");
    		if (n.isvisible) {

    			Player.health += 10000;
    			n.isvisible = false;
    		}

    	}
    }
                          */

    for (Bone b : doghouse) {

      if (Player.rect.intersects(b.hitbox)) {
        // System.out.println("yay");
        if (b.isvisible) {
          Player.speed += .1f;
          b.isvisible = false;
          Player.Counter += 1;
        }
      }

      if (Player.Counter > 10) {
        Bone.Counter = false;
        sbg.enterState(3, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
      }
    }

    /*for (Item1 h : stuff1) {

    	if (Player.rect.intersects(h.hitbox)) {
    		//System.out.println("yay");
    		if (h.isvisible) {

    			Player.speed += .1f;
    			h.isvisible = false;
    		}

    	}
    }
                          */

    //		for (Itemwin w : stuffwin) {

    //			if (Player.rect.intersects(w.hitbox)) {
    //				//System.out.println("yay");
    //				if (w.isvisible) {
    //					w.isvisible = false;
    //					makevisible();
    //					sbg.enterState(3, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    //
    //				}
    //
    //			}
    //		}

    for (Enemy e : bonez) {
      if (e.isAlive) {
        e.move();
      }
    }
    for (Enemy e : bonez) {
      if (e.isAlive) {
        if (Player.rect.intersects(e.rect)) {
          Player.health = 0;
          e.isAlive = true;
          // once they touch the enemy player die
        }
      }
    }

    Player.health -= counter / 1000;
    if (Player.health <= 0) {
      makevisible();
      sbg.enterState(2, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    }
  }
예제 #2
0
  public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

    counter += delta;

    Input input = gc.getInput();

    float fdelta = delta * Player.speed;

    Player.setpdelta(fdelta);

    double rightlimit = (forestMap.getWidth() * SIZE) - (SIZE * 0.75);

    // System.out.println("Right limit: " + rightlimit);

    float projectedright = Player.x + fdelta + SIZE;

    boolean cangoright = projectedright < rightlimit;

    // there are two types of fixes. A kludge and a hack. This is a kludge.

    if (input.isKeyDown(Input.KEY_UP)) {

      sprite = proup;

      float fdsc = (float) (fdelta - (SIZE * .15));

      if (!(isBlocked(Player.x, Player.y - fdelta)
          || isBlocked((float) (Player.x + SIZE + 1.5), Player.y - fdelta))) {

        sprite.update(delta);

        // The lower the delta the slower the sprite will animate.

        Player.y -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_DOWN)) {

      sprite = prodown;

      if (!isBlocked(Player.x, Player.y + SIZE + fdelta)
          || !isBlocked(Player.x + SIZE - 1, Player.y + SIZE + fdelta)) {

        sprite.update(delta);

        Player.y += fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_LEFT)) {

      sprite = proleft;

      if (!(isBlocked(Player.x - fdelta, Player.y)
          || isBlocked(Player.x - fdelta, Player.y + SIZE - 1))) {

        sprite.update(delta);

        Player.x -= fdelta;
      }

    } else if (input.isKeyDown(Input.KEY_RIGHT)) {

      sprite = proright;

      // the boolean-kludge-implementation

      if (cangoright
          && (!(isBlocked(Player.x + SIZE + fdelta, Player.y)
              || isBlocked(Player.x + SIZE + fdelta, Player.y + SIZE - 1)))) {

        sprite.update(delta);

        Player.x += fdelta;
      } // else { System.out.println("Right limit reached: " +
      // rightlimit);}

    }

    Player.rect.setLocation(Player.getplayershitboxX(), Player.getplayershitboxY());

    for (itemwin w : stuffwin) {

      if (Player.rect.intersects(w.hitbox)) {
        // System.out.println("yay");
        if (w.isvisible) {
          w.isvisible = false;
          makevisible();
          sbg.enterState(3, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
        }
      }
    }
    for (Enemy m : monster) {

      if (Player.rect.intersects(m.ahitbox)) {
        // System.out.println("yay");
        if (m.isvisible) {

          Player.health -= 1000;
        }
      }
    }

    Player.health = 1000;
    if (Player.health <= 0) {
      makevisible();
      sbg.enterState(2, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
    }
  }