Package ast.entity

Source Code of ast.entity.Bullet

package ast.entity;


import org.lwjgl.util.vector.Vector3f;

import ast.effect.Laser;
import ast.effect.Light;
import ast.level.Level;

public class Bullet extends Entity {
 
  float speed = 0.01f
  Light light = new Light();
 
  private Laser laser;
 
  public Bullet(Level level) {
    super(level);
    light.init(this);
  }
 
  /**
   * Initialize
   * @param pos Vector3f position
   * @param direction float direction(deg)
   */
  public void init(Vector3f pos, float direction){
    this.pos = pos; 
   
    laser = new Laser(pos);
    laser.setSpeed(speed, direction);
   
  }
 
  public void update(int delta){
   
    if(!inBounds()){   
      hit()
    }
   
    laser.update(delta);
   
    pos = laser.pos;
    light.update()
   
    checkCollisions();
  }
 
  public void render(){
    laser.render();
  }
 
  /**
   * check for collisions with all entities in level
   */
  public void checkCollisions(){
    for( Entity entity : level.asteroids){
      if(laser.collidesWith(entity)){       
        entity.hit();
        this.hit();
      }
    }
  }
 
  public void hit(){
    level.removeEntity(this);
  }
 

}

TOP

Related Classes of ast.entity.Bullet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.