diff options
Diffstat (limited to 'gameloop/src/window.cpp')
-rw-r--r-- | gameloop/src/window.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/gameloop/src/window.cpp b/gameloop/src/window.cpp index 11424dd..f998a79 100644 --- a/gameloop/src/window.cpp +++ b/gameloop/src/window.cpp @@ -1,5 +1,4 @@ #include "window.h" - WindowManager::WindowManager(){ if( !initWindow() ) { @@ -9,27 +8,40 @@ WindowManager::WindowManager(){ WindowManager::~WindowManager(){ destroyWindow(); } -bool WindowManager::init() -{ -} -bool WindowManager::loadMedia() -{ -} -void WindowManager::close() -{ - -} SDL_Renderer* WindowManager::getRenderer(){ return renderer; } -void WindowManager::update(){ + +void WindowManager::render(std::vector<GameObject*> objects){ + // Set the draw color to black and clear the screen + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); + SDL_RenderClear(renderer); + + // Print object position (optional for debugging) + //fprintf(stderr, "%d\n", objectList.size()); + for(int i = 0; i < objects.size();i++){ + //fprintf(stderr, "%f\n", objectList[i]->getX()); + // Create a rectangle representing the ball + SDL_Rect ball_rect = { + (int)objects[i]->getX(), + (int)objects[i]->getY(), + (int)objects[i]->getWidth(), + (int)objects[i]->getHeight(), + }; + // Set the draw color to white and render the ball + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderFillRect(renderer, &ball_rect); + } + + SDL_RenderPresent(renderer); } + bool WindowManager::initWindow(){ if(SDL_Init(SDL_INIT_EVERYTHING) != 0){ fprintf(stderr,"Error inititalising SDL.\n"); return false; } - window = SDL_CreateWindow("Gameloop POC",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,SCREEN_WIDTH,SCREEN_HEIGHT,SDL_WINDOW_RESIZABLE); + window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); if(!window){ fprintf(stderr,"Error creating SDL Window. \n"); return false; |