Skip to content

Commit

Permalink
The Damage component now also holds information on how to display the…
Browse files Browse the repository at this point in the history
… impact visually (shape and duration). Not sure if this is best practice but for now its good enough. Also added visual display of the other types of explosions (small, medium, large). WeaponsSystem.java now checks for bounce-information on the projectile (will have to be added when creating projectile)
  • Loading branch information
assofohdz committed Feb 26, 2023
1 parent a8c32c0 commit 89d2c78
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 68 deletions.
15 changes: 14 additions & 1 deletion api/src/infinity/es/Damage.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package infinity.es;

import com.simsilica.es.EntityComponent;
import com.simsilica.ext.mphys.ShapeInfo;

/**
* This component is carried by the bomb and holds the intended damage (of the producer). The
Expand All @@ -35,10 +36,22 @@
*/
public class Damage implements EntityComponent {

private final long explosionDecay;
private final int intendedDamage;
private final ShapeInfo explosionShape;

public Damage(final int intendedDamage) {
public ShapeInfo getExplosionShape() {
return explosionShape;
}

public long getExplosionDecay() {
return explosionDecay;
}

public Damage(long explosionDecay, final int intendedDamage, ShapeInfo explosionShape) {
this.explosionDecay = explosionDecay;
this.intendedDamage = intendedDamage;
this.explosionShape = explosionShape;
}

public int getIntendedDamage() {
Expand Down
21 changes: 9 additions & 12 deletions api/src/infinity/es/ShapeNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
*/
public class ShapeNames {

private ShapeNames(){
throw new InfinityRunTimeException("This class should not be instantiated");
}

public static final String SHIP_SHARK = "ship_shark";
public static final String SHIP_WARBIRD = "ship_warbird";
public static final String SHIP_JAVELIN = "ship_javelin";
Expand All @@ -33,35 +29,31 @@ private ShapeNames(){
public static final String SHIP_LANCASTER = "ship_lancaster";
public static final String GRAV_SPHERE = "gravSphere";
public static final String THRUST = "thrust";
public static final String EXPLOSION = "explosion";

public static final String BULLETL1 = "bullet_l1";
public static final String BULLETL2 = "bullet_l2";
public static final String BULLETL3 = "bullet_l3";
public static final String BULLETL4 = "bullet_l4";

public static final String BOMBL1 = "bomb_l1";
public static final String BOMBL2 = "bomb_l2";
public static final String BOMBL3 = "bomb_l3";
public static final String BOMBL4 = "bomb_l4";

public static final String MINEL1 = "mine_l1";
public static final String MINEL2 = "mine_l2";
public static final String MINEL3 = "mine_l3";
public static final String MINEL4 = "mine_l4";

public static final String EMPL1 = "emp_l1";
public static final String EMPL2 = "emp_l2";
public static final String EMPL3 = "emp_l3";
public static final String EMPL4 = "emp_l4";

public static final String THOR = "thor";
public static final String BURST = "burst";

public static final String PRIZE = "bounty";
public static final String ARENA = "arena";
public static final String MAPTILE = "maptile";
public static final String EXPLOSION2 = "explosion2";
public static final String EXPLOSION = "explosionEffect";
public static final String EXPLODE_0 = "explode0";
public static final String EXPLODE_1 = "explode1";
public static final String EXPLODE_2 = "explode2";
public static final String OVER1 = "over1";
public static final String OVER2 = "over2";
public static final String OVER5 = "over5";
Expand All @@ -71,8 +63,13 @@ private ShapeNames(){
public static final String FLAG = "flag";
public static final String DOOR = "door";

private ShapeNames() {
throw new InfinityRunTimeException("This class should not be instantiated");
}

/**
* Creates a ship shape based on the ship type.
*
* @param ship the ship type
* @param ed the entity data
* @return the shape info
Expand Down
24 changes: 24 additions & 0 deletions api/src/infinity/es/ship/weapons/Bounce.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package infinity.es.ship.weapons;

import com.simsilica.es.EntityComponent;

/**
* A component that indicates that an entity can bounce a certain number of times. This is used
* on bullets and bombs.
*/
public class Bounce implements EntityComponent {

private final int bounces;

public Bounce(final int bounces) {
this.bounces = bounces;
}

public int getBounces() {
return bounces;
}

public Bounce decreaseBounces() {
return new Bounce(bounces - 1);
}
}
6 changes: 5 additions & 1 deletion api/src/infinity/sim/CoreViewConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class CoreViewConstants {
public static final float FLAGSIZE = 1;
public static final float BASESIZE = 5f;
public static final float BURSTSIZE = 0.25f;
public static final float EXPLOSION2SIZE = 2f;
public static final float EXPLOSION2SIZE = 3f;
public static final float EXPLOSION1SIZE = 2f;
public static final float EXPLOSION0SIZE = 0.5f;
public static final float WORMHOLESIZE = 4f;
public static final float OVER1SIZE = 1f;
public static final float OVER2SIZE = 2f;
Expand All @@ -58,6 +60,8 @@ public class CoreViewConstants {
public static final int ARENASIZE = 1024;
// Decays must be in milliseconds
public static final long EXPLOSION2DECAY = 2000;
public static final long EXPLOSION1DECAY = 1500;
public static final long EXPLOSION0DECAY = 500;
public static final long WARPDECAY = 800;
public static final long REPELDECAY = 400;
// LightSize radius
Expand Down
8 changes: 4 additions & 4 deletions api/src/infinity/sim/GameEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,19 @@ public static EntityId createBullet(
* return lastTileInfo; }
*/
// Explosion is for now only visual, so only object type and position
public static EntityId createExplosion2(
public static EntityId createExplosion(
final EntityData ed,
@SuppressWarnings("unused") final EntityId owner,
final PhysicsSpace<?, ?> phys,
final long createdTime,
final Vec3d pos,
final long decayMillis) {
final long decayMillis,
final ShapeInfo shapeInfo){
final EntityId lastExplosion = ed.createEntity();

// Explosion is a ghost
ed.setComponents(
lastExplosion,
ShapeInfo.create(ShapeNames.EXPLOSION2, 0, ed),
lastExplosion,shapeInfo,
new SpawnPosition(phys.getGrid(), pos),
new Decay(
createdTime,
Expand Down
20 changes: 20 additions & 0 deletions infinity/assets/Materials/Explode0MaterialLight.j3m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Material Explode2MaterialLight : MatDefs/Multiline/AnimateMultilineSpriteLightShader.j3md {
MaterialParameters {
numTilesX : 7
numTilesY : 1
Speed : 20
numTilesOffsetX : 0
numTilesOffsetY : 0

DiffuseMap : Flip Textures/Subspace/explode0.bm2
UseMaterialColors : true
Specular : 1.0 1.0 1.0 1.0
Diffuse : 1.0 1.0 1.0 1.0
Shininess : 1.0

}
AdditionalRenderState {
Blend Alpha
Wireframe Off
}
}
15 changes: 15 additions & 0 deletions infinity/assets/Materials/Explode0MaterialUnshaded.j3m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Material Explode2MaterialUnshaded : MatDefs/Multiline/AnimateMultilineSpriteUnshaded.j3md {
MaterialParameters {
ColorMap : Flip Textures/Subspace/explode0.bm2
numTilesX : 7
numTilesY : 1
Speed : 20
numTilesOffsetX : 0
numTilesOffsetY : 0

}
AdditionalRenderState {
Blend Alpha
Wireframe Off
}
}
20 changes: 20 additions & 0 deletions infinity/assets/Materials/Explode1MaterialLight.j3m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Material Explode2MaterialLight : MatDefs/Multiline/AnimateMultilineSpriteLightShader.j3md {
MaterialParameters {
numTilesX : 7
numTilesY : 1
Speed : 20
numTilesOffsetX : 0
numTilesOffsetY : 0

DiffuseMap : Flip Textures/Subspace/explode1.bm2
UseMaterialColors : true
Specular : 1.0 1.0 1.0 1.0
Diffuse : 1.0 1.0 1.0 1.0
Shininess : 1.0

}
AdditionalRenderState {
Blend Alpha
Wireframe Off
}
}
15 changes: 15 additions & 0 deletions infinity/assets/Materials/Explode1MaterialUnshaded.j3m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Material Explode2MaterialUnshaded : MatDefs/Multiline/AnimateMultilineSpriteUnshaded.j3md {
MaterialParameters {
ColorMap : Flip Textures/Subspace/explode1.bm2
numTilesX : 7
numTilesY : 1
Speed : 20
numTilesOffsetX : 0
numTilesOffsetY : 0

}
AdditionalRenderState {
Blend Alpha
Wireframe Off
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ public Spatial createModel(EntityId id, String shapeName, Mass mass) {
return createBounty();
case ShapeNames.ARENA:
return createArena();
case ShapeNames.EXPLOSION2:
case ShapeNames.EXPLODE_0:
return createExplosion0();
case ShapeNames.EXPLODE_1:
return createExplosion1();
case ShapeNames.EXPLODE_2:
return createExplosion2();
case ShapeNames.OVER5:
return createOver5();
Expand Down Expand Up @@ -586,6 +590,46 @@ private Spatial createArena() {

return geom;
}
private Spatial createExplosion1() {
final Quad quad = new Quad(CoreViewConstants.EXPLOSION1SIZE, CoreViewConstants.EXPLOSION1SIZE);
final float halfSize = CoreViewConstants.EXPLOSION1SIZE * 0.5f;
quad.setBuffer(VertexBuffer.Type.Position, 3, getVerticesQuad(halfSize));
quad.setBuffer(VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer(getNormalsQuad()));
quad.updateBound();
final Geometry geom = new Geometry("Bomb", quad);

if (UNSHADED) {
geom.setMaterial(assets.loadMaterial("Materials/Explode1MaterialUnshaded.j3m"));
} else {
geom.setMaterial(assets.loadMaterial("Materials/Explode1MaterialLight.j3m"));
}

geom.getMaterial().setFloat(STARTTIME, timer.getTimeInSeconds());

geom.setQueueBucket(RenderQueue.Bucket.Transparent);
return geom;
}


private Spatial createExplosion0() {
final Quad quad = new Quad(CoreViewConstants.EXPLOSION0SIZE, CoreViewConstants.EXPLOSION0SIZE);
final float halfSize = CoreViewConstants.EXPLOSION0SIZE * 0.5f;
quad.setBuffer(VertexBuffer.Type.Position, 3, getVerticesQuad(halfSize));
quad.setBuffer(VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer(getNormalsQuad()));
quad.updateBound();
final Geometry geom = new Geometry("Bomb", quad);

if (UNSHADED) {
geom.setMaterial(assets.loadMaterial("Materials/Explode0MaterialUnshaded.j3m"));
} else {
geom.setMaterial(assets.loadMaterial("Materials/Explode0MaterialLight.j3m"));
}

geom.getMaterial().setFloat(STARTTIME, timer.getTimeInSeconds());

geom.setQueueBucket(RenderQueue.Bucket.Transparent);
return geom;
}

private Spatial createExplosion2() {
final Quad quad = new Quad(CoreViewConstants.EXPLOSION2SIZE, CoreViewConstants.EXPLOSION2SIZE);
Expand Down
10 changes: 9 additions & 1 deletion infinity/src/main/java/infinity/systems/ActionSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.simsilica.es.EntityId;
import com.simsilica.es.EntitySet;
import com.simsilica.ext.mphys.MPhysSystem;
import com.simsilica.ext.mphys.ShapeInfo;
import com.simsilica.mathd.Quatd;
import com.simsilica.mathd.Vec3d;
import com.simsilica.mblock.phys.MBlockShape;
Expand All @@ -22,11 +23,13 @@
import com.simsilica.sim.AbstractGameSystem;
import com.simsilica.sim.SimTime;
import infinity.es.Damage;
import infinity.es.ShapeNames;
import infinity.es.ship.actions.Thor;
import infinity.es.ship.actions.ThorCurrentCount;
import infinity.es.ship.actions.ThorFireDelay;
import infinity.sim.CoreGameConstants;
import infinity.sim.CorePhysicsConstants;
import infinity.sim.CoreViewConstants;
import infinity.sim.GameEntities;
import infinity.sim.GameSounds;
import infinity.sim.util.InfinityRunTimeException;
Expand Down Expand Up @@ -165,7 +168,8 @@ private void createThor(Entity requesterEntity, final long time, ActionPosition
info.attackVelocity,
CoreGameConstants.BULLETDECAY);

ed.setComponent(gunProjectile, new Damage(CoreGameConstants.THORDAMAGE));
ed.setComponent(gunProjectile, new Damage(CoreViewConstants.EXPLOSION1DECAY, CoreGameConstants.THORDAMAGE, ShapeInfo.create(
ShapeNames.EXPLODE_1, 1, ed)));
}

private boolean createSound(Entity requesterEntity, byte flag, long time, ActionPosition info) {
Expand Down Expand Up @@ -300,6 +304,10 @@ public void newContact(Contact<EntityId, MBlockShape> contact) {
}
}

public boolean isThor(EntityId idOne) {
return thorProjectiles.containsId(idOne);
}

/** A class that holds the position information needed to create an attack. */
private static class ActionPosition {

Expand Down
Loading

0 comments on commit 89d2c78

Please sign in to comment.