示例#1
0
文件: Game.cpp 项目: jimmychenn/Games
bool Game::Init()
{
	// Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
	{
		SDL_Log("Failed to initialize SDL.");
		return false;
	}
    
	// Initialize Renderer
	if (!mRenderer.Init(1024, 768))
	{
		SDL_Log("Failed to initialize renderer.");
		return false;
	}
    
    // Initialize SDL Mixer
    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048))
    {
        SDL_Log("Failed to Initizlie SDL Mixer");
        return false;
    }

	// Initialize RNG
	Random::Init();

	// Start frame timer
	mTimer.Start();
    
    //Map all actions and inputs
    AddInputMappings();

	// Run any code at game start
	StartGame();

	return true;
}
示例#2
0
void music_play (const char *file,
                 const char *alias,
                 uint32_t rate)
{
    int audio_format = MIX_DEFAULT_FORMAT;
    int audio_channels = 2;
    int audio_buffers = 4096;

    if (!music_init_done) {
        if (Mix_OpenAudio(rate,
                          audio_format,
                          audio_channels,
                          audio_buffers) != 0) {

            MSG_BOX("Mix_OpenAudio fail: %s %s",
                    Mix_GetError(), SDL_GetError());
            SDL_ClearError();
        }

        music_init_done = true;
    }

    musicp music = music_load(file, alias);

    music_update_volume();

    static int sound_loaded;
    if (!sound_loaded) {
        sound_loaded = true;
        sound_load_all();
    }

    if (Mix_FadeInMusicPos(music->music, -1, 2000, 0) == -1) {
//    if (Mix_PlayMusic(music->music, -1) == -1) {
        WARN("cannot play music %s: %s", music->tree.key, Mix_GetError());
    }
}
示例#3
0
SoundManager::SoundManager(){
    cout << "Initializing sound Manager\n";


    if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2,1024)==-1) {
        printf("Mix_OpenAudio: %s\n", Mix_GetError());
        exit(2);
    } else {
        cout << "opened audio" << "\n";
        cout << "Allocated " << Mix_AllocateChannels(m_totalChannels);
        cout << " channels of audio\n";
        cout << "opened audio" << endl;
        cout << "Allocated " << Mix_AllocateChannels(m_totalChannels)
         << " channels of audio\n";
    }


    int flags=MIX_INIT_OGG;
    int initted = Mix_Init(flags);
    if((initted & flags) != flags) {
        printf("Mix_Init: Failed to init required ogg and mod support!\n");
        printf("Mix_Init: %s\n", Mix_GetError());
        // handle error
    } else {
        cout << "mix init success\n";
    }

    //Mix_VolumeMusic(100);
    Mix_Volume(0, 50);
    Mix_Volume(1, 50);
    Mix_Volume(2, 50);

    m_eventHandler.registerHandler();
    m_eventHandler.registerEvent("play_sound");
    m_eventHandler.registerEvent("play_song");
    m_eventHandler.registerEvent("song_volume");
}
示例#4
0
void Splash::show(void)
{
    Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
    music = Mix_LoadMUS("data/muzika/music.wav");
    Mix_PlayMusic(music, -1);

    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glOrtho(0, this->wWidth, 0, this->wHeight, -1, 1);

    // Begin render

    glColor4ub(255, 255, 255, 255); // White color
    glBegin(GL_QUADS);
        glVertex2f(0, 0);
        glVertex2f(this->wWidth, 0);
        glVertex2f(this->wWidth, this->wHeight);
        glVertex2f(0, wHeight);
    glEnd();

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, this->texture);
    glBegin(GL_QUADS);
        glTexCoord2d(0, 1); glVertex2f(this->x, this->y);
        glTexCoord2d(1, 1); glVertex2f(this->x + this->width, this->y);
        glTexCoord2d(1, 0); glVertex2f(this->x + this->width, this->y + this->height);
        glTexCoord2d(0, 0); glVertex2f(this->x, this->y + this->height);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    // End render

    glPopMatrix();
    SDL_GL_SwapBuffers();
    SDL_Delay(time);
    Mix_FreeMusic(music);
}
示例#5
0
main(int argc, char *argv[]) {
  /* Initialize the SDL library */
  if (SDL_Init(SDL_INIT_AUDIO) < 0) {
    fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    exit(2);
  }
  atexit(SDL_Quit);

  /* Open the audio device */
  if (Mix_OpenAudio(8000, AUDIO_U8, 1, 512) < 0) {
    fprintf(stderr,"Mix_OpenAudio: %s\n", Mix_GetError());
  }

  if (loadSounds()) {
    while (1) {
      playSound();
    }
    
    freeSounds();
  }

  Mix_CloseAudio();
  exit(0);
}
示例#6
0
/*------------------------------------------------------------------------------------------------------------------
--       FUNCTION: 		    	init_everything
--
--       DATE:                  April 15, 2009
--
--       DESIGNER:              Alin Albu
--
--       PROGRAMMER: 		    Alin Albu
--
--       INTERFACE:                 bool init_everything(SDL_Surface* screen)
--
--	 RETURNS:		    true if SDLinitialization succeeds, false otherwise
--
--       NOTES:
--       initialises the libraries, as well as the screen and sets screen size and window caption.
----------------------------------------------------------------------------------------------------------------------*/
bool init_everything(SDL_Surface **screen) {
	printf("Init everything Started");
	//Initialize all SDL subsystems
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
		printf("Init everything Failed\n");
		return false;
	}
	printf("...");
	//Set up the screen
	*screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF);
	//If there was an error in setting up the screen
	if (*screen == NULL) {
		printf("Init SCREEN Failed\n");
		return false;
	}
	printf("...");
	//Initialize SDL_ttf
	if (TTF_Init() == -1) {
		printf("Init TTF Failed\n");
		return false;
	}
	printf("...");
	//Initialize SDL_mixer
	if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1) {
		printf("Init AUDIO Failed\n");
		return false;
	}
	printf("...");
	//Set the window caption
	SDL_WM_SetCaption("Tux Bomber", NULL);
	printf("...");
	SDL_ShowCursor(SDL_ENABLE);
	//If everything initialized fine
	printf("Init everything Done\n");
	return true;
}
示例#7
0
bool JukeBox::OpenDevice()
{
  if (m_init)
    return true;
  Config* cfg = Config::GetInstance();
  if (!cfg->GetSoundEffects() && !cfg->GetSoundMusic()) {
    End();
    return false;
  }

  /* Initialize the SDL library */
  if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
    std::cerr << "* Couldn't initialize SDL: "<< SDL_GetError() << std::endl;
    return false;
  }
  m_init = true;

  Uint16 audio_format = MIX_DEFAULT_FORMAT;
  int audio_buffer = 1024;

  /* Open the audio device */
  if (Mix_OpenAudio(cfg->GetSoundFrequency(), audio_format, channels, audio_buffer) < 0) {
    std::cerr << "* Couldn't open audio: " <<  SDL_GetError() << std::endl;
    End();
    return false;
  } else {
    int frequency;
    Mix_QuerySpec(&frequency, &audio_format, &channels);
    std::cout << Format(_("o Opened audio at %d Hz %d bit"),
                        frequency, (audio_format&0xFF)) << std::endl;
    cfg->SetSoundFrequency(frequency);
  }
  Mix_ChannelFinished(JukeBox::EndChunk);
  Mix_HookMusicFinished(JukeBox::EndMusic);
  return true;
}
//---------------------------------------------------------------------------
bool BaseApplication::setup(void)
{
    mRoot = new Ogre::Root(mPluginsCfg);

    setupResources();

    bool carryOn = configure();
    if (!carryOn) return false;

    chooseSceneManager();
    createCamera();
    createViewports();

    // Set default mipmap level (NB some APIs ignore this)
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

    // Create any resource listeners (for loading screens)
    createResourceListener();
    // Load resources
    loadResources();

    // Create the scene
    createScene();

    createFrameListener();

    SDL_Init(SDL_INIT_EVERYTHING);
    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);
    music = Mix_LoadMUS("game_music.mp3");
    Mix_PlayMusic(music,-1);
    Mix_Volume(-1, 40);

    createGUI();

    return true;
};
bool init()
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return false;
    }

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return false;
    }

    //Initialize SDL_ttf
    if( TTF_Init() == -1 )
    {
        return false;
    }


    //Iniciando SDL_Mixer
    if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
    {
        return false;
    }

    //Set the window caption
    SDL_WM_SetCaption( "Press an Arrow Key", NULL );

    //If everything initialized fine
    return true;
}
  CSDL2Renderer::CSDL2Renderer() {

    if ( SDL_Init( SDL_INIT_EVERYTHING ) != 0 ) {
      std::cout << "Something went wrong: " << SDL_GetError() << std::endl;
    }
    IMG_Init(IMG_INIT_PNG);
    mWindow = SDL_CreateWindow( "BlockyFalls",
                               SDL_WINDOWPOS_CENTERED,
                               SDL_WINDOWPOS_CENTERED,
                               640,
                               480,
                               SDL_WINDOW_SHOWN );

    if ( mWindow == nullptr ) {
      std::cout << "Could not create a Window.";
      std::cout << SDL_GetError() << std::endl;
      SDL_Quit();
      return;
    }

    mRenderer = SDL_CreateRenderer( mWindow, -1, 0 );

    if ( mRenderer == nullptr ) {
      std::cout << "Could not create renderer: ";
      std::cout << SDL_GetError() << std::endl;
      SDL_Quit();
      return;
    }


    TTF_Init();

    if ( Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1 ) {
      std::cout << "coudlnt init mixer" << std::endl;
    }
  }
