aboutsummaryrefslogtreecommitdiff
path: root/gameloop/src/window.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-09-18 15:11:04 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-09-18 15:11:04 +0200
commit61e382cedd71127033f91551298607e2e78c3809 (patch)
treedb946bf0dac5cbb504ac7875fb323243d2a6db74 /gameloop/src/window.cpp
parent7eafe293868d5d3875d0bec147e22a266e4ec86c (diff)
gameloop save
Diffstat (limited to 'gameloop/src/window.cpp')
-rw-r--r--gameloop/src/window.cpp38
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;