Package com.palepail.TestGame.Enemies

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

package com.palepail.TestGame.Enemies;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.palepail.TestGame.Actions.Action;
import com.palepail.TestGame.Actions.MoveTo;
import com.palepail.TestGame.Actions.SplineMove;
import com.palepail.TestGame.Actions.ToggleShooting;
import com.palepail.TestGame.Model.Ship;
import com.palepail.TestGame.Utilities.Configuration;
import com.palepail.TestGame.View.World;

public class LargeEnemy extends Enemy {

  float ROTATION_SPEED = 0;
  private final float SHOOTER_TOPSPEED = 3;
  float ACCELERATION = 30f;
  Array<Action> script;
  float fireRate;

  public LargeEnemy(float SPEED, float rotation, float width, float height, Vector2 position, int cooldown,
      float fireRate, String variation) {
    super(SPEED, rotation, width, height, position);
    this.acceleration = ACCELERATION;
    this.cooldown = cooldown;
    this.fireRate = fireRate;
    this.ticks = 0;
    this.attackCounter = 0;
    this.cooldownCounter = 0;
    this.variation = variation;
    setShooting(false);
    setActive(true);
    prevCounter = 0;
    script = new Array<Action>();
    grazed = false;
    bombed = false;
    topSpeed = SHOOTER_TOPSPEED;
    renderScaleX = (float) 2*Configuration.gameScale/20;
    renderScaleY = (float) 2*Configuration.gameScale/20;
    dropCount =10;

  }

  @Override
  public void update(Ship ship, World world) {
    super.update(ship, world);
    position.add(velocity.tmp().mul(Gdx.graphics.getDeltaTime() * SPEED));

    if (cooldownCounter >= cooldown) {
      cooldownCounter = 0;
      action();
    }

    if (isShooting()) {
      if (attackCounter >= fireRate) {
        if (clip > 0 || clip == -1) {
          fire(world, ship);
          if (clip != -1) {
            clip--;
          }
          if (clip == 0) {
            setShooting(false);
          }
        }

        attackCounter = 0;

      }
    }

    scriptIterator = script.iterator();
    if (scriptIterator.hasNext()) {
      action = scriptIterator.next();
      if (action.isDone()) {
        scriptIterator.remove();
      } else {
        action.update(ticks);
      }
    } else {
      setActive(false);
    }

    if (ticks > 90000) {
      ticks = 0;
    }

    if (rotation > 360) {
      rotation -= 360;
    }

  }

  protected void action() {
  }

  protected void fire(World world, Ship ship) {
  }

  public void stop() {
    setMOVE_UP(false);
    setMOVE_DOWN(false);
    setMOVE_LEFT(false);
    setMOVE_RIGHT(false);
    velocity.y = 0;
    velocity.x = 0;
  }

