Skip to content

Commit

Permalink
Merge branch 'queue_test'
Browse files Browse the repository at this point in the history
* queue_test:
  Add a preview animation
  Add a second shadowing character as a test
  • Loading branch information
NixonK committed Dec 31, 2016
2 parents 24c138c + aca1057 commit 6f4fd49
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Binary file added res/preview_animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void Game::Execute(SDL_Renderer *SDLRenderer)
try {
mainPlayer.LoadSpriteTexture(SDLRenderer);

static Player shadowPlayer;
shadowPlayer.LoadSpriteTexture(SDLRenderer);

//SDL_Texture *spriteSheet = LoadTexture("sprite.bmp", SDLRenderer);

clock = SDL_GetTicks();
Expand Down Expand Up @@ -75,6 +78,9 @@ void Game::Execute(SDL_Renderer *SDLRenderer)
keyHandler.GiveInstructions(&mainPlayer);
mainPlayer.UpdateLocRect();

keyHandler.GiveInstructions(&shadowPlayer);
shadowPlayer.UpdateLocRect();

//if (renderDelay >= (FRAME_TIME))
//{
// // render HERE
Expand All @@ -89,6 +95,8 @@ void Game::Execute(SDL_Renderer *SDLRenderer)
SDL_RenderClear(SDLRenderer);
SDL_RenderCopy(SDLRenderer, mainPlayer.GetSpriteSheet(),
&(mainPlayer.GetStateRect()), &(mainPlayer.GetLocRect()));
SDL_RenderCopy(SDLRenderer, shadowPlayer.GetSpriteSheet(),
&(shadowPlayer.GetQueueStateRect()), &(shadowPlayer.GetQueueLocRect()));
SDL_RenderPresent(SDLRenderer);
renderDelay -= (FRAME_TIME);

Expand Down
1 change: 1 addition & 0 deletions src/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
#include<SDL_image.h>
#include<iostream>
#include<string.h>
#include<queue>

#endif
18 changes: 18 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ void Player::UpdateStateRect()
spriteStateRect.y = 0;
else
spriteStateRect.y = SPRITE_HEIGHT;
if (stateQueue.size() == QUEUE_SIZE) {
stateQueue.pop();
}
stateQueue.push(spriteStateRect);
}

void Player::UpdateLocRect()
Expand Down Expand Up @@ -194,6 +198,10 @@ void Player::UpdateLocVariables()
{
spriteLocRect.x = static_cast<int>(locX + 0.5);
spriteLocRect.y = static_cast<int>(locY + 0.5);
if (locationQueue.size() == QUEUE_SIZE) {
locationQueue.pop();
}
locationQueue.push(spriteLocRect);
}

bool Player::IsOffGround()
Expand All @@ -206,11 +214,21 @@ SDL_Rect Player::GetStateRect()
return spriteStateRect;
}

SDL_Rect Player::GetQueueStateRect()
{
return stateQueue.front();
}

SDL_Rect Player::GetLocRect()
{
return spriteLocRect;
}

SDL_Rect Player::GetQueueLocRect()
{
return locationQueue.front();
}

SDL_Texture *Player::GetSpriteSheet()
{
return spriteSheet;
Expand Down
14 changes: 14 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Player : public UserInterface
SDL_Rect spriteStateRect;
SDL_Rect spriteLocRect;

const int QUEUE_SIZE = 10;
std::queue<SDL_Rect> locationQueue;
std::queue<SDL_Rect> stateQueue;

// More precise location x and y values for precision movement calculations.
double locX;
double locY;
Expand Down Expand Up @@ -133,11 +137,21 @@ class Player : public UserInterface
*/
SDL_Rect GetStateRect();

/**
* Return the crop coordinates of the sprite sheet.
*/
SDL_Rect GetQueueStateRect();

/**
* Return the location coordinates of the sprite.
*/
SDL_Rect GetLocRect();

/**
* Return the location coordinates of the sprite at the front of the queue.
*/
SDL_Rect GetQueueLocRect();

/**
* Return the sprite sheet texture.
*/
Expand Down

0 comments on commit 6f4fd49

Please sign in to comment.