Exemplo n.º 1
0
void Effect_Damage_RightPic::update() {
	time_by_gene++;

	update_damage();

}
void Fighter::update() {
	if (health >= 100) {
		blood_particles->max_particles = 4;
		blood_particles->spawn_x = pos.x + 80;
		blood_particles->spawn_y = pos.y + 64;
	}

	if (type == PLAYER) {
		left_key = universe->input->left_key[player_id];
		right_key = universe->input->right_key[player_id];
		up_key = universe->input->up_key[player_id];
		down_key = universe->input->down_key[player_id];
		a_key = universe->input->a_key[player_id];
		b_key = universe->input->b_key[player_id];
	}else {
		//TODO implement ai here
	}

	if (invincible) {
		texture->set_colour(r, g, b,  .25f + ((sin(alpha_colour / 4) + 1) / 2.5f));
		++alpha_colour;
	}

	if (!respawning) {
		update_movement();
		update_damage();
		rect.x = pos.x + universe->camera->x + universe->camera->get_offset_x(pos.x) + offset_x;
		rect.y = pos.y + universe->camera->y + universe->camera->get_offset_y(pos.y) + offset_y;
		rect.w = width * universe->camera->scale; rect.h = height * universe->camera->scale;
		origin.x = rect.w / 2; origin.y = rect.h / 2;
		universe->renderer->render_transform(texture, &src_rect, &rect, rotation, &origin, flip);

		int min_bounds_x = universe->camera->min_bounds_x - 250;
		int max_bounds_x = universe->camera->max_bounds_x + 300;
		int min_bounds_y = universe->camera->min_bounds_y - 250;
		int max_bounds_y = universe->camera->max_bounds_y + 250;
		if (pos.x < min_bounds_x || pos.x > max_bounds_x || pos.y < min_bounds_y || pos.y > max_bounds_y) {
			int p_x = pos.x; int p_y = pos.y;
			if (p_x < min_bounds_x) { p_x = min_bounds_x; }else if (p_x > max_bounds_x) { p_x = max_bounds_x; }
			if (p_y < min_bounds_y) { p_y = min_bounds_y; }else if (p_y > max_bounds_y) { p_y = max_bounds_y; }

			universe->particles->create_particle_chunk(new ParticleEmitter(p_x, p_y, 
																		   0, 250, 250, true), CLOUD);
			universe->particles->create_particle_chunk(new ParticleEmitter(p_x, p_y, 
																		   0, 250, 250, true), BLOOD_CLOUD);

			respawning = true;
			health = 0;
			universe->game_ui->update_damage_text(id, health);

			//respawn after 2.5 seconds
			universe->timer->set_timer([this](void) {
				reset();
				respawning = false;
				enable_camera_view = true;
				pos.x = 100 + (rand() % (universe->map->map_width - 400));
				pos.y = -150;
				invincible = true;
				alpha_colour = 0;
				//turn off invincibility after 1 second
				universe->timer->set_timer([this](void) { invincible = false; texture->set_colour(r, g, b, 1);
				}, 2500);
			}, 2500);

			//turn off camera view after 1.5 seconds
			universe->timer->set_timer([this](void) {
				if (respawning) {
					enable_camera_view = false;
				}
			}, 1500);
		}
	}
}