コード例 #1
0
ファイル: Enemy.cpp プロジェクト: RKX1209/Dnscript
void Enemy::update(){
  int now_frame = frame->get_frame();
  //printf("%d\n",now_frame);
  while(true){
    Action action = action_list->get_action(now_frame);
    if(action.get_type() == Action::TYPE_MOVE){
      set_state(STATE_MOVE);
      move_frame = action.get_move_frame();
    }
    else if(action.get_type() == Action::TYPE_SHOOT){
      set_state(STATE_SHOOT);
    }
    else{
      break;
    }

    if(is_state(STATE_SHOOT)){
      action.get_bullet()->shoot();
      remove_state(STATE_SHOOT);
    }
  }
  if(is_state(STATE_MOVE)){
    if(move_frame > 0){
      obj_pos->x += dx;
      obj_pos->y += dy;
      move_frame--;
    }else{
      remove_state(STATE_MOVE);
    }
  }

  for(int i = 0; i < bullet_num; i++){
    if(bullets[i]->is_shoot()){
      bullets[i]->update();
    }
  }

}
コード例 #2
0
ファイル: core.cpp プロジェクト: BackupTheBerlios/damaris-svn
int core::run() {
  // writes the config and process id to file
  write_state();

  quit_mainloop=0;

  while (!quit_mainloop && term_signal==0 && quit_signal==0) {
      // wait for a job to run...
      job * this_job=NULL;
      result* this_result=NULL;
      try {
	  this_job=wait_for_input();
      }
      catch (job_exception je) {
	  this_result=new error_result(job_counter,je);
      }
      
      if (quit_mainloop!=0 || term_signal!=0) {
	  if (this_job!=NULL) delete this_job;
	  break;
      }
      // do the work ...
      if (this_job!=NULL) {
	  this_result=do_the_job(*this_job);
	  if (term_signal!=0) {
	      delete this_job;
	      if (this_result!=NULL) delete this_result;
	      break;
	  }
      }
      else
	this_job=new job(job_counter);
      if (this_result==NULL) {
	  this_result=new error_result(job_counter,"unexpected: did not get any result");
      }
      // tell them...
      write_to_output(*this_job,*this_result);
      delete this_result;
      delete this_job;
      job_counter++;
  }

  // deletes config file
  remove_state();

  return 0;
}
コード例 #3
0
ファイル: state_manager.cpp プロジェクト: tomgalvin594/Struct
void State_Manager::update(double delta)
{
    //check if active state requested for change
    unsigned int next_state_id = m_all_states[0]->get_next_state_id();

    if(next_state_id == game_state::null_state)
    {
        //no change, update the active state
        m_all_states[0]->update(delta);
    }
    else
    {
        //change in state required
        unsigned int current_state_id = m_all_states[0]->get_state_id();

        //menu state
        if(current_state_id == game_state::menu)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::quit)
            {
                clear_states();
            }
        }

        //play state
        else if(current_state_id == game_state::play)
        {
            if(next_state_id == game_state::pause_state)
            {
                create_state(game_state::pause_state);
            }
            else if(next_state_id == game_state::game_over)
            {
                create_state(game_state::game_over);
            }
            else if(next_state_id == game_state::level_win)
            {
                create_state(game_state::level_win);
            }
        }

        //pause state
        else if(current_state_id == game_state::pause_state)
        {
            if(next_state_id == game_state::play)
            {
                remove_state();
                m_all_states[0]->reset_next_state_id();
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        //level win state
        else if(current_state_id == game_state::level_win)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        //game over state
        else if(current_state_id == game_state::game_over)
        {
            if(next_state_id == game_state::play)
            {
                clear_states();
                create_state(game_state::play);
            }
            else if(next_state_id == game_state::menu)
            {
                clear_states();
                create_state(game_state::menu);
            }
        }

        else
            std::cout << "Undefined state requested\n";
    }

}