TrashGenerator.java
01 /*
02  *
03  * Created: Jun  7 2006
04  *
05  * Copyright (C) 1999-2000 Fabien Sanglard
06  
07  * This program is free software; you can redistribute it and/or
08  * modify it under the terms of the GNU General Public License
09  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  */
21 
22 package generator;
23 
24 import org.lwjgl.util.vector.Vector2f;
25 
26 import rtype.Layer;
27 import rtype.Prototyp;
28 import rtype.entity.IEntity;
29 import rtype.entity.SpaceTrash;
30 import generator.IGenerator;
31 
32 public class TrashGenerator extends IGenerator {
33 
34   static float lastTrash = 0;
35     static SpaceTrash spawningTrash = null;
36     static int trashType = IEntity.SPACE_TRASH_1;
37     static float trashSpawningRate = 3f;
38     static float trashDeltaacc = 0;
39     static final Vector2f defaultTrashSpeed = new Vector2f(-34.3f,0);
40     static final Layer[] layers = {Prototyp.background,Prototyp.frontground};
41     static float rotationSpeed = 2f;
42     
43   public void generateEntities()
44   {
45     trashDeltaacc += Prototyp.tick ;
46     if (trashDeltaacc > trashSpawningRate)
47     {
48         trashDeltaacc = 0;
49         trashType = Prototyp.random.nextInt(29;
50         spawningTrash = new SpaceTrash(trashType);
51         if (Prototyp.random.nextInt(2== 0)
52           rotationSpeed = - rotationSpeed;
53         spawningTrash.spawn(new Vector2f(Prototyp.SCREEN_WIDTH/2+10,Prototyp.random.nextInt() % Prototyp.SCREEN_HEIGHT/2),defaultTrashSpeed,rotationSpeed,layers[Prototyp.random.nextInt(32]);
54       }
55   }
56 
57 }