示例#11
0
         InitAndQuit(bool shadersOn)
         {
            if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
            {
               std::ostringstream error;
               error << "Failed on SDL_Init: " << SDL_GetError() << "\n";
               throw std::runtime_error(error.str());
            }
            graphics::setupGraphics(shadersOn);
            SDL_WM_SetCaption("Sousaphone Hero", "Sousaphone Hero");
            if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS) != 0)
            {
               SDL_Quit();
               std::ostringstream error;
               error << "Failed on Mix_OpenAudio: " << Mix_GetError() << "\n";
               throw std::runtime_error(error.str());
            }

            std::srand(time(NULL));

            Mix_ChannelFinished(doChangedNotes); // set callback function

            startTiming();
         }
示例#12
0
void Window::initialize()
{
	showDebugInfo();

    fprintf(stdout, "Initializing SDL system\r\n");
    if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) != 0)
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }

    fprintf(stdout, "Initializing font system\r\n");
    if(TTF_Init() == -1)
    {
        fprintf(stderr, "Unable to init SDL_ttf: %s\n", TTF_GetError());
        exit(2);
    }
    fprintf(stdout, "Initializing audio system\r\n");
    if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0)
    {
    	fprintf(stderr, "Unable to open audio channel: %s\n", Mix_GetError());
        exit(3);
    }
}
示例#13
0
Audio::Audio(const std::string& name) : System(name) {
	
	sound_count = 0;
	music_count = 0;
	
	if (SDL_Init(SDL_INIT_AUDIO) != 0) {
		std::cerr << "ERROR: Failed to initialize SDL AUDIO!" << std::endl;
		std::cerr << SDL_GetError() << std::endl;
		return;
	}
	
	atexit(SDL_Quit);
	
	#define AUDIO_RATE      ((int)22050)
	#define AUDIO_FORMAT    ((unsigned short)AUDIO_S16)
	#define AUDIO_CHANNELS  ((int)2)
	#define AUDIO_BUFFERS   ((int)4096)
	
	if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS)) {
		std::cerr << "ERROR: Failed to open SDL AUDIO!" << std::endl;
		std::cerr << SDL_GetError() << std::endl;
		return;
	}
}
void SoundManager::sound_init()
{
    Larp::CustomConfigurationLoader* config = Larp::CustomConfigurationLoader::load_configurations("sound.cfg");
    _music_volume = std::stof(config->get_configuration("music_volume"));
    _effect_volume = std::stof(config->get_configuration("sound_volume"));

    SDL_Init(SDL_INIT_EVERYTHING);

    srand(time(NULL));

    Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 4096);

    /*Load sound effects here */
    _background_music = Mix_LoadMUS("assets/sound/Neotantra.mp3");
    _sound_effects.emplace("shotgun", Mix_LoadWAV("assets/sound/shotgun.wav"));
    _sound_effects.emplace("rocket_fire", Mix_LoadWAV("assets/sound/rocket_fire.wav"));
    _sound_effects.emplace("chaingun", Mix_LoadWAV("assets/sound/chaingun.wav"));
    _sound_effects.emplace("jump", Mix_LoadWAV("assets/sound/jump.wav"));
    _sound_effects.emplace("walk0", Mix_LoadWAV("assets/sound/walking0.wav"));
    _sound_effects.emplace("walk1", Mix_LoadWAV("assets/sound/walking1.wav"));

    Mix_VolumeMusic(MIX_MAX_VOLUME * _music_volume);
    Mix_Volume(-1, MIX_MAX_VOLUME * _effect_volume);
}
示例#15
0
bool init() {

	//Init video, audio
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
		printf("SDL could not initialize Video or Audio! Error: %s\n", SDL_GetError());
		return false;
	}

	//Init image loader
	if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) {
		printf("SDL could not initialize Image loader! Error: %s\n", IMG_GetError());
		return false;
	}

	//Init SDL_mixer
	if (Mix_OpenAudio(HIGH_FREQUENCY, MIX_DEFAULT_FORMAT, STEREO, CHUNKS) < 0) {
		printf("SDL_Mixer could not initialze! Error: %s\n", Mix_GetError());
		return false;
	}

	window = SDL_CreateWindow("Sound effect", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
	if (window == NULL) {
		printf("SDL_Window could not be created! Error: %s\n", SDL_GetError());
		return false;
	}

	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (renderer == NULL) {
		printf("Renderer could not be created! Error: %s\n", SDL_GetError());
		return false;
	}

	texture = new MyTexture(renderer);

	return true;
}
示例#16
0
文件: Kernel.c 项目: sigt44/ventifact
int kernel_Init_Audio(void)
{
    if(flag_Check(&kernel_Main.SDL_Init_Flags, SDL_INIT_AUDIO) == 0)
    {
        file_Log(ker_Log(), 1, "No sound device loaded.\n");
        /*Initialise sound manager with it not accepting any sounds*/
        sound_Init(0, 0, 0, 0);

        return 0;
    }

    printf("Opening audio device\n\n");
    if(Mix_OpenAudio(kernel_Main.sound_Frequency, kernel_Main.sound_Format, kernel_Main.sound_Channels, kernel_Main.sound_Chunksize) == -1)
    {
        return -1;
    }

    printf("Initalising sound manager\n");
    sound_Init(16, 32, 50, 1);

    ker_ReportAudio();

    return 0;
}
示例#17
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);
}
示例#18
0
文件: sound.cpp 项目: Ablu/invertika
void Sound::init()
{
    // Don't initialize sound engine twice
    if (mInstalled)
        return;

    logger->log("Sound::init() Initializing sound...");

    if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
    {
        logger->log("Sound::init() Failed to initialize audio subsystem");
        return;
    }

    const size_t audioBuffer = 4096;

    const int res = Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
                                  MIX_DEFAULT_CHANNELS, audioBuffer);
    if (res < 0)
    {
        logger->log("Sound::init Could not initialize audio: %s",
                    Mix_GetError());
        return;
    }

    Mix_AllocateChannels(16);
    Mix_VolumeMusic(mMusicVolume);
    Mix_Volume(-1, mSfxVolume);

    info();

    mInstalled = true;

    if (!mCurrentMusicFile.empty())
        playMusic(mCurrentMusicFile);
}
示例#19
0
void eir_snd_api_init()
{
   SDL_version compile_version;
   const SDL_version * link_version = Mix_Linked_Version();

   SDL_MIXER_VERSION(&compile_version);
   EIR_KER_LOG_MESSAGE(
      "SDL mixer compile vers: %d.%d.%d",
      compile_version.major,
      compile_version.minor,
      compile_version.patch
      );
   EIR_KER_LOG_MESSAGE(
      "SDL mixer link vers: %d.%d.%d",
      link_version->major,
      link_version->minor,
      link_version->patch
      );

   if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1)
   {
      EIR_KER_LOG_ERROR("SDL mixer open audio init failed: %s", Mix_GetError());
   }
}
示例#20
0
int  MP3_Load (const char *name)
{
	/* Initialize variables */
	audio_rate = 22050;
	audio_format = AUDIO_S16;
	audio_channels = 2;
	audio_buffers = 4096;
	
	/* Open the audio device */
	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) {
		fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
		return(2);
	} else {
		Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
		/*printf("Opened audio at %d Hz %d bit %s (%s), %d bytes audio buffer\n", audio_rate,
			(audio_format&0xFF),
			(audio_channels > 2) ? "surround" : (audio_channels > 1) ? "stereo" : "mono", 
			(audio_format&0x1000) ? "BE" : "LE",
			audio_buffers );*/
	}
	audio_open = 1;

	/* Set the music volume */
	Mix_VolumeMusic(audio_volume);

	/* Set the external music player, if any */
	Mix_SetMusicCMD(getenv("MUSIC_CMD"));

	music = Mix_LoadMUS(name);
	if ( music == NULL ) {
		fprintf(stderr, "Couldn't load %s,%s\n",name, SDL_GetError());
		CleanUp();
		exit(0);
	}
	return 1;
}
示例#21
0
int main(int argc, char *argv[])
{
  (void) argc;
  (void) argv;

  if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
    std::cout << "Failed to initialize SDL" << SDL_GetError() << std::endl;
  std::cout << "Hello SDL!" << std::endl;

  // Display SDL version information
  SDL_version compiled;
  SDL_version linked;
  SDL_VERSION(&compiled);
  SDL_GetVersion(&linked);
  logSDLVersion(std::cout, "SDL", compiled, linked, SDL_GetRevision());


  // Initialize SDL_image and display version information
  int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;
  int imgFlagsInit = IMG_Init(imgFlags);
  if ((imgFlagsInit & imgFlags) != imgFlags)
    std::cout << "Failed to initialize SDL_image:"
              << IMG_GetError() << std::endl;
  std::cout << "Hello SDL_image!" << std::endl;
  SDL_IMAGE_VERSION(&compiled);
  logSDLVersion(std::cout, "SDL_image", compiled, *IMG_Linked_Version(), "");


  // Initialize SDL_mixer and display version information
  int mixFlags = MIX_INIT_OGG;
  int mixFlagsInit = Mix_Init(mixFlags);
  if ((mixFlagsInit & mixFlags) != mixFlags) {
    std::cout << "Failed to initialize SDL_mixer"
              << Mix_GetError() << std::endl;
  }
  if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
    std::cout << "Failed to acquire sound device"
              << Mix_GetError() << std::endl;
  }
  std::cout << "Hello SDL_mixer!" << std::endl;
  SDL_MIXER_VERSION(&compiled);
  logSDLVersion(std::cout, "SDL_mixer", compiled, *Mix_Linked_Version(), "");
  logSDLMixerMediaInfo(std::cout);


  // Initialize SDL_mixer and display version information
  if (TTF_Init() != 0)
    std::cout << "Failed to initialize SDL_ttf:"
              << SDL_GetError() << std::endl;
  std::cout << "Hello SDL_ttf!" << std::endl;
  SDL_TTF_VERSION(&compiled);
  logSDLVersion(std::cout, "SDL_ttf", compiled, *TTF_Linked_Version(), "");


  // Create a window and OpenGL glContext using SDL and GLEW
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
                      SDL_GL_CONTEXT_PROFILE_CORE);
  SDL_Window* window = SDL_CreateWindow("SDL Window",
                                        SDL_WINDOWPOS_UNDEFINED,
                                        SDL_WINDOWPOS_UNDEFINED,
                                        640, 480,
                                        SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
  SDL_GLContext glContext = nullptr;
  const std::pair<int, int> glVersions[11]
     {{4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0},
      {3, 3}, {3, 2}, {3, 1}, {3, 0},
      {2, 1}, {2, 0}
  };
  const std::string glName = "OpenGL";
  for (auto& glVersion : glVersions) {
    std::cout << "Trying to create " << glName << " " << glVersion.first << "."
              << glVersion.second << " glContext" << std::endl;
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, glVersion.first);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, glVersion.second);
    glContext = SDL_GL_CreateContext(window);
    if (glContext != nullptr)
      break;
  }
  if (glContext == nullptr)
    std::cout << "Failed to create OpenGL Context " << std::endl;

  bool isOk = SDL_GL_MakeCurrent(window, glContext) <= 0;
  if (!isOk)
    std::cout << "Failed to set OpenGL context" << SDL_GetError() << std::endl;

  glewExperimental = true;
  if (glewInit() != GLEW_OK)
    std::cout << "Failed to initialize GLEW" << std::endl;

  logAcquiredGlVersion(std::cout, glName);
  logOpenGLContextInfo(std::cout);
  logGraphicsDriverInfo(std::cout);

  glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  SDL_GL_SwapWindow(window);

  // Wait for user event before closing
  bool isRunning = true;
  SDL_Event event;
  while (isRunning) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_KEYDOWN &&
          event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)
        isRunning = false;
      else if (event.type == SDL_QUIT)
        isRunning = false;
    }

    SDL_Delay(30);
  }

  // Cleanup
  SDL_DestroyWindow(window);
  SDL_GL_DeleteContext(glContext);
  IMG_Quit();
  const int nOpenAudio = Mix_QuerySpec(nullptr, nullptr, nullptr);
  for (int i = 0 ; i < nOpenAudio ; ++i)
    Mix_CloseAudio();
  while (Mix_Init(0))
    Mix_Quit();
  TTF_Quit();
  SDL_Quit();
  return 0;
}
示例#22
0
bool Game::Init(const char* title, int xpos, int ypos, int width, int height,
		int flags) {
	// attempt to initialize SDL
	if (SDL_Init(SDL_INIT_EVERYTHING) == 0) {
		Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 4097 );
		std::cout << "SDL init success\n";
		// init the window
		m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
		if (m_pWindow != 0) // window init success
				{
			std::cout << "window creation success\n";
			m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
			if (m_pRenderer != 0) // renderer init success
					{
				std::cout << "renderer creation success\n";
				SDL_SetRenderDrawColor(m_pRenderer, 0, 100, 0, 255);

			} else {
				std::cout << "renderer init fail\n";
				return false; // renderer init fail
			}
		} else {
			std::cout << "window init fail\n";
			return false; // window init fail
		}
	} else {
		std::cout << "SDL init fail\n";
		return false; // SDL init fail
	}

	std::cout << "init success\n";
	m_bRunning = true; // everything inited successfully,
