Ejemplo n.º 1
1
  /**
   * 描画処理
   *
   * @param 描画オブジェクト
   */
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // 背景を黒で塗りつぶす
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, getWidth(), getHeight());

    // X方向のオフセットを計算
    int offsetX = MainPanel.WIDTH / 2 - (int) player.getX();
    // マップの端ではスクロールしないようにする
    offsetX = Math.min(offsetX, 0);
    offsetX = Math.max(offsetX, MainPanel.WIDTH - map.getWidth());

    // Y方向のオフセットを計算
    int offsetY = MainPanel.HEIGHT / 2 - (int) player.getY();
    // マップの端ではスクロールしないようにする
    offsetY = Math.min(offsetY, 0);
    offsetY = Math.max(offsetY, MainPanel.HEIGHT - map.getHeight());

    // マップを描画
    map.draw(g, offsetX, offsetY);

    // プレイヤーを描画
    player.draw(g, offsetX, offsetY);

    // スプライトを描画
    // マップにいるスプライトを取得
    LinkedList sprites = map.getSprites();
    Iterator iterator = sprites.iterator();
    while (iterator.hasNext()) {
      Sprite sprite = (Sprite) iterator.next();
      sprite.draw(g, offsetX, offsetY);
    }
  }
Ejemplo n.º 2
1
  public void render(GameContainer container, Graphics g) throws SlickException {
    int xOffset = -(int) player.getX() + WIDTH / 2;
    int yOffset = -(int) player.getY() + HEIGHT / 2;

    tileMap.render(xOffset, yOffset);
    player.draw(WIDTH, HEIGHT);
    entity.draw(xOffset, yOffset);
    for (int i = 0; i < projectiles.size(); i++) {
      projectiles.get(i).draw(xOffset, yOffset);
    }
    this.drawHealthBar(g, player, xOffset, yOffset);
    this.drawHealthBar(g, entity, xOffset, yOffset);
  }
Ejemplo n.º 3
0
 @Override
 public void draw(Graphics2D g) {
   tileMap.draw(g);
   eManager.draw(g);
   tManager.draw(g);
   player.draw(g);
 }
Ejemplo n.º 4
0
  public void drawFromThread(Canvas canvas) {
    final float scaleFactorX = getWidth() / (WIDTH * 1.f);
    final float scaleFactorY = getHeight() / (HEIGHT * 1.f);

    if (canvas != null) {
      final int savedState = canvas.save();
      canvas.scale(scaleFactorX, scaleFactorY);
      bg.draw(canvas);
      if (!dissapear) {
        player.draw(canvas);
      }
      // draw smokepuffs
      for (Smokepuff sp : smoke) {
        sp.draw(canvas);
      }
      // draw missiles
      for (Missile m : missiles) {
        m.draw(canvas);
      }
      // draw topborder
      for (TopBorder tb : topborder) {
        tb.draw(canvas);
      }
      // draw botborder
      for (BotBorder bb : botborder) {
        bb.draw(canvas);
      }
      // draw explosion
      if (started) {
        explosion.draw(canvas);
      }
      drawText(canvas);
      canvas.restoreToCount(savedState);
    }
  }
  @Override
  public void draw(Graphics2D g) {
    g.setColor(Color.white);
    g.drawString("Score: " + SCORE, 5, 15);

    g.setColor(Color.red);
    g.drawString("Health: " + player.getHealth(), 5, 35);

    blocks.draw(g);
    player.draw(g);
    level.draw(g);

    if (level.isGameOver()) {
      g.setColor(Color.red);
      g.setFont(gameScreen);
      String gameOver = "GAME OVER!";
      int gameOverWidth = g.getFontMetrics().stringWidth(gameOver);
      g.drawString(gameOver, (Display.WIDTH / 2) - (gameOverWidth / 2), Display.HEIGHT / 2);
    }

    if (level.isComplete()) {
      g.setColor(Color.green);
      g.setFont(gameScreen);
      String complete = "LEVEL COMPLETE!";
      int completeWidth = g.getFontMetrics().stringWidth(complete);
      g.drawString(complete, (Display.WIDTH / 2) - (completeWidth / 2), Display.HEIGHT / 2);
    }
  }
Ejemplo n.º 6
0
  private void drawPlayers(Graphics2D g2d, TileMap map) {
    //		g2d.setColor(Color.LIGHT_GRAY);
    //		g2d.fill(new Rectangle(player.getX(), player.getY(), TileCell.WIDTH, TileCell.HEIGHT));
    //		g2d.setColor(Color.BLACK);
    //		g2d.drawRect(player.getX(), player.getY(), TileCell.WIDTH, TileCell.HEIGHT);

    for (Player currPlayer : players) {
      currPlayer.draw(g2d);
    }
  }
