Ejemplo n.º 1
0
void
Crystallo::active_update(float elapsed_time)
{
  if(get_pos().x > (start_position.x + radius)){
    if(dir != LEFT){
      turn_around();
    }
  }
  if( get_pos().x < (start_position.x - radius)){
    if(dir != RIGHT){
      turn_around();
    }
  }
  BadGuy::active_update(elapsed_time);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: aajarven/c
int main(void) {
    
    char str[] = "Example string";
    turn_around(str);
    printf("%s\n", str);
    return 0;
}
Ejemplo n.º 3
0
void
WalkingBadguy::active_update(float elapsed_time, float dest_x_velocity)
{
  BadGuy::active_update(elapsed_time);

  float current_x_velocity = physic.get_velocity_x ();

  if (frozen)
  {
    physic.set_velocity_x (0.0);
    physic.set_acceleration_x (0.0);
  }
  /* We're very close to our target speed. Just set it to avoid oscillation */
  else if ((current_x_velocity > (dest_x_velocity - 5.0))
      && (current_x_velocity < (dest_x_velocity + 5.0)))
  {
    physic.set_velocity_x (dest_x_velocity);
    physic.set_acceleration_x (0.0);
  }
  /* Check if we're going too slow or even in the wrong direction */
  else if (((dest_x_velocity <= 0.0) && (current_x_velocity > dest_x_velocity))
      || ((dest_x_velocity > 0.0) && (current_x_velocity < dest_x_velocity)))
  {
    /* acceleration == walk-speed => it will take one second to get from zero
     * to full speed. */
    physic.set_acceleration_x (dest_x_velocity);
  }
  /* Check if we're going too fast */
  else if (((dest_x_velocity <= 0.0) && (current_x_velocity < dest_x_velocity))
      || ((dest_x_velocity > 0.0) && (current_x_velocity > dest_x_velocity)))
  {
    /* acceleration == walk-speed => it will take one second to get twice the
     * speed to normal speed. */
    physic.set_acceleration_x ((-1.f) * dest_x_velocity);
  }
  else
  {
    /* The above should have covered all cases. */
    assert (23 == 42);
  }

  if (max_drop_height > -1) {
    if (on_ground() && might_fall(max_drop_height+1))
    {
      turn_around();
    }
  }

  if ((dir == LEFT) && (physic.get_velocity_x () > 0.0)) {
    dir = RIGHT;
    set_action (walk_right_action, /* loops = */ -1);
  }
  else if ((dir == RIGHT) && (physic.get_velocity_x () < 0.0)) {
    dir = LEFT;
    set_action (walk_left_action, /* loops = */ -1);
  }
}
HitResponse
WalkingBadguy::collision_badguy(BadGuy& , const CollisionHit& hit)
{

  if ((hit.left && (dir == LEFT)) || (hit.right && (dir == RIGHT))) {
    turn_around();
  }

  return CONTINUE;
}
Ejemplo n.º 5
0
void autonomouswalk_walk(uint8_t sensors[5])
{
	uint8_t leftSideAlgorithm = navigation_left_algorithm();
	if(leftSideAlgorithm)
	{
		if(navigation_check_left_turn(sensors[0], sensors[2]) == 2)
		{
			turn_left();
		}
		else if(sensors[4] > CORRIDOR_WIDTH)
		{
			walk_forward(sensors);
		}
		else if(navigation_check_right_turn(sensors[1], sensors[3]) == 2)
		{
			turn_right();
		}
		else
		{
			turn_around(sensors[4]);
		}
	}
	else
	{
		if(navigation_check_right_turn(sensors[1], sensors[3]) == 2)
		{
			turn_left();
		}
		else if(sensors[4] > CORRIDOR_WIDTH)
		{
			walk_forward(sensors);
		}
		else if(navigation_check_left_turn(sensors[0], sensors[2]) == 2)
		{
			turn_right();
		}
		else
		{
			turn_around(sensors[4]);
		}
	}
}
void
WalkingBadguy::active_update(float elapsed_time)
{
  BadGuy::active_update(elapsed_time);

  if (max_drop_height > -1) {
    if (on_ground() && might_fall(max_drop_height+1))
    {
      turn_around();
    }
  }

}
Ejemplo n.º 7
0
HitResponse
WalkingBadguy::collision_badguy(BadGuy& , const CollisionHit& hit)
{
  if (hit.top) {
    return FORCE_MOVE;
  }

  if ((hit.left && (m_dir == Direction::LEFT)) || (hit.right && (m_dir == Direction::RIGHT))) {
    turn_around();
  }

  return CONTINUE;
}
void change_dir(uint8_t v) //changing directions

{

int a = v - dir;

switch(a){

d=get_IR_sensor_value();

c = get_node_sensor_value();

case 1:

case -3:

turn_right();

break;

case -1:

case 3:

turn_left();

break;

case 2:

case -2:

turn_around();

break;

default:

break;

}

dir = v;

}
Ejemplo n.º 9
0
Archivo: fcfs.c Proyecto: vsbranjan/gh
/* fcfs : to implement first come first serve scheduling */
void fcfs(int size)
{
	int i, j,result;
        float result1;
	int arrival[size], burst[size], waiting[size];

	for(i=0; i<size; ++i)	
                  waiting[i]=0;

	/* input the arrival time and burst time for each process */
	for(i=0; i<size; ++i) {
		printf("\nEnter arrival time for process %d : ", i+1);
		scanf("%d", &arrival[i]);

		printf("Enter burst time for process %d : ", i+1);
		scanf("%d", &burst[i]);
	}

	/* first come first serve */
	for(i=1; i<size; ++i) {
		result=0;
		for(j=0; j<i; ++j)	result+= burst[j];
		waiting[i]=result - arrival[i];	/* waiting time = starting time - arrival time */
	}

	/* print the waiting time */
	printf("\nWaiting Time:\t");
              result=0;
	for(i=0; i<size; ++i)
		printf("%d\t", waiting[i]);

	/* average waiting time */
	for(i=0; i<size; ++i)	
            result1+=waiting[i];

	result1=(result1/size);
       
	
	printf("\nAverage Waiting Time:\t%1.2f", result1);

	/* turn around time */
	turn_around(size, burst, waiting);
	
	printf("\n");
}
void
WalkingBadguy::collision_solid(const CollisionHit& hit)
{

  update_on_ground_flag(hit);

  if (hit.top) {
    if (physic.get_velocity_y() < 0) physic.set_velocity_y(0);
  }
  if (hit.bottom) {
    if (physic.get_velocity_y() > 0) physic.set_velocity_y(0);
  }

  if ((hit.left && (hit.slope_normal.y == 0) && (dir == LEFT)) || (hit.right && (hit.slope_normal.y == 0) && (dir == RIGHT))) {
    turn_around();
  }

}
Ejemplo n.º 11
0
void
WalkingBadguy::collision_solid(const CollisionHit& hit)
{

  update_on_ground_flag(hit);

  if (hit.top) {
    if (m_physic.get_velocity_y() < 0) m_physic.set_velocity_y(0);
  }
  if (hit.bottom) {
    if (m_physic.get_velocity_y() > 0) m_physic.set_velocity_y(0);
  }

  if ((hit.left && (m_dir == Direction::LEFT)) || (hit.right && (m_dir == Direction::RIGHT))) {
    turn_around();
  }

}
Ejemplo n.º 12
0
void
Haywire::active_update(float elapsed_time)
{
  if (is_exploding) {
    if (elapsed_time >= time_until_explosion) {
      kill_fall ();
      return;
    }
    else
      time_until_explosion -= elapsed_time;
  }

  if (is_stunned) {
    if (time_stunned > elapsed_time) {
      time_stunned -= elapsed_time;
      return;
    }
    else { /* if (time_stunned <= elapsed_time) */
      elapsed_time -= time_stunned;
      time_stunned = 0.0;
      is_stunned = false;
    }
  }

  if (is_exploding && !turn_around_timer.started()) {
    Player *p = this->get_nearest_player ();

    if (p) {
      Direction player_dir = LEFT;

      if (p->get_pos ().x > this->get_pos ().x)
        player_dir = RIGHT;

      if (player_dir != dir)
        turn_around ();
    }
  }

  WalkingBadguy::active_update(elapsed_time);
}
Ejemplo n.º 13
0
void
Igel::active_update(float elapsed_time)
{
  bool wants_to_flee = false;

  // check if we see a fire bullet
  auto sector = Sector::current();
  for (const auto& object : sector->gameobjects) {
    auto bullet = reinterpret_cast<Bullet*>(object.get());
    if (!bullet) continue;
    if (bullet->get_type() != FIRE_BONUS) continue;
    if (can_see(*bullet)) wants_to_flee = true;
  }

  // if we flee, handle this ourselves
  if (wants_to_flee && (!turn_recover_timer.started())) {
    turn_around();
    BadGuy::active_update(elapsed_time);
    return;
  }

  // else adhere to default behaviour
  WalkingBadguy::active_update(elapsed_time);
}