BitUpgrade.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 org.lwjgl.opengl.GL11;
025 import org.lwjgl.util.vector.Vector2f;
026 
027 import rtype.Layer;
028 import rtype.Prototyp;
029 
030 public class BitUpgrade extends Weapon
031 {
032 
033   PlayerShip playerShip = null;
034   Vector2f postionRelativeToPlayerShip = new Vector2f(0,0);
035   
036   
037   public BitUpgrade(PlayerShip playerShip)
038   {
039     this.type = BIT_UPGRADE;
040     this.playerShip = playerShip;
041     init();
042     animationSpeed = 30f;
043     setRatio(0.40f);    
044     
045   }
046   
047   @Override
048   public void draw()
049   {
050     animationCursor += animationSpeed * tick  ;
051          animationCursor %= animationTextures.length -;
052     
053     GL11.glLoadIdentity();            
054          GL11.glTranslatef(position.x,position.y,Prototyp.DEFAULT_Z);                     // Translate Into/Out Of The Screen By z
055     GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.animationTextures[(int)animationCursor].getTextureId() );
056     GL11.glBegin(GL11.GL_QUADS);
057     {
058       GL11.glTexCoord2f(textureRight,textureUp)//Upper right
059       GL11.glVertex2f(width, -height);
060       
061       GL11.glTexCoord2f(textureLeft,textureUp)//Upper left      
062       GL11.glVertex2f(-width, -height);        
063      
064       GL11.glTexCoord2f(textureLeft,textureDown)//Lower left
065       GL11.glVertex2f(-width,height);
066         
067       GL11.glTexCoord2f(textureRight,textureDown)// Lower right
068       GL11.glVertex2f(width,height);  
069     }
070          GL11.glEnd();
071   }
072   
073   
074   float xDiff = 0;
075   float yDiff = 0;
076   float distanceFromShip = 0;
077   static final float VELOCITY = 2;
078   @Override
079   public void update()
080   {
081     
082     // Modify speed
083     xDiff = (playerShip.position.x + postionRelativeToPlayerShip.x- position.x;
084     yDiff = (playerShip.position.y + postionRelativeToPlayerShip.y- position.y;
085     distanceFromShip = (float)Math.sqrt(xDiff*xDiff + yDiff*yDiff);
086     if (distanceFromShip > 10)
087     {
088       speed.x = xDiff    * VELOCITY;
089       speed.y = yDiff    * VELOCITY;
090     }
091     else
092     {
093       speed.x = 0;
094       speed.y = 0;
095     }
096     interpolate(position,speed);
097     this.rotation += rotationSpeed * tick ;
098     
099   }
100 
101   
102   @Override
103   public boolean collided(Entity entity)
104   {
105     // Make undestructible
106     return false;
107   }
108   
109   @Override
110   public void spawn(Vector2f position,Vector2f spawningPlace,Layer layer )
111   {
112     this.postionRelativeToPlayerShip.x = position.x;
113     this.postionRelativeToPlayerShip.y = position.y;  
114     this.position.x = spawningPlace.x;
115     this.position.y = spawningPlace.y;
116     this.layer = layer;
117     this.speed.y = speed.y;
118     this.speed.x = speed.x;
119     this.layer.add(this);
120   }
121 
122   @Override
123   public void startChargingAnimation()
124   {  
125   }
126 
127   @Override
128   public void stopChargingAnimation()
129   {
130   }
131 
132   @Override
133   public void fire(float chargePercentage)
134   {
135     if (Prototyp.enemies.entities.size() != 0)
136        {
137          HomingMissile m = new HomingMissile(Prototyp.enemies,(float)Math.PI / 1000)
138          m.spawn(position,new Vector2f(400,0),Prototyp.bullets);
139        }
140     
141   }
142   
143   
144 }