Skip to content

Commit

Permalink
Jukebox
Browse files Browse the repository at this point in the history
Barebones, but functional.
  • Loading branch information
TheWindowsPro98 committed Sep 17, 2023
1 parent dc25080 commit b2c6f91
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9)
project(project_daisy LANGUAGES CXX VERSION 0.0.1.0)
link_libraries(sfml-window sfml-graphics sfml-audio sfml-system)
add_executable(project_daisy main.cxx version.cxx resources.cxx prefs.cxx utils.cxx structs.cxx title.cxx)
add_executable(project_daisy main.cxx version.cxx resources.cxx prefs.cxx utils.cxx structs.cxx title.cxx jukebox.cxx)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ It's a PC game thing.

- A working C++ compiler

- I personally use Clang++, but g++ should work too.
- I personally use Clang++, but g++ should work too. MSVC++ compatibility not guaranteed.

- [CMake](https://cmake.org/)

Expand Down
1 change: 1 addition & 0 deletions credits.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Sonic Advance 2 - Character Select Theme: Tatsuyuki Maeda, Yutaka Minobe, Teruhiko Nakagawa, Hironobu Inagaki, Atsuyoshi Isemura (temporary)
Sonic Advance 2 - Zone Select Theme: Tatsuyuki Maeda, Yutaka Minobe, Teruhiko Nakagawa, Hironobu Inagaki, Atsuyoshi Isemura (temporary)
Sonic the Hedgehog 3 - Angel Island Zone (Act 2): Jun Senoue, Tetsuyuki Maeda, Masaru Setsumaru, Tomonori Sawada, Masayuki Nagao, Sachio Ogawa, Howard Drossin (temporary)
1 change: 1 addition & 0 deletions inc/includes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
#include "version.hxx"
#include "structs.hxx"
#include "title.hxx"
#include "jukebox.hxx"
#include "prefs.hxx"
#include "utils.hxx"
5 changes: 5 additions & 0 deletions inc/jukebox.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "includes.hxx"

void jukebox();
13 changes: 12 additions & 1 deletion inc/structs.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ namespace structs
std::string label;
~Option();
};
}
class SndMData
{
public:
std::string songPath;
std::string songTitle;
std::string songAlbum;
std::string songArtist;
bool loop;
bool isSFX;
~SndMData();
};
}
4 changes: 3 additions & 1 deletion inc/utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ extern sf::SoundBuffer sbHvr;
extern sf::Sound sndHvr;
extern sf::SoundBuffer sbCnf;
extern sf::Sound sndCnf;
extern sf::Text templateText;
extern const float volFadeSpeed;

void screenFade(float speed, bool direction);
void drawMenu(const structs::Option* option, u16 length);
void fadeMusic(bool direction, float speed);
void fadeMusic(bool direction, float speed);
float pixelToTile(float pos);
124 changes: 124 additions & 0 deletions jukebox.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include "inc/includes.hxx"

const u8 sndAmnt = 7;
const u8 musX = 0;
const u8 musY = 0;
const u8 musTitleXDelta = 5;
const u8 musAlbumXDelta = 5;
const u8 musArtistXDelta = 6;
const structs::SndMData musHdr[] =
{
{testTrack,"Test Track","Game","TheWindowsPro98",true,false},
{lvlClearTrack,"Act Complete","Game","TheWindowsPro98",false,false},
{titleTrack,"Character Select","Sonic Advance","Tatsuyuki Maeda, Yutaka Minobe, Teruhiko Nakagawa",true,false},
{lfTrack,"Angel Island Zone (Act 2)","Sonic the Hedgehog 3","Unknown Artist",true,false},
{lsTrack,"Zone Select","Sonic Advance","Tatsuyuki Maeda, Yutaka Minobe, Teruhiko Nakagawa",true,false},
{hoverSFX,"Menu Hover","Game","TheWindowsPro98",false,true},
{confSFX,"Menu Select","Game","TheWindowsPro98",false,true}
};

