void Instructions_State::on_key(const SDL_KeyboardEvent &event) {
	if(event.keysym.sym == SDLK_ESCAPE && event.state == SDL_PRESSED)
		get_Game().pop_state();
		if(event.keysym.sym == SDLK_RETURN && event.state == SDL_PRESSED){
			state ++;
			if(state == 7)
				get_Game().pop_state();
	}
}
Example #2
0
  void Video_GL::render_all() {
    assert(!m_render_target);

#ifdef _WINDOWS
    glFlush();
#else
    glFinish();
#endif

    get_Textures().unlose_resources();
    get_Fonts().unlose_resources();

    get_Game().prerender();

    glViewport(0, 0, get_screen_width(), get_screen_height());

    if(!is_zwrite_enabled())
      glDepthMask(GL_TRUE);
    set_clear_color_impl(get_clear_color());
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    if(!is_zwrite_enabled())
      glDepthMask(GL_FALSE);

    get_Game().render();

    /*** Begin CPU saver ***/
#ifdef MANUAL_GL_VSYNC_DELAY
   Timer &tr = get_Timer();
   
   if(get_vertical_sync()) {
     Time buffer_swap_start_time = tr.get_time();
     
     const unsigned int time_allowed = 1000u/60u - 2u;
     const unsigned int new_time_taken = buffer_swap_start_time.get_ticks_since(m_buffer_swap_end_time);
     m_time_taken = (1.0f - m_weight_new) * m_time_taken + m_weight_new * new_time_taken;
     
     if(m_time_taken < time_allowed)
       SDL_Delay(static_cast<unsigned int>(time_allowed - m_time_taken));
   }
#endif
    
    /// Swap the buffers <-- NOT part of the CPU saver, but the reason it is "needed"
#if SDL_VERSION_ATLEAST(1,3,0)
   SDL_GL_SwapWindow(get_window());
#else
   SDL_GL_SwapBuffers();
#endif
    
#ifdef MANUAL_GL_VSYNC_DELAY
   m_buffer_swap_end_time = tr.get_time();
#endif
  }
Example #3
0
void MineSquare::Uncover()
{
    if (get_State() != SquareState::Covered)
        return;

	set_State(SquareState::Boomed);

	if (!get_Game()->IsLost())
		set_ViewState(SquareViewState::Boomed);
	else
		set_ViewState(SquareViewState::Mine);

	get_Game()->Lose();
}
void Play_State_Base::perform_logic()	
{
	for(int i = 0; i < controllers.size(); i++)	
		controllers[i]->adjust_Cam(Game_Model::get().get_player(i));

	for(int i = 0; i < controllers.size(); i++)
		controllers[i]->interact_with_player(Game_Model::get().get_player(i), Game_Model::get().get_time_step());


	//update player velocity/movement
	for(int i = 0; i < controllers.size(); i++)
		Game_Model::get().get_player_here(i)->calculate_movement(controllers[i]->give_movement());



	//updates all positions
	Game_Model::get().update();

	if (Game_Model::get().win()){
		Game_Model::get().stop();
		for(int i = 0; i < controllers.size(); i++)
			controllers[i]->reset_controls();	

		get_Game().push_state(new End_Game_State());
	}



	// networking code here
	if(WWClient::isNetwork())
		WWClient::get()->WWhost_logic();
		//Game_Model::get().get_peer()->peer_logic();
}
void Instructions_State::perform_logic()
{
	if (InputHandler::GetInstance().IsKeyDown (KeyFire))
	{
		InputHandler::GetInstance().ResetKey (KeyFire);
		if (texture < 8)
		{
			++texture;
		}
		else
		{
			get_Game().pop_state();
			get_Game().push_state (new Title_State_Custom());
		}
	}
}
void Instructions_State::on_joy_button(const SDL_JoyButtonEvent &event) {
	switch(event.button){
		case 0: // A
			if(event.state == SDL_PRESSED)	{
				state ++;
				if(state == 7)
					get_Game().pop_state();
			}
			break;

		case 1: // B
			get_Game().pop_state();
			break;
				
		default:
			break;
	}
}
void Play_State_Base::on_pop()	{
	get_Window().mouse_hide(false);
	get_Window().mouse_grab(false);
	get_Video().set_clear_Color(m_prev_clear_color);
	get_Game().joy_mouse.enabled = true;
	Game_Model::get().clean();

	for (int i = 0 ; i < player_info->size() ; i++)
		delete player_info->at(i);
	delete player_info;

	for(int i = 0; i < controllers.size() ; i++)	{
		delete controllers[i];
	}
}
  void Video_DX9::render_all() {
    assert(!m_render_target);

    static bool reset = false;

    if(reset) {
      const HRESULT result = m_d3d_device->TestCooperativeLevel();
      
      if(result == D3DERR_DEVICELOST)
        return;
      else if(result == D3DERR_DRIVERINTERNALERROR)
        throw Video_Device_Failure();
      
      if(result == D3DERR_DEVICENOTRESET) {
        if(FAILED(m_d3d_device->Reset(&m_d3d_parameters)))
          throw Video_Device_Failure();
      
        reset = false;

        init_context();
      }
    }

    get_Textures().unlose_resources();
    get_Fonts().unlose_resources();
    
    HRESULT result = m_d3d_device->Present(0, 0, 0, 0);
    
    if(result == S_OK) {
      D3DVIEWPORT9 vp = {0, 0, DWORD(get_screen_width()), DWORD(get_screen_height()), 0, 1};
      m_d3d_device->SetViewport(&vp);
      m_d3d_device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(get_clear_color().r_ub(), get_clear_color().g_ub(), get_clear_color().b_ub()), 1.0f, 0);
      m_d3d_device->BeginScene();

      get_Game().render();
      
      m_d3d_device->EndScene();
    }
    else if(result == D3DERR_DEVICELOST) {
      reset = true;
      return;
    }
    else if(result == D3DERR_DEVICEREMOVED) {
      throw Video_Device_Failure();
    }
  }
