Beispiel #1
0
/******************************************************************************
* Function: idle()
* Authors: Ian Carlson, Christopher Smith
* Description: Animates all the playing objects
* ****************************************************************************/
void idle()
{
    //We want the screen to update as quickly as possible, but
    //scale the motion to the amount of time between frames.
    //We define "Normal" as 25 frames per second and scale based on that
    static clock_t last_time = clock();
    static clock_t last_right_shrink =  clock() - 10000;
    static clock_t last_left_shrink  =  clock() - 10000;
    clock_t new_time = clock();
    clock_t delta = new_time - last_time;
    float scale_factor = ((float)delta/CLOCKS_PER_SEC)/(0.04);

    if(GAMESTATE == 1 && !PAUSED)
    {
        ball.animate(scale_factor*BALL_WARP);
        switch (ball.goal_made())
        {
        //if the right player scores
        case 1:
            RIGHT_SCORE++;
            SERVE_NUM++;
            reset_field();
            if( RIGHT_SCORE == 10 )
                GAMESTATE = 0;
            break;
        //if the left player scores
        case 2:
            LEFT_SCORE++;
            SERVE_NUM++;
            reset_field();
            if( LEFT_SCORE == 10 )
                GAMESTATE = 0;
            break;
        //if no one scores during the ball's animate call the paddles move and then collision is checked
        default:
            left_paddle.animate(scale_factor*PADDLE_WARP);
            //Shrinks the paddle by 10% if the ball strikes it
            if(ball.check_paddle_collision( left_paddle , scale_factor*BALL_WARP, scale_factor*PADDLE_WARP) && ((clock() - last_left_shrink) > 10000) )
            {
                left_paddle.shrink();
                last_left_shrink = clock();
            }
            right_paddle.animate(scale_factor*PADDLE_WARP);
            if(ball.check_paddle_collision( right_paddle , scale_factor*BALL_WARP, scale_factor*PADDLE_WARP) && ((clock() - last_right_shrink) > 10000) )
            {
                right_paddle.shrink();
                last_right_shrink = clock();
            }
            break;
        }
    }
    last_time = new_time;
    glutPostRedisplay();
}
Beispiel #2
0
void pdf_field_reset(pdf_document *doc, pdf_obj *field)
{
	pdf_obj *kids = pdf_dict_gets(field, "Kids");

	reset_field(doc, field);

	if (kids)
	{
		int i, n = pdf_array_len(kids);

		for (i = 0; i < n; i++)
			pdf_field_reset(doc, pdf_array_get(kids, i));
	}
}
Beispiel #3
0
void pdf_field_reset(fz_context *ctx, pdf_document *doc, pdf_obj *field)
{
    pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids);

    reset_field(ctx, doc, field);

    if (kids)
    {
        int i, n = pdf_array_len(ctx, kids);

        for (i = 0; i < n; i++)
            pdf_field_reset(ctx, doc, pdf_array_get(ctx, kids, i));
    }
}
Beispiel #4
0
static void reset_form(fz_context *ctx, pdf_document *doc, pdf_obj *fields, int exclude)
{
    pdf_obj *sfields = specified_fields(ctx, doc, fields, exclude);

    fz_try(ctx)
    {
        int i, n = pdf_array_len(ctx, sfields);

        for (i = 0; i < n; i++)
            reset_field(ctx, doc, pdf_array_get(ctx, sfields, i));
    }
    fz_always(ctx)
    {
        pdf_drop_obj(ctx, sfields);
    }
    fz_catch(ctx)
    {
        fz_rethrow(ctx);
    }
}
Beispiel #5
0
/**
 * search for prey on any neighboring field and eat it, if there is one
 * when the animal eats the prey, it will move forward to the neighboring field
 * and returns it new position
 *
 * otherwise, this method will return 0
 */
struct Field* check_for_food(struct Field *field)
{
	for (int i = 0; i < NUMBER_OF_DIRECTIONS; i++) // alle umliegenden Felder prüfen
	{
		struct Field *neighboring_field = get_neighboring_field_in_direction(field->x, field->y, i);

		if(field->population_type == PREDATOR)
		{
			if (neighboring_field->population_type == PREY) // Predator eats prey
			{
				// fight!
				if(fight(field, neighboring_field))
				{
					field->energy = MAX_ENERGY;
					field->last_step++;
					move_field_to(field, neighboring_field);
				}
				else
				{
					reset_field(field);
					return 0;
				}
			}
		}
		else if(field->population_type == PREY)
		{
			if (neighboring_field->contains_plant) // Prey eats Plants
			{
				field->last_step++;
				field->energy = MAX_ENERGY;
				field->contains_plant = 0;
				move_field_to(field, neighboring_field);

				return neighboring_field;
			}
		}
	}

	return 0;
}
void EnemyField::reset(){
    reset_field();
    setShipsInvisible();
    resizeBoard();
    fill();
}
Beispiel #7
0
/**
 * simulate a single step
 *
 */
void simulation_step(int step)
{
	_operations =  0;

	struct Segment *segment = get_segment();

	irecv_field();

	int fields = segment->width * segment->height;
	struct Field **movements = malloc(sizeof(struct Field *) * fields);
	get_movement_order(movements, fields);

	for (int i = 0; i < fields; i++)
	{
		_operations++;

		struct Field *field = movements[i];

		if(is_near_border(field))
			irecv_field();

		if (field->population_type != EMPTY)
		{
			check_for_food(field);
			// suche nach Beute
		}
	}

	get_movement_order(movements, fields);
	for (int i = 0; i < fields; i++)
	{
		_operations++;

		struct Field *field = movements[i];

		if(is_near_border(field))
			irecv_field();

		if (field->population_type != EMPTY)
		{
			// if the animal becomes to old or starves, it will die
			if (should_die(field))
			{
				reset_field(field);
			}
			else
			{
				// has the animal on this field been moved before? (e.g. because it has found food)
				if(field->last_step < step)
				{
					struct Field *moved = move_animal(field);
					if(moved != 0)
					{
						field->last_step++;
						if(is_field_in_segment(moved))
						{
							field = moved;
						}
						else
						{
							field = 0; // animal has moved, but is now out of our segment
						}
					}
				}

				if(field != 0)
				{
					// check, whether the animal is old enough and should get a child
					if (should_get_child(field->population_type))
					{
						create_child(field);
					}

					field->energy -= 2;
					field->age++;
				}
			}
		}
		else if(field->population_type == EMPTY)
		{
			if(random_int(1, 100) <= (PLANT_RATE * 100))
			{
				field->contains_plant = 1;
			}
		}
	}

	irecv_field();

	free(movements);
}