From e9e4485dd41c08a6c5196fa038b178c3691fae59 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 25 Jan 2021 17:00:43 -0500 Subject: [PATCH] refactor square to extend vector2 --- main.cpp | 2 +- stuff/objects/square.h | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index e34b4a0..0542846 100644 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char** argv) surface = SDL_GetWindowSurface(window); SDL_Event eventHandler; - global::entList.push_back(square(200, 200, 50, 50)); + global::entList.push_back(square(200, 200, 50)); while (global::running) { diff --git a/stuff/objects/square.h b/stuff/objects/square.h index 2e4d823..fd09fc8 100644 --- a/stuff/objects/square.h +++ b/stuff/objects/square.h @@ -1,25 +1,28 @@ #pragma once #include "SDL.h" -struct square +#include "vector2.h" +/* +squares are the basic 2D entity +*/ +struct square : public vector2 { - SDL_Rect rect; + int radius; square() { - rect.x = 0; - rect.y = 0; - rect.w = 0; - rect.h = 0; + this->x = 0; + this->y = 0; + this->radius = 0; } - square(int x_, int y_, int w_, int h_) + square(int x_, int y_, int radius_) { - rect.x = x_; - rect.y = y_; - rect.w = w_; - rect.h = h_; + this->x = x_; + this->y = y_; + this->radius = radius_; } void run(SDL_Surface* surface) { - SDL_FillRect(surface, &this->rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF)); + SDL_Rect rect{ this->x, this->y, this->radius, this->radius }; + SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF)); } }; \ No newline at end of file