Ejemplo n.º 1
0
// Gets node p, deletes all of its multiples (stops if p^2 is missing), and returns the next p
Node handleCandidate(Node p, FILE* f, int i) {
	if (!p)
		return NULL;

	Node p2 = LL_next(p);
	int isFirstThread = 0;
	while (p2 && (isFirstThread || p2->num <= p->num * p->num)) {
		if (p2->num == p->num * p->num) {
			isFirstThread = 1;
			fprintf(f, "Prime %d (by %d).\n", p->num, i);
		}

		// Delete if needed, move on either way.
		if (p2->num % p->num == 0) {
			fprintf(f, "%d\n", p2->num);
			p2 = LL_remove(p2);
		} else
			p2 = LL_next(p2);
	}

	// Reached the end of the list
	int res;
	if (p2) {
		res = release(p2->prev);
		res = release(p2);
	}

	res = acquire(p->prev);

	res = acquire(p);

	p = LL_next(p);
	return p;
}
Ejemplo n.º 2
0
void Proj_projectile_drawAll()
{
	Iterator* it = LL_getIterator(projectiles);
	while (LL_hasNext(it)) 
		Proj_projectile_draw((Projectile*) LL_next(it));
	free(it);
}
Ejemplo n.º 3
0
void Proj_projectile_updateAll()
{
	Iterator* it = LL_getIterator(projectiles);
	bool bulletHit;
	while (LL_hasNext(it)) 
	{
		Projectile *proj = (Projectile*) LL_next(it);
		Proj_projectile_update(proj);
		bulletHit = false;

		Iterator* enemyIt = LL_getIterator(enemies);
		
		while (LL_hasNext(enemyIt)) {
			Enemy *enem = (Enemy*) LL_next(enemyIt);
			
			float x1 = proj->loc.x;
			float y1 = proj->loc.y;
			float x2 = enem->loc.x;
			float y2 = enem->loc.y;
			
			float distance = sqrt(pow(x1 - x2, 2) + pow(y1-y2, 2));
			
			if (distance < 0.025) {
				enem = (Enemy*) LL_removePrevious(enemyIt);
				free(enem);
				
				((Player*)(proj->owner))->score++;
				bulletHit = true;
			}
		}
		free(enemyIt);

		if (!Proj_projectile_inBounds(proj) || bulletHit)
		{
			LL_removePrevious(it);
			free(proj);
			//proj->direction.x *= -1;
			//proj->direction.y *= -1;
		}
	}
	free(it);
}