Advertisement
raiyanshadow

AlienShot.class

Apr 7th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. package br.ol.spaceinvaders.obj;
  2.  
  3. import br.ol.spaceinvaders.SpaceInvadersGame;
  4. import br.ol.spaceinvaders.SpaceInvadersObj;
  5. import br.ol.spaceinvaders.SpaceInvadersGame.State;
  6. import br.ol.spaceinvaders.core.BitmapFontRenderer11;
  7. import br.ol.spaceinvaders.obj.Shield;
  8. import br.ol.spaceinvaders.obj.Ship;
  9. import java.awt.geom.Rectangle2D.Double;
  10.  
  11. public class AlienShot extends SpaceInvadersObj {
  12.  
  13.    public boolean hit;
  14.    public long hitTime;
  15.  
  16.  
  17.    public AlienShot(SpaceInvadersGame game) {
  18.       super(game);
  19.    }
  20.  
  21.    public void init() {
  22.       this.x = 0.0D;
  23.       this.y = 0.0D;
  24.       this.collider = new Double(this.x, this.y, 6.0D, 10.0D);
  25.       this.loadFrames(new String[]{"alien_shot_0.png", "alien_shot_1.png", "alien_shot_destroyed.png"});
  26.    }
  27.  
  28.    public void updatePlaying() {
  29.       if(this.visible) {
  30.          if(this.hit) {
  31.             this.frame = this.frames[2];
  32.             if(System.currentTimeMillis() - this.hitTime > 100L) {
  33.                this.visible = false;
  34.             }
  35.  
  36.          } else {
  37.             this.frame = this.frames[(int)((double)System.nanoTime() * 1.0E-7D) % 2];
  38.             this.y += 3.0D;
  39.             Shield shield = (Shield)((SpaceInvadersGame)this.game).checkCollision(this, Shield.class);
  40.             if(shield != null && !shield.hit) {
  41.                shield.hit();
  42.                this.visible = false;
  43.             } else {
  44.                Ship ship = (Ship)((SpaceInvadersGame)this.game).checkCollision(this, Ship.class);
  45.                if(ship != null && !ship.hit) {
  46.                   this.visible = false;
  47.                   ((SpaceInvadersGame)this.game).setState(State.HIT);
  48.                } else {
  49.                   if(this.y > 300.0D) {
  50.                      this.hit();
  51.                   }
  52.  
  53.                }
  54.             }
  55.          }
  56.       }
  57.    }
  58.  
  59.    public Boolean canShoot() {
  60.       return Boolean.valueOf(!this.visible);
  61.    }
  62.  
  63.    public void shoot(java.lang.Double x, java.lang.Double y) {
  64.       this.x = x.doubleValue();
  65.       this.y = y.doubleValue();
  66.       this.visible = true;
  67.       this.hit = false;
  68.    }
  69.  
  70.    public void stateChanged() {
  71.       if(((SpaceInvadersGame)this.game).state != State.PLAYING) {
  72.          this.visible = false;
  73.       }
  74.  
  75.    }
  76.  
  77.    public void hit() {
  78.       this.hit = true;
  79.       this.hitTime = System.currentTimeMillis();
  80.    }
  81.  
  82.    static {
  83.       BitmapFontRenderer11.a();
  84.    }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement