Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add javadoc render helper #81

Merged
merged 11 commits into from
Nov 15, 2021
Merged
12 changes: 7 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>core</groupId>
<artifactId>fromclasstogame</artifactId>
Expand Down Expand Up @@ -60,7 +61,7 @@


<properties>
<java.version>11</java.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<mainClass>fr.snapgames.fromclasstogame.core.Game</mainClass>
Expand Down Expand Up @@ -267,7 +268,8 @@
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
<!--transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
Expand Down Expand Up @@ -490,7 +492,7 @@
<phase>site</phase>
<configuration>
<executable>pandoc</executable>
<workingDirectory />
<workingDirectory/>
<arguments>
<argument>docs/ebook-metadata.yml</argument>
<!--argument>docs/00-.md</argument -->
Expand Down Expand Up @@ -527,7 +529,7 @@
<phase>package</phase>
<configuration>
<executable>pandoc</executable>
<workingDirectory />
<workingDirectory/>
<arguments>
<argument>docs/ebook-metadata.yml</argument>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package fr.snapgames.fromclasstogame.core.behaviors;

import fr.snapgames.fromclasstogame.core.entity.particles.Particle;
import fr.snapgames.fromclasstogame.core.gfx.Render;
import fr.snapgames.fromclasstogame.core.io.ActionHandler;
import fr.snapgames.fromclasstogame.core.physic.Vector2d;

public class BasicParticleBehavior implements Behavior<Particle> {

@Override
public void onCreate(Particle p) {
Behavior.super.onCreate(p);
p.alive = true;
p.life = 1000;
p.size = 1+(int)(Math.random()*5);
p.position = new Vector2d();

}

@Override
public void onInput(Particle go, ActionHandler ih) {

}

@Override
public void onUpdate(Particle go, long dt) {
if (go.alive) {
go.life = go.life - 1;
}
if (go.life < 0) {
go.alive = false;
go.life = 0;
}
}

@Override
public void onRender(Particle go, Render r) {

}

@Override
public void onAction(Particle go, ActionHandler.ACTIONS action) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import fr.snapgames.fromclasstogame.core.io.ActionHandler;

public interface Behavior<T> {

default void onCreate(T go) {
// Nothing specific to do by default.
}

void onInput(T go, ActionHandler ih);

void onUpdate(T go, long dt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Configuration(String configurationPath) {
initializeArgParser(configurationPath);
logger.info("** > Configuration file '{}' loaded [@ {}]", configurationPath, System.currentTimeMillis());
} catch (Exception e) {
logger.error("Unable to read configration", e);
logger.error("Unable to read configuration", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fr.snapgames.fromclasstogame.core.entity;

import fr.snapgames.fromclasstogame.core.physic.Vector2d;

public interface EntityUpdate {
void update(long dt);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package fr.snapgames.fromclasstogame.core.entity.particles;

import fr.snapgames.fromclasstogame.core.entity.EntityUpdate;
import fr.snapgames.fromclasstogame.core.physic.Vector2d;

import java.util.HashMap;
import java.util.Map;

public class Particle implements EntityUpdate {
public Vector2d position;
public Vector2d velocity;
public Vector2d acceleration;
public double size;

public int life = 0;
public boolean alive;

public Map<String, Object> attributes = new HashMap<>();

public Particle() {
this(0);
}

public Particle(int life) {
this.life = life;
}

public Particle setSize(double size) {
this.size = size;
return this;
}

public Particle setPosition(Vector2d pos) {
this.position = pos;
return this;
}

public Particle setVelocity(Vector2d vel) {
this.velocity = vel;
return this;
}

public Particle setAcceleration(Vector2d acc) {
this.acceleration = acc;
return this;
}

@Override
public void update(long dt) {
this.life--;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fr.snapgames.fromclasstogame.core.entity.particles;

import fr.snapgames.fromclasstogame.core.behaviors.Behavior;
import fr.snapgames.fromclasstogame.core.entity.GameObject;
import fr.snapgames.fromclasstogame.core.physic.Vector2d;

import java.util.ArrayList;
import java.util.List;

public class ParticleSystem extends GameObject {

public List<Behavior<Particle>> pBehave = new ArrayList<>();
public List<Particle> particles = new ArrayList<>();
int nbMaxParticle = 200;

public ParticleSystem(String objectName, Vector2d pos) {
super(objectName, pos);
}


public ParticleSystem create(int nb) {
nbMaxParticle = nb;
for (int i = 0; i < nbMaxParticle; i++) {
Particle p = new Particle();
if (pBehave.size() > 0) {
pBehave.forEach(b -> b.onCreate(p));
}
particles.add(p);
}
return this;
}

@Override
public void update(long dt) {
super.update(dt);
if (pBehave.size() > 0) {
for (Particle particle : particles) {
pBehave.forEach(b -> b.onUpdate(particle, dt));
}
}
}

public ParticleSystem addParticleBehavior(Behavior<Particle> bp) {
pBehave.add(bp);
return this;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,7 +63,7 @@ public void render() {
if (camera != null) {
g.translate(-camera.position.x, -camera.position.y);
}
renderWorld(g, world);
drawGrid(g, world);
for (GameObject go : objects) {
draw(g, go);
}
Expand All @@ -83,7 +82,7 @@ public void render() {
}
}

private void renderWorld(Graphics2D g, World w) {
private void drawGrid(Graphics2D g, World w) {
if (w != null && debug > 0) {
g.setColor(Color.BLUE);
for (int x = 0; x < w.width; x += 16) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Window setFrame(String title, int width, int height) {
frame.setSize(dim);
frame.setPreferredSize(dim);
frame.setMaximumSize(dim);
frame.setUndecorated(true);
//frame.setUndecorated(true);
frame.setMenuBar(null);
frame.setLocation(new Point((int) (currentDevice.getDisplayMode().getWidth() - dim.width) / 2,
(int) (currentDevice.getDisplayMode().getHeight() - dim.height) / 2));
Expand Down
Loading