//		start the main loop
	//initial game State

	SoundsBank::sound = new SoundsBank();
	SoundsBank::sound->initSoundEffect("sounds/hover.wav");
	SoundsBank::sound->initSoundEffect("sounds/connect.wav");
	SoundsBank::sound->initSoundEffect("sounds/button-24.wav");
//	SoundsBank::sound->initSoundEffect("sounds/removeCards.wav");
	SoundsBank::sound->initMusic("sounds/removeCards.mp3")
;
	m_currentGameStates = MENU;

		m_StartGameMenu.backGroundMenu.Init(m_pRenderer);
		m_StartGameMenu.backGroundForTeam.InitTeam(m_pRenderer);
		m_StartGameMenu.backGroundForTeam.InitRules(m_pRenderer);
		m_StartGameMenu.m_buttonsMenu.Init(m_pRenderer);
		for (int iter = 0; iter < 5; iter++)
		{
				m_StartGameMenu.m_buttonsMenu.setSource(iter * 320,0,320,75);
				m_StartGameMenu.m_buttonsMenu.setDestination(100,(250 + 80 * iter),280,73);

				m_StartGameMenu.m_buttonSet.push_back(m_StartGameMenu.m_buttonsMenu);
		}
		texture.Init(m_pRenderer);
//		m_temp.Init(m_pRenderer);
		m_cardLogic.Init(m_pRenderer);

		m_cardLogic.GetCardFromDeck();

	return true;

}
示例#23
0
SoundBoard::SoundBoard(){
    Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );
    dash = Mix_LoadWAV( "sound/dash.wav" );
}
示例#24
0
文件: init.c 项目: mafiosso/mgean
int
MG_init_video (int width, int height, Uint32 video_flags)
{
  SDL_Surface *screen;
  int audio_rate = 22050;
  Uint16 audio_format = AUDIO_S16;	/* 16-bit stereo */
  int audio_channels = 2;
  int audio_buffers = 2048;

  machine = (MACHINE *) malloc (sizeof (MACHINE));
  memset (machine, 0, sizeof (MACHINE));
//  machine->use_audio = 1;

  if( !( SDL_WasInit( SDL_INIT_VIDEO ) & SDL_INIT_VIDEO ) )
    {
      printf("SDL was not inited yet ... initing\n");

      if( !SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO) )
      {
	if (TTF_Init () == -1)
	  {
	    printf ("Unable to start TTF rendering\n");
	    SDL_Quit ();
	  }
      }
      else
	{
	  printf("err: can not set up SDL\n");
	  SDL_Quit();
	  return -1;
	}
    }
  else
    {
      printf("SDL was already inited\n");
    }

  screen = SDL_SetVideoMode (width, height, 32, video_flags);
  if (!screen)
    {
      printf ("[FATAL] can not set video mode properly!\n");
      exit (-1);
    }

  Mix_VolumeMusic(SDL_MIX_MAXVOLUME);

  if( Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 2048) ){
	  printf("[ERROR] Unable to open audio!\n");
	  exit(-1);
  }

  Mix_ChannelFinished(on_mix_halt);

  machine->screen = screen;

  if( !machine->game_world )
    {
      machine->game_world = SDL_CreateRGBSurface( SDL_SWSURFACE, width, height,
						  screen->format->BitsPerPixel,
						  screen->format->Rmask, screen->format->Gmask,
						  screen->format->Bmask, screen->format->Amask
						  );
    }

  SDL_Rect v = {0,0,machine->screen->w , machine->screen->h };
  MG_set_view_rect( v );

  MG_get_keys ();
  return 0;
}
示例#25
0
static int OPL_SDL_Init(unsigned int port_base)
{
    // Check if SDL_mixer has been opened already
    // If not, we must initialize it now

    if (!SDLIsInitialized())
    {
        if (SDL_Init(SDL_INIT_AUDIO) < 0)
        {
            fprintf(stderr, "Unable to set up sound.\n");
            return 0;
        }

        if (Mix_OpenAudio(opl_sample_rate, AUDIO_S16SYS, 2, GetSliceSize()) < 0)
        {
            fprintf(stderr, "Error initialising SDL_mixer: %s\n", Mix_GetError());

            SDL_QuitSubSystem(SDL_INIT_AUDIO);
            return 0;
        }

        SDL_PauseAudio(0);

        // When this module shuts down, it has the responsibility to 
        // shut down SDL.

        sdl_was_initialized = 1;
    }
    else
    {
        sdl_was_initialized = 0;
    }

    opl_sdl_paused = 0;
    pause_offset = 0;

    // Queue structure of callbacks to invoke.

    callback_queue = OPL_Queue_Create();
    current_time = 0;

    // Get the mixer frequency, format and number of channels.

    Mix_QuerySpec(&mixing_freq, &mixing_format, &mixing_channels);

    // Only supports AUDIO_S16SYS

    if (mixing_format != AUDIO_S16SYS || mixing_channels != 2)
    {
        fprintf(stderr, 
                "OPL_SDL only supports native signed 16-bit LSB, "
                "stereo format!\n");

        OPL_SDL_Shutdown();
        return 0;
    }

    // Mix buffer:

    mix_buffer = malloc(mixing_freq * sizeof(uint32_t));

    // Create the emulator structure:

    DBOPL_InitTables();
    Chip__Chip(&opl_chip);
    Chip__Setup(&opl_chip, mixing_freq);

    callback_mutex = SDL_CreateMutex();
    callback_queue_mutex = SDL_CreateMutex();

    // TODO: This should be music callback? or-?
    Mix_HookMusic(OPL_Mix_Callback, NULL);

    return 1;
}
示例#26
0
bool SDLWrapper::initialize(){
	bool successSDL = false;
	bool successIMG = false;
	bool successMixer = false;
	bool successTTF = false;

	SDL_version compiled;

	Log(DEBUG) << "Initializing systems...";

	// Initializing SDL_TTF.
	const int ttfInit = TTF_Init();
	if(ttfInit == 0){
		successTTF = true;

		SDL_TTF_VERSION(&compiled);
		SDLWrapper::logSDLVersion("SDL_TTF", compiled);
	}
	else{
		Log(ERROR) << "Could not initialize TTF." << TTF_GetError();
	}

	// Initializing SDL with initFlags.
	const Uint32 initFlags = SDL_INIT_EVERYTHING;
	const int sdlInit = SDL_Init(initFlags);

	if(sdlInit == 0){
		successSDL = true;

		SDL_version linked;
		SDL_VERSION(&compiled);
		SDL_GetVersion(&linked);

		SDLWrapper::logSDLVersion("SDL", compiled, SDL_GetRevision());
	}
	else{
		Log(ERROR) << "Could not initialize SDL." << SDL_GetError();
	}

	// Initializing SDL_image with imgFlags.
	const Uint32 imgFlags = IMG_INIT_PNG;
	if((IMG_Init(imgFlags) & imgFlags)){
		successIMG = true;

		SDL_IMAGE_VERSION(&compiled);
		SDLWrapper::logSDLVersion("SDL_image", compiled);
	}
	else{
		Log(ERROR) << "Could not initialize SDL_Image." << IMG_GetError();
	}

	// Initializing SDL_mixer.
	const int frequency = 44100;
	const int channels = 2;
	const int chunksize = 4096;
	const int initialized = Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, channels, chunksize);
	if(initialized == 0){
		successMixer = true;

		SDL_MIXER_VERSION(&compiled);
		SDLWrapper::logSDLVersion("SDL_mixer", compiled);
	}
	else{
		Log(ERROR) << "Could not initialize SDL_Mixer" << Mix_GetError();
	}

	// If even one system fails to initialize, returns false.
	return (successSDL && successIMG && successMixer && successTTF);
}
示例#27
0
//Initializes SDL_Window
bool cWindow::InitializeSDLWindow(SDL_Window*& window, string gameName,
					 SDL_Renderer*& gRenderer)
{
	//Initialization flag
	bool success = true;

	//Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
	{
		printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
		success = false;
	}
	else
	{
		//Create window
		window = SDL_CreateWindow(gameName.c_str(), SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
			SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (window == nullptr)
		{
			printf("Window could not be created! SDL_Error: %s\n",
				SDL_GetError());
			success = false;
		}
		else
		{
			//Create renderer for window 
			gRenderer = SDL_CreateRenderer( window, -1, 
												SDL_RENDERER_ACCELERATED ); 
			if( gRenderer == NULL ) 
			{ 
				printf( "Renderer could not be created! SDL Error: %s\n", 
										SDL_GetError() ); success = false;
			} 
			else 
			{ 
				//Initialize renderer color 
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				//Initialize PNG loading 
				int imgFlags = IMG_INIT_PNG; 
				if( !( IMG_Init( imgFlags ) & imgFlags ) ) 
				{ 
					printf( "SDL_image could not initialize! "
						"SDL_image Error: %s\n", IMG_GetError() ); 
					success = false; 
				} 
			}
			//Initialize SDL_mixer 
			if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
			{
				printf("SDLmixer couldn't initialize! SDL_mixer Error: %s\n",
					Mix_GetError()); success = false;
			}
			else
			{
				//Get window surface 
				//screenSurface = SDL_GetWindowSurface(window);
			}
		}
	}

	return success;
}
示例#28
0
文件: fuzed.cpp 项目: dave18/Fuzed
int main( int argc, char* args[] )
{

    int err,z;

    for (z=0;z<100;z++)
    {
        hiname[z]=(char*)malloc(5);
        //hiscores[z]=10000-z*100;
        hiscores[z]=0;
        hinew[z]=0;
        if (z&1) strcpy(hiname[z],"ED!"); else  strcpy(hiname[z],"FUZ");
    }


    #ifdef _WIN32
    _setmode( _fileno( stdin ), _O_BINARY );
    _setmode( _fileno( stdout ), _O_BINARY );
    #endif

    // Initialize all SDL subsystems
    err=SDL_Init( SDL_INIT_JOYSTICK | SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO );

    if (err ==-1)
    {
        printf(  "SDL Init error: %d\n",  err  );
        return 1;
    }
    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF);
    SDL_ShowCursor(false);

    if (Mix_OpenAudio(44100, AUDIO_S16, MIX_DEFAULT_CHANNELS, 1024))
    {
        printf ("SDL Could not open sound hardware\n");
        soundpresent=0;
    }

    srand((int)SDL_GetTicks());

	// Do PC specific stuff
    #ifdef _WIN32
	// Set the window caption
	SDL_WM_SetCaption( "FuZeD", NULL );
    #endif // PLATFORM_PC

    SDL_Surface* intro_screen_scroll;
    SDL_Surface* intro_header;
    SDL_Surface* intro_footer;
    SDL_Surface* intro_icons;
    SDL_Surface* mouse_pointer;


    loadgfx(&intro_screen_scroll,(char*)"graphics/page_background_1280_scroll_wrap.png");
    loadgfx(&intro_header,(char*)"graphics/page_header.png");
    loadgfx(&intro_footer,(char*)"graphics/page_footer.png");

    loadgfx(&intro_icons,(char*)"graphics/intro_icons.png");
    loadgfx(&mouse_pointer,(char*)"graphics/mouse_pointer.png");

    loadgfx(&font,(char*)"graphics/16x16_font.png");
    loadgfx(&smallfont,(char*)"graphics/8x8_font.png");

    loadgfx(&spritemasks,(char*)"graphics/collmask.png");
    loadgfx(&coin_collide,(char*)"graphics/coin_collide.png");

    music = NULL;

    if (soundpresent)
    {

        mine_arm_snd=Mix_LoadWAV("audio/blips4.wav");
        explosion_snd=Mix_LoadWAV("audio/explosion_x.wav");
        collect_snd=Mix_LoadWAV("audio/sound005.wav");
        jump_snd=Mix_LoadWAV("audio/sound008.wav");
        bomb_land_snd=Mix_LoadWAV("audio/hammer.wav");
    }

    playercontrols[0].left=SDLK_LEFT;
    playercontrols[0].right=SDLK_RIGHT;
    playercontrols[0].cycle=SDLK_PAGEUP;
    playercontrols[0].jump=SDLK_PAGEDOWN;
    playercontrols[0].fire=SDLK_END;

    playercontrols[1].left=SDLK_z;
    playercontrols[1].right=SDLK_x;
    playercontrols[1].cycle=SDLK_c;
    playercontrols[1].jump=SDLK_t;
    playercontrols[1].fire=SDLK_f;

    playercontrols[0].joy=10; //keyboard
    playercontrols[1].joy=10;


InitCollisions(15);
level.Init();
wheelie.init();
grog.init();
slinky.init();
bomb.init();
explosion.init();
smoke.init();
mine.init();
dynamite.init();
player.init();
gem.init();
coin.init();
pickup.init();
pickedup16.init();
pickedup32.init();
hiscore.init();
LoadScores();
LoadSettings();
quitgame=0;
//level=new Tlevel;
while (quitgame==0)
{
    int keydata=0;
    int introscroll=0;
    int s1clip=640;
    long ticks=SDL_GetTicks();

    int exit_intro=0;
    int intro_option=0;
    startlevel=0;

    if (soundpresent)
    {
        if (music) Mix_FreeMusic(music);
        music = Mix_LoadMUS("audio/FuZED.title.Main.xm");
        if (!music) printf("SDL could not load music: %s\n" , SDL_GetError());
        if (music) Mix_PlayMusic(music, -1);
    }
    while (exit_intro<2)
    {
        introscroll+=4;
        if (introscroll>=1280) introscroll=0;
        s1clip=640-(introscroll-640);
        if (s1clip>640) s1clip=640;

        drawSprite(intro_screen_scroll, screen, introscroll, 0, 0, 96, s1clip, 352);
        if (s1clip<640) drawSprite(intro_screen_scroll, screen, 0, 0, s1clip, 96, 640-s1clip, 352);

        //drawSprite(intro_screen_scroll, screen, 0, 0, introscroll, 96, 1280, 352);
        //drawSprite(intro_screen_scroll, screen, 0, 0, 1280+introscroll, 96, 1280, 352);

        drawSprite(intro_header, screen, 0, 0, 0, 0, 640, 96);
        drawSprite(intro_footer, screen, 0, 0, 0, 448, 640, 32);

        drawSprite(intro_icons, screen, 0, 0, 32, 160, 96, 96);
        drawSprite(intro_icons, screen, 96, 0, 192, 160, 96, 96);
        drawSprite(intro_icons, screen, 192, 0, 352, 160, 96, 96);
        drawSprite(intro_icons, screen, 288, 0, 512, 160, 96, 96);

        drawSprite(intro_icons, screen, 288+96, 0, 32, 300, 96, 96);
        drawSprite(intro_icons, screen, 288+192, 0, 192, 300, 96, 96);
        drawSprite(intro_icons, screen, 288+288+96, 0, 352, 300, 96, 96);
        drawSprite(intro_icons, screen, 288+288, 0, 512, 300, 96, 96);


        drawSprite(mouse_pointer, screen, 0, 0, mx,my, 19, 31);

        if (images_collide(mx, my, 8, 8, mouse_pointer, 0, 0, 24, 31, 0xFF00FF, 32, 160, 96, 96, intro_icons, 0, 0, 96, 96, 0xFF00FF))
        {
            Text((char*)"SINGLE PLAYER",216,462);
            if (keydata & MY_BUTT_B)
            {
                exit_intro=2;
                intro_option=0;
            }
        }
        if (images_collide(mx, my, 8, 8, mouse_pointer, 0, 0, 24, 31, 0xFF00FF, 192, 160, 96, 96, intro_icons, 0, 0, 96, 96, 0xFF00FF))
        {
            Text((char*)"TWO PLAYER TEAM",200,462);
               if (keydata & MY_BUTT_B)
            {
                exit_intro=2;
                intro_option=1;
            }
        }
        //if (images_collide(mx, my, 8, 8, mouse_pointer, 0, 0, 24, 31, 0xFF00FF, 32, 160, 96, 96, intro_icons, 0, 0, 96, 96, 0xFF00FF)) Text((char*)"SINGLE PLAYER",216,462);
        //if (images_collide(mx, my, 8, 8, mouse_pointer, 0, 0, 24, 31, 0xFF00FF, 32, 160, 96, 96, intro_icons, 0, 0, 96, 96, 0xFF00FF)) Text((char*)"SINGLE PLAYER",216,462);
        if (images_collide(mx, my, 8, 8, mouse_pointer, 0, 0, 24, 31, 0xFF00FF, 512, 300, 96, 96, intro_icons, 0, 0, 96, 96, 0xFF00FF))
        {
            Text((char*)"EXIT GAME",248,462);
               if (keydata & MY_BUTT_B)
            {
                exit_intro=2;
                intro_option=7;
            }
        }


        SDL_Flip(screen);


        keydata=get_key(0);

//        printf("MS %d Millisecs\n",SDL_GetTicks()-ticks);
//        ticks=SDL_GetTicks();
    }

    if (soundpresent) Mix_HaltMusic();

    if ((intro_option>=0) && (intro_option<=3))
    {
		level.Create(startlevel);							//Create level (level id)
		player.spawn(1,level.GetPx(0),level.GetPy(0),2,0,0,3,1);		//Create Player 1
		if (intro_option>0) player.spawn(2,level.GetPx(1),level.GetPy(1),2,0,0,3,0);		//Create Player 2
		if (soundpresent)
		{
		    if (music) Mix_FreeMusic(music);
			if (startlevel<5) music = Mix_LoadMUS("audio/FuZED.lev.Checkers.xm");
			if ((startlevel>=5) && (startlevel<10)) Mix_LoadMUS("audio/FuZED.lev.Ancient.xm");

		}
		level.AddEnemies();

		level.Fadein();
		keydata=0;
        if ((soundpresent) && (music)) Mix_PlayMusic(music, -1);	//Start music playing
		while ((player.CountList()>0) && (QDOWN==0))
		{
		    while ((((player.CountList()>0) && (level.door_appear<4)) || hiscore.CountList()>0) && (QDOWN==0))
		    {
                level.Play();

                SDL_Flip(screen);
                keydata=get_key(0);
/*                if (keydata & MY_BUTT_A)
                {
                    SDL_SaveBMP(screen,"screenshot.bmp");
                    printf("screenshot saved\n");
                }*/
		    }
		    if ((player.CountList()>0) && (QDOWN==0))
		    {
				ClearAllLists();
				level.ScrollToNext();
				level.AddEnemies();
                player.InitialPosition();

		    }
		}

		level.Fadeout();
		ClearAllLists();
		player.ClearList();

    }


    if (intro_option==7) quitgame=1;
}
    Mix_FreeMusic(music);
    SaveScores();
    SaveSettings();
    SDL_Quit();

    return 0;

}
void PersonajeJugador::logic(Uint8* teclas_presionadas)
{
Mix_Chunk *Sonido = NULL;

 Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 );
