Music/SE/no sounds controls.

master
sigonasr2 2 years ago
parent 10bbb07894
commit 90a2b5c562
  1. 3
      olcCodeJam2023Entry/Scenario.cpp
  2. 17
      olcCodeJam2023Entry/Unit.cpp
  3. 2
      olcCodeJam2023Entry/Unit.h
  4. 31
      olcCodeJam2023Entry/VirusAttack.cpp
  5. 4
      olcCodeJam2023Entry/VirusAttack.h
  6. BIN
      olcCodeJam2023Entry/assets/ending.png
  7. 11
      olcCodeJam2023Entry/olcPGEX_AudioSource.h

@ -288,6 +288,7 @@ void Stage3::Start(){
flags.playerInControl=false;
flags.unitMetersGreyedOut=true;
flags.guideEnabled=false;
flags.limitedBuildOptions=true;
SetCameraTarget({3*24,6*24},true);
oopsTimer=0.3;
nextLevel=LevelName::STAGE4;
@ -359,7 +360,9 @@ void Stage3::Update(){
if(oopsTimer==0){
SetObjective("Defeat all enemy units.");
state=10;
flags.limitedBuildOptions=false;
flags.playerInControl=true;
box.SetVisible(false);
}
}break;
case 10:{

@ -8,8 +8,8 @@
Unit::~Unit(){};
void Unit::RandomHit(int chance,std::vector<std::unique_ptr<Audio>>&SOUNDS){
switch(rand()%chance){
void Unit::RandomHit(std::vector<std::unique_ptr<Audio>>&SOUNDS){
switch(rand()%3){
case 0:{SOUNDS[Sound::HIT1]->Play(GetPos(),1,0.6);}break;
case 1:{SOUNDS[Sound::HIT2]->Play(GetPos(),1,0.6);}break;
case 2:{SOUNDS[Sound::HIT3]->Play(GetPos(),1,0.6);}break;
@ -24,7 +24,7 @@ LeftShifter::LeftShifter(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_pt
void LeftShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&SOUNDS){
victim<<=1;
RandomHit(6,SOUNDS);
RandomHit(SOUNDS);
}
std::string RightShifter::unitName="Right Shifter";
@ -35,7 +35,7 @@ RightShifter::RightShifter(PixelGameEngine*pge,vf2d pos,std::vector<std::unique_
void RightShifter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits ,std::vector<std::unique_ptr<Audio>>&SOUNDS){
victim>>=1;
RandomHit(6,SOUNDS);
RandomHit(SOUNDS);
}
std::string BitRestorer::unitName="Bit Restorer";
@ -124,7 +124,7 @@ void MemorySwapper::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherU
if(victim.atkSpd.index==9999999)victim.atkSpd.index=0;
if(victim.moveSpd.index==9999999)victim.moveSpd.index=0;
if(victim.procedure.index==9999999)victim.procedure.index=0;
RandomHit(4,SOUNDS);
RandomHit(SOUNDS);
}
std::string Corrupter::unitName="Corrupter";
@ -137,7 +137,7 @@ void Corrupter::Attack(Unit&victim,std::vector<std::shared_ptr<Unit>>&otherUnits
//Chooses a bit at random and corrupts it.
int randomBit=rand()%victim.memory.size();
if(victim.memory[randomBit]){
RandomHit(5,SOUNDS);
RandomHit(SOUNDS);
}
victim.memory[randomBit]=false;
}
@ -990,14 +990,15 @@ bool Unit::IsAllocator(){
}
void Unit::SetBuildUnit(float buildTime,std::shared_ptr<Unit>finalUnit,std::vector<std::unique_ptr<Audio>>&SOUNDS){
this->buildTime=buildTime;
this->buildTransformUnit=std::move(finalUnit);
if(this->IsAllocator()){
SOUNDS[Sound::SMALLBUILD]->Play(GetPos());
} else
if(this->IsPlatform()){
SOUNDS[Sound::BIGBUILD]->Play(GetPos());
}
//Once the units start building they aren't considered allocators/platforms anymore, must do it before.
this->buildTime=buildTime;
this->buildTransformUnit=std::move(finalUnit);
}
bool Unit::IsBuilding(){

@ -93,7 +93,7 @@ public:
bool IsPlatform();
bool IsAttached();
bool IsRAMBank();
void RandomHit(int chance,std::vector<std::unique_ptr<Audio>>&SOUNDS); //3 of chance odds of making a sound.
void RandomHit(std::vector<std::unique_ptr<Audio>>&SOUNDS); //3 of chance odds of making a sound.
Unit*GetBuildUnit();
Marker health={};
Marker range={};

@ -227,12 +227,12 @@ void VirusAttack::LoadLevel(LevelName level){
if(bgm==nullptr){
bgm=SOUNDS[int(selectedLevel.bgm)].get();
bgm->PlayCentered(1,1,true);
bgm_handle=bgm->PlayCentered(1,1,true);
} else
if(bgm!=SOUNDS[int(selectedLevel.bgm)].get()){
bgm->Stop();
bgm=SOUNDS[int(selectedLevel.bgm)].get();
bgm->PlayCentered(1,1,true);
bgm_handle=bgm->PlayCentered(1,1,true);
}
player_resources=selectedLevel.player_starting_resources;
enemy_resources=selectedLevel.enemy_starting_resources;
@ -349,6 +349,7 @@ void VirusAttack::InitializeSounds(){
LoadSound(Sound::REFRESHER,"refresher.mp3");
LoadSound(Sound::TURRET,"turret.mp3");
LoadSound(Sound::MEMORY_GUARD,"memoryguard.mp3");
LoadSound(Sound::SPAWN,"spawn.mp3");
}
bool VirusAttack::UnitCreationClickHandled(){
@ -726,6 +727,11 @@ void VirusAttack::RenderCollectionPoints(CollectionPoint*cp){
bool VirusAttack::OnUserUpdate(float fElapsedTime){
UpdateMatrixTexture(fElapsedTime);
gameplayTime+=fElapsedTime;
if(gameplayTime>=1){
gameplayTime--;
gameSeconds++;
}
switch(state){
#pragma region MAIN_MENU
case GameState::MAIN_MENU:{
@ -735,6 +741,27 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
SOUNDS[Sound::BUTTONSELECT]->PlayCentered();
state=GameState::GAMEPLAY;
RestartLevel();
gameplayTime=0;
}
if(audioToggleButton->bPressed){
audioMode=(audioMode+1)%3;
switch(audioMode){
case 0:{
AL.bMusicOn=AL.bSoundOn=true;
bgm_handle=bgm->PlayCentered(bgm_handle);
audioToggleButton->sText="Audio: On";
}break;
case 1:{
AL.bSoundOn=true;
AL.bMusicOn=false;
bgm->Stop(bgm_handle);
audioToggleButton->sText="Audio: SE Only";
}break;
case 2:{
AL.bMusicOn=AL.bSoundOn=false;
audioToggleButton->sText="Audio: Off";
}break;
}
}
if(exitGameButton->bPressed){
SOUNDS[Sound::BUTTONSELECT]->PlayCentered();

@ -42,6 +42,7 @@ public:
olcPGEX_AudioListener AL;
Audio*bgm=nullptr;
int bgm_handle=-1;
Resources player_resources,player_prev_resources,player_display_resources,enemy_resources;
@ -49,6 +50,9 @@ public:
Textbox unitCreationBox,testBox,memoryAllocatorBox,platformCreationBox,restartBox;
Level*currentLevel;
float gameplayTime;
int gameSeconds;
int audioMode=0; //0=Play everything, 1=Play sound effects, 2=Everything off.
std::map<LevelName,Level>levelData;

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

@ -104,7 +104,7 @@ public:
// Instruct Audio Listener to load this sound (if not loaded already)
void LoadAudioSample(int ID, const char* fileName);
int PlayCentered(float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false);
int PlayCentered(float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false,bool bgm=false);
// Play the Audio Sample, with given parameters
int Play(vf2d pos, float speed = 1.0f, float vol = 1.0f, bool looping = false, bool paused = false);
@ -141,8 +141,10 @@ void olcPGEX_AudioSource::LoadAudioSample(int ID, const char* fileName)
AL->LoadAudioSample(ID, fileName);
}
int olcPGEX_AudioSource::PlayCentered(float speed, float vol, bool looping, bool paused)
int olcPGEX_AudioSource::PlayCentered(float speed, float vol, bool looping, bool paused,bool bgm)
{
if(bgm&&!AL->bMusicOn)return -1;
if(!bgm&&!AL->bSoundOn)return -1;
// Set parameters
fPlaySpeed = speed;
fVolume = vol;
@ -164,6 +166,7 @@ int olcPGEX_AudioSource::PlayCentered(float speed, float vol, bool looping, bool
int olcPGEX_AudioSource::Play(vf2d pos, float speed, float vol, bool looping, bool paused)
{
if(!AL->bSoundOn)return -1;
// Set parameters
fPlaySpeed = speed;
fVolume = vol*std::max(0.f,abs(1-std::min(1.0f,(AL->GetDistance(pos)/1024.f))));
@ -200,7 +203,9 @@ void olcPGEX_AudioSource::Pause(bool pauseState)
void olcPGEX_AudioSource::Stop(int handle)
{
// Use the Audio Listener to stop the sound
AL->soloud.stop(handle);
if(handle!=-1){
AL->soloud.stop(handle);
}
}
void olcPGEX_AudioSource::Stop()

Loading…
Cancel
Save