diff options
Diffstat (limited to 'src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java')
-rw-r--r-- | src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java b/src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java index 9338888..362e680 100644 --- a/src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java +++ b/src/main/java/fr/umlv/java/wallj/block/GarbageBlock.java | |||
@@ -2,19 +2,17 @@ package fr.umlv.java.wallj.block; | |||
2 | 2 | ||
3 | import fr.umlv.java.wallj.board.TileVec2; | 3 | import fr.umlv.java.wallj.board.TileVec2; |
4 | import fr.umlv.java.wallj.context.Context; | 4 | import fr.umlv.java.wallj.context.Context; |
5 | import fr.umlv.java.wallj.context.GraphicsContext; | 5 | import fr.umlv.java.wallj.context.Updateables; |
6 | import fr.umlv.java.wallj.event.BombExplosionEvent; | 6 | import fr.umlv.java.wallj.event.BombExplosionEvent; |
7 | import fr.umlv.java.wallj.event.Event; | 7 | import fr.umlv.java.wallj.event.Event; |
8 | import fr.umlv.java.wallj.event.Events; | 8 | import fr.umlv.java.wallj.event.Events; |
9 | import org.jbox2d.common.Vec2; | 9 | import org.jbox2d.common.Vec2; |
10 | import org.jbox2d.dynamics.BodyType; | 10 | import org.jbox2d.dynamics.BodyType; |
11 | import org.jbox2d.dynamics.Fixture; | 11 | import org.jbox2d.dynamics.Fixture; |
12 | import org.jbox2d.dynamics.World; | ||
13 | 12 | ||
14 | import java.awt.*; | 13 | import java.awt.*; |
15 | import java.util.Collections; | ||
16 | import java.util.List; | ||
17 | import java.util.Objects; | 14 | import java.util.Objects; |
15 | import java.util.stream.Stream; | ||
18 | 16 | ||
19 | /** | 17 | /** |
20 | * A garbage block. | 18 | * A garbage block. |
@@ -31,24 +29,26 @@ public class GarbageBlock extends JBoxBlock { | |||
31 | } | 29 | } |
32 | 30 | ||
33 | @Override | 31 | @Override |
34 | public List<Event> update(Context context) { | 32 | public Stream<Event> update(Context context) { |
35 | handleExplosionBlasts(context.getEvents(), context.getGame().getCurrentStage().getWorld()); | 33 | return Updateables.updateAll(context, |
36 | paint(context.getGraphicsContext()); | 34 | this::handleExplosionBlasts, |
37 | return Collections.emptyList(); | 35 | this::paint); |
38 | } | 36 | } |
39 | 37 | ||
40 | private void handleExplosionBlasts(List<Event> events, World world) { | 38 | private Stream<Event> handleExplosionBlasts(Context context) { |
41 | Events.filter(events, BombExplosionEvent.class).forEach(explosion -> { | 39 | Events.filter(context.getEvents(), BombExplosionEvent.class).forEach(explosion -> { |
42 | Vec2 source = explosion.getSource().toVec2(); | 40 | Vec2 source = explosion.getSource().toVec2(); |
43 | world.raycast((fixture, point, normal, fraction) -> { | 41 | context.getGame().getCurrentStage().getWorld().raycast((fixture, point, normal, fraction) -> { |
44 | if (isSelf(fixture)) getBody().applyForceToCenter(computeBlastForce(source)); | 42 | if (isSelf(fixture)) getBody().applyForceToCenter(computeBlastForce(source)); |
45 | return STOP_RAYCAST; | 43 | return STOP_RAYCAST; |
46 | }, source, getPos()); | 44 | }, source, getPos()); |
47 | }); | 45 | }); |
46 | return Stream.empty(); | ||
48 | } | 47 | } |
49 | 48 | ||
50 | private void paint(GraphicsContext graphicsContext) { | 49 | private Stream<Event> paint(Context context) { |
51 | graphicsContext.paintCircle(COLOR, getPos(), TileVec2.TILE_DIM); | 50 | context.getGraphicsContext().paintCircle(COLOR, getPos(), TileVec2.TILE_DIM); |
51 | return Stream.empty(); | ||
52 | } | 52 | } |
53 | 53 | ||
54 | private boolean isSelf(Fixture fixture) { | 54 | private boolean isSelf(Fixture fixture) { |