Ejemplo n.º 7
0
  public void draw(Graphics2D g) {

    /*
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, GamePanel.WIDTH, GamePanel.HEIGHT);
    g.setColor(Color.white);
    */
    // bgManager.draw(g);
    /*
                mAlimentos.drawAlimentos(g);
        mAlimentos.drawPoderes(g);
    */
    // draw the backgrounds
    /*
    bgSky.draw(g);
    bgSoil.draw(g);
    */
    bgKitchen.draw(g);

    // draw the rails
    /*
    g.setColor(Color.blue);
    g.fillRect(0, 484, GamePanel.WIDTH, 3);
    g.fillRect(0, 592, GamePanel.WIDTH, 3);
    g.fillRect(0, 700, GamePanel.WIDTH, 3);
    */

    // draw the dishes
    for (int i = 0; i < dishes.size(); i++) {
      dishes.get(i).draw(g);
    }

    // draw the player
    player.draw(g);

    // draw the npc
    npc.draw(g);

    // draw the hud
    hud.draw(g);

    // drawing rails
    // {444, 552, 660}

    // draw the dish values
    for (int i = 0; i < numbers.size(); i++) {
      numbers.get(i).draw(g);
    }

    // draw the explosion
    for (int i = 0; i < explosions.size(); i++) {
      explosions.get(i).draw(g);
    }

    // draw the heart bg animation
    if (player.getCholesterol() >= 85) {
      g.drawImage(
          ImagesLoader.getImage("heartattackbg"),
          GamePanel.WIDTH / 2 - ImagesLoader.getImage("heartattackbg").getWidth() / 2,
          GamePanel.HEIGHT / 2 - ImagesLoader.getImage("heartattackbg").getHeight() / 2,
          null);
      heartAttack.draw(g);
    }
    if (player.getCholesterol() <= 25) {
      warning.draw(g);
    }

    // end of heart bg animation
    // Text.drawString(g, "Testing Colesterage", 200, 400, "leishoFont", null);
    // Text.drawString(g, "Font testing", 600, 200, "leishoFont", txtAnimation);
    if (eventIntro) {
      if (titleIntroA != null) titleIntroA.draw(g);
      if (titleIntroB != null) titleIntroB.draw(g);
    }

    if (eventCaught) {
      if (titleCaught != null) titleCaught.draw(g);
    }

    if (eventClear) {
      if (titleClear != null) if (!showResults) titleClear.draw(g);
      if (showResults) {
        g.setColor(new Color(0, 0, 0, 226));
        g.fillRect(
            GamePanel.WIDTH / 2 - squarewidth / 2,
            GamePanel.HEIGHT / 2 - squareheight / 2,
            squarewidth,
            squareheight);
        if (ticksResults > 35) {
          g.setStroke(new BasicStroke(6));
          g.setColor(Color.white);
          g.drawRect(
              GamePanel.WIDTH / 2 - squarewidth / 2,
              GamePanel.HEIGHT / 2 - squareheight / 2,
              squarewidth,
              squareheight);
        }
        if (ticksResults > 40)
          Text.drawString(g, "Resultados", Text.CENTERED, 150, "leishoFont", null);
        if (ticksResults > 50)
          Text.drawString(
              g, "Puntos adquiridos: " + player.getScoreLevel(), 250, 250, "leishoFont", null);
        if (ticksResults > 55)
          Text.drawString(
              g, "Alimentos consumidos: " + player.getEatenDishes(), 250, 300, "leishoFont", null);
        if (ticksResults > 60)
          Text.drawString(
              g,
              "Ocasiones en Paro Cardiaco: " + hud.getTimesHeartAttack(),
              250,
              350,
              "leishoFont",
              null);
        if (ticksResults > 60)
          Text.drawString(
              g, "Ocasiones en Débil: " + hud.getTimesWeak(), 250, 400, "leishoFont", null);
        if (ticksResults > 65 && ticksResults < 80)
          Text.drawString(
              g, "Presiona Enter para continuar", Text.CENTERED, 500, "leishoFont", null);
      }
    }

    if (eventDead) {
      if (titleDead != null) titleDead.draw(g);
    }

    if (eventPoints) eventPoints();
  }