void jukebox()
{
fadeRect.setFillColor(sf::Color::Black);
sf::Text songDrawable(templateText);
songDrawable.setPosition(pixelToTile(musX+musTitleXDelta),pixelToTile(musY));
sf::Text songAlbumDrawable(templateText);
songAlbumDrawable.setPosition(pixelToTile(musX+musAlbumXDelta),pixelToTile(musY+1));
sf::Text songArtistDrawable(templateText);
songArtistDrawable.setPosition(pixelToTile(musX+musArtistXDelta),pixelToTile(musY+2));
sf::Text songLabel(templateText);
songLabel.setString("Title:");
songLabel.setPosition(pixelToTile(musX),pixelToTile(musY));
sf::Text songAlbumLabel(templateText);
songAlbumLabel.setString("Album:");
songAlbumLabel.setPosition(pixelToTile(musX),pixelToTile(musY+1));
sf::Text songArtistLabel(templateText);
songArtistLabel.setString("Artist:");
songArtistLabel.setPosition(pixelToTile(musX),pixelToTile(musY+2));
sf::SoundBuffer sb;
sf::Sound snd;
while(window.isOpen())
{
sf::Event e;
songDrawable.setString(musHdr[*menuIndex].songTitle);
songAlbumDrawable.setString(musHdr[*menuIndex].songAlbum);
songArtistDrawable.setString(musHdr[*menuIndex].songArtist);
screenFade(volFadeSpeed*3,true);
window.clear();
window.draw(songDrawable);
window.draw(songAlbumDrawable);
window.draw(songArtistDrawable);
window.draw(songLabel);
window.draw(songAlbumLabel);
window.draw(songArtistLabel);
window.draw(fadeRect);
window.display();
while(window.pollEvent(e))
{
switch (e.type)
{
case sf::Event::Closed:
{
window.close();
break;
}
case sf::Event::KeyPressed:
{
if (!window.hasFocus() or fadeRect.getFillColor().a != 0)
{
break;
}
if (e.key.scancode == sf::Keyboard::Scan::Left)
{
sndHvr.play();
if (*menuIndex == 0)
{
*menuIndex = sndAmnt-1;
}
else
{
(*menuIndex)--;
}
}
else if (e.key.scancode == sf::Keyboard::Scan::Right)
{
sndHvr.play();
if (*menuIndex == sndAmnt-1)
{
*menuIndex = 0;
}
else
{
(*menuIndex)++;
}
}
if (e.key.scancode == sf::Keyboard::Scan::Enter)
{
if (!musHdr[*menuIndex].isSFX)
{
music.openFromFile(musHdr[*menuIndex].songPath);
music.setLoop(musHdr[*menuIndex].loop);
music.play();
}
else
{
sb.loadFromFile(musHdr[*menuIndex].songPath);
snd.setBuffer(sb);
snd.setLoop(musHdr[*menuIndex].loop);
snd.play();
}
}
else if (e.key.scancode == sf::Keyboard::Scan::Escape)
{
sndCnf.play();
}
break;
}
default:
{
break;
}
}
}
}
}
11 changes: 9 additions & 2 deletions main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ int main(int argc, char** argv)
std::string titleStr = programTitle + " " + releaseStageStringsL[releaseStage] + " " + vcStr + " " + buildTitle;
window.setTitle(titleStr);
sf::Image icon;
icon.loadFromFile(favicon);
if (!icon.loadFromFile(favicon))
{
fprintf(stderr,"Assets not found.");
exit(1);
}
window.setIcon(16,16,icon.getPixelsPtr());
font.loadFromFile(blazeTTF);
window.setFramerateLimit(60);
menuIndex = new u8(0);
fadeRect.setSize(sf::Vector2f(1280,720));
fadeRect.setFillColor(sf::Color::Transparent);
fadeRect.setFillColor(sf::Color::Black);
sbHvr.loadFromFile(hoverSFX);
sndHvr.setBuffer(sbHvr);
sbCnf.loadFromFile(confSFX);
sndCnf.setBuffer(sbCnf);
templateText.setFont(font);
templateText.setCharacterSize(fontSize);
templateText.setString("Default string.");
title();
return 0;
}
20 changes: 11 additions & 9 deletions prefs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ static void selectMenuPrefs()
}
switch (*menuIndex)
{
case 6:
{
*menuIndex = 0;
jukebox();
break;
}
case 7:
{
*menuIndex = 3;
Expand All @@ -69,20 +75,16 @@ void prefsScreen()
music.play();
*menuIndex = 0;
fadeRect.setFillColor(sf::Color::Black);
sf::Text diffStr;
diffStr.setFont(font);
sf::Text diffStr(templateText);
diffStr.setString("Difficulty:");
diffStr.setCharacterSize(fontSize);
diffStr.setPosition(prefsX*fontSize,prefsY*fontSize);
sf::Text plrStr;
plrStr.setFont(font);
diffStr.setPosition(pixelToTile(prefsX),pixelToTile(prefsY));
sf::Text plrStr(templateText);
plrStr.setString("Player:");
plrStr.setCharacterSize(fontSize);
plrStr.setPosition((prefsX+plrXDeltaGlobal)*fontSize,(prefsY+2)*fontSize);
plrStr.setPosition(pixelToTile(prefsX+plrXDeltaGlobal),pixelToTile(prefsY+2));
while (window.isOpen())
{
sf::Event e;
screenFade(volFadeSpeed*2,true);
screenFade(volFadeSpeed*3,true);
window.clear(sf::Color::Black);
window.draw(diffStr);
window.draw(plrStr);
Expand Down
1 change: 1 addition & 0 deletions structs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
namespace structs
{
Option::~Option(){};
SndMData::~SndMData(){};
}
18 changes: 9 additions & 9 deletions title.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static void selectMenuTitle()

void title()
{
fadeRect.setFillColor(sf::Color::Black);
std::string vmajStr = std::to_string(versionMajor);
std::string vminStr = std::to_string(versionMinor);
std::string vrevStr = std::to_string(versionRevision);
Expand All @@ -64,15 +65,12 @@ void title()
music.openFromFile(titleTrack);
music.setLoop(true);
music.play();
sf::Text copyInfo,versionText;
sf::Text copyInfo(templateText);
sf::Text versionText(templateText);
copyInfo.setString(L"©TheWindowsPro98 2023");
copyInfo.setCharacterSize(fontSize);
copyInfo.setFont(font);
copyInfo.setPosition(0,696);
copyInfo.setPosition(0,pixelToTile(29));
versionText.setString(versionCombined);
versionText.setFont(font);
versionText.setCharacterSize(fontSize);
versionText.setPosition(160,144);
versionText.setPosition(pixelToTile(6.75),pixelToTile(6));
sf::Texture titleTexture;
sf::Image titlePixels;
titlePixels.loadFromFile(titleImg);
Expand All @@ -81,16 +79,18 @@ void title()
titleTexture.setSmooth(true);
sf::Sprite titleSprite;
titleSprite.setTexture(titleTexture);
titleSprite.setPosition(160,0);
titleSprite.setPosition(pixelToTile(6.75),0);
float volume = 100;
while (window.isOpen())
{
sf::Event event;
screenFade(volFadeSpeed*3,true);
window.clear(sf::Color::Black);
window.draw(copyInfo);
window.draw(versionText);
window.draw(titleSprite);
drawMenu(titleMenu,4);
window.draw(fadeRect);
window.display();
while (window.pollEvent(event))
{
Expand All @@ -103,7 +103,7 @@ void title()
}
case sf::Event::KeyPressed:
{
if (!window.hasFocus())
if (!window.hasFocus() or fadeRect.getFillColor().a != 0)
{
break;
}
Expand Down
22 changes: 14 additions & 8 deletions utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ sf::SoundBuffer sbHvr;
sf::Sound sndHvr;
sf::SoundBuffer sbCnf;
sf::Sound sndCnf;
sf::Text templateText;
const float volFadeSpeed = 1.75;
const float scrnFadeSpeed = 2;

/// @brief Fades the screen in or out.
/// @param speed Speed of the fade. Bigger value = faster fade.
Expand Down Expand Up @@ -45,17 +47,13 @@ void drawMenu(const structs::Option* option, u16 length)
for (u8 i = 0; i < length; i++)
{
structs::Option o(option[i]);
sf::Text optionLabel;
optionLabel.setFont(font);
sf::Text optionLabel(templateText);
optionLabel.setString(o.label);
optionLabel.setPosition(o.x*fontSize,o.y*fontSize);
optionLabel.setCharacterSize(fontSize);
optionLabel.setPosition(pixelToTile(o.x),pixelToTile(o.y));
window.draw(optionLabel);
sf::Text selectedLabel;
selectedLabel.setFont(font);
sf::Text selectedLabel(templateText);
selectedLabel.setString(option[*menuIndex].label);
selectedLabel.setPosition(option[*menuIndex].x*fontSize,option[*menuIndex].y*fontSize);
selectedLabel.setCharacterSize(fontSize);
selectedLabel.setPosition(pixelToTile(option[*menuIndex].x),pixelToTile(option[*menuIndex].y));
selectedLabel.setOutlineThickness(3.5);
selectedLabel.setOutlineColor(playerColors[!player]);
window.draw(selectedLabel);
Expand Down Expand Up @@ -85,4 +83,12 @@ void fadeMusic(bool direction, float speed)
}
}
music.setVolume(volume);
}

/// @brief Converts a pixel co-ordinate to a tile co-ordinate (font size).
/// @param pos Position (in tiles)
/// @return Position in tiles
float pixelToTile(float pos)
{
return pos * fontSize;
}
4 changes: 2 additions & 2 deletions version.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const std::string releaseStageStringsS[] = {"ppa","pa","a","pb","b","rc","r"};
const std::string releaseStageStringsL[] = {"Pre-Pre Alpha","Pre-Alpha","Alpha","Pre-Beta","Beta","Release Candidate","Release"};
const std::string programTitle = "Project Daisy";
const std::string buildTitle = "Build 20230913-PC";
const std::string buildTitle = "Build 20230916-PC";
const u8 versionMajor = 1;
const u8 versionMinor = 1;
const u8 versionRevision = 2;
const u8 versionRevision = 3;
const u8 releaseStage = 0;

0 comments on commit b2c6f91

Please sign in to comment.