예제 #1
0
bool GameOverLogic::advance( ::controller::Logic& l, ::controller::InputEventHandler::keyboard_event const& ev ) {
	if (ev.key == 'r') {
		_model->setAlive(false);

		auto world = std::dynamic_pointer_cast< flappy_box::model::World >(*std::find_if(
				l.game_model()->objects().begin(), l.game_model()->objects().end(),
				[](std::shared_ptr< ::model::GameObject> const& p) { return p->name() == "World"; }));
		world->setShallRestartTheGame(true);

	}

	return false;
}
예제 #2
0
bool PaddleLogic::advance( ::controller::Logic& l, ::controller::InputEventHandler::keyboard_event const& ev )
{
    // key, special_key, modifier_mask, key_state, mouse_pos
    
    if(ev.key_state == ev.KEY_UP) _model->setPlayerControl(vec3_type(0., 0., 0.));
    else if(ev.key_state == ev.KEY_DOWN && ev.special_key == GLUT_KEY_LEFT) _model->setPlayerControl(vec3_type(-1., 0., 0.));
    else if(ev.key_state == ev.KEY_DOWN && ev.special_key == GLUT_KEY_RIGHT) _model->setPlayerControl(vec3_type(1., 0., 0.));
    
    vec3_type palt = _model->position();
    vec3_type valt = _model->velocity();
    vec3_type aalt = _model->acceleration();
    const double dt = l.game_model()->timestep().count();
    
    // gesucht: a, v, p
    vec3_type aneu = _model->playerControl()*1000; // Skalierung=1000
    vec3_type vneu = valt*0.8 + aneu*dt; // decay=0.8
    if(vneu(0) > 100.) vneu(0) = 100.; // limit speed to 100.
    if(vneu(0) < -100.) vneu(0) = -100.;
    vec3_type pneu = palt + vneu*dt;
    
    //_model->size();
    vec3_type max = _model->maxPosition();
    
    // check and set max or min position
    vec3_type pmax = _model->maxPosition();
    if (pneu(0) > pmax(0)) pneu(0) = pmax(0);
    else if (pneu(0) < -pmax(0)) pneu(0) = -pmax(0);
    if (pneu(1) > pmax(1)) pneu(1) = pmax(1);
    else if (pneu(1) < -pmax(1)) pneu(1) = -pmax(1);
    if (pneu(2) > pmax(2)) pneu(2) = pmax(2);
    else if (pneu(2) < -pmax(2)) pneu(2) = -pmax(2);

    _model->setAcceleration(aneu);
    _model->setVelocity(vneu);
    _model->setPosition(pneu);
    
	double t = l.game_model()->timestep().count();
	double bladesAngle = _model->bladesAngle();
	bladesAngle += 720 * t;
	bladesAngle = bladesAngle - ((static_cast<int>(bladesAngle) / 360) * 360); // avoid overflow
	_model->setBladesAngle(bladesAngle);

    return false;
}