Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#include "GameH.h"
#include <iostream>
#include "SDL.h"
#include "ObjectH.h"
Game::Game()
{
}
Game::~Game()
{
}
void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
{
//// Sets the Full Screen Mode ////
int _flags = 0;
if (fullscreen)
{
_flags = SDL_WINDOW_FULLSCREEN;
}
//// Checks if is Everythin running ////
if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
std::cout << "Initializing Subsystems!" << std::endl;
window = SDL_CreateWindow(title, xpos, ypos, width, height, _flags);
if (window)
{
std::cout << "Window Created!" << std::endl;
}
if (!window)
{
std::cout << "Window Closed!" << std::endl;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer)
{
SDL_SetRenderDrawColor(renderer, 200, 24, 43, 0);
peppa.setDest(50, 50, 75, 75);
peppa.setSource(0, 0, 75, 75);
peppa.setImage("peppa.png", renderer);
std::cout << "Renderer Created!" << std::endl;
}
isRunning = true;
effect.load("Drum.wav");
}
else
{
isRunning = false;
}
}
void Game::handleEvents()
{
SDL_Event event;
SDL_PollEvent(&event);
switch (event.type)
{
case SDL_QUIT:
isRunning = false;
std::cout << "Quitting!!!" << std::endl;
break;
default:
break;
}
////INPUTS////
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)isRunning = false;
if (event.key.keysym.sym == SDLK_o) effect.play();
if (event.key.keysym.sym == SDLK_p) effect.stop();
}
SDL_GetMouseState(&mousex, &mousey);
////INPUTS////
}
void Game::update()
{
//// gives the mouse position ////
std::cout << mousex << " , " << mousey << std::endl;
}
void Game::render()
{
SDL_RenderClear(renderer);
////render things////
draw(peppa);
SDL_RenderPresent(renderer);
}
void Game::clean()
{
////Clean Everything////
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_Quit();
std::cout << "Game Cleaned" << std::endl;
}
//// draw ////
void Game::draw(Object o)
{
SDL_Rect dest = o.getDest();
SDL_Rect src = o.getSource();
SDL_RenderCopyEx(renderer, o.getTex(), &src, &dest, 0, NULL, SDL_FLIP_NONE);
}