Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.ol.spaceinvaders.obj;
- import br.ol.spaceinvaders.SpaceInvadersGame;
- import br.ol.spaceinvaders.SpaceInvadersObj;
- import br.ol.spaceinvaders.SpaceInvadersGame.State;
- import br.ol.spaceinvaders.core.BitmapFontRenderer11;
- import br.ol.spaceinvaders.obj.Shield;
- import br.ol.spaceinvaders.obj.Ship;
- import java.awt.geom.Rectangle2D.Double;
- public class AlienShot extends SpaceInvadersObj {
- public boolean hit;
- public long hitTime;
- public AlienShot(SpaceInvadersGame game) {
- super(game);
- }
- public void init() {
- this.x = 0.0D;
- this.y = 0.0D;
- this.collider = new Double(this.x, this.y, 6.0D, 10.0D);
- this.loadFrames(new String[]{"alien_shot_0.png", "alien_shot_1.png", "alien_shot_destroyed.png"});
- }
- public void updatePlaying() {
- if(this.visible) {
- if(this.hit) {
- this.frame = this.frames[2];
- if(System.currentTimeMillis() - this.hitTime > 100L) {
- this.visible = false;
- }
- } else {
- this.frame = this.frames[(int)((double)System.nanoTime() * 1.0E-7D) % 2];
- this.y += 3.0D;
- Shield shield = (Shield)((SpaceInvadersGame)this.game).checkCollision(this, Shield.class);
- if(shield != null && !shield.hit) {
- shield.hit();
- this.visible = false;
- } else {
- Ship ship = (Ship)((SpaceInvadersGame)this.game).checkCollision(this, Ship.class);
- if(ship != null && !ship.hit) {
- this.visible = false;
- ((SpaceInvadersGame)this.game).setState(State.HIT);
- } else {
- if(this.y > 300.0D) {
- this.hit();
- }
- }
- }
- }
- }
- }
- public Boolean canShoot() {
- return Boolean.valueOf(!this.visible);
- }
- public void shoot(java.lang.Double x, java.lang.Double y) {
- this.x = x.doubleValue();
- this.y = y.doubleValue();
- this.visible = true;
- this.hit = false;
- }
- public void stateChanged() {
- if(((SpaceInvadersGame)this.game).state != State.PLAYING) {
- this.visible = false;
- }
- }
- public void hit() {
- this.hit = true;
- this.hitTime = System.currentTimeMillis();
- }
- static {
- BitmapFontRenderer11.a();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement