Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Cave-Crawler/GameManager.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
79 lines (64 sloc)
1.53 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "GameManager.h" | |
#include <iostream> | |
#include "TextureManager.h" | |
#include "Components.h" | |
#include "Vector2D.h" | |
SDL_Renderer* GameManager::render = nullptr; | |
Manager manager; | |
auto& newCharacter(manager.addEntity()); | |
GameManager::GameManager() | |
{} | |
GameManager::~GameManager() | |
{} | |
void GameManager::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) { | |
std::cout << "Subsystems Initialized!" << std::endl; | |
window = SDL_CreateWindow(title, xpos, ypos, width, height, flags); | |
if (window) { | |
std::cout << "Window created!" << std::endl; | |
} | |
render = SDL_CreateRenderer(window, -1, 0); | |
if (render) { | |
SDL_SetRenderDrawColor(render, 255, 255, 255, 255); | |
std::cout << "Render created!" << std::endl; | |
} | |
isRunning = true; | |
} | |
newCharacter.addComp<TransformComp>(); | |
newCharacter.addComp<SpriteComp>("assets/player3.png"); | |
} | |
void GameManager::handleEvents() | |
{ | |
SDL_Event event; | |
SDL_PollEvent(&event); | |
switch (event.type) { | |
case SDL_QUIT: | |
isRunning = false; | |
break; | |
default: | |
break; | |
} | |
} | |
void GameManager::update() | |
{ | |
manager.refresh(); | |
manager.update(); | |
} | |
void GameManager::renderer() | |
{ | |
SDL_RenderClear(render); | |
manager.draw(); | |
SDL_RenderPresent(render); | |
} | |
void GameManager::clean() | |
{ | |
SDL_DestroyWindow(window); | |
SDL_DestroyRenderer(render); | |
SDL_Quit(); | |
std::cout << "Game cleaned!" << std::endl; | |
} | |