public boolean wallCollision(Bullet bullet) {
    Rectangle boundingBox = bullet.getBoundingBox();
    int tile;
    int tileWidth = tileMap.getTileWidth();
    int tileHeight = tileMap.getTileHeight();

    /*
     * nested four loop only is grabbing the 4 corners of the
     * bullet's hit box and checking the type of tiles that they
     * contact. The current bullets range from 8x8 to 17x17, so they
     * all can contact the same range of tiles at any given time:
     * 1-4 A bullet expires on contact with a solid object(besides
     * ring bullets)
     */

    for (int y = bullet.yPos;
        y <= bullet.yPos + boundingBox.getHeight();
        y += boundingBox.getHeight()) {
      for (int x = bullet.xPos;
          x <= bullet.xPos + boundingBox.getWidth();
          x += boundingBox.getWidth()) {
        int tileCoordX = (int) (x + distanceScrolled) / tileWidth;
        int tileCoordY = y / tileHeight;

        tile = tileMap.getTile(((tileCoordY) * tileMap.getTileMapWidth()) + (tileCoordX));
        if (tile < 17 || 23 < tile) {
          return true;
        }
      }
    }
    return false;
  }
  LevelModel(ModelController theModelController, String fileLocation) {
    modelController = theModelController;
    levelFile = loadToJson(fileLocation);
    tileMap = new TileMap(levelFile);
    playerModel = new PlayerModel(this);
    theModelController
        .getViewController()
        .getDrawPanel()
        .getInputHandler()
        .registerInputResponder(playerModel);

    distanceScrolled = 0.0f;
    scrollVelocity = 0.05f;
    scrollDelta = 0;

    queuedEnemies = new ArrayList<EnemyModel>();
    activeEnemies = new ArrayList<EnemyModel>();
    activeBullets = new ArrayList<Bullet>();
    levelPickups = new ArrayList<Pickup>();

    // Retrieves Enemies, pickups, and tileMap
    loadObjects(levelFile, queuedEnemies, levelPickups);

    paused = false;

    deathTimer = null;

    SoundManager.get().playSound("music");

    mapWidthInPixels = tileMap.getTileMapWidth() * tileMap.getTileWidth();
  }
 public TileMap buildTileMap(
     TileImageSourceFactory tileImageSourceFactory,
     BoundingBoxOpFactory boundingBoxOpFactory,
     boolean forceArgb) {
   TileMap tileMap = buildTileMap(tileImageSourceFactory, forceArgb);
   tileMap.setBoundingBoxOpFactory(boundingBoxOpFactory);
   return tileMap;
 }
Example #4
0
 public void render() {
   glPushMatrix();
   {
     glClearColor(0, 0, 0, 0);
     glColor4f(255, 255, 255, 255);
     tileMap.render();
     player.render(tileMap.getX(), tileMap.getY());
     chat.render();
     robot.render();
   }
   glPopMatrix();
 }
Example #5
0
  public CanvasGame() {
    // TODO Auto-generated constructor stub
    instance = this;

    carregaImagens();

    MAPA = new TileMap(tileset, GamePanel.PWIDTH / 16, GamePanel.PHEIGHT / 16);
    MAPA.AbreMapa("60x60.map");

    gerenciadorTorre = new GerenciadorTorre();
    gerenciadorEfeitos = new GerenciadorEfeitos();
    gerenciadorRespawn = new GerenciadorRespawn();
    gerenciadorHud = new GerenciadorHud();
    gerenciadorObstaculos = new GerenciadorObstaculos();
    gerenciadorDeRaids = new GerenciadorDeRaids();

    largura = MAPA.Largura * 16;
    altura = MAPA.Altura * 16;

    base = new Base(largura / 2, altura / 2, Constantes.BASE_SIZEX_1, Constantes.BASE_SIZEY_1);

    setMiraAtiva(new Mira());
    // objetos.add(miraAtiva);

    inimigos.add(new Inimigo(Constantes.inimigoUm));
    heroi = new Heroi(GamePanel.PWIDTH / 2, GamePanel.PHEIGHT / 2, Constantes.LoadImage("t1.png"));

    carregaFontes();
  }
