/**
**  Toggle music on / off.
*/
static void UiToggleMusic()
{
	static int vol;
	if (SoundEnabled()) {
		if (GetMusicVolume()) {
			vol = GetMusicVolume();
			SetMusicVolume(0);
			UI.StatusLine.Set(_("Music is off."));
		} else {
			SetMusicVolume(vol);
			UI.StatusLine.Set(_("Music is on."));
		}
	}
}
Exemple #2
0
/////////////////////////////////////////////
// sets sount volume
///////////////////////////////////////////
int CSound::SetSoundVolume(int vol)
{
	SOUND_VOLUME = vol;
	FSOUND_SetSFXMasterVolume(SOUND_VOLUME);
	SetMusicVolume(MUSIC_VOLUME);
	return vol;
};
Exemple #3
0
int CSound::Startmusic(char *song)
{

	songname = song;
	CurrentSong = FSOUND_Stream_OpenFile(song,FSOUND_LOOP_NORMAL,0);

	
	//if (!CurrentSong)
	//{
		//printf("Error Loading!\n");
		//printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
	//	return 1;
	//}
	FSOUND_Stream_Play(0,CurrentSong);
	SetMusicVolume(MUSIC_VOLUME); // be adam: stream play seems to reset the music volume
//	ret = FMUSIC_PlaySong(CurrentSong);
	
//	if (!ret)
	{
		//printf("Error Playing!\n");
		//printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
//		return 2;
		//printf("Press Any Key.\n");
	}
//	getchar();
	return 0;
}
Exemple #4
0
bool cAudio :: Init( void )
{
	if( bInitialised || ( !bMusic && !bSounds ) )
	{
		return 0;
	}

	if( bDebug )
	{
		printf( "Initialising Audio System ,Buffer (%i), Frequenzy (%i)\n", iBuffer, iHz );
	}

	/*	Initialising prefered Audio System specs with Mixer Standard format (Stereo)
	*
	*	format		: Output sample format.
	*	channels	: Number of sound channels in output.
	*	Set this to 2 for stereo, 1 for mono.
	*	chunksize	: Bytes used per output sample.
	*/

	if( Mix_OpenAudio( iHz, MIX_DEFAULT_FORMAT , iChannels, iBuffer ) < 0 ) 
	{
		printf( "Warning : Could not init 16-bit Audio\n- Reason : %s\n", SDL_GetError() );
		return 0;
	}

	bInitialised = 1;
	SetMusicVolume( Music_Volume );
	SetSoundVolume( Sound_Volume );

	return 1;
}
Exemple #5
0
void
AlienTalkSegue (COUNT wait_track)
{
	// this skips any talk segues that follow an aborted one
	if ((GLOBAL (CurrentActivity) & CHECK_ABORT) || TalkingFinished)
		return;

	if (!pCurInputState->Initialized)
	{
		InitSpeechGraphics ();
		SetColorMap (GetColorMapAddress (CommData.AlienColorMap));
		SetContext (AnimContext);
		DrawAlienFrame (NULL, 0, TRUE);
		UpdateSpeechGraphics ();
		CommIntroTransition ();
		
		pCurInputState->Initialized = TRUE;

		PlayMusic (CommData.AlienSong, TRUE, 1);
		SetMusicVolume (BACKGROUND_VOL);

		InitCommAnimations ();

		LastActivity &= ~CHECK_LOAD;
	}
	
	TalkingFinished = TalkSegue (wait_track);
	if (TalkingFinished && !VolasPackPresent)
		FadeMusic (FOREGROUND_VOL, ONE_SECOND);
}
Exemple #6
0
void CSoundPlayer::PlayMusic(int aLooping)
{
	if (!iInitialized)
		return;

	StopMusic();
	Mix_FadeInMusic(iMusic,aLooping, KFadeInTime );
	SetMusicVolume(iMusicVolume);
}
Exemple #7
0
void CSoundSystem::Initialize(
	int audioRate, 
	uint16_t audioFormat,
	int audioChannels, 
	int audioBuffers)
{
	if(Mix_OpenAudio(audioRate, audioFormat, audioChannels,audioBuffers) != 0) {
		common->Error("Couldn't initialize sound: %s\n", Mix_GetError());
	}

	SetMusicVolume(config_local.AudioConfig().musicVolume);
}
void ControlEvent::CloseMusicVOL(HSTREAM m_stream,float a)
{
	//if (!volumstatus)
	//{
	//	SetMusicVolume(a,m_stream);
	//	volumstatus=1;
	//} 
	//else
	//{

		SetMusicVolume(a,m_stream);
	/*	volumstatus=0;
	}*/
}
Exemple #9
0
void CGameOptions::EnsureSettings() {
  SetScreenBrightness(x48_screenBrightness, true);
  SetGamma(m_gamma, true);
  SetScreenPositionX(x4c_screenXOffset, true);
  SetScreenPositionY(x50_screenYOffset, true);
  SetScreenStretch(x54_screenStretch, true);
  SetSfxVolume(x58_sfxVol, true);
  SetMusicVolume(x5c_musicVol, true);
  SetSurroundMode(int(x44_soundMode), true);
  SetHelmetAlpha(x64_helmetAlpha);
  SetHUDLag(x68_24_hudLag);
  SetInvertYAxis(x68_25_invertY);
  SetIsRumbleEnabled(x68_26_rumble);
  SetIsHintSystemEnabled(x68_28_hintSystem);
  SetSwapBeamControls(x68_27_swapBeamsControls);
}
Exemple #10
0
int CSound::Initialise(int rate,int channels,int svol,int mvol)
{
	if((channels > 16) || (channels < 0))
	{
		return 1;
	}
	FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
	FSOUND_Init(rate,channels,FSOUND_INIT_USEDEFAULTMIDISYNTH);

	songname = "Empty";


	SetSoundVolume(svol);
	SetMusicVolume(mvol);

	CurrentSong = NULL;
	CurrentSound = 0;
	
	pan = 127;
	freq = 11250;

	FSOUND_Sample_Load(0,"sfx/click.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(1,"sfx/dong.wav",FSOUND_LOOP_OFF,0);

	FSOUND_Sample_Load(3,"sfx/computer.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(4,"sfx/scitech.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(5,"sfx/speed.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(6,"sfx/placetrack.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(7,"sfx/removetrack.wav",FSOUND_LOOP_OFF,0);

	FSOUND_Sample_Load(8, "sfx/click3.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(9, "sfx/pickuptrack.wav",FSOUND_LOOP_OFF,0);

	FSOUND_Sample_Load(10, "sfx/cartexplode.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(11, "sfx/cart-good.wav",FSOUND_LOOP_OFF,0);
	FSOUND_Sample_Load(12, "sfx/pickup.wav",FSOUND_LOOP_OFF,0);

	FSOUND_Sample_Load(13, "sfx/crusher.wav",FSOUND_LOOP_OFF, 0);

	return 0;

}
Exemple #11
0
SoundEngine::SoundEngine(bool disableSound) :
	nosound(disableSound),
	mutesound(false),
	musicFinished(true),
	currentTrack(playlist.begin())
{
    if (nosound){
        return;
    }


	// Warning the Mix_OpenAudio uses libmikmod witch seems to create the music.raw file
    if (Mix_OpenAudio(SOUND_FREQUENCY, SOUND_FORMAT, SOUND_CHANNELS, 1024 /*4096*/) < 0) {
        logger->error("%s line %i: Unable to open sound: %s\n", __FILE__, __LINE__, Mix_GetError());
        nosound = true;
    }

    // Set volumes to half of max by default; this should be a fallback, real setting should be read from config
    SetSoundVolume(MIX_MAX_VOLUME / 2);
    SetMusicVolume(MIX_MAX_VOLUME / 2);
}
Exemple #12
0
bool JukeBox::PlayMusicSample(const std::vector<std::string>::const_iterator& file_it)
{
  if (!m_init || !Config::GetInstance()->GetSoundMusic())
    return false;

  std::string file = *file_it;

  if (music)
    Mix_FreeMusic(music);

  music = Mix_LoadMUS(file.c_str());
  SetMusicVolume(Config::GetInstance()->GetVolumeMusic());
  MSG_DEBUG("jukebox", "We trying to load music %s", file.c_str());

  if (!music || Mix_PlayMusic(music, 0) < 0) {
    std::cerr << "[Music] Error : Unable to load music " << file << std::endl;
     playing_music = playing_pl->second.end();
     return false;
  }

  playing_music = file_it;
  return true;
}
Exemple #13
0
int SelectVolume(int cmd)
{
	static int index = 0;
	char s[10];
	int x, y;

	if (cmd == CMD_ESC)
		return MODE_MAIN;

	if (AnyButton(cmd) && index == VOLUME_COUNT - 1)
		return MODE_MAIN;

	if (Left(cmd)) {
		switch (index) {
			case 0:
				if (FXVolume() > 8)
					SetFXVolume(FXVolume() - 8);
				break;
			case 1:
				if (MusicVolume() > 8)
					SetMusicVolume(MusicVolume() - 8);
				break;
			case 2:
				if (FXChannels() > 2)
					SetFXChannels(FXChannels() - 2);
				break;
			case 3:
				break;
		}

		PlaySound(SND_SWITCH, 0, 255);
	} else if (Right(cmd)) {
		switch (index) {
			case 0:
				if (FXVolume() < 64)
					SetFXVolume(FXVolume() + 8);
				break;
			case 1:
				if (MusicVolume() < 64)
					SetMusicVolume(MusicVolume() + 8);
				break;
			case 2:
				if (FXChannels() < 8)
					SetFXChannels(FXChannels() + 2);
				break;
			case 3:
				break;
		}

		PlaySound(SND_SWITCH, 0, 255);
	} else if (Up(cmd)) {
		index--;

		if (index < 0)
			index = VOLUME_COUNT - 1;

		PlaySound(SND_SWITCH, 0, 255);
	} else if (Down(cmd)) {
		index++;

		if (index >= VOLUME_COUNT)
			index = 0;

		PlaySound(SND_SWITCH, 0, 255);
	}

	TextStringSpecial("Configure Sound:", TEXT_XCENTER | TEXT_TOP, 0, (SCREEN_WIDTH / 12));
	
	x = CenterX(MenuWidth(volumeMenu, VOLUME_COUNT));
	y = CenterY(MenuHeight(volumeMenu, VOLUME_COUNT));
	
	DisplayMenuAt(x - 20, y, volumeMenu, VOLUME_COUNT, index);
	
	x += MenuWidth(volumeMenu, VOLUME_COUNT);
	x += 10;	

	sprintf(s, "%d", FXVolume() / 8);
	TextStringAt(x, y, s);
	sprintf(s, "%d", MusicVolume() / 8);
	TextStringAt(x, y + TextHeight(), s);
	sprintf(s, "%d", FXChannels());
	TextStringAt(x, y + 2 * TextHeight(), s);
	TextStringAt(x, y + 3 * TextHeight(), "No");

	return MODE_VOLUME;
}
Exemple #14
0
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
	// Initialization
	//---------------------------------------------------------
#if defined(PLATFORM_DESKTOP)
    // TODO: Support for dropped files on the exe
    
    // Support command line argument for custom music file
    if (argc > 1)
    {
        // Just supporting an input argument parameter!!! o__O
        
        if ((IsFileExtension(argv[1], ".ogg")) ||
            (IsFileExtension(argv[1], ".wav")))
        {
            if (sampleFilename != NULL) free(sampleFilename);
            
            sampleFilename = (char *)malloc(256);
            strcpy(sampleFilename, argv[1]);
            
            printf("Custom audio file: %s", sampleFilename);
        }
    }
#endif

#ifndef PLATFORM_ANDROID
    SetConfigFlags(FLAG_MSAA_4X_HINT);
#endif
    // Note windowTitle is unused on Android
    InitWindow(screenWidth, screenHeight, "GGJ17 - WAVE COLLECTOR");

    // Global data loading (assets that must be available in all screens, i.e. fonts)
    InitAudioDevice();

    font = LoadFont("resources/font.fnt");
    music = LoadMusicStream("resources/audio/wave.ogg");
    
    SetMusicVolume(music, 1.0f);

    // Setup and Init first screen
    currentScreen = LOGO;
    InitLogoScreen();
    //InitTitleScreen();
    //InitGameplayScreen();
    //InitEndingScreen();

#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
    SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        UpdateDrawFrame();
    }
#endif

    // De-Initialization
    //--------------------------------------------------------------------------------------
    switch (currentScreen)
    {
        case LOGO: UnloadLogoScreen(); break;
        case TITLE: UnloadTitleScreen(); break;
        case GAMEPLAY: UnloadGameplayScreen(); break;
        case ENDING: UnloadEndingScreen(); break;
        default: break;
    }
    
    // Unload all global loaded data (i.e. fonts) here!
    UnloadFont(font);
    UnloadMusicStream(music);

    CloseAudioDevice();     // Close audio context
    
    CloseWindow();          // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
Exemple #15
0
void LoadConfig(void)
{
	FILE *f;
	int fx, music, channels, musicChannels;
	int dynamic;
	char s[128];

	f = fopen(GetConfigFilePath("options.cnf"), "r");

	if (f) {
		fscanf(f, "%d %d %d %d %d %d %d %d %d\n",
		       &gOptions.displayFPS,
		       &gOptions.displayTime,
		       &gOptions.playersHurt,
		       &gOptions.copyMode,
		       &gOptions.brightness,
		       &gOptions.swapButtonsJoy1,
		       &gOptions.swapButtonsJoy2,
		       &gOptions.xSplit, &gOptions.ySplit);
		fscanf(f, "%d\n%d %d %d %d %d %d\n",
		       &gPlayer1Data.controls,
		       &gPlayer1Data.keys[0],
		       &gPlayer1Data.keys[1],
		       &gPlayer1Data.keys[2],
		       &gPlayer1Data.keys[3],
		       &gPlayer1Data.keys[4], &gPlayer1Data.keys[5]);
		fscanf(f, "%d\n%d %d %d %d %d %d\n",
		       &gPlayer2Data.controls,
		       &gPlayer2Data.keys[0],
		       &gPlayer2Data.keys[1],
		       &gPlayer2Data.keys[2],
		       &gPlayer2Data.keys[3],
		       &gPlayer2Data.keys[4], &gPlayer2Data.keys[5]);
		fscanf(f, "%d\n", &gOptions.mapKey);
		fscanf(f, "%d %d %d %d\n",
		       &fx, &music, &channels, &musicChannels);
		SetFXVolume(fx);
		SetMusicVolume(music);
		SetFXChannels(channels);
		SetMinMusicChannels(musicChannels);

		fscanf(f, "%d\n", &dynamic);
		fscanf(f, "%s\n", s);
		SetModuleDirectory(s);
		fscanf(f, "%u\n", &gCampaign.seed);
		fscanf(f, "%d %d\n", &gOptions.difficulty,
		       &gOptions.slowmotion);

		fscanf(f, "%d\n", &gOptions.density);
		if (gOptions.density < 25 || gOptions.density > 200)
			gOptions.density = 100;
		fscanf(f, "%d\n", &gOptions.npcHp);
		if (gOptions.npcHp < 25 || gOptions.npcHp > 200)
			gOptions.npcHp = 100;
		fscanf(f, "%d\n", &gOptions.playerHp);
		if (gOptions.playerHp < 25 || gOptions.playerHp > 200)
			gOptions.playerHp = 100;
		
		{
			int w, h, s, fs;

			if (fscanf(f, "%dx%d:%d:%d\n", &w, &h, &fs, &s) == 4) {
				Gfx_SetHint(HINT_WIDTH, w);
				Gfx_SetHint(HINT_HEIGHT, h);

				if (fs != 0) Gfx_HintOn(HINT_FULLSCREEN);
				if (s > 1)  Gfx_SetHint(HINT_SCALEFACTOR, s);
			}
		}

		fclose(f);
	}

	return;
}
Exemple #16
0
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(void) 
{
	// Initialization (Note windowTitle is unused on Android)
	//---------------------------------------------------------
    InitWindow(screenWidth, screenHeight, "KOALA SEASONS");

    // Load global data here (assets that must be available in all screens, i.e. fonts)
    font = LoadFont("resources/graphics/mainfont.png");

    atlas01 = LoadTexture("resources/graphics/atlas01.png");
    atlas02 = LoadTexture("resources/graphics/atlas02.png");
    
#if defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_ANDROID)
    colorBlend = LoadShader("resources/shaders/glsl100/base.vs", "resources/shaders/glsl100/blend_color.fs");
#else
    colorBlend = LoadShader("resources/shaders/glsl330/base.vs", "resources/shaders/glsl330/blend_color.fs");
#endif

    InitAudioDevice();
    
    // Load sounds data
    fxJump = LoadSound("resources/audio/jump.ogg");
    fxDash = LoadSound("resources/audio/dash.ogg");
    fxEatLeaves = LoadSound("resources/audio/eat_leaves.ogg");
    fxHitResin = LoadSound("resources/audio/resin_hit.ogg");
    fxWind = LoadSound("resources/audio/wind_sound.ogg");
    fxDieSnake = LoadSound("resources/audio/snake_die.ogg");
    fxDieDingo = LoadSound("resources/audio/dingo_die.ogg");
    fxDieOwl = LoadSound("resources/audio/owl_die.ogg");
    
    
    music = LoadMusicStream("resources/audio/jngl.xm");
    PlayMusicStream(music);
    SetMusicVolume(music, 1.0f);

    // Define and init first screen
    // NOTE: currentScreen is defined in screens.h as a global variable
    currentScreen = TITLE;

    InitLogoScreen();
    //InitOptionsScreen();
    InitTitleScreen();
    InitGameplayScreen();
    InitEndingScreen();

#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
    SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------
    
    // Main game loop
    while (!WindowShouldClose()) UpdateDrawFrame();
#endif

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadEndingScreen();
    UnloadTitleScreen();
    UnloadGameplayScreen();
    UnloadLogoScreen();
    
    UnloadTexture(atlas01);
    UnloadTexture(atlas02);
    UnloadFont(font);
    
    UnloadShader(colorBlend);   // Unload color overlay blending shader
    
    UnloadSound(fxJump);
    UnloadSound(fxDash);
    UnloadSound(fxEatLeaves);
    UnloadSound(fxHitResin);
    UnloadSound(fxWind);
    UnloadSound(fxDieSnake);
    UnloadSound(fxDieDingo);
    UnloadSound(fxDieOwl);
    
    UnloadMusicStream(music);
    
    CloseAudioDevice();         // Close audio device

    CloseWindow();              // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
sint32
openAL_Init (audio_Driver *driver, sint32 flags)
{
	int i;
	TFB_DecoderFormats formats =
	{
		MIX_IS_BIG_ENDIAN, MIX_WANT_BIG_ENDIAN,
		audio_FORMAT_MONO8, audio_FORMAT_STEREO8,
		audio_FORMAT_MONO16, audio_FORMAT_STEREO16
	};
	
	log_add (log_Info, "Initializing OpenAL.");
	alcDevice = alcOpenDevice (NULL);

	if (!alcDevice)
	{
		log_add (log_Error, "Couldn't initialize OpenAL: %d",
				alcGetError (NULL));
		return -1;
	}

	*driver = openAL_Driver;
	atexit (unInitAudio);

	alcContext = alcCreateContext (alcDevice, NULL);
	if (!alcContext)
	{
		log_add (log_Error, "Couldn't create OpenAL context: %d",
				alcGetError (alcDevice));
		alcCloseDevice (alcDevice);
		alcDevice = NULL;
		return -1;
	}

	alcMakeContextCurrent (alcContext);

	log_add (log_Info, "OpenAL initialized.\n"
			"    version:     %s\n"
			"    vendor:      %s\n"
			"    renderer:    %s\n"
			"    device:      %s",
			alGetString (AL_VERSION), alGetString (AL_VENDOR),
			alGetString (AL_RENDERER),
			alcGetString (alcDevice, ALC_DEFAULT_DEVICE_SPECIFIER));
    //log_add (log_Info, "    extensions:  %s", alGetString (AL_EXTENSIONS));
		
	log_add (log_Info, "Initializing sound decoders.");
	if (SoundDecoder_Init (flags, &formats))
	{
		log_add (log_Error, "Sound decoders initialization failed.");
		alcMakeContextCurrent (NULL);
		alcDestroyContext (alcContext);
		alcContext = NULL;
		alcCloseDevice (alcDevice);
		alcDevice = NULL;
		return -1;
	}
	log_add (log_Error, "Sound decoders initialized.");

	alListenerfv (AL_POSITION, listenerPos);
	alListenerfv (AL_VELOCITY, listenerVel);
	alListenerfv (AL_ORIENTATION, listenerOri);

	for (i = 0; i < NUM_SOUNDSOURCES; ++i)
	{
		float zero[3] = {0.0f, 0.0f, 0.0f};
		
		alGenSources (1, &soundSource[i].handle);
		alSourcei (soundSource[i].handle, AL_LOOPING, AL_FALSE);
		alSourcefv (soundSource[i].handle, AL_POSITION, defaultPos);
		alSourcefv (soundSource[i].handle, AL_VELOCITY, zero);
		alSourcefv (soundSource[i].handle, AL_DIRECTION, zero);
		
		soundSource[i].stream_mutex = CreateMutex ("OpenAL stream mutex", SYNC_CLASS_AUDIO);
	}

	if (InitStreamDecoder ())
	{
		log_add (log_Error, "Stream decoder initialization failed.");
		// TODO: cleanup source mutexes [or is it "muti"? :) ]
		SoundDecoder_Uninit ();
		alcMakeContextCurrent (NULL);
		alcDestroyContext (alcContext);
		alcContext = NULL;
		alcCloseDevice (alcDevice);
		alcDevice = NULL;
		return -1;
	}
	
	SetSFXVolume (sfxVolumeScale);
	SetSpeechVolume (speechVolumeScale);
	SetMusicVolume ((COUNT) musicVolume);

	if (optStereoSFX)
		alDistanceModel (AL_INVERSE_DISTANCE);
	else
		alDistanceModel (AL_NONE);

	(void) driver; // eat compiler warning

	return 0;
}
Exemple #18
0
// Gameplay Screen Initialization logic
void InitGameplayScreen(void)
{
    // TODO: Initialize GAMEPLAY screen variables here!
    framesCounter = 0;
    finishScreen = 0;
    
    // MAP LAODING
        // TODO: Read .bmp file propierly in order to get image width & height
    Color *mapPixels = malloc(GRID_WIDTH*GRID_HEIGHT * sizeof(Color));
    mapPixels = GetImageData(LoadImage("assets/gameplay_screen/maps/map.bmp"));
    
    maxTriangles = 0;
    maxPlatforms = 0;
    
    for (int i=0; i<GRID_WIDTH*GRID_HEIGHT; i++)
    {
        /*
        printf("r: %i\n", mapPixels[i].r);
        printf("g: %i\n", mapPixels[i].g);
        printf("b: %i\n\n", mapPixels[i].b);
        */
        if (mapPixels[i].r == 255 && mapPixels[i].g == 0 && mapPixels[i].b == 0) maxTriangles++;
        else if (mapPixels[i].r == 0 && mapPixels[i].g == 255 && mapPixels[i].b == 0) maxPlatforms++;
    }
    
    triangles = malloc(maxTriangles * sizeof(TriangleObject));
    platforms = malloc(maxPlatforms * sizeof(SquareObject));
    
    int trianglesCounter=0;
    int platformsCounter=0;
    
    
    for (int y=0; y<GRID_HEIGHT; y++)
    {
        for (int x=0; x<GRID_WIDTH; x++)
        {
            if (mapPixels[y*GRID_WIDTH+x].r == 255 && mapPixels[y*GRID_WIDTH+x].g == 0 && mapPixels[y*GRID_WIDTH+x].b == 0) 
            {
                InitializeTriangle(&triangles[trianglesCounter], (Vector2){x, y});
                trianglesCounter++;
            }
            else if (mapPixels[y*GRID_WIDTH+x].r == 0 && mapPixels[y*GRID_WIDTH+x].g == 255 && mapPixels[y*GRID_WIDTH+x].b == 0) 
            {
                InitializePlatform(&platforms[platformsCounter], (Vector2){x, y});
                platformsCounter++;
            }
        }
    }
    
    free(mapPixels);
    
    //DEBUGGING && TESTING variables
    pause = FALSE;
    srand(time(NULL)); 
    
    // Textures loading
    player.texture = LoadTexture("assets/gameplay_screen/cube_main.png");
    triangleTexture = LoadTexture("assets/gameplay_screen/triangle_main.png");
    platformTexture = LoadTexture("assets/gameplay_screen/platform_main.png");
    player.pEmitter.texture = LoadTexture("assets/gameplay_screen/particle_main.png");
    
    bg = LoadTexture("assets/gameplay_screen/bg_main.png");
    
    // Sound loading
    InitAudioDevice();
    PlayMusicStream("assets/gameplay_screen/music/Flash_Funk_MarshmelloRemix.ogg");
    PauseMusicStream();
    SetMusicVolume(0.5f);
    
    // Did player win?
    startGame = FALSE;
    
    /*
    player.texture = LoadTexture("assets/gameplay_screen/debug.png");
    triangleTexture = LoadTexture("assets/gameplay_screen/debug.png");
    platformTexture = LoadTexture("assets/gameplay_screen/debug.png");
    player.pEmitter.texture = LoadTexture("assets/gameplay_screen/particle_main.png");
    */
    
    // Camera initialization
    mainCamera = (Camera2D){Vector2Right(), (Vector2){6.5f, 6.5f}, Vector2Zero(), TRUE};
    
    // Gravity initialization
    gravity = (GravityForce){Vector2Up(), 1.5f};
    
    // Ground position and coordinate
    groundCoordinadeY = GetScreenHeight()/CELL_SIZE-1;
    groundPositionY = GetOnGridPosition((Vector2){0, groundCoordinadeY}).y;
    
    // Player initialization
    InitializePlayer(&player, (Vector2){4, groundCoordinadeY-1}, (Vector2){0, 15}, 0.35f*GAME_SPEED);
    
    /*
    // Triangles initialization
    InitializeTriangle(&triangles[0], (Vector2){40, groundCoordinadeY-1});
    InitializeTriangle(&triangles[1], (Vector2){50, groundCoordinadeY-1});
    InitializeTriangle(&triangles[2], (Vector2){85, groundCoordinadeY-1});
    
    // Platforms initialization
    InitializePlatform(&platforms[0], (Vector2){20, groundCoordinadeY-1});
    InitializePlatform(&platforms[1], (Vector2){21, groundCoordinadeY-1});
    InitializePlatform(&platforms[2], (Vector2){22, groundCoordinadeY-1});
    InitializePlatform(&platforms[3], (Vector2){23, groundCoordinadeY-2});
    InitializePlatform(&platforms[4], (Vector2){24, groundCoordinadeY-2});
    */
}
Exemple #19
0
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(void)
{
	// Initialization
	//---------------------------------------------------------
    InitWindow(screenWidth, screenHeight, "GGJ16 - LIGHT MY RITUAL!");

    // Global data loading (assets that must be available in all screens, i.e. fonts)
    InitAudioDevice();

    Image image = LoadImage("resources/lights_map.png");  // Load image in CPU memory (RAM)
    
    lightsMap = GetImageData(image);            // Get image pixels data as an array of Color
    lightsMapWidth = image.width;
    lightsMapHeight = image.height;
    
    UnloadImage(image);                         // Unload image from CPU memory (RAM)
    
    font = LoadSpriteFont("resources/font_arcadian.png");
	//doors = LoadTexture("resources/textures/doors.png");
    //sndDoor = LoadSound("resources/audio/door.ogg");
    
    music = LoadMusicStream("resources/audio/ambient.ogg");
    PlayMusicStream(music);
    SetMusicVolume(music, 1.0f);

    // Setup and Init first screen
    currentScreen = LOGO_RL;
    //InitTitleScreen();
    //InitGameplayScreen();
    rlInitLogoScreen();

#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else
    SetTargetFPS(60);   // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        UpdateDrawFrame();
    }
#endif

    // De-Initialization
    //--------------------------------------------------------------------------------------
    switch (currentScreen)
    {
        case LOGO_RL: rlUnloadLogoScreen(); break;
        case TITLE: UnloadTitleScreen(); break;
        case GAMEPLAY: UnloadGameplayScreen(); break;
        default: break;
    }
    
    // Unload all global loaded data (i.e. fonts) here!
    UnloadSpriteFont(font);
    //UnloadSound(sndDoor);
    
    UnloadMusicStream(music);
    
    free(lightsMap);
    
    CloseAudioDevice();
    
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------
	
    return 0;
}