Example #9
0
  void Gamestate_II::fire_missed_events() {
    Game &gr = get_Game();

    for(std::map<Zeni_Input_ID, int>::iterator it = m_ii.begin(), iend = m_ii.end(); it != iend; ++it) {
      switch(it->first.type) {
      case SDL_KEYDOWN:
        {
          const float confidence = gr.get_key_state(it->first.subid) ? 1.0f : 0.0f;

          if(m_firing_missed_events && it->first.previous_confidence != confidence)
            on_event(it->first, confidence, it->second);

          it->first.previous_confidence = confidence;
        }
        break;

      case SDL_MOUSEBUTTONDOWN:
        {
          const float confidence = gr.get_mouse_button_state(it->first.subid) ? 1.0f : 0.0f;

          if(m_firing_missed_events && it->first.previous_confidence != confidence)
            on_event(it->first, confidence, it->second);

          it->first.previous_confidence = confidence;
        }
        break;

      case SDL_JOYBUTTONDOWN:
        {
          const float confidence = gr.get_joy_button_state(it->first.which, it->first.subid) ? 1.0f : 0.0f;

          if(m_firing_missed_events && it->first.previous_confidence != confidence)
            on_event(it->first, confidence, it->second);

          it->first.previous_confidence = confidence;
        }
        break;

      default:
        break;
      }
    }
  }
void Play_State_Base::on_push()	{
		get_Window().mouse_hide(true);
		get_Window().mouse_grab(true);
		get_Video().set_clear_Color(Color(0,.1,.1,.1));
		get_Game().joy_mouse.enabled = false;

		Game_Model::get().change_level(create_level(level.std_str()));
		Game_Model::get().start_up(*player_info);

		if(!isLocal)
			Game_Model::get().initialize_peer(isServer, host_addr);
				
		for(int i = 0; i < Game_Model::get().num_players_here() ; i++)	{
			controllers.push_back(new Controls(false, i));
			if(player_info->at(i)->controls_ == 1)
				controllers[i]->set_inverted(true);
			controllers[i]->set_input_sensitivity(player_info->at(i)->sensitivities_);
		}
}
Example #11
0
  void Console_State::on_key(const SDL_KeyboardEvent &event) {
    Game &gr = get_Game();
    const bool mod_nonshift = gr.get_key_state(SDLK_LALT) || gr.get_key_state(SDLK_RALT) ||
                              gr.get_key_state(SDLK_LCTRL) || gr.get_key_state(SDLK_RCTRL) ||
#if SDL_VERSION_ATLEAST(1,3,0)
                              gr.get_key_state(SDLK_LGUI) || gr.get_key_state(SDLK_LGUI);
#else
                              gr.get_key_state(SDLK_LMETA) || gr.get_key_state(SDLK_RMETA) ||
                              gr.get_key_state(SDLK_LSUPER) || gr.get_key_state(SDLK_RSUPER);
#endif

    if(event.type == SDL_KEYDOWN &&
       !mod_nonshift)
    {
      switch(event.keysym.sym) {
        case SDLK_RETURN:
          if(m_prompt.get_edit_pos() != -1) {
            fire_command(m_prompt.get_text());
            m_prompt.set_text("");
          }
          break;

        default:
          if(m_prompt.get_edit_pos() != -1) {
            const String backup_text = m_prompt.get_text();
            const int backup_pos = m_prompt.get_edit_pos();
            const bool restore = m_prompt.get_num_lines() == 1;

            m_prompt.on_event(event);

            if(m_prompt.get_num_lines() > 1 && restore) {
              m_prompt.set_text(backup_text);
              m_prompt.seek(backup_pos);
            }
          }
          break;
      }
    }

    m_handled_event = m_prompt.get_edit_pos() != -1;
  }
