Beispiel #1
0
  public boolean changeTile(int x, int y, String image) {
    Tile temp = getTile(x, y);

    Entity ent = game.getEntityManager().getEntity(temp.getX(), temp.getY());

    if (ent != null) {
      if (image.contains("concrete"))
        if (ent.getImage().contains("dinosaur") || ent.getImage().contains("fence")) return false;
    }

    if (game.getEntityManager().entityAt(temp.getX(), temp.getY()) && image.contains("water"))
      return false;

    if (game.getParkManager().purchaseEntity(image)) temp.setImage(image);

    return true;
  }
Beispiel #2
0
  public void Draw(Canvas canvas) {
    if (!initialized) {
      tiles = new ArrayList<Tile>();
      water = new ArrayList<Tile>();

      TILE_WIDTH = game.getBitmapManager().getBitmap(R.drawable.terrain_grass).getWidth();
      TILE_HEIGHT = game.getBitmapManager().getBitmap(R.drawable.terrain_grass).getHeight();

      generateTerrain(tiles);
      generateWater(water);

      initialized = true;
    }

    float tempWaterOffset = waterOffset;
    tempWaterOffset = (float) Math.round(waterOffset);
    tempWaterOffset = tempWaterOffset % 2 == 0 ? tempWaterOffset : tempWaterOffset + 1;

    for (int i = 0; i < water.size(); i++) {
      float offset_x = (float) (water.get(i).x) * TILE_WIDTH / 2;
      float offset_y = (float) (water.get(i).y) * TILE_HEIGHT;

      if (water.get(i).x % 2 == 1) offset_y += TILE_HEIGHT / 2;

      offset_x += tempWaterOffset;
      offset_y += tempWaterOffset / 2;

      offset_x -= 2 * TILE_WIDTH;
      offset_y -= 2 * TILE_HEIGHT;

      offset_x += (game.getCameraManager().getX() % 2) * TILE_WIDTH / 2;
      offset_y += (game.getCameraManager().getY() % 1) * TILE_HEIGHT;

      Bitmap bmp = game.getBitmapManager().getBitmap(water.get(i).getImageId());
      canvas.drawBitmap(bmp, offset_x, offset_y, null);
    }

    float hoverOffsetX = 100000;
    float hoverOffsetY = 100000;
    int tempHoverX = hoverX - TILE_WIDTH / 2;
    int tempHoverY = hoverY - TILE_HEIGHT;
    Tile temp = tiles.get(0);

    for (int i = 0; i < tiles.size(); i++) {
      Bitmap bmp = game.getBitmapManager().getBitmap(tiles.get(i).getImageId());

      float offset_x = (float) (tiles.get(i).x + game.getCameraManager().getX()) * TILE_WIDTH / 2;
      float offset_y = (float) (tiles.get(i).y + game.getCameraManager().getY()) * TILE_HEIGHT;

      if (tiles.get(i).x % 2 == 1) offset_y += TILE_HEIGHT / 2;

      if (Math.sqrt(Math.pow(offset_x - tempHoverX, 2) + Math.pow(offset_y - tempHoverY, 2))
          < Math.sqrt(
              Math.pow(hoverOffsetX - tempHoverX, 2) + Math.pow(hoverOffsetY - tempHoverY, 2))) {
        hoverOffsetX = offset_x;
        hoverOffsetY = offset_y;
        temp = tiles.get(i);
      }

      if (offset_x < (canvas.getWidth() + TILE_WIDTH)
          && offset_y < (canvas.getHeight() + TILE_HEIGHT)
          && offset_x > -TILE_WIDTH
          && offset_y > -TILE_HEIGHT) canvas.drawBitmap(bmp, offset_x, offset_y, null);
    }

    int color = Color.parseColor("#96FFFF00");

    Entity ent = game.getEntityManager().getEntity(temp.getX(), temp.getY());

    if (ent != null) {
      if (hoverImage.contains("concrete"))
        if (ent.getImage().contains("dinosaur") || ent.getImage().contains("fence"))
          color = Color.parseColor("#96FF0000");
    }

    if (game.getEntityManager().entityAt(temp.getX(), temp.getY()) && hoverImage.contains("water"))
      color = Color.parseColor("#96FF0000");

    Paint paint = new Paint(color);
    ColorFilter filter = new LightingColorFilter(color, 1);
    paint.setColorFilter(filter);
    canvas.drawBitmap(
        game.getBitmapManager()
            .getBitmap(
                game.getResources()
                    .getIdentifier(hoverImage, "drawable", "cpsc372.dinosaur_tycoon")),
        hoverOffsetX,
        hoverOffsetY,
        paint);

    long delta = (System.currentTimeMillis() - gameTime);

    Update(delta);
    gameTime = System.currentTimeMillis();
  }