public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; c.getAlpha(); g.setFont(font2); g.setColor(c); g.drawImage(fon, 0, 0, 1024, 700, null); if (type_bullet1 == true) g.drawImage(pointer, 30, 550, 49, 47, null); image_bullet = new Sphere(); g.drawImage(image_bullet.getImage(), 40, 600, 24, 24, null); g.drawString(Integer.toString(count_sphere), 35, 650); if (type_bullet2 == true) g.drawImage(pointer, 85, 550, 49, 47, null); image_bullet = new FireBall(); g.drawImage(image_bullet.getImage(), 95, 600, 24, 24, null); g.drawString(Integer.toString(count_fireball), 95, 650); if (type_bullet3 == true) g.drawImage(pointer, 140, 550, 49, 47, null); image_bullet = new Rocket(); g.drawImage(image_bullet.getImage(), 145, 595, 40, 40, null); g.drawString(Integer.toString(count_rocket), 150, 650); distance = 10; // Draw life for (int i = 0; i < player_live; i++) { g.drawImage(live, distance, 10, 11, 57, null); distance += 20; } // Create bullet for (int i = 0; i < bullet.size(); i++) { if (type_bullet1 == true && count_sphere > 0) { g2d.drawImage( bullet.get(i).getImage(), (int) bullet.get(i).bullet_x, (int) bullet.get(i).bullet_y, this); } if (type_bullet2 == true && count_fireball > 0) { g2d.drawImage( bullet.get(i).getImage(), (int) bullet.get(i).bullet_x, (int) bullet.get(i).bullet_y, this); } if (type_bullet3 == true && count_rocket != 0) { bullet.get(i).set_rotate(angle); g2d.setTransform(bullet.get(i).rotateX()); g2d.drawImage( bullet.get(i).getImage(), (int) bullet.get(i).bullet_x, (int) bullet.get(i).bullet_y, this); } } g2d.setTransform(player.rotateX(angle)); g2d.drawImage(player.getImage(), (int) player.getX(), (int) player.getY(), this); for (int i = 0; i < v_explosion.size(); i++) { g.drawImage(explosion, (int) v_explosion.get(i).x, (int) v_explosion.get(i).y, 59, 57, null); } for (int i = 0; i < enemy.size(); i++) { double povorot3 = Math.atan2(player.getY() - enemy.get(i).getY(), player.getX() - enemy.get(i).getX()) * 180 / 3.14; g2d.setTransform(enemy.get(i).rotateX(povorot3)); // new g2d.drawImage( enemy.get(i).getImage(), (int) enemy.get(i).getX(), (int) enemy.get(i).getY(), this); g2d.setTransform(enemy.get(i).rotateX(0)); // new g.drawString( Integer.toString(enemy.get(i).get_live()), (int) enemy.get(i).getX() + (int) enemy.get(i).get_spr_w() / 2, (int) enemy.get(i).getY()); } g.setFont(font); g2d.setTransform(affine); g.drawString("Level: " + Integer.toString(level), 710, 50); g.drawString("Next level: " + Integer.toString(time_level), 710, 90); }
// private void initLevel(int level){//initializes levels according to the level parameter // // } public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; // Windmill drawing g2d.rotate(wind.getDirection() * Math.PI / 180, 636, 64); g2d.drawImage(wind.getImage(), 572, 0, this); g2d.rotate(-wind.getDirection() * Math.PI / 180, 636, 64); // Boat drawing if (boat.isVisible()) { g2d.rotate( TIGHT_TURN_FACTOR * boat.getDirection() * Math.PI / 180, boat.getX() + 16, boat.getY() + 16); // g2d.drawImage(boat.getImage(), boat.getX(), boat.getY(), this); g2d.drawImage(boat.getImage(), boat.getX(), boat.getY(), this); // TEST-sınırları görmek için // Rectangle r1 = boat.getBounds(); // g2d.drawRect(r1.x, r1.y, r1.width, r1.height); g2d.rotate( -TIGHT_TURN_FACTOR * boat.getDirection() * Math.PI / 180, boat.getX() + 16, boat.getY() + 16); if ((buoys.size() == 0) && (currentLevel <= LAST_LEVEL)) { // level atlama ve başarılı bir şekilde oyunu bitirme burada olacak System.out.println("All buoys finished, well done!"); int tp = computeTotalScore(); System.out.println("Total Score: " + tp); nextLevelFlag = true; // Actionlistenera tek seferlik girebilmek için bir flag // System.exit(0); } } else { // If boat is dead then check for remaining lives if (boat.getNumOfLives() > 0) { boat.decrementNumOfLives(); boat.setPosition(0, 20); boat.setDirection(0); boat.setVisible(true); } else { // No remaining lives case // g2d.drawString("Game Over!", 80, 15); System.out.println("Game Over"); int tp = computeTotalScore(); System.out.println("Total Score: " + tp); currentLevel = 1; CardLayout c2 = (CardLayout) (mgf.getCanvas().getLayout()); c2.show(mgf.getCanvas(), "GUI"); // System.exit(0); } } // Island drawing for (int i = 0; i < islands.size(); i++) { Island is = (Island) islands.get(i); g2d.drawImage(is.getImage(), is.getX(), is.getY(), this); } // Bullet drawing ArrayList<Bullet> bs = boat.getBulletsList(); for (int i = 0; i < bs.size(); i++) { Bullet b = (Bullet) bs.get(i); g2d.drawImage(b.getImage(), b.getX(), b.getY(), this); } // Buoy drawing for (int i = 0; i < buoys.size(); i++) { Buoy b = (Buoy) buoys.get(i); if (b.isVisible()) { g2d.drawImage(b.getImage(), b.getX(), b.getY(), this); } } // Bonus drawing for (int i = 0; i < bonuses.size(); i++) { Bonus b = (Bonus) bonuses.get(i); if (b.isVisible()) { g2d.drawImage(b.getImage(), b.getX(), b.getY(), this); } else { if (b.getBonusType().equalsIgnoreCase("lifebonus")) { boat.incrementNumOfLives(); } if (b.getBonusType().equalsIgnoreCase("speedbonus")) { boat.setFlashForward(true); } if (b.getBonusType().equalsIgnoreCase("bulletbonus")) { boat.addBonusBullets(); } } } // Information g2d.drawString("Buoys left: " + buoys.size(), 5, 15); if (boat.getNumOfLives() == 0) g2d.drawString("Last Chance!", 80, 15); else g2d.drawString("Lives: " + boat.getNumOfLives(), 90, 15); // g2d.drawString("-" + (int)System.currentTimeMillis()/1000, 5, 25); g2d.drawString("Score: " + gamePoint, 160, 15); g2d.drawString("Bullets: " + boat.getRemainingNumOfBullets(), 235, 15); g2d.drawString("Level: " + currentLevel, 320, 15); // Generates new random wind wind.generateWindDirection(); // Default system methods Toolkit.getDefaultToolkit().sync(); // ? g.dispose(); // ? }