Skip to content

Commit

Permalink
Waves via displacement (#111)
Browse files Browse the repository at this point in the history
* introduce displacement

* fix missing animations

* fix displacement
  • Loading branch information
srcimon committed Sep 27, 2023
1 parent 2d64c06 commit 5b44d1b
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.srcimon.screwbox.core.Angle;
import io.github.srcimon.screwbox.core.Percent;
import io.github.srcimon.screwbox.core.Vector;
import io.github.srcimon.screwbox.core.entities.Component;
import io.github.srcimon.screwbox.core.graphics.Flip;
import io.github.srcimon.screwbox.core.graphics.Sprite;
Expand All @@ -16,6 +17,7 @@ public class RenderComponent implements Component {
public double scale = 1;
public Angle rotation = Angle.none();
public Flip flip = Flip.NONE;
public Vector displacement = Vector.zero();

public RenderComponent() {
this(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public void update(final Engine engine) {
final var sprite = render.sprite;
final var spriteDimension = sprite.size();
final var spriteBounds = Bounds.atOrigin(
entityPosition.x() - spriteDimension.width() / 2.0,
entityPosition.y() - spriteDimension.height() / 2.0,
entityPosition.x() - spriteDimension.width() / 2.0 + render.displacement.x(),
entityPosition.y() - spriteDimension.height() / 2.0 + render.displacement.y(),
spriteDimension.width() * render.scale,
spriteDimension.height() * render.scale);

if (spriteBounds.intersects(visibleArea)) {
spriteBatch.addEntry(
render.sprite,
spriteBounds.origin(),
spriteBounds.origin().add(render.displacement),
render.scale,
render.opacity,
render.rotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class Cherries implements Converter<GameObject> {

private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/cherries.json");
private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/cherries.json", "animation");

@Override
public Entity convert(final GameObject object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DeboB implements Converter<GameObject> {

private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-b.json");
private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-b.json", "animation");

@Override
public Entity convert(final GameObject object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DeboD implements Converter<GameObject> {

private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-d.json");
private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-d.json", "animation");

@Override
public Entity convert(final GameObject object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DeboE implements Converter<GameObject> {

private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-e.json");
private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-e.json", "animation");

@Override
public Entity convert(GameObject object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DeboO implements Converter<GameObject> {

private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-o.json");
private static final Asset<Sprite> SPRITE = spriteAssetFromJson("tilesets/collectables/debo-o.json", "animation");

@Override
public Entity convert(GameObject object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@
"value":true
}],
"renderorder":"right-down",
"tiledversion":"1.8.4",
"tiledversion":"1.10.1",
"tileheight":16,
"tilesets":[
{
Expand All @@ -981,6 +981,6 @@
}],
"tilewidth":16,
"type":"map",
"version":"1.8",
"version":"1.10",
"width":256
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name":"cherries",
"spacing":0,
"tilecount":4,
"tiledversion":"1.5.0",
"tiledversion":"1.10.1",
"tileheight":16,
"tiles":[
{
Expand All @@ -27,9 +27,15 @@
"duration":200,
"tileid":3
}],
"id":0
"id":0,
"properties":[
{
"name":"name",
"type":"string",
"value":"animation"
}]
}],
"tilewidth":10,
"type":"tileset",
"version":1.5
"version":"1.10"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name":"debo-b",
"spacing":0,
"tilecount":3,
"tiledversion":"1.5.0",
"tiledversion":"1.10.1",
"tileheight":16,
"tiles":[
{
Expand All @@ -27,9 +27,15 @@
"duration":200,
"tileid":1
}],
"id":0
"id":0,
"properties":[
{
"name":"name",
"type":"string",
"value":"animation"
}]
}],
"tilewidth":16,
"type":"tileset",
"version":1.5
"version":"1.10"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name":"debo-d",
"spacing":0,
"tilecount":3,
"tiledversion":"1.5.0",
"tiledversion":"1.10.1",
"tileheight":16,
"tiles":[
{
Expand All @@ -27,9 +27,15 @@
"duration":200,
"tileid":1
}],
"id":0
"id":0,
"properties":[
{
"name":"name",
"type":"string",
"value":"animation"
}]
}],
"tilewidth":16,
"type":"tileset",
"version":1.5
"version":"1.10"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name":"debo-e",
"spacing":0,
"tilecount":3,
"tiledversion":"1.5.0",
"tiledversion":"1.10.1",
"tileheight":16,
"tiles":[
{
Expand All @@ -27,9 +27,15 @@
"duration":200,
"tileid":1
}],
"id":0
"id":0,
"properties":[
{
"name":"name",
"type":"string",
"value":"animation"
}]
}],
"tilewidth":16,
"type":"tileset",
"version":1.5
"version":"1.10"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name":"debo-o",
"spacing":0,
"tilecount":3,
"tiledversion":"1.5.0",
"tiledversion":"1.10.1",
"tileheight":16,
"tiles":[
{
Expand All @@ -27,9 +27,15 @@
"duration":200,
"tileid":1
}],
"id":0
"id":0,
"properties":[
{
"name":"name",
"type":"string",
"value":"animation"
}]
}],
"tilewidth":16,
"type":"tileset",
"version":1.5
"version":"1.10"
}

0 comments on commit 5b44d1b

Please sign in to comment.