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
026 import rtype.Prototyp;
027
028 public abstract class Orb extends Weapon
029 {
030
031 public FireBall fb = new FireBall(this);
032 protected static float DEFAULT_DISTANCE_FROM_SHIP = 60;
033 protected float distanceFromShipRequested = DEFAULT_DISTANCE_FROM_SHIP;
034
035
036
037 @Override
038 public void startChargingAnimation()
039 {
040 this.displayChargeAnimation = true;
041 this.fb.startAnimation();
042
043 }
044
045 @Override
046 public void stopChargingAnimation()
047 {
048 displayChargeAnimation = false;
049 chargeAnimationCursor = 0;
050 this.fb.stopAnimation();
051
052 }
053
054 @Override
055 public void draw()
056 {
057 animationCursor += animationSpeed * tick ;
058 animationCursor %= animationTextures.length;
059
060 GL11.glLoadIdentity();
061 //GL11.glTranslatef(playerShip.position.x+playerShip.width+100,playerShip.position.y,Prototyp.DEFAULT_Z); // Translate Into/Out Of The Screen By z
062 GL11.glTranslatef(position.x,position.y,Prototyp.DEFAULT_Z); // Translate Into/Out Of The Screen By z
063 GL11.glRotatef(rotation,0f,0f,1f);
064 GL11.glColor4f(1,1,1,1);
065 GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
066 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.animationTextures[(int)animationCursor].getTextureId() );
067
068 GL11.glBegin(GL11.GL_QUADS);
069 {
070 GL11.glTexCoord2f(textureRight,textureUp); //Upper right
071 GL11.glVertex2f(width, -height);
072
073 GL11.glTexCoord2f(textureLeft,textureUp); //Upper left
074 GL11.glVertex2f(-width, -height);
075
076 GL11.glTexCoord2f(textureLeft,textureDown); //Lower left
077 GL11.glVertex2f(-width,height);
078
079 GL11.glTexCoord2f(textureRight,textureDown); // Lower right
080 GL11.glVertex2f(width,height);
081 }
082 GL11.glEnd();
083
084
085
086 if (this.displayChargeAnimation)
087 {
088 chargeAnimationCursor += chargeAnimationSpeed * tick ;
089 if (chargeAnimationCursor >= animationTextures.length)
090 chargeAnimationCursor = animationTextures.length - 1;
091
092 float alphaPercentage = chargeAnimationCursor/(animationTextures.length - 1) ;
093 alphaPercentage *= 2.5;
094
095 if (alphaPercentage > 0.6f)
096 alphaPercentage = 0.6f ;
097 else if (alphaPercentage < 0.15 )
098 {
099 alphaPercentage = 0;
100 }
101
102 Prototyp.fadeAlpha = alphaPercentage ;
103
104 // Draw fireball above that shit
105 //fb.tick = tick;
106 //fb.draw(alphaPercentage*5);
107
108 }
109 else
110 Prototyp.fadeAlpha = 0;
111 }
112
113 public boolean collided(Entity entity)
114 {
115 return false;
116 }
117
118 protected double rotationRadians = 0;
119 protected void updateOrbAngle()
120 {
121 float xDiff = position.x - playerShip.position.x;
122 float yDiff = position.y-playerShip.position.y;
123 rotationRadians = Math.atan(yDiff/xDiff);
124 if (xDiff < 0)
125 rotationRadians +=Math.PI ;
126
127 if (rotationRadians < 0)
128 rotationRadians = 2 * Math.PI + rotationRadians;
129
130 //if (xDiff < 0)
131 // this.rotationRadians += 2 * Math.PI;
132 this.rotation = GLUTILS.radiansToDegres((float)rotationRadians);
133 //if (xDiff < 0)
134 // this.rotation += 180 ;
135
136 this.rotation = (float)this.rotation;
137 }
138
139 float xDiffWithPlayerShip = 0;
140 float yDiffWithPlayerShip = 0;
141 float distanceFromShip = 0;
142 private int mode = STICKED;
143 public void calculateDistanceFromShip()
144 {
145 xDiffWithPlayerShip = playerShip.position.x - position.x ;
146 yDiffWithPlayerShip = playerShip.position.y - position.y ;
147 distanceFromShip = (float)Math.sqrt(xDiffWithPlayerShip*xDiffWithPlayerShip + yDiffWithPlayerShip*yDiffWithPlayerShip);
148 }
149
150
151 static final float VELOCITY = 1f;
152 public static final int STICKED = 0;
153 public static final int ADJUDTING = 1;
154
155 @Override
156 public void update()
157 {
158 calculateDistanceFromShip();
159 if (mode == ADJUDTING || distanceFromShip > distanceFromShipRequested)
160 {
161
162 if (distanceFromShip > distanceFromShipRequested)
163 {
164 speed.x = xDiffWithPlayerShip * VELOCITY ;
165 speed.y = yDiffWithPlayerShip * VELOCITY;
166 }
167 else
168 {
169 speed.x = 0;
170 speed.y = 0;
171 }
172 interpolate(position,speed);
173 updateOrbAngle();
174 }
175 else
176 {
177 interpolate(position,playerShip.speed);
178 }
179 }
180
181 public void setMove(int mode)
182 {
183 this.mode = mode;
184
185 }
186
187
188
189 }
|