Sonido = Mix_LoadWAV("sound.wav");




    SDL_Rect temp = this->rectangulo;

    if( teclas_presionadas[ SDL_SCANCODE_UP ] )
    {

        rectangulo.y-=1;
        if(orientacion!="up")
            textura_actual=texturas_up.begin();
        orientacion="up";
    }
    if( teclas_presionadas[ SDL_SCANCODE_DOWN ] )
    {
        rectangulo.y+=1;
        if(orientacion!="down")
            textura_actual=texturas_down.begin();
        orientacion="down";
    }
    if( teclas_presionadas[ SDL_SCANCODE_RIGHT ] )
    {
        rectangulo.x+=1;
        if(orientacion!="right")
            textura_actual=texturas_right.begin();
        orientacion="right";
    }
    if( teclas_presionadas[ SDL_SCANCODE_LEFT ] )
    {
        rectangulo.x-=1;
        if(orientacion!="left")
            textura_actual=texturas_left.begin();
        orientacion="left";
    }
//     if( teclas_presionadas[ SDL_SCANCODE_X ] )
//    {
//    SDL_Renderer* renderer2;
//    SDL_Rect rect_character;
//    SDL_Texture *poder = IMG_LoadTexture(renderer2, "assets/llamas/01.png");
//
//SDL_RenderCopy(renderer2,poder, NULL, &rect_character);
//
//    SDL_RenderCopy(renderer2, poder, NULL, &rect_character);
//        SDL_RenderPresent(renderer2);
////        rectangulo.x-=1;
////        if(orientacion!="left")
////            textura_actual=texturas_left.begin();
////        orientacion="left";
//    }