Example #12
0
  void Level_1::perform_logic() {
    const Time_HQ current_time = get_Timer_HQ().get_time();
    float processing_time = float(current_time.get_seconds_since(time_passed));
    time_passed = current_time;

    /** Get forward and left vectors in the XY-plane **/
    const Vector3f forward = m_player.get_camera().get_forward().get_ij().normalized();
    const Vector3f left = m_player.get_camera().get_left().get_ij().normalized();

    /** Get velocity vector split into a number of axes **/
	int grav_dir = m_player.get_gravity_direction();
	Vector3f velocity;
	Vector3f x_vel, y_vel, z_vel;

    velocity = (m_controls.forward - m_controls.back) * 50.0f * forward
                            + (m_controls.left - m_controls.right) * 50.0f * left;
	x_vel = velocity.get_i();
      y_vel = velocity.get_j();
     z_vel = m_player.get_velocity().get_k();

	 if (m_fire)
	 {
		 m_fire = false;
		 m_bullets.push_back(m_player.fire());
	 }

	 //Move bullets forward and heck collision 
	for(list<Bullet *>::iterator it = m_bullets.begin(); it != m_bullets.end();)
	{
		(*it)->move_forward(processing_time * 200.0f);
		
		if (m_crate.get_body().intersects((*it)->get_body()))
		{
			m_crate.set_velocity(m_player.get_gravity_direction());
			delete *it;
			it = m_bullets.erase(it);
		}
		else
			++it;
	}

	m_crate.move(processing_time * 10.0f);

    /** Bookkeeping for sound effects **/
    if(velocity.magnitude() != 0.0f)
      m_moved = true;

    /** Keep delays under control (if the program hangs for some time, we don't want to lose responsiveness) **/
    if(processing_time > 0.1f)
      processing_time = 0.1f;

    /** Physics processing loop**/
    for(float time_step = 0.05f; processing_time > 0.0f; processing_time -= time_step)
    {
      if(time_step > processing_time)
        time_step = processing_time;

      /** Gravity has its effect **/
		z_vel -= Vector3f(0.0f, 0.0f, 50.0f * time_step);

		on_top = false;
      /** Try to move on each axis **/
      partial_step(time_step, x_vel);
      partial_step(time_step, y_vel);
      partial_step(time_step, z_vel);

	  if (m_crate.get_body().intersects(m_player.get_body()) && m_player.get_body().get_end_point_b().z > m_crate.get_body().get_point().z + m_crate.get_body().get_edge_c().k)
	  { //Currently only works for up/down movement while on crate
		  Point3f base_pos =  m_player.get_camera().position;
		  m_player.set_position(base_pos + m_crate.get_velocity());
	  }

      /** Keep player above ground; Bookkeeping for jumping controls **/
      const Point3f &position = m_player.get_camera().position;
      if(position.z < 50.0f) {
        m_player.set_position(Point3f(position.x, position.y, 50.0f));
        m_player.set_on_ground(true);
      }
    }

	if (m_crate2.get_body().intersects(m_player.get_body()))
	{
		//get_Game().pop_state();
		get_Game().push_state(new Crate_State());
	}
  }
void Play_State_Base::on_uncover()	{
	get_Window().mouse_hide(true);
	get_Window().mouse_grab(true);
	get_Game().joy_mouse.enabled = false;
}
void Play_State_Base::on_joy_button(const SDL_JoyButtonEvent &event)	{
	if(!controllers[event.which]->HandleJoy(event))	{
		Gamestate_Base::on_joy_button(event);
		get_Game().joy_mouse.enabled = false;
	}
}
Example #15
0
 void Gamestate_II::on_event(const Zeni_Input_ID &id, const float &confidence, const int &) {
   if(id.type == SDL_KEYDOWN && id.subid == SDLK_ESCAPE && confidence == 1.0f)
     get_Game().push_state(new Popup_Menu_State);
 }
