예제 #1
0
 private void paintLifes(Graphics2D g2d) {
   int lifes = c.getLifes();
   for (int i = 0; i < lifes; i++) {
     ImageIcon imageIcon =
         new ImageIcon(
             ItemFactory.class.getResource(Config.getImagePath() + Level.getLevel().getLife()));
     Life life =
         ItemFactory.createLife(
             Config.getBoardDimension().getLength() - (2 + i) * imageIcon.getIconWidth(),
             0,
             imageIcon);
     g2d.drawImage(life.getImage(), life.getPosition().getX(), life.getPosition().getY(), this);
   }
 }
예제 #2
0
파일: Grass.java 프로젝트: NixSilva/ecogame
 @Override
 public void update(float delta) {
   super.update(delta);
   if (tile.getClass() == SpringTile.class) state = State.Deleted;
   fertility = reproducibility * tile.getWater();
   tile.incWater(-water_consume * delta);
 }
예제 #3
0
파일: Grass.java 프로젝트: NixSilva/ecogame
 @Override
 public void drawShape(ShapeRenderer shapes) {
   if (state == State.Growing) {
     shapes.setColor(0.0f, 1.0f, 0.0f, 1.0f);
   } else if (state == State.Dead) {
     float color = nutrition / (nutrition_max * age / max_life);
     shapes.setColor(color, color, 0.0f, 1.0f);
   }
   super.drawShape(shapes);
 }
예제 #4
0
  void mark(int[][] line) {
    if (line.length == 0) return;
    for (int i = 0; i < line.length; i++) Life.makeBlue(line[i][0], line[i][1]);

    Life.critterMap[y][x] = false;

    this.x = line[line.length - 1][0];
    this.y = line[line.length - 1][1];

    Life.critterMap[y][x] = true;
  }
예제 #5
0
  public void start() {
    // ウィンドウの生成
    try {
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      // Display.setTitle("SimField");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    initGL();

    // メインループ
    while (!Display.isCloseRequested()) {
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
      /**
       * for(Life l : lifeSet.getArray()){ l.renderLife(); } for(Life lr: lifeRedSet.getArray()){
       * lr.renderLife(); } for(Life lb: lifeBlueSet.getArray()){ lb.renderLife(); }
       */
      for (Life l : life) {
        l.renderLife();
      }
      for (Life lr : lifeRed) {
        lr.renderLife();
      }
      for (Life lb : lifeBlue) {
        lb.renderLife();
      }
      status.updateFPS();
      Display.update(); // オンスクリーンに反映
      Display.sync(60); // FPSを60に固定
    }
  }
예제 #6
0
  void move(int[][] terrain) throws CritterListException {
    boolean repeat = true;
    int randomNum, xCoor = -1, yCoor = -1;
    int[] position = {0, 0};
    int[][] line = null;

    // check to see if any of the yummy critters are next to me
    // if more than one yummy critters are next to me, eat the first available one from yummyList

    for (int i = 0; i < Life.yummyList.length; i++) {
      if (Math.abs(Life.yummyList[i].x - this.x) <= 1
          && Math.abs(Life.yummyList[i].y - this.y) <= 1) {
        xCoor = Life.yummyList[i].x;
        yCoor = Life.yummyList[i].y;
        int[] refe1 = {terrain[y][x], y, x};
        int[] refe2 = {terrain[yCoor][xCoor], yCoor, xCoor};
        line = clearLine(terrain, refe1, refe2);
        mark(line);
        eat(Life.yummyList[i].x, Life.yummyList[i].y, i);
        return;
      }
    }

    // code fragment to check if cells within a 7x7 window
    // note: there are 9 = 3x3 - 1 candidate cells

    while (repeat) {
      line = null;
      // get a random number between 0..9
      randomNum = Life.random.nextInt(9);
      // turn this value to be 0..23 and 25..48
      // position 4 is the center of the 7x7 window
      if (randomNum > 4) randomNum++;
      // convert that to a coordinate in a 7x7 window
      yCoor = y - 1 + randomNum / 3; // row
      xCoor = x - 1 + randomNum % 3; // column

      if (Life.kosherCoords(xCoor, yCoor))
      // xCoor and yCoor are inside the terrain and
      // not currently occupied by another critter )
      {
        // check to see if that location is visible
        int[] ref1 = {terrain[y][x], y, x};
        int[] ref2 = {terrain[yCoor][xCoor], yCoor, xCoor};
        line = clearLine(terrain, ref1, ref2);
        if (line != null) {
          repeat = false;
          mark(line);
        }
      }
    }
  }
예제 #7
0
  void eat(int xCoor, int yCoor, int i) {

    Life.critterMap[yCoor][xCoor] = false;
    Life.makeRed(xCoor, yCoor);
    Life.removeHungry(this);
  }
예제 #8
0
 public HungryCritter(int xCoor, int yCoor, int aPos) {
   super(xCoor, yCoor, aPos);
   Life.makeBlue(xCoor, yCoor);
 }