Skip to content

Commit cc6cabe

Browse files
committed
Added asteroid loot drops... you can't pick them up or anything
but they're there and fancy-looking.
1 parent 12d4675 commit cc6cabe

File tree

8 files changed

+101
-6
lines changed

8 files changed

+101
-6
lines changed
24.6 KB
Loading

sigem/assets/Textures/power-up.png

21.2 KB
Loading

sigem/src/main/java/sigem/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public Main() {
113113
}
114114

115115
public void simpleInitApp() {
116-
116+
117117
setPauseOnLostFocus(false);
118118
setDisplayFps(false);
119119
setDisplayStatView(false);

sigem/src/main/java/sigem/es/ObjectType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class ObjectType implements EntityComponent {
5454
public static final String TYPE_THRUST = "thrust";
5555
public static final String TYPE_MISSILE = "missile";
5656
public static final String TYPE_PLASMA_EXPLOSION = "plasmaExplosion";
57+
public static final String TYPE_FUEL_DROP = "fuelDrop";
58+
public static final String TYPE_SHIELD_DROP = "shieldDrop";
5759

5860
private int type;
5961

sigem/src/main/java/sigem/sim/AsteroidHitListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void newContact( Contact c ) {
9696
return;
9797
}
9898

99-
log.info("contact:" + c + " types:" + t1 + ", " + t2);
99+
//log.info("contact:" + c + " types:" + t1 + ", " + t2);
100100

101101
if( ObjectType.TYPE_MISSILE.equals(t1) ) {
102102
// Blow up b2
@@ -150,6 +150,8 @@ protected void missileHit( Body missile, Body asteroid, Contact contact ) {
150150
size);
151151
}
152152

153+
gameEntities.lootDrop(ObjectType.TYPE_ASTEROID, debrisLoc, 1/asteroid.radius);
154+
153155
// And remove the old one
154156
ed.removeEntity(asteroid.bodyId);
155157
}

sigem/src/main/java/sigem/sim/CollisionSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private Contact checkContact( Body b1, Body b2 ) {
199199
if( dist >= b1.radius + b2.radius ) {
200200
return null;
201201
}
202-
log.info("contact:" + b1.bodyId + " and:" + b2.bodyId);
202+
//log.info("contact:" + b1.bodyId + " and:" + b2.bodyId);
203203
Contact c = new Contact(b1, b2);
204204
c.cn = b2.pos.subtract(b1.pos);
205205
c.cn.y = 0; // just in case

sigem/src/main/java/sigem/sim/GameEntities.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
package sigem.sim;
3838

39+
import java.util.*;
40+
3941
import org.slf4j.*;
4042

4143
import com.simsilica.es.*;
@@ -55,6 +57,7 @@ public class GameEntities extends AbstractGameSystem {
5557
static Logger log = LoggerFactory.getLogger(GameEntities.class);
5658

5759
private EntityData ed;
60+
private Random rand = new Random(0);
5861

5962
public GameEntities( EntityData ed ) {
6063
this.ed = ed;
@@ -115,6 +118,43 @@ public EntityId createExplosion( Vec3d location, double size ) {
115118
);
116119
return result;
117120
}
121+
122+
private static String[] LOOT_TYPES = new String[] {
123+
ObjectType.TYPE_FUEL_DROP,
124+
ObjectType.TYPE_SHIELD_DROP
125+
};
126+
127+
public void lootDrop( String type, Vec3d location, double chance ) {
128+
129+
// Always do it for testing
130+
if( rand.nextDouble() >= chance ) {
131+
return;
132+
}
133+
134+
SimTime time = getManager().getStepTime();
135+
136+
int count = rand.nextInt(2) + 1;
137+
log.info("loot count:" + count);
138+
for( int i = 0; i < count; i++ ) {
139+
double x = rand.nextDouble() * 2 - 1;
140+
double z = rand.nextDouble() * 2 - 1;
141+
142+
Vec3d v = location.add(x, 0, z);
143+
144+
String lootType = LOOT_TYPES[i];
145+
log.info("creating loot drop:" + lootType);
146+
EntityId loot = ed.createEntity();
147+
ed.setComponents(loot,
148+
new Position(v),
149+
new SphereShape(0, new Vec3d()),
150+
new MassProperties(1/5.0),
151+
ObjectType.create(lootType, ed),
152+
new Impulse(new Vec3d(x, 0, z), new Vec3d(0, 8, 0)),
153+
new Decay(time.getTime(), time.getFutureTime(15))
154+
);
155+
}
156+
157+
}
118158
}
119159

120160

sigem/src/main/java/sigem/view/ModelViewState.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ protected Geometry createQuad( float size, String asset, BlendMode blendMode ) {
263263
//Material mat = globals.createMaterial(ColorRGBA.Blue, false).getMaterial();
264264
Material mat = globals.createMaterial(texture, false).getMaterial();
265265
mat.getAdditionalRenderState().setBlendMode(blendMode);
266+
mat.setFloat("AlphaDiscardThreshold", 0.01f);
266267
geom.setQueueBucket(Bucket.Transparent);
267268
geom.rotate(-FastMath.HALF_PI, 0, 0);
268269
geom.setMaterial(mat);
@@ -321,15 +322,59 @@ protected Spatial createPlasmaExplosion( Entity entity ) {
321322
ColorRGBA color2 = new ColorRGBA(2, 1, 1, 0);
322323
mat.setColor("Color", color);
323324

324-
// Fade it out over five seconds. We could have created a system to do
325-
// this based on decay, blah blah... but this is really easy.
326-
//getState(AnimationState.class).add(new ColorTween(color, ColorRGBA.White, new ColorRGBA(1, 1, 1, 0), 5));
327325
getState(AnimationState.class).add(new ColorTween(color, color1, color2, 2));
328326

329327
result.attachChild(geom);
330328

331329
return result;
332330
}
331+
332+
protected Spatial createDrop( Entity entity, ColorRGBA color ) {
333+
Node result = new Node("thrust");
334+
Geometry geom;
335+
Material mat;
336+
ColorRGBA pupColor, base, start, end;
337+
338+
geom = createQuad(10, "Textures/light-burst.png", BlendMode.AlphaAdditive);
339+
geom.move(0, -0.01f, 0);
340+
mat = geom.getMaterial();
341+
LayerComparator.setLayer(geom, 1);
342+
343+
pupColor = color.clone();
344+
base = new ColorRGBA(0.25f, 1f, 1f, 1);
345+
pupColor.interpolateLocal(base, 0.5f);
346+
347+
start = pupColor.clone();
348+
start.a = 1;
349+
end = pupColor.clone();
350+
end.a = 0;
351+
mat.setColor("Color", pupColor);
352+
353+
getState(AnimationState.class).add(Tweens.delay(10), new ColorTween(pupColor, start, end, 5));
354+
355+
result.attachChild(geom);
356+
357+
geom = createQuad(2, "Textures/power-up.png", BlendMode.Alpha);
358+
geom.move(0, 0, 0);
359+
mat = geom.getMaterial();
360+
LayerComparator.setLayer(geom, 2);
361+
362+
pupColor = color.clone();
363+
base = new ColorRGBA(0.75f, 0.75f, 0.75f, 1);
364+
pupColor.interpolateLocal(base, 0.5f);
365+
366+
start = pupColor.clone();
367+
start.a = 1;
368+
end = pupColor.clone();
369+
end.a = 0;
370+
mat.setColor("Color", pupColor);
371+
372+
getState(AnimationState.class).add(Tweens.delay(10), new ColorTween(pupColor, start, end, 5));
373+
374+
result.attachChild(geom);
375+
376+
return result;
377+
}
333378

334379
protected Spatial createModel( Entity entity ) {
335380
// Check to see if one already exists
@@ -361,6 +406,12 @@ protected Spatial createModel( Entity entity ) {
361406
case ObjectType.TYPE_PLASMA_EXPLOSION:
362407
result = createPlasmaExplosion(entity);
363408
break;
409+
case ObjectType.TYPE_FUEL_DROP:
410+
result = createDrop(entity, new ColorRGBA(1, 0.4f, 0.95f, 1));
411+
break;
412+
case ObjectType.TYPE_SHIELD_DROP:
413+
result = createDrop(entity, new ColorRGBA(0.2f, 0.9f, 1f, 1));
414+
break;
364415
default:
365416
throw new RuntimeException("Unknown spatial type:" + typeName);
366417
}

0 commit comments

Comments
 (0)