0

I mainly am trying to create a simple window to a game but can't figure out where I'm going wrong or what I need to delete. From looking around there was on one answer that I could possibly pin point what may be going wrong but I am still fairly new to this and would like better direction than YouTube.

main.cpp

#include "Game.h"

Game* game = NULL;

int main(int argc, char args[]) {

game = new Game();

game->init("A Fun Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);

while (game->running()) {

    game->handleEvents();
    game->update();
    game->render();

}
game->clean();

return 0;
}

Game.cpp

#include "Game.h"

using namespace std;

Game::Game()
{}
Game::~Game()
{}

void Game::init(const char* title,int xpos, int ypos, int width, int height,bool fullscreen)
{
int flags = 0;
if (fullscreen)
{
    flags = SDL_WINDOW_FULLSCREEN;
}


if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
    cout << "subsystems, initialized" << endl;

    window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
    if (window) {
        cout << "window created!" << endl;
    }
    renderer = SDL_CreateRenderer(window, -1, 0);
    if (renderer) {
        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
            cout << "renderer created!" << endl;
    }
    isRunning = true;
}else{
    isRunning = false;
}
}

void Game::handleEvents()
{
SDL_Event event;
SDL_PollEvent(&event);
switch (event.type) {
case SDL_QUIT:
    isRunning = false;
    break;

default:
    break;
}
}

void Game::update()
{}

void Game::render()
{
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}

void Game::clean()
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit;
cout << "Game Cleaned!" << endl;
}

Game.hpp

#ifndef Game_h
#define Game_h
#include <SDL.h>
#include <iostream>

class Game {

public:
Game();
~Game();

void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);

void handleEvents();
void update();
void render();
void clean();

bool running() { return isRunning; }

private:
bool isRunning;
SDL_Window* window;
SDL_Renderer* renderer;

};
#endif

I tried checking in properties to see in I linked my libraries to the file incorrectly but everything that I've seen looks right.

halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0