//    for(list<Personaje*>::iterator i = personajes->begin();
//            i!=personajes->end();
//            i++)
//    {
//        if(this==(*i))
//            continue;
//        if(colision(this->rectangulo, (*i)->rectangulo))
//        {
//            rectangulo=temp;
//           c+=1;
//            break;
//        }
//    }
//    cout<<c;


     for(list<Personaje*>::iterator i = personajes->begin();
            i!=personajes->end();
            i++)
    {
        if(this==(*i))
            continue;
        if(colision(this->rectangulo, (*i)->rectangulo)&&teclas_presionadas[ SDL_SCANCODE_X ])
        {
            //rectangulo=temp;
            personajes->erase(i);
            Mix_PlayChannel( -1, Sonido, 0 );
            break;
        }
    }


}
示例#30
0
文件: sub_music.c 项目: gtalis/gp2xmb
void sub_music_handle_input(unsigned int button)
{
    switch (button)
    {
    case GP2X_BUTTON_L:
        if (music_stage == MUS_FULLSCREEN)
        {
            if (LIST_up())
            {
                mus_stop();
                while (!mus_ready());
                sub_music_playsel();
            }
        }
        break;

    case GP2X_BUTTON_R:
        if (music_stage == MUS_FULLSCREEN)
        {
            if (LIST_down())
            {
                mus_stop();
                while (!mus_ready());
                sub_music_playsel();
            }
        }
        break;

    case GP2X_BUTTON_B:
        if (music_stage == MUS_FULLSCREEN && sub_music_playing)
        {
            sub_music_playing = 0;
            mus_stop();
            music_stage = 0;
            xmb_deactivateFlag(XMB_APPFULLSCREEN);

            while (!mus_ready());

            if (Mix_OpenAudio
                (AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS))
            {
                printf("Unable to open audio!\n");
            }
            break;
        }
    case GP2X_BUTTON_LEFT:
        {
            if (music_stage == MUS_FULLSCREEN && sub_music_playing)
            {
                mus_bwd();
                break;
            }

            if (!music_stage && music_stage < 5)
            {
                sfx_play(SFXBACK);
                LIST_setEmptyMsg(NULL);
                if (LIST_out())
                    music_stage = 4;
                else
                    music_stage = 2;
                music_levels--;
                music_animtimer_b = music_animtimer = SDL_GetTicks();
            }
            break;
        }
    case GP2X_BUTTON_RIGHT:
        if (music_stage == MUS_FULLSCREEN && sub_music_playing)
        {
            mus_fwd();
            break;
        }
        break;
    case GP2X_BUTTON_UP:
        {
            if (music_stage == MUS_FULLSCREEN && sub_music_playing)
            {
                break;
            }

            if (LIST_up())
                sfx_play(SFXMOVE);
            break;
        }
    case GP2X_BUTTON_DOWN:
        {
            if (music_stage == MUS_FULLSCREEN && sub_music_playing)
            {
                break;
            }

            if (LIST_down())
                sfx_play(SFXMOVE);
            break;
        }
    case GP2X_BUTTON_Y:
        {
            break;
        }
    case GP2X_BUTTON_X:
        {
            if (!music_stage && LIST_getSelected())
            {
                if (music_stage == MUS_FULLSCREEN && sub_music_playing)
                {
                    break;
                }

                if (li_create_new)
                    break;

                LIST_setEmptyMsg(NULL);

                sub_music_playsel();
            }
            break;
        }
    default:
        break;
    }
}