From 61e382cedd71127033f91551298607e2e78c3809 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 18 Sep 2024 15:11:04 +0200 Subject: gameloop save --- gameloop/src/window.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'gameloop/src/window.cpp') 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() ) { @@ -8,28 +7,41 @@ 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 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; -- cgit v1.2.3