  public void setTopLeftToBottomScript() {

    script.add(new MoveTo(this, new Vector2(1 * Configuration.gameScale, 22 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(3 * Configuration.gameScale, 21 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(4 * Configuration.gameScale, 20 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(6 * Configuration.gameScale, 19 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(8 * Configuration.gameScale, 17 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 15 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(11 * Configuration.gameScale, 14 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(12 * Configuration.gameScale, 13 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(13 * Configuration.gameScale, 10 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(14 * Configuration.gameScale, 6 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(15 * Configuration.gameScale, 3 * Configuration.gameScale)));
    script.add(new ToggleShooting(this, false));
    script.add(new MoveTo(this, new Vector2(16 * Configuration.gameScale, -3 * Configuration.gameScale)));

  }

  public void setTopRightToBottomScript() {

    script.add(new MoveTo(this, new Vector2(19 * Configuration.gameScale, 22 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(17 * Configuration.gameScale, 21 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(16 * Configuration.gameScale, 20 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(14 * Configuration.gameScale, 19 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(12 * Configuration.gameScale, 17 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 15 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(9 * Configuration.gameScale, 14 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(8 * Configuration.gameScale, 13 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(6 * Configuration.gameScale, 10 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(5 * Configuration.gameScale, 6 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(4 * Configuration.gameScale, 3 * Configuration.gameScale)));
    script.add(new ToggleShooting(this, false));
    script.add(new MoveTo(this, new Vector2(3 * Configuration.gameScale, -3 * Configuration.gameScale)));

  }

  public void setSplineLoopLeftScript() {

    Array<Vector2> path = new Array<Vector2>();
    path.add(new Vector2(0 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(1 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(5 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(9 * Configuration.gameScale, 17 * Configuration.gameScale));
    path.add(new Vector2(7 * Configuration.gameScale, 21 * Configuration.gameScale));
    path.add(new Vector2(2 * Configuration.gameScale, 20 * Configuration.gameScale));
    path.add(new Vector2(1 * Configuration.gameScale, 17 * Configuration.gameScale));
    path.add(new Vector2(2 * Configuration.gameScale, 14 * Configuration.gameScale));
    path.add(new Vector2(5 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(10 * Configuration.gameScale, 15 * Configuration.gameScale));
    path.add(new Vector2(13 * Configuration.gameScale, 23 * Configuration.gameScale));
    path.add(new Vector2(14 * Configuration.gameScale, 24 * Configuration.gameScale));

    script.add(new SplineMove(this, path));

  }

  public void setSplineLoopRightScript() {

    Array<Vector2> path = new Array<Vector2>();
    path.add(new Vector2(20 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(19 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(15 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(11 * Configuration.gameScale, 17 * Configuration.gameScale));
    path.add(new Vector2(13 * Configuration.gameScale, 21 * Configuration.gameScale));
    path.add(new Vector2(18 * Configuration.gameScale, 20 * Configuration.gameScale));
    path.add(new Vector2(19 * Configuration.gameScale, 17 * Configuration.gameScale));
    path.add(new Vector2(18 * Configuration.gameScale, 14 * Configuration.gameScale));
    path.add(new Vector2(15 * Configuration.gameScale, 12 * Configuration.gameScale));
    path.add(new Vector2(10 * Configuration.gameScale, 15 * Configuration.gameScale));
    path.add(new Vector2(7 * Configuration.gameScale, 23 * Configuration.gameScale));
    path.add(new Vector2(6 * Configuration.gameScale, 24 * Configuration.gameScale));

    script.add(new SplineMove(this, path));

  }

  public void setDownCrossLeftScript() {

    script.add(new MoveTo(this, new Vector2(5, 19)));
    script.add(new ToggleShooting(this, true, 3));
    script.add(new MoveTo(this, new Vector2(8, 17)));
    script.add(new MoveTo(this, new Vector2(10, 15)));
    script.add(new MoveTo(this, new Vector2(11, 14)));
    script.add(new MoveTo(this, new Vector2(12, 13)));
    script.add(new MoveTo(this, new Vector2(13, 10)));
    script.add(new MoveTo(this, new Vector2(14, 6)));
    script.add(new MoveTo(this, new Vector2(15, 3)));
    script.add(new MoveTo(this, new Vector2(16, -3)));

  }

  public void setDownCrossRightScript() {

    script.add(new MoveTo(this, new Vector2(14, 19)));
    script.add(new ToggleShooting(this, true, 3));
    script.add(new MoveTo(this, new Vector2(12, 17)));
    script.add(new MoveTo(this, new Vector2(10, 15)));
    script.add(new MoveTo(this, new Vector2(9, 14)));
    script.add(new MoveTo(this, new Vector2(8, 13)));
    script.add(new MoveTo(this, new Vector2(6, 10)));
    script.add(new MoveTo(this, new Vector2(5, 6)));
    script.add(new MoveTo(this, new Vector2(4, 3)));
    script.add(new MoveTo(this, new Vector2(3, -3)));

  }

  public void setRightDownUpScript() {

    script.add(new MoveTo(this, new Vector2(14 * Configuration.gameScale, 19 * Configuration.gameScale)));
    script.add(new ToggleShooting(this, true, 3));
    script.add(new MoveTo(this, new Vector2(12 * Configuration.gameScale, 17 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 15 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 19 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 23 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 25 * Configuration.gameScale)));

  }

  public void setLeftDownUpScript() {

    script.add(new MoveTo(this, new Vector2(5 * Configuration.gameScale, 19 * Configuration.gameScale)));
    script.add(new ToggleShooting(this, true, 3));
    script.add(new MoveTo(this, new Vector2(8 * Configuration.gameScale, 17 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 15 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 19 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 23 * Configuration.gameScale)));
    script.add(new MoveTo(this, new Vector2(10 * Configuration.gameScale, 25 * Configuration.gameScale)));

  }

}
 
TOP

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

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.