Esempio n. 1
0
File: Game.cpp Progetto: ziz/solarus
/**
 * @brief This function is called when a game key is pressed.
 * @param key a key
 */
void Game::key_pressed(GameControls::GameKey key) {

  if (!is_suspended()) {    

    if (key == GameControls::PAUSE) {
      if (can_pause()) {
        set_paused(true);
      }
    }
    else {
      // when the game is not suspended, all other keys apply to the hero
      hero->key_pressed(key);
    }
  }

  // is a message being shown?
  else if (is_showing_message()) {
    dialog_box->key_pressed(key);
  }

  // is the game paused?
  else if (is_paused()) {
    pause_menu->key_pressed(key);
  }

  // is the game over sequence shown?
  else if (is_showing_gameover()) {
    gameover_sequence->key_pressed(key);
  }
}
Esempio n. 2
0
Time::Time(int delta)
    : current(0)
    , last_dt(0.0f)
    , delta(delta)
    , scale(0)
    , steps(0)
    , paused(true)
    , sound_last_time(0.0)
    , sound(nullptr) {

    set_paused(false);
}
Esempio n. 3
0
/**
 * \brief This function is called when a game command is pressed.
 * \param command A game command.
 */
void Game::notify_command_pressed(GameCommands::Command command) {

  // Is a built-in dialog box being shown?
  if (is_dialog_enabled()) {
    if (dialog_box.notify_command_pressed(command)) {
      return;
    }
  }

  // See if the game script handles the command.
  if (get_lua_context().game_on_command_pressed(*this, command)) {
    return;
  }

  // See if the map script handled the command.
  if (get_lua_context().map_on_command_pressed(get_current_map(), command)) {
    return;
  }

  // Lua scripts did not override the command: do the built-in behavior.
  if (command == GameCommands::PAUSE) {
    if (is_paused()) {
      if (can_unpause()) {
        set_paused(false);
      }
    }
    else {
      if (can_pause()) {
        set_paused(true);
      }
    }
  }

  else if (!is_suspended()) {
    // When the game is not suspended, all other commands apply to the hero.
    hero->notify_command_pressed(command);
  }
}
Esempio n. 4
0
void SimTimeSync::MergeFrom(const SimTimeSync& from) {
  GOOGLE_CHECK_NE(&from, this);
  if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    if (from.has_sim_time()) {
      mutable_sim_time()->::llsf_msgs::Time::MergeFrom(from.sim_time());
    }
    if (from.has_real_time_factor()) {
      set_real_time_factor(from.real_time_factor());
    }
    if (from.has_paused()) {
      set_paused(from.paused());
    }
  }
  mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