Example #6
0
 public Game() {
   sems = new Semaphore[2];
   for (int i = 0; i < 2; i++) {
     sems[i] = new Semaphore(1);
   }
   chat = new ChatHandler(0, 720 - 32, 14, 6);
   tileMap = new TileMap("testMap.txt", 32, sems);
   player = new Player(tileMap, tileMap.getPlayerSpawnX(), tileMap.getPlayerSpawnY(), chat);
   robot =
       new Robot(
           "Resources/Textures/NPCs/Enemies/Test",
           tileMap.getPlayerSpawnX(),
           tileMap.getPlayerSpawnY() - 10,
           "bob",
           player,
           tileMap,
           chat,
           sems);
 }
  public void loadLevel(Level level) {

    levelFile = loadToJson(level);
    tileMap = new TileMap(levelFile);

    distanceScrolled = 0.0f;
    scrollVelocity = 0.05f;
    scrollDelta = 0;

    queuedEnemies = new ArrayList<EnemyModel>();
    activeEnemies = new ArrayList<EnemyModel>();
    activeBullets = new ArrayList<Bullet>();
    levelPickups = new ArrayList<Pickup>();

    // Retrieves Enemies, pickups, and tileMap
    loadObjects(levelFile, queuedEnemies, levelPickups);

    SoundManager.get().playSound("music");
    mapWidthInPixels = tileMap.getTileMapWidth() * tileMap.getTileWidth();
  }
Example #8
0
 /**
  * Set tiles to use. Set to null at finish.
  *
  * @param xtiles
  * @param ytiles
  */
 public void setTiles(TileMap tiles) {
   if (null == tiles) {
     if (null != mTileDrawTask) {
       if (!mTileDrawTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
         /*
          * Always honor the latest query
          */
         mTileDrawTask.cancel(true);
       }
     }
   } else {
     tiles.setOrientation();
   }
   mTiles = tiles;
 }
Example #9
0
  @Override
  public void mousePressed(MouseEvent e) {
    mousePressedPoint = e.getPoint();

    TileCell targetCell = map.getCell(TileCell.transformCellPoint(e.getPoint()));
    if (targetCell == null || !targetCell.isCanPass()) {
      return;
    }

    if (isMouseLeftKey(e)) {
      recollectActors(targetCell);
      return;
    }
    // System.out.println(targetCell);

    actorsCancelTaskAndSubmitNew(targetCell);
  }
Example #10
0
  /** @param canvas */
  private void drawTiles(Canvas canvas) {
    mPaint.setShadowLayer(0, 0, 0, 0);

    if (null != mTiles) {

      for (int tilen = 0; tilen < mTiles.getTilesNum(); tilen++) {

        BitmapHolder tile = mTiles.getTile(tilen);

        /*
         * Scale, then move under the plane which is at center
         */
        boolean nochart = false;
        if (null == tile) {
          nochart = true;
        } else if (null == tile.getBitmap()) {
          nochart = true;
        }
        if (nochart) {
          continue;
        }

        /*
         * Pretty straightforward. Pan and draw individual tiles.
         */
        tile.getTransform().setScale(mScale.getScaleFactor(), mScale.getScaleCorrected());
        tile.getTransform()
            .postTranslate(
                getWidth() / 2.f
                    - BitmapHolder.WIDTH / 2.f * mScale.getScaleFactor()
                    + ((tilen % mTiles.getXTilesNum()) * BitmapHolder.WIDTH
                            - BitmapHolder.WIDTH * (int) (mTiles.getXTilesNum() / 2))
                        * mScale.getScaleFactor()
                    + mPan.getMoveX() * mScale.getScaleFactor()
                    + mPan.getTileMoveX() * BitmapHolder.WIDTH * mScale.getScaleFactor()
                    - (float) mMovement.getOffsetLongitude() * mScale.getScaleFactor(),
                getHeight() / 2.f
                    - BitmapHolder.HEIGHT / 2.f * mScale.getScaleCorrected()
                    + mPan.getMoveY() * mScale.getScaleCorrected()
                    + ((tilen / mTiles.getXTilesNum()) * BitmapHolder.HEIGHT
                            - BitmapHolder.HEIGHT * (int) (mTiles.getYTilesNum() / 2))
                        * mScale.getScaleCorrected()
                    + mPan.getTileMoveY() * BitmapHolder.HEIGHT * mScale.getScaleCorrected()
                    - (float) mMovement.getOffsetLatitude() * mScale.getScaleCorrected());

        Bitmap b = tile.getBitmap();
        if (null != b) {
          canvas.drawBitmap(b, tile.getTransform(), mPaint);
        }
      }
    }
  }
