11package dev .screwbox .playground ;
22
33import dev .screwbox .core .Angle ;
4+ import dev .screwbox .core .Duration ;
45import dev .screwbox .core .Engine ;
56import dev .screwbox .core .Percent ;
67import dev .screwbox .core .ScrewBox ;
1213import dev .screwbox .core .environment .core .LogFpsSystem ;
1314import dev .screwbox .core .environment .core .TransformComponent ;
1415import dev .screwbox .core .environment .importing .ImportOptions ;
16+ import dev .screwbox .core .environment .light .BackdropOccluderComponent ;
1517import dev .screwbox .core .environment .light .DirectionalLightComponent ;
1618import dev .screwbox .core .environment .light .OccluderComponent ;
1719import dev .screwbox .core .environment .light .PointLightComponent ;
1820import dev .screwbox .core .environment .light .StaticOccluderComponent ;
21+ import dev .screwbox .core .environment .physics .ChaoticMovementComponent ;
1922import dev .screwbox .core .environment .physics .ColliderComponent ;
2023import dev .screwbox .core .environment .physics .CollisionDetailsComponent ;
2124import dev .screwbox .core .environment .physics .CollisionSensorComponent ;
2427import dev .screwbox .core .environment .physics .PhysicsComponent ;
2528import dev .screwbox .core .environment .physics .StaticColliderComponent ;
2629import dev .screwbox .core .environment .rendering .RenderComponent ;
30+ import dev .screwbox .core .environment .softphysics .RopeOccluderComponent ;
31+ import dev .screwbox .core .environment .softphysics .RopeRenderComponent ;
32+ import dev .screwbox .core .environment .softphysics .SoftBodyOccluderComponent ;
33+ import dev .screwbox .core .environment .softphysics .SoftBodyRenderComponent ;
34+ import dev .screwbox .core .environment .softphysics .SoftPhysicsSupport ;
2735import dev .screwbox .core .graphics .Color ;
2836import dev .screwbox .core .graphics .Sprite ;
37+ import dev .screwbox .core .graphics .options .ShadowOptions ;
2938import dev .screwbox .core .utils .TileMap ;
39+ import dev .screwbox .playground .misc .InteractionSystem ;
3040
3141import static dev .screwbox .core .Vector .$ ;
3242
@@ -39,13 +49,18 @@ public static void main(String[] args) {
3949 .move ($ (40 , 40 ))
4050 .setZoom (4 );
4151 engine .loop ().unlockFps ();
52+
4253 engine .graphics ().configuration ().setLightQuality (Percent .half ());
4354 var map = TileMap .fromString ("""
4455 O O
4556 P # ### ##
46- # ## O
47- O ##
48- ### ######
57+ # RRR## O
58+ T O ##
59+
60+
61+
62+
63+ ############ ######
4964 """ );
5065 engine .environment ()
5166 .enableAllFeatures ()
@@ -66,22 +81,41 @@ public static void main(String[] args) {
6681 .add (new StaticColliderComponent ())
6782 .add (new RenderComponent (Sprite .placeholder (Color .GREY , 16 )))
6883 )
84+ .assignComplex ('T' , (tile , idPool ) -> {
85+ var body = SoftPhysicsSupport .createSoftBody (tile .bounds ().expand (-2 ), idPool );
86+ body .root ().add (new SoftBodyRenderComponent (Color .ORANGE .opacity (0.5 )), r -> r .outlineColor = Color .ORANGE );
87+ body .root ().add (new SoftBodyOccluderComponent (ShadowOptions .rounded ().backdropDistance (0.4 ).distortion (Percent .of (0.04 ))));
88+ body .forEach (node -> node .get (PhysicsComponent .class ).friction = 2 );
89+ body .forEach (node -> node .add (new LeftRightControlComponent ()));
90+ body .forEach (node -> node .add (new JumpControlComponent ()));
91+ return body ;
92+ })
93+ .assignComplex ('R' , (tile , idPool ) -> {
94+ var rope = SoftPhysicsSupport .createRope (tile .position ().addY (tile .size ().height () / -2.0 ), tile .position ().addY (20 ), 9 , idPool );
95+ rope .forEach (node -> node .get (PhysicsComponent .class ).friction = 2 );
96+ rope .forEach (node -> node .add (new ChaoticMovementComponent (400 , Duration .ofMillis (800 ))));
97+ rope .root ()
98+ .add (new RopeOccluderComponent (ShadowOptions .angular ().backdropDistance (0.45 )))
99+ .add (new RopeRenderComponent (Color .WHITE , 1.25 ))
100+ .remove (PhysicsComponent .class );
101+ return rope ;
102+ })
69103 .assign ('P' , tile -> new Entity ().bounds (tile .bounds ().expand (-8 ))
70- .add (new StaticOccluderComponent ())
71- .add (new OccluderComponent (false ))
72104 .add (new PhysicsComponent (), p -> p .friction = 3 )
73105 .add (new LeftRightControlComponent ())
106+ .add (new BackdropOccluderComponent (ShadowOptions .angular ().backdropDistance (0.75 )))
74107 .add (new JumpControlComponent (), j -> j .acceleration = 300 )
75108 .add (new CollisionSensorComponent ())
76109 .add (new CollisionDetailsComponent ())
77110 .add (new SuspendJumpControlComponent (), s -> s .maxJumps = 2 )
78111 .add (new RenderComponent (Sprite .placeholder (Color .YELLOW , 8 )))))
79112 .addEntity (new Entity ().add (new GravityComponent (Vector .y (500 ))))
80113 .addSystem (new LogFpsSystem ())
81- .addEntity (new Entity (). add ( new TransformComponent ()). add ( new CursorAttachmentComponent ()). add ( new PointLightComponent ( 80 , Color . BLACK ) ))
82- .addEntity (new Entity ().bounds ( map . bounds (). expand ( 1000 )).add (new DirectionalLightComponent (), d -> d . angle = Angle . degrees (- 10 )))
114+ .addSystem (new InteractionSystem ( ))
115+ .addEntity (new Entity ().add ( new TransformComponent ( 0 , 0 , 120 , 40 )). add ( new CursorAttachmentComponent ( )).add (new PointLightComponent ( 60 , Color . BLACK )))
83116 .addSystem (e -> e .environment ().tryFetchSingletonComponent (DirectionalLightComponent .class ).ifPresent (d -> d .angle = Angle .degrees (e .mouse ().position ().x () / 4 )))
84- .addSystem (e -> e .graphics ().canvas ().fillWith (Color .BLUE ));
117+ .addSystem (e -> e .graphics ().canvas ().fillWith (Color .BLUE ))
118+ .addSystem (e -> e .graphics ().camera ().setZoom (e .graphics ().camera ().zoom () + e .mouse ().unitsScrolled () / 10.0 ));
85119
86120 engine .start ();
87121 }
0 commit comments