1 /** scene with 2d rendering */
2 
3 module re.ng.scene2d;
4 
5 static import raylib;
6 public import raylib : Camera2D;
7 import re.ng.camera;
8 import re;
9 import std.string;
10 import re.ecs;
11 import re.math;
12 
13 /// represents a scene rendered in 2d
14 abstract class Scene2D : Scene {
15     /// the 2d scene camera
16     public SceneCamera2D cam;
17 
18     override void setup() {
19         super.setup();
20 
21         // create a camera entity
22         auto camera_nt = create_entity("camera");
23         cam = camera_nt.add_component(new SceneCamera2D());
24     }
25 
26     void render_renderable(Component component) {
27         auto renderable = cast(Renderable2D) component;
28         assert(renderable !is null, "renderable was not 2d");
29         renderable.render();
30         if (Core.debug_render) {
31             renderable.debug_render();
32         }
33     }
34 
35     override void render_scene() {
36         raylib.BeginMode2D(cam.camera);
37 
38         // render 2d components
39         foreach (component; ecs.storage.renderable_components) {
40             render_renderable(component);
41         }
42         foreach (component; ecs.storage.updatable_renderable_components) {
43             render_renderable(component);
44         }
45 
46         render_hook();
47 
48         raylib.EndMode2D();
49     }
50 
51     override void update() {
52         super.update();
53 
54         cam.update();
55     }
56 }