Compare commits
3 commits
21502a5854
...
db90d6bd03
Author | SHA1 | Date | |
---|---|---|---|
|
db90d6bd03 | ||
|
ce09bd79e9 | ||
|
fc534fd8e1 |
7 changed files with 86 additions and 1 deletions
|
@ -9,14 +9,19 @@ import std.format;
|
|||
import std.conv : to;
|
||||
import core.time;
|
||||
import toki.symbols;
|
||||
import world;
|
||||
|
||||
|
||||
extern(C) __gshared string[] rt_options = [ "gcopt=initReserve:128 minPoolSize:256 parallel:2 profile:1" ];
|
||||
|
||||
int main(string[] args) {
|
||||
try {
|
||||
worldContents = new WorldObjectList;
|
||||
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 +42,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;
|
||||
|
@ -55,6 +59,12 @@ int main(string[] args) {
|
|||
log(LogLevel.INFOLOW, "Render start...");
|
||||
BeginDrawing();{
|
||||
ClearBackground(Colors.WHITE);
|
||||
|
||||
foreach (obj; worldContents)
|
||||
{
|
||||
obj.render(deltaTime);
|
||||
}
|
||||
|
||||
DrawFPS(0,0);
|
||||
auto pos = GetMousePosition();
|
||||
DrawText(toStringz(format("%f, %f", pos.x, pos.y)), 0, 24, 20, Colors.GREEN);
|
||||
|
|
10
source/utils/shapes.d
Normal file
10
source/utils/shapes.d
Normal file
|
@ -0,0 +1,10 @@
|
|||
module utils.shapes;
|
||||
|
||||
public struct Vec2f {
|
||||
float x,y;
|
||||
}
|
||||
|
||||
public struct Rectf {
|
||||
float x, y;
|
||||
float width, height;
|
||||
}
|
7
source/world/entity.d
Normal file
7
source/world/entity.d
Normal file
|
@ -0,0 +1,7 @@
|
|||
module world.entity;
|
||||
|
||||
import world.world_object;
|
||||
|
||||
class Entity : WorldObject {
|
||||
|
||||
}
|
10
source/world/package.d
Normal file
10
source/world/package.d
Normal file
|
@ -0,0 +1,10 @@
|
|||
module world;
|
||||
|
||||
public {
|
||||
import world.world_object;
|
||||
import world.entity;
|
||||
import world.rigid;
|
||||
import world.screen;
|
||||
|
||||
WorldObjectList worldContents;
|
||||
}
|
25
source/world/rigid.d
Normal file
25
source/world/rigid.d
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
9
source/world/screen.d
Normal file
9
source/world/screen.d
Normal file
|
@ -0,0 +1,9 @@
|
|||
module world.screen;
|
||||
|
||||
public ScreenT Screen;
|
||||
|
||||
struct ScreenT {
|
||||
float x,y;
|
||||
float width, height;
|
||||
int px_width, px_height;
|
||||
}
|
14
source/world/world_object.d
Normal file
14
source/world/world_object.d
Normal file
|
@ -0,0 +1,14 @@
|
|||
module world.world_object;
|
||||
|
||||
import utils.shapes;
|
||||
import utils.indexedarray;
|
||||
|
||||
alias WorldObjectList = IndexedArray!(WorldObject, 1<<15);
|
||||
|
||||
class WorldObject {
|
||||
public Vec2f position;
|
||||
public Rectf hitbox;
|
||||
|
||||
abstract void update(float deltaTime);
|
||||
abstract void render(float deltaTime);
|
||||
}
|
Reference in a new issue