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
023 package rtype.entity;
024
025 import org.lwjgl.opengl.GL11;
026 import org.lwjgl.util.vector.Vector2f;
027
028 import rtype.Prototyp;
029
030 public class Missile extends AnimatedEntity
031 {
032
033
034
035 public Missile()
036 {
037 this.type = MISSILE;
038 init();
039 this.animationSpeed = 40;
040 setRatio(0.25f);
041 this.life = 1;
042 }
043
044 public void draw()
045 {
046
047 animationCursor += animationSpeed * tick ;
048 animationCursor %= animationTextures.length;
049
050 GL11.glLoadIdentity();
051 GL11.glTranslatef(position.x,position.y,Prototyp.DEFAULT_Z); // Translate Into/Out Of The Screen By z
052
053 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.animationTextures[(int)animationCursor].getTextureId() );
054 GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
055
056
057 GL11.glBegin(GL11.GL_QUADS);
058 {
059 GL11.glTexCoord2f(textureRight,textureUp); //Upper right
060 GL11.glVertex2f(width, -height);
061
062 GL11.glTexCoord2f(textureLeft,textureUp); //Upper left
063 GL11.glVertex2f(-width, -height);
064
065 GL11.glTexCoord2f(textureLeft,textureDown); //Lower left
066 GL11.glVertex2f(-width,height);
067
068 GL11.glTexCoord2f(textureRight,textureDown); // Lower right
069 GL11.glVertex2f(width,height);
070
071 }
072 GL11.glEnd();
073
074 }
075
076 Smoke smoke = null;
077 Vector2f smokePosition = new Vector2f();
078
079 private float smokeAccumulator = 0;
080 private float smokeGenSpeed = 130f;
081 private static final float SMOKE_LIMIT = 5f;
082
083 @Override
084 public void update()
085 {
086
087
088 smokeAccumulator += smokeGenSpeed * tick;
089 if (smokeAccumulator > SMOKE_LIMIT)
090 {
091 smoke = new Smoke();
092 //smoke.setRatio(smokeAccumulator/SMOKE_LIMIT );
093 smokePosition.x = position.x -15 ;
094 //smokePosition.x = (Prototyp.random.nextInt(1) == 0)? smokePosition.x: -smokePosition.x;
095 smokePosition.y = Prototyp.random.nextInt(5);
096 smokePosition.y = (Prototyp.random.nextInt(2) == 0)? smokePosition.y: -smokePosition.y;
097 smokePosition.y += position.y -5;
098 smoke.spawn(smokePosition,Prototyp.DEFAULT_SCROLLING_SPEED,Prototyp.fx);
099 smokeAccumulator=0;
100 }
101
102 super.update();
103 }
104
105 @Override
106 public boolean collided(Entity entity)
107 {
108 this.life -= entity.damage;
109 if (life < 0)
110 {
111 this.unSpawn();
112 ex = new Explosion(Prototyp.random.nextInt(2)+IEntity.EXPLOSION1);
113 ex.spawn(this.position,speedNull,Prototyp.frontground);
114 return true;
115 }
116 return false;
117 }
118 }
|