LightningOrb.java
001 /*
002  *
003  * Created: Jun  7 2006
004  *
005  * Copyright (C) 1999-2000 Fabien Sanglard
006  
007  * This program is free software; you can redistribute it and/or
008  * modify it under the terms of the GNU General Public License
009  * as published by the Free Software Foundation; either version 2
010  * of the License, or (at your option) any later version.
011  
012  * This program is distributed in the hope that it will be useful,
013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015  * GNU General Public License for more details.
016  
017  * You should have received a copy of the GNU General Public License
018  * along with this program; if not, write to the Free Software
019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020  */
021 
022 package rtype.entity;
023 
024 import java.util.ArrayList;
025 
026 import org.lwjgl.opengl.GL11;
027 import org.lwjgl.util.vector.Vector2f;
028 
029 import rtype.Collision;
030 import rtype.Prototyp;
031 
032 public class LightningOrb extends Orb
033 {
034   protected static float DEFAULT_DISTANCE_FROM_SHIP_WHEN_FIRING = DEFAULT_DISTANCE_FROM_SHIP + 70;
035   
036   
037   public LightningOrb(PlayerShip player)
038   {
039     this.playerShip = player;
040     this.type = BLUE_ORB;
041     init();
042     animationSpeed = 20f;
043     chargeAnimationSpeed = 0.9f;
044     setRatio(0.35f);
045     this.damage = 1000;
046     
047   }
048 
049   
050   static float coefDirecteur = 0;
051   
052   static float min_ordonneeOrigine = 0;
053   static float max_ordonneeOrigine = 0;
054   
055   float min_y = 0;
056   float max_y = 0;
057   
058   
059   private float bulletsToFire = 0;
060   private float bulletTimeCounter = 0;
061   private float bulletFireRate = 40;
062 
063   
064   
065   private static final float MAX_BULLETS = 1;
066   private static final float FIRE_RATE_LIMIT = 2;
067   
068   public void fire(float chargePercentage)
069   {
070     this.bulletsToFire = 2;//(int)MAX_BULLETS * chargePercentage;
071     //distanceFromShipRequested = DEFAULT_DISTANCE_FROM_SHIP_WHEN_FIRING ;
072     
073     
074   }
075   
076   @Override
077   public void update()
078   {
079     super.update();
080     
081     if (bulletsToFire > )
082     {
083       bulletTimeCounter+= bulletFireRate * tick;
084       if (bulletTimeCounter > FIRE_RATE_LIMIT)
085       {
086         bulletsToFire--;
087         bulletTimeCounter = ;
088         fireBeam();
089         fireBeam();
090         //fireBeam();
091       }
092       if (bulletsToFire < )
093       {
094         //distanceFromShipRequested = DEFAULT_DISTANCE_FROM_SHIP;
095 
096       }
097     }
098   }
099   
100   private static float BEAM_HEIGHT_MODULO = 20;
101   private static float MIN_BEAM_HEIGHT = 50;
102   
103   public void fireBeam()
104   {
105     Vector2f[] p = new Vector2f[5];
106     p[0new Vector2f(0,0);
107     p[1new Vector2f(130,0);
108     p[2new Vector2f(350,0);
109     p[3new Vector2f(850,0);
110     p[4new Vector2f(1950,0);
111     
112     
113     OrbBeam ob = new OrbBeam(this,p,2f,true,0.3f,0.8f,1,0.85f,20,MIN_BEAM_HEIGHT);
114     ob.spawn(this.position,new Vector2f(-75.3f,0),Prototyp.fx);
115     
116     Vector2f[] p2 = new Vector2f[5];
117     p2[0new Vector2f(0,0);
118     p2[1new Vector2f(130,0);
119     p2[2new Vector2f(370,0);
120     p2[3new Vector2f(870,0);
121     p2[4new Vector2f(1970,0);
122     
123     OrbBeam ob2 = new OrbBeam(this,p,3f,false,0.3f,0.8f,1f,0.85f,20,MIN_BEAM_HEIGHT);
124     ob2.spawn(this.position,new Vector2f(-75.3f,0),Prototyp.fx);
125     
126     Vector2f[] p3 = new Vector2f[4];
127     p3[0new Vector2f(0,0);
128     p3[1new Vector2f(200,0);
129     p3[2new Vector2f(840,0);
130     p3[3new Vector2f(940,0);
131     
132     OrbBeam ob3 = new OrbBeam(this,p3,3f,Prototyp.random.nextInt(2== false : true,1f,1f,1f,0.85f,15,MIN_BEAM_HEIGHT-10);
133     ob3.spawn(this.position,new Vector2f(-75.3f,0),Prototyp.fx);
134     
135     Vector2f[] p4 = new Vector2f[4];
136     p4[0new Vector2f(0,0);
137     p4[1new Vector2f(200,0);
138     p4[2new Vector2f(440,0);
139     p4[3new Vector2f(940,0);
140     
141     OrbBeam ob4 = new OrbBeam(this,p3,55f,Prototyp.random.nextInt(2== false : true,1f,1f,1f,0.3f,15,MIN_BEAM_HEIGHT-40);
142     ob4.spawn(this.position,new Vector2f(-75.3f,0),Prototyp.fx);
143     
144     /*
145     Vector2f[] p5 = new Vector2f[4];
146     p5[0] = new Vector2f(0,0);
147     p5[1] = new Vector2f(200,0);
148     p5[2] = new Vector2f(440,0);
149     p5[3] = new Vector2f(940,0);
150     
151     OrbBeam ob5 = new OrbBeam(this,p3,25f,Prototyp.random.nextInt(2) == 0 ? false : true,1f,1f,1f,0.4f,0,MIN_BEAM_HEIGHT-40);
152     ob5.spawn(this.position,new Vector2f(-75.3f,0),Prototyp.fx);
153     */
154     
155     
156     Vector2f[] p6 = new Vector2f[4];
157     p6[0new Vector2f(0,0);
158     p6[1new Vector2f(200,0);
159     p6[2new Vector2f(440,0);
160     p6[3new Vector2f(940,0);
161     
162     OrbBeam ob6 = new OrbBeam(this,p3,20f,Prototyp.random.nextInt(2== false : true,1f,1f,1f,0.8f,0,MIN_BEAM_HEIGHT-40);
163     ob6.spawn(this.position,new Vector2f(-75.3f,0),Prototyp.fx);
164     
165     
166     min_y = Math.min(ob.getMinNormalWidth(),ob2.getMinNormalWidth());
167       max_y = Math.max(ob.getMaxNormalWidth(),ob2.getMaxNormalWidth());
168     
169       coefDirecteur = (floatMath.tan(rotationRadians);
170       
171      
172       
173       min_ordonneeOrigine = (position.y + min_y- coefDirecteur * position.x;
174       max_ordonneeOrigine = (position.y + max_y- coefDirecteur * position.x;
175      
176       
177       
178     //Detect collision here...    
179       ArrayList<Entity> enemyArray = Prototyp.enemies.entities;
180       Entity currentEnemy = null;
181       
182       if (this.rotationRadians < Math.PI)
183       {
184         
185         if (this.rotationRadians   < Math.PI/)
186         {
187           
188           for (int j= ; j < enemyArray.size(); j++ )
189           {
190             currentEnemy = enemyArray.get(j);
191             if (currentEnemy.position.x > this.position.x && currentEnemy.position.y > this.position.y)
192             {
193               if (betweenTwoLines(currentEnemy))
194               if (currentEnemy.collided(this))
195                 j--;
196             }
197           }
198         }
199         else
200         {
201           for (int j= ; j < enemyArray.size(); j++ )
202           {
203             currentEnemy = enemyArray.get(j);
204             if (currentEnemy.position.x < this.position.x && currentEnemy.position.y > this.position.y)
205             {
206               if (betweenTwoLines(currentEnemy))
207               if (currentEnemy.collided(this))
208                 j--;
209             }
210           }
211         }
212       }
213       else // rotation > PI
214       {
215         if (this.rotationRadians  > * Math.PI/)
216         {
217           for (int j= ; j < enemyArray.size(); j++ )
218           {
219             currentEnemy = enemyArray.get(j);
220             if (currentEnemy.position.x > this.position.x && currentEnemy.position.y < this.position.y)
221             {
222               if (betweenTwoLines(currentEnemy))
223               if (currentEnemy.collided(this))
224                 j--;
225             }
226           }
227         }
228         else
229         {
230           for (int j= ; j < enemyArray.size(); j++ )
231           {
232             currentEnemy = enemyArray.get(j);
233             if (currentEnemy.position.x < this.position.x && currentEnemy.position.y < this.position.y)
234             {
235               if (betweenTwoLines(currentEnemy))
236               if (currentEnemy.collided(this))
237                 j--;
238             }
239           }
240         }
241       }
242       
243     
244   }
245 
246   public boolean betweenTwoLines(Entity entity)
247   {
248     return 
249     (entity.position.y < (coefDirecteur*entity.position.x + max_ordonneeOrigine)  &&
250      entity.position.y > (coefDirecteur*entity.position.x + min_ordonneeOrigine)
251     ;
252   }
253 }