Created
August 14, 2020 05:47
-
-
Save schosin/c3b4d3da65a7c3c7aa2c86c0750827f7 to your computer and use it in GitHub Desktop.
Example of a movement system in artemis-odb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @All({ Position.class, Velocity.class }) | |
| public class MovementSystem extends IteratingSystem { | |
| // Component mappers | |
| private ComponentMapper<Position> posM; | |
| private ComponentMapper<Velocity> velocityM; | |
| @Override | |
| protected void process(int entityId) { | |
| var velocity = velocityM.get(entityId); | |
| if (velocity.moving()) { | |
| var pos = posM.get(entityId); | |
| pos.translate(velocity.vx() * world.delta, velocity.vy() * world.delta); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Data | |
| public class Position extends PooledComponent { | |
| private boolean immutable; | |
| private float x, y; | |
| public Position translate(float x, float y) { | |
| this.x += x; | |
| this.y += y; | |
| return this; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Data | |
| public class Velocity extends PooledComponent { | |
| private float vx, vy; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment