Guest User

Untitled

a guest
Apr 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. package edu.cs151.trigger.util;
  2.  
  3. import edu.cs151.trigger.entities.enemies.Enemy;
  4.  
  5. public class Path {
  6.     //Hiding constructor
  7.     private Path(){};
  8.     static boolean leftOrRight = false;
  9.  
  10.     public static enum PathType{
  11.         SINE_WAVE, STRAIGHT_DOWN, IN_AND_OUT, FAST_STRAIGHT_DOWN, WIDE_SINE_WAVE, BOSS1
  12.     }
  13.  
  14.     /**
  15.      * Grabs the next Y position for an Enemy depending on varying factors.
  16.      * @param currentX Current X position of the Enemy
  17.      * @param currentY Current Y position of the Enemy
  18.      * @param pathType The type of path this entity should use.
  19.      * @param xOffset The X offset of this Enemy starting position relative to the (0,0) point
  20.      * @param yOffset The Y offset of this Enemy starting position relative to the (0,0) point
  21.      * @param spawnTime How long this Enemy has be alive for.
  22.      * @param enemy The Enemy which the Path class is updating for.
  23.      * @return The new Y position
  24.      */
  25.     public static double getNextY(double currentX, double currentY, PathType pathType, int xOffset, int yOffset, int spawnTime, Enemy enemy){
  26.         switch(pathType){
  27.         case SINE_WAVE:
  28.             if(currentY>800){
  29.                 enemy.setTermination();
  30.             }
  31.             return currentY + 2;
  32.         case STRAIGHT_DOWN:
  33.             if(currentY>800){
  34.                 enemy.setTermination();
  35.             }
  36.             return currentY + 3;
  37.         case IN_AND_OUT:
  38.             if(spawnTime > 600)
  39.             {
  40.                 enemy.setTermination();
  41.             }
  42.             if(spawnTime > 200){
  43.                 return currentY - 2;
  44.             }
  45.             return currentY + 2;   
  46.         case FAST_STRAIGHT_DOWN:
  47.             if(currentY>800){
  48.                 enemy.setTermination();
  49.             }
  50.             return currentY + 7;
  51.         case WIDE_SINE_WAVE:
  52.             if(currentY>800){
  53.                 enemy.setTermination();
  54.             }
  55.             return currentY + 1.5;
  56.         case BOSS1:
  57.             if(spawnTime < 140)
  58.             {
  59.                 return currentY = currentY + 1;
  60.             }
  61.             return currentY;
  62.  
  63.  
  64.         default:
  65.             return 0;
  66.  
  67.  
  68.  
  69.         }
  70.     }
  71.  
  72.     /**
  73.      * Grabs the next X position for an Enemy depending on varying factors.
  74.      * @param currentX Current X position of the Enemy
  75.      * @param currentY Current Y position of the Enemy
  76.      * @param pathType The type of path this entity should use.
  77.      * @param xOffset The X offset of this Enemy starting position relative to the (0,0) point
  78.      * @param yOffset The Y offset of this Enemy starting position relative to the (0,0) point
  79.      * @param spawnTime How long this Enemy has be alive for.
  80.      * @param enemy The Enemy which the Path class is updating for.
  81.      * @return The new X position
  82.      */
  83.     public static double getNextX(double currentX, double currentY, PathType pathType, int xOffset, int yOffset, int spawnTime, Enemy enemy){
  84.         switch(pathType){
  85.         case SINE_WAVE:
  86.             /*
  87.              * The function here is f(fequency*(y-yOffset))+xOffset, where f(y) = 45*sin(y)
  88.              * The smaller the fequency the longer the wave will be stretched out
  89.              * So with any path that uses a function, define it in terms of y so that x = f(y-yOffset) + xOffset.
  90.              * It is important to make your function pass the (0,0) point and be continuous.
  91.              */
  92.             return (int)(45*Math.sin(.02*(currentY-yOffset)))+xOffset;
  93.         case STRAIGHT_DOWN:
  94.             return currentX;
  95.         case IN_AND_OUT:
  96.             if(spawnTime > 50 && spawnTime < 200){
  97.                 if(currentX >= 300) //Have the enemy move to the left
  98.                 {
  99.                     return currentX - 1;
  100.                 }
  101.                 else //Have the enemy move to the right
  102.                 {
  103.                     return currentX + 1;
  104.                 }
  105.             }
  106.             return currentX;
  107.         case FAST_STRAIGHT_DOWN:
  108.             return currentX;
  109.         case WIDE_SINE_WAVE:
  110.             return (int)(400*Math.sin(.0125*(currentY-yOffset)))+xOffset;
  111.         case BOSS1:
  112.             if(spawnTime < 140)
  113.             {
  114.                 return currentX;
  115.             }
  116.             if(currentX == -20)
  117.             {
  118.                 leftOrRight = true;
  119.             }
  120.             else if(currentX == 220)
  121.             {
  122.                 leftOrRight = false;
  123.             }
  124.             if(leftOrRight == true)
  125.             {
  126.                 return currentX+1;
  127.             }
  128.             else
  129.             {
  130.                 return currentX-1;
  131.             }
  132.            
  133.         default:
  134.             return 0;
  135.         }
  136.     }
  137. }
Add Comment
Please, Sign In to add comment