From 456ef376530fc4644732d499c862f1413b9987d9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 5 Aug 2024 15:47:55 -0400 Subject: level solid; basic collision/gravity --- include/components/texture.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'include/components/texture.hpp') diff --git a/include/components/texture.hpp b/include/components/texture.hpp index f4d414e..14253f1 100644 --- a/include/components/texture.hpp +++ b/include/components/texture.hpp @@ -1,6 +1,7 @@ #ifndef COMPONENTS_TEXTURE_HPP #define COMPONENTS_TEXTURE_HPP +#include "components/point.hpp" #include "window.hpp" class Texture @@ -8,6 +9,8 @@ class Texture public: Texture(const char *path) { tex = sdl2LoadTexture(path); + if (tex) + SDL_QueryTexture(tex, nullptr, nullptr, &w, &h); } ~Texture() { @@ -18,15 +21,18 @@ public: void operator()(SDL_Renderer *rend, Point p) const noexcept { const int x = static_cast(p.x); const int y = static_cast(p.y); - SDL_Rect rect {x, y, 0, 0}; + SDL_Rect rect {x, y, w, h}; - /* TODO err check */ - SDL_QueryTexture(tex, nullptr, nullptr, &rect.w, &rect.h); SDL_RenderCopy(rend, tex, nullptr, &rect); } + Point dim() const noexcept { + return Point {static_cast(w), static_cast(h)}; + } + private: SDL_Texture *tex; + int w, h; }; #endif // COMPONENTS_TEXTURE_HPP -- cgit v1.2.3