Example #1
0
void Engine::handleKey(int key){
	switch(key){
		case TCODK_UP: attemptMove(0,-1); break;
		case TCODK_DOWN: attemptMove(0,1); break;
		case TCODK_LEFT: attemptMove(-1,0); break;
		case TCODK_RIGHT: attemptMove(1,0); break;
		default: break;
	}
}
Example #2
0
int
minidragon::moveLeftRight()
{
    if ( !walking )
        return 0;
    int gx = 0, gy = 0;

    gx = ( walk_dir == 1 ) ? 1 : -1;

    if ( gx < 0 )
    {
        flip_x = 1;
    }
    else if ( gx > 0 )
    {
        flip_x = 0;
    }
    if ( gx == 0 )
        return 0;

    if ( !attemptMove(&gx, &gy, 0) == 0 )
    {
        walk_dir = ( walk_dir == 1 ) ? 2 : 1;
    }

    return 1;
}
Example #3
0
void Lifeform::update( float dt ){
	sf::Vector2f pos = this->getPosition();

	if(!_onGround && !_isFlying)
		getTargetVelocity().y += 80.0f;

	calculateVelocity();

	if(pos.y < getHeight()/2) setPosition(pos.x,getHeight()/2);
	if(pos.y > Game::SCREEN_WIDTH - getHeight()/2 ) setPosition(pos.x,Game::SCREEN_WIDTH - getHeight()/2);
    if(pos.x  < getSprite().getOrigin().x){
        _velocity.x = 0;
		setPosition(getSprite().getOrigin().x,pos.y);
    }else if(pos.x > (Game::SCREEN_WIDTH - getSprite().getOrigin().x)){
		_velocity.x = 0;
		setPosition((Game::SCREEN_WIDTH - getSprite().getOrigin().x),pos.y);
	}
    _lastPos = getPosition();

	attemptMove( dt );
	
	//BUGGY Collisions  \/ \/ \/
	//getSprite().move(sf::Vector2f(0,_velocity.y) * dt);
	//_onGround = collidesGround();

	//if(_onGround)
		//setPosition(getPosition().x,_lastPos.y);
} 
Example #4
0
  // Recommend a move for a player at (r,c):  A false return means the
  // recommendation is that the player should stand; otherwise, bestDir is
  // set to the recommended direction to move.
bool recommendMove(const Arena& a, int r, int c, int& bestDir)
{
      // How dangerous is it to stand?
    int standDanger = computeDanger(a, r, c);

      // if it's not safe, see if moving is safer
    if (standDanger > 0)
    {
        int bestMoveDanger = standDanger;
        int bestMoveDir = NORTH;  // arbitrary initialization

          // check the four directions to see if any move is
          // better than standing, and if so, record the best
        for (int dir = 0; dir < NUMDIRS; dir++)
        {
            int rnew = r;
            int cnew = c;
            if (attemptMove(a, dir, rnew, cnew))
            {
                int danger = computeDanger(a, rnew, cnew);
                if (danger < bestMoveDanger)
                {
                    bestMoveDanger = danger;
                    bestMoveDir = dir;
                }
            }
        }

          // if moving is better than standing, recommend move
        if (bestMoveDanger < standDanger)
        {
            bestDir = bestMoveDir;
            return true;
        }
    }
    return false;  // recommend standing
}
Example #5
0
int
minidragon::moveGravity()
{
    int gy = 3, gx = 0;
    return !attemptMove(&gx, &gy, 0);
}
Example #6
0
int main(int argc, char *argv[])
{
  parseCommandLineOptions(argc, argv);
  initializeRandomNumberGeneratorTo(rng_seed);
  initializeOutput();
  setInitialConditions();
  if (graphicsModeEnabled()) initializeDisplay();
  
  perturbation_length=fixed_perturbation_length;

  for(monte_carlo_steps=start_mcs; monte_carlo_steps<=end_mcs; monte_carlo_steps++)
  {
    updatePairList();
    generateOutput();
    attempted_moves = 0;
    accepted_moves = 0;

    for (monte_carlo_step_counter=0; monte_carlo_step_counter<number_of_molecules; monte_carlo_step_counter++) 
    {
      double boltzmann_factor;
      double the_exponential;
  
      delta_energy = 0;
      attemptMove();
      attempted_moves++;

      if (delta_energy < 0) 
      {
        change_flag = 1;
        accepted_moves++;
        continue; /* move accepted */
      }

      // the following uses reduced temperature
      the_exponential = 0.0 - delta_energy/temperature;
     /* evaluate exponential, unless it's arbitrarily small */
      if (the_exponential > -25)
      {
        boltzmann_factor = exp(the_exponential);
        if (boltzmann_factor > rnd())
        {
          change_flag = 1;
          accepted_moves++;
          continue; /* move accepted */
        }
      }

      // revert move
      x[particle_number] -= dx;
      y[particle_number] -= dy;
      z[particle_number] -= dz;
    }

    if (monte_carlo_steps < relaxation_allowance) 
    {
      acceptance_ratio = (0.0 + accepted_moves)/(0.0 + attempted_moves);
      if (acceptance_ratio < target_acceptance_ratio) perturbation_length *= .9;
      else if (perturbation_length*perturbation_length*perturbation_length*16 < box_x*box_y*box_z) perturbation_length *=1.1;
    }
    else perturbation_length = fixed_perturbation_length;
    if (graphicsModeEnabled() && changeFlagIsSet()) drawGraphicalRepresentation();
  } 

  finalizeOutput();
  return 0;
} /* end main */