Skip to content

Commit

Permalink
feat(mat): change materials
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgivrer committed May 4, 2024
1 parent a85bd7a commit 4926f8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/main/java/my/karma/app/KarmaPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ default void dispose(KarmaPlatform app) {

Collection<Entity> getEntities();

Entity getEntity(String entityName);
<T extends Entity> T getEntity(String entityName);

void clearEntities();

Expand Down Expand Up @@ -1083,8 +1083,8 @@ public void clearEntities() {
entities.clear();
}

public KarmaPlatform.Entity getEntity(String name) {
return entities.get(name);
public <T extends Entity> T getEntity(String name) {
return (T) entities.get(name);
}

public Collection<KarmaPlatform.Entity> getEntities() {
Expand Down Expand Up @@ -1668,12 +1668,16 @@ public void update(double d, Map<String, Object> stats) {
public void updateEntity(double d, Entity e) {
// if concerned, apply World disturbances.
applyWorldDisturbance(world, e, d);
// compute physic on the Entity (velocity & position)
applyPhysics(world, e, d);

// detect collision and apply response
detectCollision(world, e, d);

// compute physic on the Entity (velocity & position)
applyPhysics(world, e, d);

// update the entity (lifetime and active status)
e.update(d);

// update the bounding box for that entity
e.updateBox();
}
Expand Down Expand Up @@ -1721,8 +1725,8 @@ private void applyPhysics(World world, Entity entity, double d) {
entity.updateBox();
// apply physic computation on children (if any)
entity.getChild().stream().filter(Entity::isActive).forEach(c -> {
applyPhysics(world, c, d);
detectCollision(world, c, d);
applyPhysics(world, c, d);
});
entity.resetForces();
}
Expand Down Expand Up @@ -1787,7 +1791,6 @@ private void keepInPlayArea(World w, Entity e) {
private void detectCollision(World w, Entity e, double d) {
if (Optional.ofNullable(sceneManager).isPresent()) {
Collection<Entity> entities = sceneManager.getCurrent().getEntities();
// TODO: broad phase detect Entity at proximity cell through a Quadtree
List<Entity> collisionList = new CopyOnWriteArrayList<>();
spacePartition.find(collisionList, e);
collisionCounter = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/my/karma/app/scenes/PlayScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void create(KarmaPlatform app) {
.setTweenFactor(0.2)
.setViewport(new Rectangle2D.Double(0, 0, app.getScreenSize().width, app.getScreenSize().height));
setCamera(cam);
KarmaPlatform.Material playerMat = new KarmaPlatform.Material("PLAYER_MAT", 0.98, 1.0, 0.25);
KarmaPlatform.Material playerMat = new KarmaPlatform.Material("PLAYER_MAT", 0.998, 1.0, 0.85);
// Add a player.
KarmaPlatform.Entity player = new KarmaPlatform.Entity("player")
.setPosition(160, 30)
Expand All @@ -81,7 +81,7 @@ public void create(KarmaPlatform app) {
.setForegroundColor(new Color(0.0f, 0.0f, 0.0f, 0.0f))
.setBackgroundColor(new Color(0.0f, 0.0f, 0.0f, 0.0f))
.setSize(app.getScreenSize().getWidth(), app.getScreenSize().getHeight())
.addBehavior(new StarFieldParticleBehavior(player, 0.0005, 50, 30));
.addBehavior(new StarFieldParticleBehavior(player, -0.0005, 50, 30));
addEntity(particleSystem);

// Add some enemies.
Expand All @@ -92,7 +92,7 @@ public void create(KarmaPlatform app) {
}

private void createPlatforms(KarmaPlatform app) {
KarmaPlatform.Material platformMat = new KarmaPlatform.Material("PLATFORM_MAT", 1.0, 1.0, 0.1);
KarmaPlatform.Material platformMat = new KarmaPlatform.Material("PLATFORM_MAT", 0.999, 1.0, 0.99);

KarmaPlatform.Entity platform2 = new KarmaPlatform.Entity("platform_border_top")
.setPosition(0, 0)
Expand Down

0 comments on commit 4926f8d

Please sign in to comment.