This repository has been archived on 2024-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
game-project/source/world/rigid.d

25 lines
789 B
D
Raw Permalink Normal View History

2023-10-02 13:03:07 +00:00
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);
}
}
}