Example #11
0
 private void drawMap(Graphics2D g2d, TileMap map) {
   for (TileCell[] columns : map.getCells()) {
     for (TileCell cell : columns) {
       if (cell.isEnd()) {
         drawCellWithColor(g2d, cell, Color.GREEN);
       } else if (cell.isPath()) {
         if (!cell.isStart()) {
           drawCellWithColor(g2d, cell, Color.YELLOW);
         }
         drawCellG(g2d, cell);
       } else if (!cell.isCanPass()) {
         drawCellWithColor(g2d, cell, Color.DARK_GRAY);
       } else {
         g2d.setColor(Color.BLACK);
         g2d.drawRect(cell.getX(), cell.getY(), TileCell.WIDTH, TileCell.HEIGHT);
         drawCellG(g2d, cell);
       }
     }
   }
 }
Example #12
0
 public void update() {
   chat.update();
   player.update();
   tileMap.update((1280 / 2) - (int) player.getX(), (720 / 2) - (int) player.getY());
   robot.update();
 }
Example #13
0
  void SimulaSe(long DiffTime) {

    getMiraAtiva().SimulaSe((int) DiffTime);
    if (!GerenciadorRespawn.isRespawn()) {
      MAPA.Posiciona(
          (int) (heroi.getX() - (GamePanel.PWIDTH / 2)),
          (int) heroi.getY() - (GamePanel.PHEIGHT / 2));
    }

    // MAPA.Posiciona((int)(mousex-(GamePanel.PWIDTH/2)), (int)mousey-(GamePanel.PHEIGHT/2));

    Iterator<Objeto> itO = objetos.iterator();
    while (itO.hasNext()) {
      Objeto inim = itO.next();
      inim.SimulaSe((int) DiffTime);
      if (inim.isVivo() == false) {
        itO.remove();
      }
    }
    base.SimulaSe((int) DiffTime);
    heroi.SimulaSe((int) DiffTime);

    Iterator<Projetil> itP = projeteis.iterator();
    while (itP.hasNext()) {
      Projetil inim = itP.next();
      inim.SimulaSe((int) DiffTime);
      if (inim.isVivo() == false) {
        itP.remove();
      }
    }

    gerenciadorObstaculos.SimulaSe((int) DiffTime);

    gerenciadorDeRaids.SimulaSe((int) DiffTime);

    //		for	(int i=0;i<inimigos.size();i++) {
    ////		Iterator<Inimigo> it = inimigos.iterator();
    ////		while(it.hasNext()){
    ////			Inimigo inim = it.next();
    ////			inim.SimulaSe((int)DiffTime);
    ////			if(inim.isVivo()==false){
    ////				it.remove();
    ////				gerenciadorEfeitos.ganhouXp(inim.getX(), inim.getY(),inim.getTipoAssasino() );
    ////				}
    //			Inimigo inim = inimigos.get(i);
    //			inim.SimulaSe((int)DiffTime);
    //			if(inim.isVivo()==false){
    //				inimigos.remove(i);
    //
    //				inimigos.add(new Inimigo(Constantes.inimigoUm));
    //				inimigos.add(new Inimigo(Constantes.inimigoUm));
    //
    //
    //				gerenciadorEfeitos.ganhouXp(inim.getX(), inim.getY(),inim.getTipoAssasino() );
    //				}
    ////		}
    //		}
    gerenciadorTorre.SimulaSe((int) DiffTime);
    gerenciadorEfeitos.SimulaSe((int) DiffTime);
    gerenciadorRespawn.SimulaSe((int) DiffTime);
    gerenciadorHud.SimulaSe((int) DiffTime);
  }
 public TileMap buildTileMap(TileImageSourceFactory factory, boolean forceArgb) {
   TileMap tileMap = buildTileMap();
   tileMap.setTileImageSourceFactory(factory);
   tileMap.setForceArgb(forceArgb);
   return tileMap;
 }
 public Vector2 getWorldCoordinates() {
   return parentGrid.getWorldCoordinates();
 }
 public Rectangle getWorldDimensions() {
   return parentGrid.getWorldDimensions();
 }