2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "NoteEntity.h"
|
|
|
|
#include "../World.h"
|
2014-09-26 13:13:19 -04:00
|
|
|
#include "json/value.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2013-11-14 09:37:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
|
|
|
|
super(E_BLOCK_NOTE_BLOCK, a_BlockX, a_BlockY, a_BlockZ, a_World),
|
|
|
|
m_Pitch(0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 11:14:54 -05:00
|
|
|
void cNoteEntity::UsedBy(cPlayer * a_Player)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-24 14:29:59 -05:00
|
|
|
UNUSED(a_Player);
|
2013-07-29 07:13:03 -04:00
|
|
|
IncrementPitch();
|
|
|
|
MakeSound();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 11:14:54 -05:00
|
|
|
void cNoteEntity::MakeSound(void)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
char instrument;
|
|
|
|
AString sampleName;
|
|
|
|
|
|
|
|
switch (m_World->GetBlock(m_PosX, m_PosY - 1, m_PosZ))
|
|
|
|
{
|
|
|
|
case E_BLOCK_PLANKS:
|
|
|
|
case E_BLOCK_LOG:
|
|
|
|
case E_BLOCK_NOTE_BLOCK:
|
|
|
|
{
|
|
|
|
// TODO: add other wood-based blocks if needed
|
|
|
|
instrument = E_INST_DOUBLE_BASS;
|
|
|
|
sampleName = "note.db";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case E_BLOCK_SAND:
|
|
|
|
case E_BLOCK_GRAVEL:
|
|
|
|
case E_BLOCK_SOULSAND:
|
|
|
|
{
|
|
|
|
instrument = E_INST_SNARE_DRUM;
|
|
|
|
sampleName = "note.snare";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case E_BLOCK_GLASS:
|
|
|
|
case E_BLOCK_GLASS_PANE:
|
|
|
|
case E_BLOCK_GLOWSTONE:
|
|
|
|
{
|
|
|
|
instrument = E_INST_CLICKS;
|
|
|
|
sampleName = "note.hat";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case E_BLOCK_STONE:
|
|
|
|
case E_BLOCK_STONE_BRICKS:
|
|
|
|
case E_BLOCK_COBBLESTONE:
|
|
|
|
case E_BLOCK_OBSIDIAN:
|
|
|
|
case E_BLOCK_NETHERRACK:
|
|
|
|
case E_BLOCK_BRICK:
|
|
|
|
case E_BLOCK_NETHER_BRICK:
|
|
|
|
{
|
|
|
|
// TODO: add other stone-based blocks if needed
|
|
|
|
instrument = E_INST_BASS_DRUM;
|
|
|
|
sampleName = "note.bassattack";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
instrument = E_INST_HARP_PIANO;
|
|
|
|
sampleName = "note.harp";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_World->BroadcastBlockAction(m_PosX, m_PosY, m_PosZ, instrument, m_Pitch, E_BLOCK_NOTE_BLOCK);
|
|
|
|
|
|
|
|
// TODO: instead of calculating the power function over and over, make a precalculated table - there's only 24 pitches after all
|
2015-05-24 07:56:56 -04:00
|
|
|
float calcPitch = pow(2.0f, static_cast<float>(m_Pitch - 12.0f) / 12.0f);
|
|
|
|
m_World->BroadcastSoundEffect(
|
2015-05-28 07:29:26 -04:00
|
|
|
sampleName,
|
|
|
|
static_cast<double>(m_PosX),
|
|
|
|
static_cast<double>(m_PosY),
|
|
|
|
static_cast<double>(m_PosZ),
|
|
|
|
3.0f,
|
|
|
|
calcPitch
|
|
|
|
);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 11:14:54 -05:00
|
|
|
char cNoteEntity::GetPitch(void)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return m_Pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 11:14:54 -05:00
|
|
|
void cNoteEntity::SetPitch(char a_Pitch)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
m_Pitch = a_Pitch % 25;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-14 11:14:54 -05:00
|
|
|
void cNoteEntity::IncrementPitch(void)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2013-11-14 11:14:54 -05:00
|
|
|
SetPitch(m_Pitch + 1);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|