void Team_Select_State::perform_logic(){

		if(start_game > 5.0f){

			vector<Player_info *> *player_list = new vector<Player_info*>;

			for(int player_idx = 0; player_idx < 4; player_idx ++){

				if(player_state[player_idx] != 2) continue;

				Player_info * newPlayer = new Player_info();

				newPlayer->genders_ = player_gender[player_idx];
				newPlayer->controls_ = player_control_state[player_idx];
				newPlayer->sensitivities_ = player_sensitivity_state[player_idx];


				if(player_team[player_idx] == "Green"){
					newPlayer->colors_ = 0;
				}
				else if(player_team[player_idx] == "Red"){
					newPlayer->colors_ = 1;
				}
				else if(player_team[player_idx] == "Blue"){
					newPlayer->colors_ = 2;
				}
				else if(player_team[player_idx] == "Orange"){
					newPlayer->colors_ = 3;
				}

				newPlayer->self_addr = RakNet::UNASSIGNED_SYSTEM_ADDRESS;

				player_list->push_back(newPlayer);
			}

			get_Sound().stop_BGM();
			get_Game().pop_state();
			get_Game().push_state(new Play_State_Base(player_list, level));
		}


		for(int player_idx = 0; player_idx < 4; player_idx ++){
			if(player_gender_state[player_idx] == 0)
				player_gender[player_idx] = "Boy";
			else
				player_gender[player_idx] = "Girl";

			if(player_control_state[player_idx] == 0)
				player_control[player_idx] = "Normal";
			else
				player_control[player_idx] = "Invert";

			if(player_team_state[player_idx] == 0)
				player_team[player_idx] = "Green";
			else if(player_team_state[player_idx] == 1)
				player_team[player_idx] = "Red";
			else if(player_team_state[player_idx] == 2)
				player_team[player_idx] = "Blue";
			else
				player_team[player_idx] = "Orange";

		}
	}
void Team_Select_State::on_key(const SDL_KeyboardEvent &event) {
		switch(event.keysym.sym)	{
		case SDLK_1:
			keyboard_index = 0;
			break;
		case SDLK_2:
			keyboard_index = 1;
			break;
		case SDLK_3:
			keyboard_index = 2;
			break;
		case SDLK_4:
			keyboard_index = 3;
			break;
		default:
			break;
		}



        if(event.keysym.sym == SDLK_ESCAPE && event.state == SDL_PRESSED){
            get_Game().pop_state();
        }
		else if(event.keysym.sym == SDLK_w && event.state == SDL_PRESSED){
			if(player_cursor[keyboard_index] != 0)
				player_cursor[keyboard_index] --;
		}
		else if(event.keysym.sym == SDLK_s && event.state == SDL_PRESSED){
			if(player_cursor[keyboard_index] != 3)
				player_cursor[keyboard_index] ++;
		}
		else if(event.keysym.sym == SDLK_a && event.state == SDL_PRESSED){
			if(player_cursor[keyboard_index] == 0){
				player_gender_state[keyboard_index] = (player_gender_state[keyboard_index] + 1) % 2;
			}
			else if(player_cursor[keyboard_index] == 2){
				player_control_state[keyboard_index] = (player_control_state[keyboard_index] + 1) % 2;
			}
			else if(player_cursor[keyboard_index] == 3){
				player_sensitivity_state[keyboard_index] = (player_sensitivity_state[keyboard_index] + 9) % 10 + 1;
			}
			else{
				player_team_state[keyboard_index] = (player_team_state[keyboard_index] + 3) % 4;
			}
		}
		else if(event.keysym.sym == SDLK_d && event.state == SDL_PRESSED){
			if(player_cursor[keyboard_index] == 0){
				player_gender_state[keyboard_index] = (player_gender_state[keyboard_index] + 1) % 2;
			}
			else if(player_cursor[keyboard_index] == 2){
				player_control_state[keyboard_index] = (player_control_state[keyboard_index] + 1) % 2;
			}
			else if(player_cursor[keyboard_index] == 3){
				player_sensitivity_state[keyboard_index] = (player_sensitivity_state[keyboard_index]) % 10 + 1;
			}
			else{
				player_team_state[keyboard_index] = (player_team_state[keyboard_index] + 1) % 4;
			}
		}
        else if(event.keysym.sym == SDLK_RETURN && event.state == SDL_PRESSED){
			if(player_state[keyboard_index] != 2)
				player_state[keyboard_index] ++;
			else{
				if(keyboard_index == 0 && player_state[1] != 1 && player_state[2] != 1 && player_state[3] != 1)
					loading = true;
			}
		}
    }