Package com.palepail.TestGame.Enemies

Source Code of com.palepail.TestGame.Enemies.FollowerSplit

package com.palepail.TestGame.Enemies;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.palepail.TestGame.Model.Ship;
import com.palepail.TestGame.Model.Items.Item;
import com.palepail.TestGame.Utilities.Configuration;
import com.palepail.TestGame.View.World;

public class FollowerSplit extends Follower {
  int timesToSplit;
  boolean root;
  boolean fired = false;
  int maxHealth;
  public static final int BASE_HEALTH=100;

  public FollowerSplit(float SPEED, float rotation, float width, float height, Vector2 position, float cooldown,
      float fireRate, String variation, int timesToSplit, boolean root, int maxHealth) {
    super(SPEED, rotation, width, height, position, cooldown, fireRate, variation);
    this.root=root;
    this.timesToSplit = timesToSplit;
    this.health = maxHealth;
    this.maxHealth = maxHealth;
    spriteName = "FollowerGreen";
    dropCount =5;
 

  }

  @Override
  public void update(Ship ship,World world){
  super.update(ship, world);
 
  if(!root)
  {
    if (time < .5f) {
      position.add(velocity.tmp().mul(Gdx.graphics.getDeltaTime() * SPEED));
      velocity.y-=.0001;
    } else if (time<1.3f){
      setVelocity(0, 0);
      ROTATION_SPEED+=.5;
    }else if (time>1f){
      if(!fired){
        setSPEED(30*Configuration.gameScale);
        setVelocity(new Vector2(ship
            .getPosition().tmp().sub(getPosition()).nor()));
        fired=true;
      }
     
      position.add(velocity.tmp().mul(Gdx.graphics.getDeltaTime() * SPEED));
     
    }
  } else{
    position.lerp(ship.getPosition(), .0001f);
  }
 

}
 
  @Override
  protected void die(World world) {
    this.setActive(false);
    if (timesToSplit < 1) {
      int dropNum = this.getNumberOfDrops();
      for (int x = 0; x < dropNum; x++) {
        Item item = this.getDrop();
        if (item != null) {
          world.putItem(item);
        }
      }
    } else {
     
      spawnSplit(world);
     
    }

   
  }

  private void spawnSplit(World world) {
   
   
    FollowerSplit follower = new FollowerSplit(10f * Configuration.gameScale, 0, width / 2, height / 2,
        new Vector2(getPosition().x+width/2, getPosition().y+height/2), this.cooldown, this.fireRate, VARIATION_GREEN, timesToSplit - 1, false, maxHealth/2);
    follower.setVelocity(-.3f,1f);
    world.getEnemies().add(follower);
   
   
    follower = new FollowerSplit(10f * Configuration.gameScale, 0, width / 2, height / 2,
        new Vector2(getPosition().x+width/2, getPosition().y+height/2), this.cooldown, this.fireRate, VARIATION_GREEN, timesToSplit - 1, false, maxHealth/2);
    follower.setVelocity(.3f,1f);
    world.getEnemies().add(follower);
   
   
   
   
  }

}
TOP

Related Classes of com.palepail.TestGame.Enemies.FollowerSplit

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.