Exemplo n.º 1
0
void IMuseDigital::playDigMusic(const char *songName, const imuseDigTable *table, int atribPos, bool sequence) {
	int hookId = 0;

	if (songName != NULL) {
		if ((_attributes[DIG_SEQ_OFFSET + 38] != 0) && (_attributes[DIG_SEQ_OFFSET + 41] == _attributes[DIG_SEQ_OFFSET + 38])) {
			if ((atribPos == 43) || (atribPos == 44))
				hookId = 3;
		}

		if ((_attributes[DIG_SEQ_OFFSET + 46] != 0) && (_attributes[DIG_SEQ_OFFSET + 48] == 0)) {
			if ((atribPos == 38) || (atribPos == 39))
				hookId = 3;
		}

		if ((_attributes[DIG_SEQ_OFFSET + 53] != 0)) {
			if ((atribPos == 50) || (atribPos == 51))
				hookId = 3;
		}

		if ((atribPos != 0) && (hookId == 0)) {
			if (table->atribPos != 0)
				atribPos = table->atribPos;
			hookId = _attributes[DIG_STATE_OFFSET + atribPos];
			if (table->hookId != 0) {
				if ((hookId != 0) && (table->hookId > 1)) {
					_attributes[DIG_STATE_OFFSET + atribPos] = 2;
				} else {
					_attributes[DIG_STATE_OFFSET + atribPos] = hookId + 1;
					if (table->hookId < hookId + 1)
						_attributes[DIG_STATE_OFFSET + atribPos] = 1;
				}
			}
		}
	}

	fadeOutMusic(120);

	switch(table->opcode) {
		case 0:
		case 5:
		case 6:
			break;
		case 3:
		case 4:
			if (table->filename[0] == 0) {
				return;
			}
			if ((!sequence) && (table->atribPos != 0) &&
					(table->atribPos == _digStateMusicTable[_curMusicState].atribPos)) {
				startMusic(table->filename, table->soundId, 0, 127);
				return;
			}
			startMusic(table->filename, table->soundId, hookId, 127);
			break;
	}
}
GameState::GameState(StateStack& stack, Context context)
	: State(stack, context)
	, mECSM()
	, clearColor(sf::Color(237,182,31))
{

	initializeSystems();
	createBackground();
	createSwing();
	startMusic();

	// TESTING

	sf::Sprite* personSprite = new sf::Sprite();
	personSprite->setTexture(getContext().textures->get(Textures::Person));
	personSprite->setScale(sf::Vector2f(-4.0f, 4.0f));

	Entity* testPerson = new Entity(2);
	testPerson->addComponent(new ComponentPosition(20, 550));
	testPerson->addComponent(new ComponentVelocity(0.1f, 0));
	testPerson->addComponent(new ComponentSprite(personSprite));

	mECSM.registerEntity(testPerson);

	// DONE TESTING

}
Exemplo n.º 3
0
void Player_AD::startSound(int sound) {
	Common::StackLock lock(_mutex);

	// Setup the sound volume
	setupVolume();

	// Query the sound resource
	const byte *res = _vm->getResourceAddress(rtSound, sound);
	assert(res);

	if (res[2] == 0x80) {
		// Stop the current sounds
		stopMusic();

		// Lock the new music resource
		_musicResource = sound;
		_vm->_res->lock(rtSound, _musicResource);

		// Start the new music resource
		_musicData = res;
		startMusic();
	} else {
		const byte priority = res[0];
		// The original specified the channel to use in the sound
		// resource. However, since we play as much as possible we sill
		// ignore it and simply use the priority value to determine
		// whether the sfx can be played or not.
		//const byte channel  = res[1];

		// Try to allocate a sfx slot for playback.
		SfxSlot *sfx = allocateSfxSlot(priority);
		if (!sfx) {
			::debugC(3, DEBUG_SOUND, "AdLib: No free sfx slot for sound %d", sound);
			return;
		}

		// Try to start sfx playback
		sfx->resource = sound;
		sfx->priority = priority;
		if (startSfx(sfx, res)) {
			// Lock the new resource
			_vm->_res->lock(rtSound, sound);
		} else {
			// When starting the sfx failed we need to reset the slot.
			sfx->resource = -1;

			for (int i = 0; i < ARRAYSIZE(sfx->channels); ++i) {
				sfx->channels[i].state = kChannelStateOff;

				if (sfx->channels[i].hardwareChannel != -1) {
					freeHWChannel(sfx->channels[i].hardwareChannel);
					sfx->channels[i].hardwareChannel = -1;
				}
			}
		}
	}
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
void MusicInformation::resumeMusic()
{
    if(m_music_waiting)
    {
        startMusic();
        m_music_waiting = false;
        return;
    }
    if (m_normal_music != NULL) m_normal_music->resumeMusic();
    if (m_fast_music   != NULL) m_fast_music->resumeMusic();
}   // resumeMusic
Exemplo n.º 5
0
//----------------------------------------------------------------------------
bool Audio::init( void)
{
    XTRACE();
    LOG_INFO << "Initializing Audio..." << endl;

    bool audio;
    if( !ConfigS::instance()->getBoolean( "audio", audio))
    {
        audio = false;
    }
    if( audio)
    {
        if( SDL_InitSubSystem( SDL_INIT_AUDIO) < 0 )
        {
            LOG_ERROR << "Init Audio: failed # " << SDL_GetError() << endl;
            return false;
        }

        if( Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) < 0 )
        {
            LOG_ERROR << "Init Audio (Mixer): failed # "
                        << SDL_GetError() << endl;
            return false;
        }

        _sampleManager = new SampleManager();

        //make sure we have default volumes
        float dummy;
        if (!ConfigS::instance()->getFloat( "musicVolume", dummy))
        {
            Value *v = new Value( 0.8f);
            ConfigS::instance()->updateKeyword( "musicVolume", v);
        }
        if (!ConfigS::instance()->getFloat( "effectsVolume", dummy))
        {
            Value *v = new Value( 0.8f);
            ConfigS::instance()->updateKeyword( "effectsVolume", v);
        }

        ConfigS::instance()->getBoolean( "playMusic", _playMusic);
        ConfigS::instance()->getBoolean(
            "playDefaultSoundtrack", _playDefaultSoundtrack);
        startMusic();

        LOG_INFO << "Audio ON." << endl;
    }
    else
    {
        LOG_INFO << "Audio OFF." << endl;
    }

    return true;
}
Exemplo n.º 6
0
bool UIWindow::onPush ()
{
	bool push = true;
	for (UINodeListConstIter i = _nodes.begin(); i != _nodes.end(); ++i) {
		const bool val = (*i)->onPush();
		if (!val)
			push = false;
	}
	if (push) {
		Commands.executeCommandLine(_onPush);
		startMusic();
		addFirstFocus();
	}

	return push;
}
Exemplo n.º 7
0
void SDLInteraction::setMusicTrack(const QString & musicFile)
{
    bool wasPlayingMusic = m_isPlayingMusic;

    stopMusic();

    if (m_music != NULL)
    {
        Mix_FreeMusic(m_music);
        m_music = NULL;
    }

    m_musicTrack = musicFile;

    if (wasPlayingMusic)
        startMusic();
}
Exemplo n.º 8
0
void IMuseDigital::playFtMusic(const char *songName, int opcode, int volume) {
	fadeOutMusic(200);

	switch (opcode) {
	case 0:
	case 4:
		break;
	case 1:
	case 2:
	case 3:
		{
			int soundId = getSoundIdByName(songName);
			if (soundId != -1) {
				startMusic(soundId, volume);
			}
		}
		break;
	}
}
Exemplo n.º 9
0
//----------------------------------------------------------------------------
void Audio::updateSettings( void)
{
    if (Mix_FadingMusic() != MIX_NO_FADING)
        return;

    bool oldPlayMusic = _playMusic;
    bool oldPlayDefaultSoundtrack = _playDefaultSoundtrack;

    ConfigS::instance()->getBoolean( "playMusic", _playMusic);
    ConfigS::instance()->getBoolean( "playDefaultSoundtrack",
        _playDefaultSoundtrack);

    if( (oldPlayMusic == _playMusic) &&
        (oldPlayDefaultSoundtrack == _playDefaultSoundtrack))
    {
        return;
    }

    startMusic();
}
Exemplo n.º 10
0
SoundManager::SoundManager() :
    volume(SDL_MIX_MAXVOLUME),
    currentSound(-1),
    music(NULL),
    audioBuffers(4096),
    sounds(),
    channels(),
    throwWaitTime(500),
    throwLastPlayed(0),
    stepWaitTime(500),
    stepLastPlayed(0)
{
        if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 4, audioBuffers))
        {
            std::cerr << "audio open" << std::endl;
            throw std::string("Unable to open audio");
        }
        music = Mix_LoadMUS("resources/sounds/freezeezy.wav");
        if(!music) {
            std::cerr << "freez" << std::endl; 
            throw std::string(Mix_GetError());
        }
        startMusic();
        Mix_Chunk *check=NULL;
        sounds.push_back( check = Mix_LoadWAV("resources/sounds/snowstep.wav"));
        if(!check) {
            std::cerr << "step" << std::endl;
            throw std::string(Mix_GetError());
        }
        sounds.push_back( check = Mix_LoadWAV("resources/sounds/snowthrow.wav"));
        if(!check) {
            std::cerr << "throw" << std::endl;
            throw std::string(Mix_GetError());
        }
        for(unsigned int i=0; i< sounds.size(); ++i) channels.push_back(i);
}
Exemplo n.º 11
0
void IMuseDigital::parseScriptCmds(int cmd, int b, int c, int d, int e, int f, int g, int h) {
	int soundId = b;
	int sub_cmd = c;

	if (!cmd)
		return;

	switch (cmd) {
	case 10: // ImuseStopAllSounds
		stopAllSounds();
		break;
	case 12: // ImuseSetParam
		switch (sub_cmd) {
		case 0x400: // select group volume
			selectVolumeGroup(soundId, d);
			break;
		case 0x500: // set priority
			setPriority(soundId, d);
			break;
		case 0x600: // set volume
			setVolume(soundId, d);
			break;
		case 0x700: // set pan
			setPan(soundId, d);
			break;
		default:
			warning("IMuseDigital::doCommand SetParam DEFAULT command %d", sub_cmd);
			break;
		}
		break;
	case 14: // ImuseFadeParam
		switch (sub_cmd) {
		case 0x600: // set volume fading
			if ((d != 0) && (e == 0))
				setVolume(soundId, d);
			else if ((d == 0) && (e == 0))
				stopSound(soundId);
			else
				setFade(soundId, d, e);
			break;
		default:
			warning("IMuseDigital::doCommand FadeParam DEFAULT sub command %d", sub_cmd);
			break;
		}
		break;
	case 25: // ImuseStartStream
		debug(3, "ImuseStartStream (%d, %d, %d)", soundId, c, d);
		break;
	case 26: // ImuseSwitchStream
		debug(3, "ImuseSwitchStream (%d, %d, %d, %d, %d)", soundId, c, d, e, f);
		break;
	case 0x1000: // ImuseSetState
		debug(5, "ImuseSetState (%d)", b);
		if ((_vm->_game.id == GID_DIG) && (_vm->_game.features & GF_DEMO)) {
			if (b == 1) {
				fadeOutMusic(200);
				startMusic(1, 127);
			} else {
				if (getSoundStatus(2) == 0) {
					fadeOutMusic(200);
					startMusic(2, 127);
				}
			}
		} else if ((_vm->_game.id == GID_CMI) && (_vm->_game.features & GF_DEMO)) {
			if (b == 2) {
				fadeOutMusic(108);
				startMusic("in1.imx", 1100, 0, 127);
			} else if (b == 4) {
				fadeOutMusic(108);
				startMusic("in2.imx", 1120, 0, 127);
			} else if (b == 8) {
				fadeOutMusic(108);
				startMusic("out1.imx", 1140, 0, 127);
			} else if (b == 9) {
				fadeOutMusic(108);
				startMusic("out2.imx", 1150, 0, 127);
			} else if (b == 16) {
				fadeOutMusic(108);
				startMusic("gun.imx", 1210, 0, 127);
			} else {
				fadeOutMusic(120);
			}
		} else if (_vm->_game.id == GID_DIG) {
			setDigMusicState(b);
		} else if (_vm->_game.id == GID_CMI) {
			setComiMusicState(b);
		} else if (_vm->_game.id == GID_FT) {
			setFtMusicState(b);
		}
		break;
	case 0x1001: // ImuseSetSequence
		debug(5, "ImuseSetSequence (%d)", b);
		if (_vm->_game.id == GID_DIG) {
			setDigMusicSequence(b);
		} else if (_vm->_game.id == GID_CMI) {
			setComiMusicSequence(b);
		} else if (_vm->_game.id == GID_FT) {
			setFtMusicSequence(b);
		}
		break;
	case 0x1002: // ImuseSetCuePoint
		debug(5, "ImuseSetCuePoint (%d)", b);
		if (_vm->_game.id == GID_FT) {
			setFtMusicCuePoint(b);
		}
		break;
	case 0x1003: // ImuseSetAttribute
		debug(5, "ImuseSetAttribute (%d, %d)", b, c);
		assert((_vm->_game.id == GID_DIG) || (_vm->_game.id == GID_FT));
		if (_vm->_game.id == GID_DIG) {
			_attributes[b] = c;
		}
		break;
	case 0x2000: // ImuseSetGroupSfxVolume
		break;
	case 0x2001: // ImuseSetGroupVoiceVolume
		break;
	case 0x2002: // ImuseSetGroupMusicVolume
		break;
	default:
		error("IMuseDigital::doCommand DEFAULT command %d", cmd);
	}
}
Exemplo n.º 12
0
void IMuseDigital::playComiMusic(const char *songName, const imuseComiTable *table, int attribPos, bool sequence) {
	int hookId = 0;

	if ((songName != NULL) && (attribPos != 0)) {
		if (table->attribPos != 0)
			attribPos = table->attribPos;
		hookId = _attributes[COMI_STATE_OFFSET + attribPos];
		if (table->hookId != 0) {
			if ((hookId != 0) && (table->hookId > 1)) {
				_attributes[COMI_STATE_OFFSET + attribPos] = 2;
			} else {
				_attributes[COMI_STATE_OFFSET + attribPos] = hookId + 1;
				if (table->hookId < hookId + 1)
					_attributes[COMI_STATE_OFFSET + attribPos] = 1;
			}
		}
	}

	if (!songName) {
		fadeOutMusic(120);
		return;
	}

	switch (table->transitionType) {
	case 0:
		break;
	case 8:
		setHookIdForMusic(table->hookId);
		break;
	case 9:
		_stopingSequence = 1;
		setHookIdForMusic(table->hookId);
		break;
	case 2:
	case 3:
	case 4:
	case 12:
		if (table->filename[0] == 0) {
			fadeOutMusic(60);
			return;
		}
		if (getCurMusicSoundId() == table->soundId)
			return;
		if (table->transitionType == 4)
			_stopingSequence = 1;
		if (table->transitionType == 2) {
			fadeOutMusic(table->fadeOutDelay);
			startMusic(table->filename, table->soundId, table->hookId, 127);
			return;
		}
		if ((!sequence) && (table->attribPos != 0) &&
				(table->attribPos == _comiStateMusicTable[_curMusicState].attribPos)) {
			fadeOutMusicAndStartNew(table->fadeOutDelay, table->filename, table->soundId);
		} else if (table->transitionType == 12) {
			TriggerParams trigger;
			strcpy(trigger.marker, "exit"); trigger.fadeOutDelay = table->fadeOutDelay;
			strcpy(trigger.filename, table->filename); trigger.soundId = table->soundId;
			trigger.hookId = table->hookId; trigger.volume = 127;
			setTrigger(&trigger);
		} else {
			fadeOutMusic(table->fadeOutDelay);
			startMusic(table->filename, table->soundId, hookId, 127);
		}
		break;
	}
}
Exemplo n.º 13
0
void Imuse::playMusic(const ImuseTable *table, int atribPos, bool sequence) {
	int hookId = 0;

	if (atribPos) {
		if (table->atribPos)
			atribPos = table->atribPos;
		hookId = _attributes[atribPos];
		if (table->hookId) {
			if (hookId && table->hookId > 1) {
				_attributes[atribPos] = 2;
			} else {
				_attributes[atribPos] = hookId + 1;
				if (table->hookId < hookId + 1)
					_attributes[atribPos] = 1;
			}
		}
	}
	if (hookId == 0)
		hookId = 100;

	if (table->opcode == 0) {
		fadeOutMusic(120);
		return;
	}

	if (table->opcode == 2 || table->opcode == 3) {
		if (table->filename[0] == 0) {
			fadeOutMusic(60);
			return;
		}
		char *soundName = getCurMusicSoundName();
		int pan;

		if (table->pan == 0)
			pan = 64;
		else
			pan = table->pan;
		if (!soundName) {
			startMusic(table->filename, hookId, 0, pan);
			setVolume(table->filename, 0);
			setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
			return;
		}
		int old_pan = getCurMusicPan();
		int old_vol = getCurMusicVol();
		if (old_pan == -1)
			old_pan = 64;
		if (old_vol == -1)
			old_vol = 127;

		if (table->opcode == 2) {
			fadeOutMusic(table->fadeOut60TicksDelay);
			startMusic(table->filename, hookId, table->volume, pan);
			setVolume(table->filename, 0);
			setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
			setFadePan(table->filename, pan, table->fadeOut60TicksDelay);
			return;
		}
		if (strcmp(soundName, table->filename) == 0) {
			setFadeVolume(soundName, table->volume, table->fadeOut60TicksDelay);
			setFadePan(soundName, pan, table->fadeOut60TicksDelay);
			return;
		}

		if (!sequence && table->atribPos && table->atribPos == _stateMusicTable[_curMusicState].atribPos) {
			fadeOutMusicAndStartNew(table->fadeOut60TicksDelay, table->filename, hookId, old_vol, old_pan);
			setVolume(table->filename, 0);
			setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
			setFadePan(table->filename, pan, table->fadeOut60TicksDelay);
		} else {
			fadeOutMusic(table->fadeOut60TicksDelay);
			startMusic(table->filename, hookId, table->volume, pan);
			setVolume(table->filename, 0);
			setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
		}
	}
}
Exemplo n.º 14
0
void IMuseDigital::switchToNextRegion(Track *track) {
	assert(track);

	if (track->trackId >= MAX_DIGITAL_TRACKS) {
		flushTrack(track);
		debug(5, "SwToNeReg(trackId:%d) - fadetrack can't go next region, exiting SwToNeReg", track->trackId);
		return;
	}

	int num_regions = _sound->getNumRegions(track->soundDesc);

	if (++track->curRegion == num_regions) {
		flushTrack(track);
		debug(5, "SwToNeReg(trackId:%d) - end of region, exiting SwToNeReg", track->trackId);
		return;
	}

	ImuseDigiSndMgr::SoundDesc *soundDesc = track->soundDesc;
	if (_triggerUsed && track->soundDesc->numMarkers) {
		if (_sound->checkForTriggerByRegionAndMarker(soundDesc, track->curRegion, _triggerParams.marker)) {
			debug(5, "SwToNeReg(trackId:%d) - trigger %s reached", track->trackId, _triggerParams.marker);
			debug(5, "SwToNeReg(trackId:%d) - exit current region %d", track->trackId, track->curRegion);
			debug(5, "SwToNeReg(trackId:%d) - call cloneToFadeOutTrack(delay:%d)", track->trackId, _triggerParams.fadeOutDelay);
			Track *fadeTrack = cloneToFadeOutTrack(track, _triggerParams.fadeOutDelay);
			if (fadeTrack) {
				fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundDesc, fadeTrack->curRegion);
				fadeTrack->regionOffset = 0;
				debug(5, "SwToNeReg(trackId:%d)-sound(%d) select region %d, curHookId: %d", fadeTrack->trackId, fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId);
				fadeTrack->curHookId = 0;
			}
			flushTrack(track);
			startMusic(_triggerParams.filename, _triggerParams.soundId, _triggerParams.hookId, _triggerParams.volume);
			_triggerUsed = false;
			return;
		}
	}

	int jumpId = _sound->getJumpIdByRegionAndHookId(soundDesc, track->curRegion, track->curHookId);
	if (jumpId != -1) {
		int region = _sound->getRegionIdByJumpId(soundDesc, jumpId);
		assert(region != -1);
		int sampleHookId = _sound->getJumpHookId(soundDesc, jumpId);
		assert(sampleHookId != -1);
		debug(5, "SwToNeReg(trackId:%d) - JUMP found - sound:%d, track hookId:%d, data hookId:%d", track->trackId, track->soundId, track->curHookId, sampleHookId);
		if (track->curHookId == sampleHookId) {
			int fadeDelay = (60 * _sound->getJumpFade(soundDesc, jumpId)) / 1000;
			debug(5, "SwToNeReg(trackId:%d) - sound(%d) match hookId", track->trackId, track->soundId);
			if (fadeDelay) {
				debug(5, "SwToNeReg(trackId:%d) - call cloneToFadeOutTrack(delay:%d)", track->trackId, fadeDelay);
				Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay);
				if (fadeTrack) {
					fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundDesc, fadeTrack->curRegion);
					fadeTrack->regionOffset = 0;
					debug(5, "SwToNeReg(trackId:%d) - sound(%d) faded track, select region %d, curHookId: %d", fadeTrack->trackId, fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId);
					fadeTrack->curHookId = 0;
				}
			}
			track->curRegion = region;
			debug(5, "SwToNeReg(trackId:%d) - sound(%d) jump to region %d, curHookId: %d", track->trackId, track->soundId, track->curRegion, track->curHookId);
			track->curHookId = 0;
		} else {
			debug(5, "SwToNeReg(trackId:%d) - Normal switch region, sound(%d), hookId(%d)", track->trackId, track->soundId, track->curHookId);
		}
	} else {
		debug(5, "SwToNeReg(trackId:%d) - Normal switch region, sound(%d), hookId(%d)", track->trackId, track->soundId, track->curHookId);
	}

	debug(5, "SwToNeReg(trackId:%d) - sound(%d), select region %d", track->trackId, track->soundId, track->curRegion);
	track->dataOffset = _sound->getRegionOffset(soundDesc, track->curRegion);
	track->regionOffset = 0;
	debug(5, "SwToNeReg(trackId:%d) - end of func", track->trackId);
}
Exemplo n.º 15
0
void IMuseDigital::playComiMusic(const char *songName, const imuseComiTable *table, int atribPos, bool sequence) {
	int hookId = 0;

	if ((songName != NULL) && (atribPos != 0)) {
		if (table->atribPos != 0)
			atribPos = table->atribPos;
		hookId = _attributes[COMI_STATE_OFFSET + atribPos];
		if (table->hookId != 0) {
			if ((hookId != 0) && (table->hookId > 1)) {
				_attributes[COMI_STATE_OFFSET + atribPos] = 2;
			} else {
				_attributes[COMI_STATE_OFFSET + atribPos] = hookId + 1;
				if (table->hookId < hookId + 1)
					_attributes[COMI_STATE_OFFSET + atribPos] = 1;
			}
		}
	}

	switch (table->opcode) {
		case 0:
			fadeOutMusic(120);
			break;
		case 8:
		case 9:
			setHookId(table->soundId, table->soundId);
			break;
		case 1:
			if (table->filename[0] == 0) {
				fadeOutMusic(120);
				return;
			}
			fadeOutMusic(120);
			startMusic(table->filename, table->soundId, 0, 1);
			setFade(table->soundId, 127, 120);
			break;
		case 2:
			if (table->filename[0] == 0) {
				fadeOutMusic(60);
				return;
			}
			fadeOutMusic(table->fadeOut60TicksDelay);
			startMusic(table->filename, table->soundId, table->hookId, 127);
			break;
		case 3:
		case 4:
		case 12:
			if (table->filename[0] == 0) {
				fadeOutMusic(60);
				return;
			}
			fadeOutMusic(table->fadeOut60TicksDelay);
			if ((!sequence) && (table->atribPos != 0) &&
					(table->atribPos == _comiStateMusicTable[_curMusicState].atribPos)) {
				startMusic(table->filename, table->soundId, 0, 127);
				return;
			}
			if (table->opcode == 12) {
				startMusic(table->filename, table->soundId, table->hookId, 127);
			} else {
				startMusic(table->filename, table->soundId, hookId, 127);
			}
			break;
	}
}
Exemplo n.º 16
0
bool ScreenGameplay::HandleInput(int32_t key, KeyEventType code, bool isMouseInput)
{
    if (Screen::HandleInput(key, code, isMouseInput))
        return true;

    /* Notes */
    if (Measure < CurrentDiff->Measures.size() && // if measure is playable
        (BindingsManager::TranslateKey(key) == KT_Select || BindingsManager::TranslateKey(key) == KT_SelectRight ||
        BindingsManager::TranslateKey(key) == KT_GameplayClick)// is mouse input and it's a mouse button..
        )
    {
        if (CursorZooming)
        {
            if (code == KE_PRESS)
                Cursor.SetScale(0.85f);
            else
                Cursor.SetScale(1);
        }

        // For all measure notes..
        if (!IsPaused)
        {
            do
            {
                if (Measure > 0 && JudgeVector(NotesInMeasure[Measure - 1], code, key))
                    break;

                if (JudgeVector(NotesInMeasure[Measure], code, key))
                    break;

                if (Measure + 1 < NotesInMeasure.size() && JudgeVector(NotesInMeasure[Measure + 1], code, key))
                    break;
            } while (false);

            Judgment Val;
            Vec2 mpos = WindowFrame.GetRelativeMPos();
            // For all held notes...
            for (std::vector<GameObject>::iterator i = NotesHeld.begin();
            i != NotesHeld.end();
                i++)
            {
                // See if something's going on with the hold.
                if ((Val = i->Hit(SongTime, mpos, code != KE_RELEASE, IsAutoplaying, key)) != None)
                {
                    // Judge accordingly..
                    Lifebar.HitJudgment(Val);
                    aJudgment.ChangeJudgment(Val);
                    StoreEvaluation(Val);
                    i = NotesHeld.erase(i); // Delete this object. The hold is done!
                    break;
                }
            }
            return true;
        }
    }

    /* Functions */
    if (code == KE_PRESS)
    {
        switch (key)
        {
#ifndef NDEBUG
        case 'R':
            Cleanup();
            Init(MySong, 0);
            return true;
#endif
        case 'A': // Autoplay
            IsAutoplaying = !IsAutoplaying;
            break;
        case 'F':
            FailEnabled = !FailEnabled;
            break;
        case 'T':
            TappingMode = !TappingMode;
            break;
        case 'Q':
            Running = false;
            break;
        default:
            if (BindingsManager::TranslateKey(key) == KT_Escape)
            {
                /* TODO: pause */
                if (!IsPaused)
                    stopMusic();
                else
                {
                    Music->SeekTime(SongTime);
                    startMusic();
                }
                IsPaused = !IsPaused;
            }
        }
        return true;
    }

    return false;
}
Exemplo n.º 17
0
void menuCommand2()
{
	int mx, my;
	FILE *file;

	if( SDL_GetMouseState(&mx, &my) &SDL_BUTTON_LMASK )
	{
		if( (mx > MENU_X + 130) && (mx < (MENU_X + 510)) )
		{
			// Main Menu
			if( HUD.menu == 1 )
			{
				// New game
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
					//endGame();
					if(!Mix_PlayingMusic())
						startMusic();
					else if(!players[0].inGame)
					{
						Mix_HookMusicFinished(nextSong);
						Mix_FadeOutMusic(100);
					}
					startGame(MAX_PLAYERS);
				}	

				// Resume
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					if(players[0].inGame)
						HUD.menu = 0;
				}

				// Save/Load
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					HUD.menu = 2;
				}

				// Options
				else if( (my > (MENU_Y + 285)) && (my < (MENU_Y + 355)) )
				{
					HUD.menu = 3;
				}

				// Quit
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					exit(0);
				}
			}

			// Save/Load submenu
			else if( HUD.menu == 2 )
			{
				// Save
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
					fprintf(stderr,"Saving not yet implemented.\n");
				}	

				// Load
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					fprintf(stderr,"Loading not yet implemented.\n");
				}

				// Main Menu
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 1;
				}
			}

			// Options submenu
			else if( HUD.menu == 3 )
			{
				// Sound
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
					HUD.menu = 4;
				}	

				// Controls
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					HUD.menu = 5;
				}

				// HUD
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					HUD.menu = 6;
				}

				// Game
				else if( (my > (MENU_Y + 285)) && (my < (MENU_Y + 355)) )
				{
					HUD.menu = 7;
				}

				// Main Menu
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 1;
				}
			}

			// Sound submenu
			else if( HUD.menu == 4 )
			{
				// Volume sliders
				if( (mx > MENU_X + 350) && (mx < (MENU_X + 490)) )
				{
					// Sound effects volume
					if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
					{
						audio.slide = 1;
					}	

					// Music volume
					else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
					{
						audio.slide = 2;
					}
				}

				// Mute
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					audio.mute = 1-audio.mute;
				}

				// Options
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 3;
					// ADD save settings
				}
			}

			// ADD Controls submenu
			else if( HUD.menu == 5 )
			{
				// 
				if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
				{
				}	

				// 
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
				}

				// 
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
				}

				// 
				else if( (my > (MENU_Y + 285)) && (my < (MENU_Y + 355)) )
				{
				}

				// Options
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 3;
				}
			}

			// HUD submenu
			else if( HUD.menu == 6 )
			{
				// Alpha slider
				if( (mx > MENU_X + 350) && (mx < (MENU_X + 490)) )
				{
					if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
					{
						aSlide = true;
					}
				}

				// Save
		/*		else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					saveHUD();
				}

				// Load
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					file = fopen("config/hud.txt","r");
					if(file != NULL)
						loadHUD(file);
					else
						fprintf(stderr,"hud.txt failed to load\n");
				}
*/
				// Options
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 3;
				}
			}

			// Game submenu
			else if( HUD.menu == 7 )
			{
				// Scroll sensitivity slider
				if( (mx > MENU_X + 350) && (mx < (MENU_X + 490)) )
				{
					if( (my > (MENU_Y + 40)) && (my < (MENU_Y + 105)) )
					{
						HUD.sSlide = true;
					}
				}

				// Tool tips on/off
				else if( (my > (MENU_Y + 122)) && (my < (MENU_Y + 190)) )
				{
					HUD.ttips = 1 - HUD.ttips;
				}

				// Game res
				else if( (my > (MENU_Y + 205)) && (my < (MENU_Y + 275)) )
				{
					if( (mx > (MENU_X + 350)) && (mx < (MENU_X + 490)) )
					{
						nextRes();
					}
				}

				// Options
				else if( (my > (MENU_Y + 365)) && (my < (MENU_Y + 435)) )
				{
					HUD.menu = 3;
				}
			}
		}
	}
}
Exemplo n.º 18
0
int main( int argc, char *argv[] )
{
	struct highscoreItem *highscore = loadHighscore();

	res.width = 1280;
	res.height = 720;

	// Load a font

	if (TTF_Init() != 0)
	{
		printf("TTF_Init() Failed: %s\n", TTF_GetError());
		SDL_Quit();
		exit(1);
	}

	fontBig = TTF_OpenFont("resources/fonts/DejaVuSans.ttf", FONT_SIZE_BIG);
	fontSmall = TTF_OpenFont("resources/fonts/DejaVuSans.ttf", FONT_SIZE_SMALL);
	TTF_SetFontStyle(fontSmall, TTF_STYLE_BOLD);
	font = fontBig;
	if (fontBig == NULL || fontSmall == NULL)
	{
		printf("TTF_OpenFont() Failed: %s\n", TTF_GetError());
		TTF_Quit();
		SDL_Quit();
		exit(1);
	}
	
	// Initialisiere SDL
	if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0 ) {
		fprintf( stderr, "SDL konnte nicht initialisiert werden:  %s\n", SDL_GetError() );
		return 1;
	}

	// Initialisiere SDL_Image
	IMG_Init(IMG_INIT_PNG);

	// Timer einrichten
	SDL_AddTimer (16, generate_userevent, NULL);

	// Event-System initialisieren
	SDL_Event event;

	SDL_WM_SetCaption("Jump and Run", "Jump and Run");
	SDL_Surface *icon = IMG_Load("resources/images/icon.png");
	if (icon != NULL)
		SDL_WM_SetIcon(icon, NULL);

	// Erstelle die Bildschirmfläche
	SDL_Surface *screen = NULL;
	screen = SDL_SetVideoMode( res.width, res.height, SCREEN_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF);

	

	SDL_ShowCursor(0);

	initializeSounds();
	startMusic();

	initializeClouds();

	int returnValue = drawMenu(screen, event);
	while (1)
	{
		switch (returnValue)
		{
			case MENU:
				returnValue = drawMenu(screen, event);
				break;

			case START_GAME:
				returnValue = LEVEL_OFFSET;
				break;

			case HIGHSCORES:
				drawHighscore(screen, font, event, highscore);
				returnValue = MENU;
				break;

			default:
				if (returnValue >= LEVEL_OFFSET && returnValue < LEVEL_OFFSET + MAX_LEVEL)
				{
					returnValue = addScore(screen, startGame (screen, event, res, returnValue - LEVEL_OFFSET), event, &highscore);
				}
				else if (returnValue <= EXIT_GAME)
				{
					printf("Spiel beenden\n");
					freeHighscore(highscore);
					freeAudio();
					TTF_CloseFont(fontBig);
					TTF_CloseFont(fontSmall);
					TTF_Quit();
					SDL_Quit();
					exit(returnValue - EXIT_GAME);
				}
				else
					returnValue = MENU;
		}
	}
	
	return 0;
}
Exemplo n.º 19
0
void ToucheEngine::res_loadMusic(int num) {
	debugC(9, kDebugResource, "ToucheEngine::res_loadMusic() num=%d", num);
	startMusic(num);
}
Exemplo n.º 20
0
/* TODO: Use measure ratios instead of song time for the barline. */
bool ScreenGameplay::Run(double TimeDelta)
{
    if (Music && LeadInTime <= 0)
    {
        SongDelta = Music->GetStreamedTime() - SongTime;

        SongTime += SongDelta;
    }

    float ScreenTime = Screen::GetScreenTime();
    if (ScreenTime > ScreenPauseTime || !ShouldChangeScreenAtEnd) // we're over the pause?
    {
        if (SongTime <= 0)
        {
            if (LeadInTime > 0)
            {
                LeadInTime -= TimeDelta;
                SongTime = -LeadInTime;
            }
            else
                startMusic();
        }

        if (Next) // We have a pending screen?
            return RunNested(TimeDelta); // use that instead.

        RunMeasure(SongDelta);

        if (LeadInTime)
            Barline.Run(TimeDelta, MeasureRatio);
        else
            Barline.Run(SongDelta, MeasureRatio);

        if (SongTime > CurrentDiff->Offset)
        {
            while (BarlineRatios.size() && BarlineRatios.at(0).Time <= SongTime)
            {
                RatioPerSecond = BarlineRatios.front().Value;
                BarlineRatios.erase(BarlineRatios.begin());
            }

            MeasureRatio += RatioPerSecond * SongDelta;

            if (SongDelta == 0 && !IsPaused)
            {
                if ((!Music || !Music->IsPlaying()))
                    MeasureRatio += RatioPerSecond * TimeDelta;
            }

            if (MeasureRatio > 1.0f)
            {
                MeasureRatio -= 1.0f;
                Measure += 1;
            }
            Lifebar.Run(SongDelta);
            aJudgment.Run(TimeDelta);
        }
    }

    if (ShouldChangeScreenAtEnd)
    {
        float TotalTime = (CurrentDiff->Offset + MySong->LeadInTime + ScreenPauseTime);
        float X = GetScreenTime() / TotalTime;
        float xPos;

        if (X < 0.5)
            xPos = ((-2)*X*X + 2 * X) * ScreenWidth;
        else
            xPos = ScreenWidth - ((-2)*X*X + 2 * X) * ScreenWidth;

        ReadySign.SetPosition(xPos, ScreenHeight / 2);
        ReadySign.Alpha = 2 * ((-2)*X*X + 2 * X);

        // Lights
        float LightProgress = GetScreenTime() / 1.5;
        if (LightProgress <= 1)
            WindowFrame.SetLightMultiplier(LightProgress * 1.2);
    }
    else
        ReadySign.Alpha = 0;

    RenderObjects(TimeDelta);

    if (ShouldChangeScreenAtEnd && Measure >= CurrentDiff->Measures.size())
    {
        auto Eval = std::make_shared<ScreenEvaluation>();
        Eval->Init(Evaluation, MySong->SongAuthor, MySong->SongName);
        Next = Eval;
        Music->Stop();
    }

    // You died? Not editing? Failing is enabled?
    if (Lifebar.Health <= 0 && !EditMode && FailEnabled)
        Running = false; // It's over.

    return Running;
}
Exemplo n.º 21
0
// ***************************************************************************
void		CMusicSoundManager::update()
{
	// if disabled, then just quit
	if(!_Enabled)
		return;

	// update playing music each frame
	NLMISC::TTime		currentTime= CTime::getLocalTime();
	CAudioMixerUser		*mixer= CAudioMixerUser::instance();

	// **** First, see if the current music played is cut-able
	bool	canPlayNewMusic= true;
	// if the current played music has not ended his "minimum play time"
	if(_TimeConstraintEnabled && _CurrentMusicPlaying && currentTime<=_PlayStartTime+_CurrentMusicPlaying->getMinimumPlayTime())
		canPlayNewMusic= false;

	// if cannot play new music, continue the current one
	if(!canPlayNewMusic)
		return;

	// **** Search a music to replace the currently played one
	CMusicSound		*bestSound= _CurrentMusicPlaying;
	CMusicSource	*bestSource= NULL;
	std::set<CMusicSource*>::iterator	it= _Sources.begin();
	// for all possibles music sources
	for(;it!=_Sources.end();it++)
	{
		CMusicSource	*src= *it;
		CMusicSound		*snd= dynamic_cast<CMusicSound*>(src->getSound());
		// error, -> skip
		if(!snd)
			continue;
		// If the source was already played (this is not a loop sound), skip it
		// NB: It may be the current one but in this case it doesn't matters....
		if(_AlreadyPlayedSources.find(src)!=_AlreadyPlayedSources.end())
			continue;
		// verify that this sound can be played again from the last time it has been played
		if(_TimeConstraintEnabled && snd->LastStopTime>INT_MIN && currentTime<=snd->LastStopTime+snd->getTimeBeforeCanReplay())
			continue;
		// if no sound yet, take it
		if(!bestSound)
		{
			bestSource= src;
			bestSound= snd;
		}
		// else compare sound
		else
		{
			// take the higher priority (priority value is inversed: 0 is the best priority)
			if(snd->getPriority()<bestSound->getPriority())
			{
				bestSound= snd;
				bestSource= src;
			}
			// else, other criteria
			else if(snd->getPriority()==bestSound->getPriority())
			{
				/* if the new sound is not looping and the best is, consider the new sound as an "instant sound"
					which is prioritary
				*/
				if(!snd->getLooping() && bestSound->getLooping())
				{
					bestSound= snd;
					bestSource= src;
				}
				else if(snd->getLooping() == bestSound->getLooping())
				{
					// if the bestSound is the current sound played, prefer to not change the sound
					if(bestSound!=_CurrentMusicPlaying)
					{
						/* NB: here, bestSound can be != from _CurrentMusicPlaying in the following cases:
							- _CurrentMusicPlaying= NULL
							- bestSound was assigned to a higher priority sound than _CurrentMusicPlaying
								thereFore snd should be different from _CurrentMusicPlaying, since this one is of
								lower priority...
						 */
						// compare name to avoid full random jitter
						string	snd0= CStringMapper::unmap(bestSound->getFileName());
						string	snd1= CStringMapper::unmap(snd->getFileName());
						if(snd1>snd0)
						{
							bestSound= snd;
							bestSource= src;
						}
					}
				}
			}
		}
	}

	// if some new music found (different from the currently played one)
	if(bestSound && bestSound!= _CurrentMusicPlaying)
	{
		// then launch the new music
		startMusic(bestSound, bestSource);
	}
	// else, no new music found => if the music is currently playing
	else if(_CurrentMusicPlaying)
	{
		// if the music has ended (and not loop), stop
		if(_CurrentMusicPlaying->getLooping()==false && mixer->isMusicEnded())
		{
			// without fade (no need since ended)
			stopMusic(false);
		}
		else
		{
			// verify that a source with this sound still exist. If not, we have to cut this sound too
			bool	found= false;
			std::set<CMusicSource*>::iterator	it= _Sources.begin();
			for(;it!=_Sources.end();it++)
			{
				CMusicSource	*src= *it;
				CMusicSound		*snd= dynamic_cast<CMusicSound*>(src->getSound());
				if(snd && snd==_CurrentMusicPlaying)
				{
					found= true;
					break;
				}
			}
			// if not found, cut the music
			if(!found)
			{
				// with fade
				stopMusic(true);
			}
		}
	}
}