Esempio n. 5
0
void systems_init()
{
    SDL_Init(SDL_INIT_EVERYTHING);
    TTF_Init();

    atexit(SDL_Quit);
    atexit(TTF_Quit);

    srand((unsigned int)time(NULL));

    assets_init();
    ent_table_init();

    set_started(0);
    set_game_over(0);
    set_paused(1);
}
Esempio n. 6
0
void Boat_m_touch(Ent *ent1, Ent *ent2)
{
    Boat *boat = (Boat*)ent1;
    if(Ent_GET(flags, ent2) & EFLAGS_SOLID) {
        if(ent_class_is_subclass(ent2->eclass, &Enemy_CLASS)) {
            set_paused(1);
            set_game_over(1);
        } else {
            float dir_angle = vec2_to_angle(Ent_GET(move_direction, boat)),
                  coll_angle;
            vec2 boat_pos = *Ent_GET(position, boat),
                 coll_pos = *Ent_GET(position, ent2);
            vec2 coll_vec = coll_pos;
        
            vec2_sub(&coll_vec, &boat_pos);
            vec2_norm(&coll_vec);

            coll_angle = vec2_to_angle(&coll_vec);

            if(fabs(dir_angle - coll_angle) <= 45)
                Ent_SET(speed, boat, 0);
        }
    }
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
    FMOD_CHANNEL    *channel[2] = { 0,0 };
    FMOD_RESULT       result;
    int               key, outputrate, slot = 0, count, numdrivers;
    unsigned int      version;
    
    printf("=============================================================================\n");
    printf("Granular Synthesis SetDelay example.\n");
    printf("Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("=============================================================================\n");
    printf("\n");
    printf("TOGGLE #define USE_STREAMS ON/OFF TO SWITCH BETWEEN STREAMS/STATIC SAMPLES.\n");
    printf("Press space to pause, Esc to quit\n");
    printf("\n");
    
    /*
        ===============================================================================================================
        RECOMMENDED STARTUP SEQUENCE BEGIN
        ===============================================================================================================
    */

    result = FMOD_System_Create(&gSystem);
    ERRCHECK(result);
    
    result = FMOD_System_GetVersion(gSystem, &version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
        printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
        return 0;
    }
    
    result = FMOD_System_GetNumDrivers(gSystem, &numdrivers);
    ERRCHECK(result);

    if (numdrivers == 0)
    {
        result = FMOD_System_SetOutput(gSystem, FMOD_OUTPUTTYPE_NOSOUND);
        ERRCHECK(result);
    }
    else
    {
        FMOD_CAPS caps;
        FMOD_SPEAKERMODE speakermode;
        char name[256];
        
        result = FMOD_System_GetDriverCaps(gSystem, 0, &caps, 0, &speakermode);
        ERRCHECK(result);

        result = FMOD_System_SetSpeakerMode(gSystem, speakermode);       /* Set the user selected speaker mode. */
        ERRCHECK(result);

        if (caps & FMOD_CAPS_HARDWARE_EMULATED)             /* The user has the 'Acceleration' slider set to off!  This is really bad for latency!. */
        {                                                   /* You might want to warn the user about this. */
            result = FMOD_System_SetDSPBufferSize(gSystem, 1024, 10);
            ERRCHECK(result);
        }

        result = FMOD_System_GetDriverInfo(gSystem, 0, name, 256, 0);
        ERRCHECK(result);

        if (strstr(name, "SigmaTel"))   /* Sigmatel sound devices crackle for some reason if the format is PCM 16bit.  PCM floating point output seems to solve it. */
        {
            result = FMOD_System_SetSoftwareFormat(gSystem, 48000, FMOD_SOUND_FORMAT_PCMFLOAT, 0,0, FMOD_DSP_RESAMPLER_LINEAR);
            ERRCHECK(result);
        }
    }

    result = FMOD_System_Init(gSystem, 100, FMOD_INIT_NORMAL, 0);
    if (result == FMOD_ERR_OUTPUT_CREATEBUFFER)         /* Ok, the speaker mode selected isn't supported by this soundcard.  Switch it back to stereo... */
    {
        result = FMOD_System_SetSpeakerMode(gSystem, FMOD_SPEAKERMODE_STEREO);
        ERRCHECK(result);
            
        result = FMOD_System_Init(gSystem, 100, FMOD_INIT_NORMAL, 0);/* ... and re-init. */
        ERRCHECK(result);
    }
    
    /*
        ===============================================================================================================
        RECOMMENDED STARTUP SEQUENCE END
        ===============================================================================================================
    */
        
    result = FMOD_System_GetSoftwareFormat(gSystem, &outputrate, 0,0,0,0,0);
    ERRCHECK(result);   
   
#if !defined(USE_STREAMS)
    for (count = 0; count < NUMSOUNDS; count++)
    {
        result = FMOD_System_CreateSound(gSystem, soundname[count], FMOD_IGNORETAGS, 0, &sound[count]);
        ERRCHECK(result);
    }
#endif

    /*
        Kick off the first 2 sounds.  First one is immediate, second one will be triggered to start after the first one.
    */
    channel[slot] = queue_next_sound(outputrate, channel[1-slot], rand()%NUMSOUNDS, slot);
    slot = 1-slot;  /* flip */
    channel[slot] = queue_next_sound(outputrate, channel[1-slot], rand()%NUMSOUNDS, slot);
    slot = 1-slot;  /* flip */

    /*
        Main loop.
    */
    do
    {
        int isplaying;
        static int paused = 0;

        if (_kbhit())
        {
            key = _getch();

            switch (key)
            {
                case ' ' :
                {
                    set_paused(channel, paused);
                    paused = !paused;
                    break;
                }
            }
        }

        FMOD_System_Update(gSystem);

        /*
            Replace the sound that just finished with a new sound, to create endless seamless stitching!
        */
        result = FMOD_Channel_IsPlaying(channel[slot], &isplaying);
        if (!isplaying && !paused)
        {
            printf("sound %d finished, start a new one\n", slot);
            #ifdef USE_STREAMS
            /* 
                Release the sound that isn't playing any more. 
            */
            result = FMOD_Sound_Release(sound[slot]);       
            ERRCHECK(result);
            sound[slot] = 0;
            #endif
   
            /*
                Replace sound that just ended with a new sound, queued up to trigger exactly after the other sound ends.
            */
            channel[slot] = queue_next_sound(outputrate, channel[1-slot], rand()%NUMSOUNDS, slot);
            slot = 1-slot;  /* flip */
        }
        
        Sleep(10);  /* If you wait too long, ie longer than the length of the shortest sound, you will get gaps. */

    } while (key != 27);

    printf("\n");

    for (count = 0; count < sizeof(sound) / sizeof(sound[0]); count++)
    {
        if (sound[count])
        {
            FMOD_Sound_Release(sound[count]);
        }
    }
    
    /*
        Shut down
    */
    result = FMOD_System_Release(gSystem);
    ERRCHECK(result);

    return 0;
}
Esempio n. 8
0
/**
 * \brief Restarts the animation.
 */
void Sprite::restart_animation() {
  set_current_frame(0);
  set_paused(false);
}
Esempio n. 9
0
void Time::toggle_pause() {
    set_paused(!paused);
}