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.Random;
025
026 import org.lwjgl.opengl.GL11;
027 import org.lwjgl.util.vector.Vector2f;
028
029 import rtype.BonusFactory;
030 import rtype.Prototyp;
031
032 public class LadyBird extends Enemy
033 {
034 private int BONUS_RANGE = 600;
035 private int BONUS_LIMIT = 1;
036
037
038 public LadyBird()
039 {
040 this.type = LADYBIRD;
041 init();
042 animationSpeed = 15f;
043 setRatio(0.45f);
044 flipYAxis();
045 this.fireSpeed = 0.05f;
046 lastFireCounter = Prototyp.random.nextInt();
047 animationCursor = System.currentTimeMillis() % (this.animationTextures.length -1) ;
048 this.life = 1;
049 }
050
051
052 public void draw()
053 {
054 animationCursor += animationSpeed * tick ;
055 animationCursor %= animationTextures.length;
056
057 GL11.glLoadIdentity();
058 GL11.glTranslatef(position.x,position.y,Prototyp.DEFAULT_Z); // Translate Into/Out Of The Screen By z
059 GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.animationTextures[(int)animationCursor].getTextureId() );
060
061
062 if (freezing)
063 GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);
064 else
065 GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
066
067 GL11.glBegin(GL11.GL_QUADS);
068 {
069 GL11.glTexCoord2f(textureRight,textureUp); //Upper right
070 GL11.glVertex2f(width, -height);
071
072 GL11.glTexCoord2f(textureLeft,textureUp); //Upper left
073 GL11.glVertex2f(-width, -height);
074
075 GL11.glTexCoord2f(textureLeft,textureDown); //Lower left
076 GL11.glVertex2f(-width,height);
077
078 GL11.glTexCoord2f(textureRight,textureDown); // Lower right
079 GL11.glVertex2f(width,height);
080 }
081 GL11.glEnd();
082
083 }
084
085 public void update()
086 {
087 super.update();
088 this.lastFireCounter += this.fireSpeed * tick ;
089 if (this.lastFireCounter > 1)
090 {
091 this.lastFireCounter = 0;
092 this.fire();
093 }
094 }
095
096 public void fire()
097 {
098 // Fire a bullet to player's ship
099 Vector2f directionToplayer = new Vector2f(Prototyp.player1.position.x-this.position.x,Prototyp.player1.position.y-this.position.y);
100 directionToplayer.normalise();
101 directionToplayer.x *= 50;
102 directionToplayer.y *= 50;
103
104 EnemyBullet b = new EnemyBullet();
105
106 b.spawn(this.position,directionToplayer,Prototyp.enemies);
107 //Entity.dumpEntity(this);
108 }
109
110 Bonus bonus = null;
111 private Bonus presetBonus = null;
112
113 @Override
114 public boolean collided(Entity entity)
115 {
116 if ( super.collided(entity))
117 {
118 if (presetBonus != null)
119 bonus = presetBonus;
120
121 if (bonus == null && Prototyp.random.nextInt(BONUS_RANGE) <= BONUS_LIMIT)
122 bonus = BonusFactory.createBonus(Prototyp.random.nextInt(Bonus.BONUS_COUNT)+BONUS_BOOSTER);
123
124 if (bonus != null)
125 bonus.spawn(this.position,this.speed,Prototyp.bonus);
126
127 return true;
128 }
129
130 return false;
131 }
132
133
134 public Bonus getPresetBonus() {
135 return presetBonus;
136 }
137
138
139 public void setPresetBonus(Bonus presetBonus) {
140 this.presetBonus = presetBonus;
141 }
142
143
144
145 }
|