Ejemplo n.º 8
0
  @Override
  public void tick(Graphics2D g, Input p1, Input p2, Sound s) {

    // Menu
    if (gameState == 0) {
      // Song
      sound.loadSound("Resources/Sounds/Menu.wav");
      sound.runLoop();

      // background
      g.setColor(Color.BLACK);
      g.fillRect(0, 0, WIDTH, HEIGHT);

      // title
      g.setColor(Color.GREEN);
      g.setFont(new Font("Arial", Font.BOLD, 100));
      centerText("DARKLIGHT 2", g, WIDTH / 2, 180);

      // selection
      g.setColor(Color.RED);
      if (gameState == 0) {
        // Song
        sound.loadSound("Resources/Sounds/Menu.wav");
        sound.runLoop();

        // background
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, WIDTH, HEIGHT);

        // title
        g.setColor(Color.GREEN);
        g.setFont(new Font("Arial", Font.BOLD, 100));
        centerText("DARKLIGHT 2", g, WIDTH / 2, 180);

        // selection
        g.setColor(Color.RED);
        if (button == 0) {

          // PLAY
          g.fillRect(WIDTH / 2 - 160, 240, 320, 90);
          if (justPressed(p1, Button.U)) {
            button = 2;
          }
          if (justPressed(p1, Button.D)) {
            button = 1;
          }
          if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) {
            inv[0] = wep1;
            gameState = 1;
            sound.reset();
            sound.stop();
          }
        } else if (button == 1) {

          // LEADERBOARDS
          g.fillRect(WIDTH / 2 - 160, 340, 320, 90);
          if (justPressed(p1, Button.U)) {
            button = 0;
          }
          if (justPressed(p1, Button.D)) {
            button = 2;
          }
          if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) {
            gameState = 5;
          }
        } else {
          // EXIT
          g.fillRect(WIDTH / 2 - 160, 440, 320, 90);
          if (justPressed(p1, Button.U)) {
            button = 1;
          }
          if (justPressed(p1, Button.D)) {
            button = 0;
          }
          if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) {
            System.exit(0);
          }
        }

        // option boxes
        g.setColor(Color.GREEN);
        g.fillRect(WIDTH / 2 - 150, 250, 300, 70);
        g.fillRect(WIDTH / 2 - 150, 350, 300, 70);
        g.fillRect(WIDTH / 2 - 150, 450, 300, 70);
        // option box text
        g.setColor(Color.BLACK);
        g.setFont(new Font("Arial", Font.PLAIN, 30));
        centerText("PLAY", g, WIDTH / 2, 295);
        centerText("LEADERBOARD", g, WIDTH / 2, 395);
        centerText("EXIT", g, WIDTH / 2, 495);

        //			g.setColor(Color.YELLOW);
        //			g.fillRect(WIDTH/2 - 352, 20, 704, 192);
      }
    }
    // Game
    if (gameState == 1) {
      arena.draw(g);

      // Sound
      sound.loadSound("Resources/Sounds/ambient.wav");
      sound.runLoop();

      //			// offset borders
      //			g.setColor(Color.RED);
      //			g.drawRect(0, 0, arena.xOffsetBorder, HEIGHT);								// left
      //			g.drawRect(WIDTH - arena.xOffsetBorder, 0, arena.xOffsetBorder, HEIGHT);	// right
      //			g.drawRect(0, 0, WIDTH, arena.yOffsetBorder);								// top
      //			g.drawRect(0, HEIGHT - arena.yOffsetBorder, WIDTH, arena.yOffsetBorder);	// bottom

      if (wave.falling) {
        count = 0;
        gameState = 2;
      }

      // wave
      wave.newWave(g, arena, player);
      wave.maintain(g, arena, player, swordSpec);

      // If enemy spots, play battle sound
      for (Enemy enemy : wave.enemies.values()) {
        if (enemy.spottedPlayer) {

          // Check to play noise
          int temp = (int) (Math.random() * 150);
          if (temp <= 1) {
            // Check for Ghoul or Golem
            if (enemy.type <= 60) {
              // Play Ghoul sound
              monster.loadSound("Resources/Sounds/ghoul.wav");
              monster.run();
            }

            if (enemy.type > 85) {
              // Play golem sound
              monster.loadSound("Resources/Sounds/golem.wav");
              monster.run();
            }
          }

          battle.loadSound("Resources/Sounds/Game Song.wav");
          battle.runLoop();
          break;
        }
      }

      // Stop battle sound, new wave
      if (wave.waveStart && wave.wave != 0) {
        battle.stop();
        battle.reset();
      }

      // player
      player.draw(g);
      player.movement(p1, arena);
      player.weapon = weapon;
      basicAttack(g, p1);
      specialAttack(g, p1);
      weaponPickup(g, p1, arena);
      weaponSwap(p1);

      if (player.health <= 0) {
        gameState = 3;
        sound.stop();
        sound.reset();
        battle.stop();
        battle.reset();
      }

      if (justPressed(p1, Button.C)) {
        wave.enemies.clear();
      }

      g.setColor(Color.BLACK);
      g.fillRect(0, 0, (int) (player.x - 256), HEIGHT);
      g.fillRect((int) (player.x + 256), 0, (int) (WIDTH - player.x - 255), HEIGHT);
      g.fillRect(0, 0, WIDTH, (int) (player.y - 256));
      g.fillRect(0, (int) (player.y + 256), WIDTH, (int) (HEIGHT - player.y - 255));
      g.drawImage(TextureLoader.light, (int) (player.x - 256), (int) (player.y - 256), null);

      // HUD
      int floor = (wave.wave % 10 == 0) ? (wave.wave + 9) / 10 : (wave.wave + 10) / 10;
      int currentWave = (wave.wave % 10 == 0) ? 10 : wave.wave % 10;
      g.setColor(Color.WHITE);
      g.setFont(new Font("Arial", Font.BOLD, 20));
      g.drawString("Floor " + floor + " | Wave " + currentWave, 5, 20);
      g.setFont(new Font("Arial", Font.PLAIN, 10));
      g.drawString("Remaining enemies: " + wave.enemies.size(), 5, 30);

      g.setColor(Color.DARK_GRAY);
      g.fillRect(347, 531, 330, 10);
      g.fillRect(347, 541, 10, 20);
      g.fillRect(507, 541, 10, 20);
      g.fillRect(667, 541, 10, 20);
      g.fillRect(347, 561, 330, 15);
      g.setColor(Color.GREEN);
      if (player.health <= 100) {
        g.fillRect(357, 541, (int) (150 * (player.health / 100)), 20);
      } else {
        g.fillRect(357, 541, 150, 20);
        g.setColor(Color.ORANGE);
        g.fillRect(357, 541, (int) (150 * ((player.health - 100) / 100)), 20);
      }
      g.setColor(Color.BLUE);
      g.fillRect(
          517 + (int) (150 - (150 * (player.mana / 100))),
          541,
          (int) (150 * (player.mana / 100)),
          20);

      g.dispose();
    }

    // Floor switching
    if (gameState == 2) {
      g.setColor(new Color(0, 0, 0, 4 * count));
      g.fillRect(0, 0, WIDTH, HEIGHT);
      count++;
      if (count == 60) {
        arena = new Arena();
        player.x = WIDTH / 2;
        player.y = HEIGHT / 2;
        wave.falling = false;
        wave.hole = false;
        wave.transition.reset();
        wave.waveStart = true;
        wave.difficulty *= 1.1;
        gameState = 1;
      }
    }

    // Game Over
    if (gameState == 3) {

      // Sound
      sound.loadSound("Resources/Sounds/Death.wav");
      sound.runOnce();

      g.setColor(Color.RED);
      g.setFont(new Font("Arial", Font.BOLD, 150));
      centerText("GAME OVER", g, WIDTH / 2, HEIGHT / 2);
      wait++;
      yourScore = wave.score;
      waveNum = (wave.wave % 10 == 0) ? 10 : wave.wave % 10;
      if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) {

        sound.stop();
        sound.reset();
        gameState = 0;
        reset();
      }

      if (wait == 3000) {
        sound.stop();
        sound.reset();
        gameState = 0;
        reset();
      }
    }
    // Enter Your initials
    if (gameState == 4) {
      g.setColor(Color.BLACK);
      g.fillRect(0, 0, WIDTH, HEIGHT);
      g.setColor(Color.RED);
      g.setFont(new Font("Arial", Font.PLAIN, 45));
      centerText("Enter Your Initials", g, (Game.WIDTH / 2), (Game.HEIGHT / 4));
      centerText("Press C to enter", g, (Game.WIDTH / 2), (Game.HEIGHT / 2 + 100));
      g.drawString(abcs[i], (Game.WIDTH / 2) - 55, (Game.HEIGHT / 2));
      g.drawString(abcs[j], (Game.WIDTH / 2), (Game.HEIGHT / 2));
      g.drawString(abcs[k], (Game.WIDTH / 2) + 55, (Game.HEIGHT / 2));
      name = abcs[i] + abcs[j] + abcs[k];

      if (active1) g.fillRect((Game.WIDTH / 2) - 55, (Game.HEIGHT / 2) + 5, 35, 5);
      if (active2) g.fillRect((Game.WIDTH / 2) + 5, (Game.HEIGHT / 2) + 5, 35, 5);
      if (active3) g.fillRect((Game.WIDTH / 2) + 55, (Game.HEIGHT / 2) + 5, 35, 5);

      if (!pressedBefore) {
        if (p1.pressed(Button.U)
            || p1.pressed(Button.D)
            || p1.pressed(Button.L)
            || p1.pressed(Button.R)
            || p1.pressed(Button.A)
            || p1.pressed(Button.B)
            || p1.pressed(Button.C)) {
          pressedBefore = true;
        } else {
          pressedBefore = false;
        }
      } else {
        if (!p1.pressed(Button.U)
            && !p1.pressed(Button.D)
            && !p1.pressed(Button.L)
            && !p1.pressed(Button.R)
            && !p1.pressed(Button.A)
            && !p1.pressed(Button.B)
            && !p1.pressed(Button.C)) {
          pressedBefore = false;
        } else {
          return;
        }
      }
      if (p1.pressed(Button.C)) {
        storeScores.main();
        reset();
        gameState = 5;
      }
      if (active1) {

        if (p1.pressed(Button.U)) {
          i += 1;
          if (i > abcs.length - 1) i = 0;
        }
        if (p1.pressed(Button.D)) {
          i -= 1;
          if (i < 0) i = abcs.length - 1;
        }
        if (p1.pressed(Button.L)) {
          active1 = false;
          active3 = true;
        }
        if (p1.pressed(Button.R)) {
          active1 = false;
          active2 = true;
        }
        return;
      }
      if (active2) {

        if (p1.pressed(Button.U)) {
          j += 1;
          if (j > abcs.length - 1) j = 0;
        }
        if (p1.pressed(Button.D)) {
          j -= 1;
          if (j < 0) j = abcs.length - 1;
        }
        if (p1.pressed(Button.L)) {
          active2 = false;
          active1 = true;
        }
        if (p1.pressed(Button.R)) {
          active2 = false;
          active3 = true;
        }
        return;
      }
      if (active3) {

        if (p1.pressed(Button.U)) {
          k += 1;
          if (k > abcs.length - 1) k = 0;
        }
        if (p1.pressed(Button.D)) {
          k -= 1;
          if (k < 0) k = abcs.length - 1;
        }
        if (p1.pressed(Button.L)) {
          active3 = false;
          active2 = true;
        }
        if (p1.pressed(Button.R)) {
          active3 = false;
          active1 = true;
        }
        return;
      }
    }

    // high scores
    if (gameState == 5) {
      storeScores.Read();
      g.setColor(Color.BLACK);
      g.fillRect(0, 0, WIDTH, HEIGHT);
      g.setColor(Color.RED);
      g.setFont(new Font("Arial", Font.PLAIN, 35));
      centerText("High Scores", g, (Game.WIDTH / 2), (Game.HEIGHT / 16));
      g.drawLine(0, Game.HEIGHT / 16 + 8, 1200, Game.HEIGHT / 16 + 8);
      g.drawString("Enemies killed", Game.WIDTH / 2 + 150, Game.HEIGHT / 16 + 60);
      g.drawString("Wave", Game.WIDTH / 2, Game.HEIGHT / 16 + 60);
      g.drawString("Floor", Game.WIDTH / 2 - 210, Game.HEIGHT / 16 + 60);
      int height = -80;
      for (int l = 0; l < 10; l++) {
        g.drawString(storeScores.nameList.get(l), Game.WIDTH / 2 - 400, Game.HEIGHT / 8 - height);
        height = height - 40;
      }
      // g.drawString(storeScores, Game.WIDTH / 2, Game.HEIGHT / 2);
      wait++;
      if (wait == 1005) {
        sound.stop();
        sound.reset();
        wait = 0;
        yourScore = 0;
        waveNum = 0;
        i = 0;
        j = 0;
        k = 0;
        floorNum = 0;
        gameState = 0;
      }
    }

    updateKeyState(p1);
  }
Ejemplo n.º 9
0
 private void renderPlayer(Matrix4 mviewmx) {
   sb.setTransformMatrix(mviewmx);
   sb.begin();
   player.draw(sb);
   sb.end();
 }