Skip to content

Fix array indexing when no record is selected #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Timeless Recordplayer/Timeless Recordplayer/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,19 @@ void Game::update(sf::Time t_deltaTime)
checkVinylPlayerCollision(); // checks if vinyl is on record player - plays music if true
checkVinylAlbumCollision();

if (albums[m_albumRevealed].m_revealAlbum &&
albums[m_albumRevealed].m_revealedBy < albums[m_albumRevealed].MAX_REVEAL_BY) // moves up record until revealed or switched
{
albums[m_albumRevealed].moveUp();
albums[m_albumRevealed].m_revealedBy++;
}
else if (albums[m_albumRevealed].m_revealedBy == albums[m_albumRevealed].MAX_REVEAL_BY)
{
if (!m_holdingVinyl)
if (m_albumRevealed != NO_ALBUM_REVEALED) {
if (albums[m_albumRevealed].m_revealAlbum &&
albums[m_albumRevealed].m_revealedBy < albums[m_albumRevealed].MAX_REVEAL_BY) // moves up record until revealed or switched
{
albums[m_albumRevealed].moveUp();
albums[m_albumRevealed].m_revealedBy++;
}
else if (albums[m_albumRevealed].m_revealedBy == albums[m_albumRevealed].MAX_REVEAL_BY)
{
m_instructions.setString("CLICK THE CHOSEN COVER TO TAKE THE VINYL OUT");
if (!m_holdingVinyl)
{
m_instructions.setString("CLICK THE CHOSEN COVER TO TAKE THE VINYL OUT");
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Timeless Recordplayer/Timeless Recordplayer/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class Game
sf::Vector2f m_mouseEndVector; // converts to vector
sf::CircleShape m_mouseDot{1.0f}; // used to check collisions


int m_albumRevealed = -1; // tracking the album currently revealed
static constexpr int NO_ALBUM_REVEALED = -1; // magical constant for no album revealed
int m_albumRevealed = NO_ALBUM_REVEALED; // tracking the album currently revealed
bool m_holdingVinyl = false; // if the vinyl is held

bool m_mouseReleased = true; // if mouse is released or not
Expand Down