Advertisement
Guest User

Motstander

a guest
Apr 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. public class Motstander extends Model{
  4.     public int width = 50;
  5.     public int heigth = 50;
  6.     public Rectangle motstander = new Rectangle();
  7.     public boolean alive = true;
  8.     int posx = 500;
  9.     int posy = 450;
  10.     public boolean left = true;
  11.     public boolean right;
  12.     int monstermaxHP = 15;
  13.     int monsterHP = monstermaxHP;
  14.  
  15.  
  16.     public void kjor(Graphics2D g){
  17.         bevegelse();
  18.         tegne(g);
  19.         if (playerRect.intersects(motstander)){
  20.             monsterHP -= 5;
  21.             System.out.println("truffet");
  22.         }
  23.         //truffet(playerRect, motstander);
  24.     }
  25.  
  26.     public void truffet(Rectangle en, Rectangle to){
  27.  
  28.     }
  29.  
  30.     public void bevegelse() {
  31.  
  32.         if (left)
  33.             posx -= 2;
  34.  
  35.         if (right)
  36.             posx += 2;
  37.  
  38.         if (posx < 50) {
  39.             right = true;
  40.             left = false;
  41.         }
  42.         if (posx > 500) {
  43.             right = false;
  44.             left = true;
  45.         }
  46.     }
  47.  
  48.     public void tegne(Graphics2D g) {
  49.         if (alive) {
  50.             double dmaxHP = monstermaxHP, dHP = monsterHP, prosentHP = (dHP/dmaxHP)*100;
  51.             int HPBar = (int)prosentHP;
  52.             //int HPbar = (HP/maxHP)*100;
  53.             //System.out.println(HPBar);
  54.             g.setColor(Color.GREEN);
  55.             g.fillRect(posx, posy, width, heigth);
  56.             g.setColor(Color.RED);
  57.             g.fillRect(posx + 3, posy - 16, ((width - 6)*HPBar)/100, 8);
  58.             g.setColor(Color.BLACK);
  59.             g.drawRect(posx + 3, posy - 16, width - 6, 8);
  60.             motstander.setBounds(posx, posy, width, heigth);
  61.             if (monsterHP <= 0){
  62.                 alive = false;
  63.             }
  64.         }
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement