Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- public class Motstander extends Model{
- public int width = 50;
- public int heigth = 50;
- public Rectangle motstander = new Rectangle();
- public boolean alive = true;
- int posx = 500;
- int posy = 450;
- public boolean left = true;
- public boolean right;
- int monstermaxHP = 15;
- int monsterHP = monstermaxHP;
- public void kjor(Graphics2D g){
- bevegelse();
- tegne(g);
- if (playerRect.intersects(motstander)){
- monsterHP -= 5;
- System.out.println("truffet");
- }
- //truffet(playerRect, motstander);
- }
- public void truffet(Rectangle en, Rectangle to){
- }
- public void bevegelse() {
- if (left)
- posx -= 2;
- if (right)
- posx += 2;
- if (posx < 50) {
- right = true;
- left = false;
- }
- if (posx > 500) {
- right = false;
- left = true;
- }
- }
- public void tegne(Graphics2D g) {
- if (alive) {
- double dmaxHP = monstermaxHP, dHP = monsterHP, prosentHP = (dHP/dmaxHP)*100;
- int HPBar = (int)prosentHP;
- //int HPbar = (HP/maxHP)*100;
- //System.out.println(HPBar);
- g.setColor(Color.GREEN);
- g.fillRect(posx, posy, width, heigth);
- g.setColor(Color.RED);
- g.fillRect(posx + 3, posy - 16, ((width - 6)*HPBar)/100, 8);
- g.setColor(Color.BLACK);
- g.drawRect(posx + 3, posy - 16, width - 6, 8);
- motstander.setBounds(posx, posy, width, heigth);
- if (monsterHP <= 0){
- alive = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement