Package pl.edu.pw.elka.mmarkiew.model.entities

Examples of pl.edu.pw.elka.mmarkiew.model.entities.Player


   *
   * @param event - Event from View or Timer event
   */
  private void checkInput(final QueueEvent event)
  {
    final Player player = model.getPlayer();
    final boolean xVelocity = (player.getXVelocity() != 0);
    final boolean yVelocity = (player.getYVelocity() != 0);
   
    if (event instanceof ViewKeyPress)
    {
      final Keys code = ((ViewKeyPress) event).getKey();
      final boolean pressed = ((ViewKeyPress) event).isPress();
     
      switch (code)
      {        //set velocity only if it's needed to set it, and reset it the same
        case UP:  if (pressed && !yVelocity)
              {
                player.setYVelocity(-player.getMaxVelocity());
              }
              else if (!pressed && yVelocity)
              {
                player.setYVelocity(0);
              }
              break;
        case DOWN:  if (pressed && !yVelocity)
              {
                player.setYVelocity(player.getMaxVelocity());
              }
              else if (!pressed && yVelocity)
              {
                player.setYVelocity(0);
              }
              break;
        case LEFT:  if (pressed && !xVelocity)
              {
                player.setXVelocity(-player.getMaxVelocity());
              }
              else if (!pressed && xVelocity)
              {
                player.setXVelocity(0);
              }
              break;
        case RIGHT:  if (pressed && !xVelocity)
              {
                player.setXVelocity(player.getMaxVelocity());
              }
              else if (!pressed && xVelocity)
              {
                player.setXVelocity(0);
              }
              break;
        case PLANT:  if (pressed)
              {
                model.plantBomb();
              }
              break;
        case TIMER_1:
        case TIMER_2:
        case TIMER_3:  if (pressed)
                {
                  // depends on the number of timer enum, sets appropriate number of seconds
                  player.setBombTimer( (code.ordinal() - Keys.TIMER_1.ordinal() + 1) * 1000 );
                }
                break;
        case PAUSE:  if (pressed)
              {
                model.switchPause();
View Full Code Here


   *
   * @param entities - Entities with which is need to be checked collision
   */
  private void checkPlayerEntityCollision(final LinkedList<Entity> entities)
  {
    final Player player = map.getPlayer();
   
    for (Entity e : entities)
    {
      // If entity is dead, do not do nothing
      if (e.isAlive() && isEntitiesCollision(player, e))
      {
        /*
         * if there is collision with alive enemy or explosion
         * set player dead and return, model take care about player
         */
        if (e instanceof Enemy || e instanceof ExplosionEntity)
        {
          player.setDead();
          Model.sound.playSound(SoundManager.KILL);
          return;
        }
          // If there is destroyed brick, just stop player
        else if (e instanceof DestroyingBrick)
View Full Code Here

   *
   * @param bombs - List of planted bombs
   */
  private void checkPlayerBombCollision(final LinkedList<Bomb> bombs)
  {
    final Player player = map.getPlayer();
    int onAnyBombStanding = 0;
   
    for (Bomb b : bombs)
    {
      if (isEntitiesCollision(player, b))
      {
        if (!player.isOnBomb())
        {
          checkPlayerStopCollision(player, b);
         
          if (player.isBouncingBomb())
          {
            b.collisionX();
            b.collisionY();
          }
        }
      }
      else
      {
        ++onAnyBombStanding;
      }
    }
   
    // If player isn't standing on any bomb, block him down with bombs collision
    if (onAnyBombStanding == bombs.size())
    {
      player.setOnBomb(false);
    }
  }
View Full Code Here

   *
   * @param bonuses - list of active bonuses
   */
  private void checkPlayerBonusCollision(final LinkedList<Bonus> bonuses)
  {
    final Player player = map.getPlayer();
   
    // If there is collision, add bonus to player and kill bonus
    for (Bonus b : bonuses)
    {
      if (b.isAlive() && isEntitiesCollision(player, b))
View Full Code Here

   *
   * @param timer - Time to explode
   */
  public void plantBomb(final long timer)
  {
    final Player player = map.getPlayer();
   
    // Check if player can plant any bomb at all
    if (player.canPlantBomb()) {
     
      // If there is any bomb on this place. One bomb, one block
      for (Bomb b : map.getBombs())
      {
        if (player.getX() > GameMap.getTilePosition(b.getX())    * GameMap.BLOCK_SIZE &&
          player.getX() < (GameMap.getTilePosition(b.getX()) + 1* GameMap.BLOCK_SIZE &&
          player.getY() > GameMap.getTilePosition(b.getY())    * GameMap.BLOCK_SIZE &&
          player.getY() < (GameMap.getTilePosition(b.getY()) + 1* GameMap.BLOCK_SIZE)
        {
          return;
        }
      }

      player.plantBomb();
      map.addBomb(player.getX(), player.getY(), System.currentTimeMillis(), timer, player.getBombArea());
      player.setOnBomb(true);
    }
  }
View Full Code Here

TOP

Related Classes of pl.edu.pw.elka.mmarkiew.model.entities.Player

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.