From fc534fd8e1309525909112f1e269529d2f3f6798 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Mon, 2 Oct 2023 15:03:07 +0200 Subject: [PATCH] Handle rendering of Rigids --- source/game.d | 5 ++++- source/utils/shapes.d | 10 ++++++++++ source/world/entity.d | 7 +++++++ source/world/package.d | 7 +++++++ source/world/rigid.d | 25 +++++++++++++++++++++++++ source/world/screen.d | 9 +++++++++ source/world/world_object.d | 12 ++++++++++++ 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 source/utils/shapes.d create mode 100644 source/world/entity.d create mode 100644 source/world/package.d create mode 100644 source/world/rigid.d create mode 100644 source/world/screen.d create mode 100644 source/world/world_object.d diff --git a/source/game.d b/source/game.d index 4c77d13..231e795 100644 --- a/source/game.d +++ b/source/game.d @@ -9,6 +9,7 @@ import std.format; import std.conv : to; import core.time; import toki.symbols; +import world.screen; extern(C) __gshared string[] rt_options = [ "gcopt=initReserve:128 minPoolSize:256 parallel:2 profile:1" ]; @@ -17,6 +18,9 @@ int main(string[] args) { try { InitWindow(800,600,"Unnamed project"); log(LogLevel.INFOHIGH, "Window Initialized..."); + Screen.x = Screen.y = 0; + Screen.width = Screen.px_width = 800; + Screen.height = Screen.px_height = 600; log(LogLevel.INFOHIGH, "Readying the engine..."); GrEngine engine = new GrEngine(); auto grstd = grLoadStdLibrary(); @@ -37,7 +41,6 @@ int main(string[] args) { engine.load(bytecode); log(LogLevel.INFOHIGH, "Go Hot Dog, Go..."); engine.process(); - Toki[] p = convert("toki pona"); auto reference = MonoTime.currTime(); auto deltaTime = 1f/60f; diff --git a/source/utils/shapes.d b/source/utils/shapes.d new file mode 100644 index 0000000..80dd14d --- /dev/null +++ b/source/utils/shapes.d @@ -0,0 +1,10 @@ +module utils.shapes; + +public struct Vec2f { + float x,y; +} + +public struct Rectf { + float x, y; + float width, height; +} \ No newline at end of file diff --git a/source/world/entity.d b/source/world/entity.d new file mode 100644 index 0000000..b0f5977 --- /dev/null +++ b/source/world/entity.d @@ -0,0 +1,7 @@ +module world.entity; + +import world.world_object; + +class Entity : WorldObject { + +} \ No newline at end of file diff --git a/source/world/package.d b/source/world/package.d new file mode 100644 index 0000000..808dae5 --- /dev/null +++ b/source/world/package.d @@ -0,0 +1,7 @@ +module world; + +public { + import world.world_object; + import world.entity; + import world.rigid; +} \ No newline at end of file diff --git a/source/world/rigid.d b/source/world/rigid.d new file mode 100644 index 0000000..13d16d5 --- /dev/null +++ b/source/world/rigid.d @@ -0,0 +1,25 @@ +module world.rigid; + +import world.world_object; +import world.screen; +import raylib; +import std.conv; + +class Rigid : WorldObject { + Texture2D sprite; + + override void render(float) { + if(IsTextureReady(sprite)){ + // Get position + int drawX = to!int(Screen.px_width*(position.x + hitbox.x - Screen.x)/Screen.width); + int drawY = to!int(Screen.px_height*(position.y + hitbox.y - Screen.y)/Screen.height); + float scale = Screen.px_height/Screen.height; + + // Culling + if(drawX > Screen.width || drawX + sprite.width*scale < 0) return; + if(drawY > Screen.height || drawY + sprite.height*scale < 0) return; + + DrawTextureEx(sprite, Vector2(drawX, drawY), 0, scale, Colors.WHITE); + } + } +} \ No newline at end of file diff --git a/source/world/screen.d b/source/world/screen.d new file mode 100644 index 0000000..36fd95f --- /dev/null +++ b/source/world/screen.d @@ -0,0 +1,9 @@ +module world.screen; + +public ScreenT Screen; + +struct ScreenT { + float x,y; + float width, height; + int px_width, px_height; +} \ No newline at end of file diff --git a/source/world/world_object.d b/source/world/world_object.d new file mode 100644 index 0000000..a3e7b9e --- /dev/null +++ b/source/world/world_object.d @@ -0,0 +1,12 @@ +module world.world_object; + +import utils.shapes; + + +class WorldObject { + public Vec2f position; + public Rectf hitbox; + + void update(float deltaTime); + void render(float deltaTime); +} \ No newline at end of file