Added inputSystem

This commit is contained in:
Gulum
2017-10-24 15:58:03 +02:00
parent eb5c1e4ec3
commit 70857cb258
10 changed files with 171 additions and 19 deletions

View File

@@ -2,17 +2,14 @@
#include <SDL2/SDL_image.h>
#include "DarkRP2D.h"
#include "utility/utility.h"
#include "utility/Utility.h"
void DarkRP2D::create(SDL_Renderer *gRenderer) {
void DarkRP2D::create(SDL_Renderer *gRenderer, InputHandler *inputHandler) {
this->gRenderer = gRenderer;
this->inputHandler = inputHandler;
//Load PNG texture
gTexture = utility::loadTexture( "assets/police_officer.png", gRenderer);
}
}
unsigned int ups = 0;
unsigned int acc = 0;
@@ -20,7 +17,10 @@
accumulator += deltaTime;
acc += deltaTime;
//Process Input
Command *command = inputHandler->handleInput();
if (command) {
command->execute();
}
skippedFrames = 0;
while (accumulator >= MS_PER_UPDATE && skippedFrames <= MAX_FRAMESKIP) {
@@ -46,8 +46,14 @@
//Clear screen
SDL_RenderClear( gRenderer );
SDL_Rect textureRect; //create a rect
textureRect.x = 0; //controls the rect's x coordinate
textureRect.y = 0; // controls the rect's y coordinte
textureRect.w = 64; // controls the width of the rect
textureRect.h = 64; // controls the height of the rect
//Render texture to screen
SDL_RenderCopy( gRenderer, gTexture, NULL, NULL );
SDL_RenderCopy( gRenderer, gTexture, NULL, &textureRect );
//Update screen
SDL_RenderPresent( gRenderer );
@@ -57,8 +63,8 @@
}
void DarkRP2D::dispose() {
//Free loaded image
SDL_DestroyTexture( gTexture );
gTexture = NULL;
DarkRP2D::~DarkRP2D() {
//Free loaded image
SDL_DestroyTexture( gTexture );
gTexture = NULL;
}