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 import java.util.Random;
026
027 import org.lwjgl.opengl.GL11;
028 import org.lwjgl.util.vector.Vector2f;
029
030 import com.sun.media.sound.AlawCodec;
031
032 import rtype.Prototyp;
033
034 public class OrbBeam extends Entity
035 {
036
037 float percentage = 0;
038 LightningOrb orb = null;
039 private ArrayList meltingPoints = new ArrayList();
040 float fThickness = 4;
041 private float disaperanceSpeed = 1.7f;// 0.3f;//
042 private float maxNormalWidth = 0;
043 private float minNormalWidth = 0;
044 private float SEQ_IN_BEAM = 8;
045 private static Vector2f controlPoint[] = new Vector2f[3];
046
047 public OrbBeam(LightningOrb orb, Vector2f[] p,float fThickness,boolean bWay,float r,float g,float b,float a, float modulo, float minimalArcHeight)
048 {
049 this.disaperanceSpeed = a * disaperanceSpeed;
050 this.r = r;
051 this.g = g;
052 this.b = b;
053 this.a = a;
054 this.fThickness = fThickness;
055 this.type = ORB_BEAM;
056 init();
057 this.orb = orb;
058 this.position.x = orb.position.x;
059 this.position.y = orb.position.y;
060 this.rotation = orb.rotation;
061 this.damage = 1000;
062
063 Vector2f p1 ;
064 Vector2f p2 ;
065 int i,k;
066
067
068 for(i=0, k=1; i<(int)p.length-1; i++, k++)
069 {
070 p1=p[i];
071 p2=p[k];
072 meltingPoints.add(0,p1);
073 Vector2f norm = GLUTILS.makeNormalForPoints(p1,p2);
074 if (Logger.isLogActivate) Logger.log("norm"+norm);
075
076
077 int ran = (int) (Prototyp.random.nextInt() % modulo + minimalArcHeight);
078
079
080 Vector2f mid= bWay ?
081 new Vector2f(p1.x + ((p2.x-p1.x)*0.5f) + norm.x * ran,
082 p1.y + ((p2.y-p1.y)*0.5f) + norm.y * ran)
083 :
084 new Vector2f(p1.x + ((p2.x - p1.x )*0.5f) - norm.x * ran,
085 p1.y + ((p2.y - p1.y )*0.5f) - norm.y * ran
086 );
087
088 if (bWay)
089 {
090 if (norm.y * ran > this.maxNormalWidth)
091 this.maxNormalWidth = norm.y * ran;
092 }
093 else
094 {
095 if (- norm.y * ran < this.minNormalWidth)
096 this.minNormalWidth = - norm.y * ran;
097 }
098 bWay = !bWay;
099
100 float f = 1.0f/(float)(SEQ_IN_BEAM+1);
101 float s= f;
102
103
104
105 controlPoint[0]=p1;
106 controlPoint[2]=mid;
107 controlPoint[1]=p2;
108
109
110 for(int n=0; n<SEQ_IN_BEAM; n++)
111 {
112 meltingPoints.add(0,calculatePointOnCurve(controlPoint,s));
113 s+=f;
114 }
115
116 }
117
118 }
119
120 private static Vector2f calculatePointOnCurve(Vector2f[] c, float distance)
121 {
122 float a = 1;
123 float b = 0;
124 float step = distance;
125 Vector2f p = new Vector2f();
126 a-=step;
127 b=1-a;
128 p.x = c[0].x*a*a + c[2].x*2*a*b + c[1].x*b*b;
129 p.y = c[0].y*a*a + c[2].y*2*a*b + c[1].y*b*b;
130 return p;
131 }
132
133 float r = 0.3f;
134 float g = 0.8f;
135 float b = 1;
136 float a=1;
137 //float alphaToDisplay = a;
138
139 public void draw()
140 {
141 if (a < 0)
142 {
143 layer.remove(this);
144 if (Logger.isLogActivate) Logger.log("OrbBeam removed itself from the layer");
145 return;
146 }
147
148 a -= disaperanceSpeed * tick ;
149
150 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texture.getTextureId() );
151 GL11.glLoadIdentity();
152 GL11.glTranslatef(position.x,position.y,Prototyp.DEFAULT_Z);
153 GL11.glRotatef(rotation,0f,0f,1f);
154
155 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
156 //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
157
158 Vector2f p,p2,p3,n,n2;
159
160
161 GL11.glColor4f(r,g,b,a);
162
163 GL11.glBegin(GL11.GL_QUADS);
164 {
165
166 for(int i=0; i<(int)meltingPoints.size()-2; i++)
167 {
168
169 p = (Vector2f)meltingPoints.get(i);
170 p2 = (Vector2f)meltingPoints.get(i+1);
171 p3 = (Vector2f)meltingPoints.get(i+2);
172 n= (Vector2f) GLUTILS.makeNormalForPoints(p ,p2).scale(fThickness);
173 n2= (Vector2f) GLUTILS.makeNormalForPoints(p2,p3).scale(fThickness);
174
175 if (i == meltingPoints.size()-3)
176 {
177
178 GL11.glColor4f(r,g,b,0);
179 //System.out.println(0);
180 }
181 GL11.glTexCoord2f(15/32.0f,1);
182 GL11.glVertex2f(p2.x+n2.x,p2.y+n2.y);
183
184 GL11.glTexCoord2f(15/32.0f,0);
185 GL11.glVertex2f(p2.x-n2.x,p2.y-n2.y);
186
187 if (i == meltingPoints.size()-3)
188 {
189 GL11.glColor4f(r,g,b,a);
190 //System.out.println(a);
191 }
192
193 GL11.glTexCoord2f(15/32.0f,0);
194 GL11.glVertex2f(p.x-n.x,p.y-n.y);
195
196 GL11.glTexCoord2f(15/32.0f,1);
197 GL11.glVertex2f(p.x+n.x,p.y+n.y);
198
199
200
201
202
203
204
205
206 }
207 }
208 GL11.glEnd();
209
210 GL11.glColor4f(1f,1f,1f,1f);
211 }
212
213 public boolean collided(Entity entity)
214 {
215 return false;
216 }
217
218 public float getMaxNormalWidth()
219 {
220 return maxNormalWidth;
221 }
222
223 public float getMinNormalWidth()
224 {
225 return minNormalWidth;
226 }
227
228
229 }
|