Example #1
0
background_actor *background_actor_init(background_actor *bg)
{
    actor_init(&bg->a, background_render_handler, NULL);
    sprite_init(
            &bg->background_sprite, 
            800,
            600,
            &eng.sand_decal);
    bg->background_sprite.r[0] = 400;
    bg->background_sprite.r[1] = 300;
    return bg;
}
Example #2
0
/*
 * Place a swarm at start with a number of leaders that all have 
 * the same initial velocity. 
 */
Swarm *swarm_create(Point *start, Vector *initVel, Module *shape, 
					int numLeaders, int numActorsPerLeader, float spread){
	int i, j, id = 0, verbose = 1;
 	float genX, genY, genZ;

	if(verbose) printf("creating swarm\n");

	Swarm *s = malloc(sizeof(Swarm));
	s->leaders = malloc(sizeof(Leader)*numLeaders);
	s->actors = malloc(sizeof(Actor)*numActorsPerLeader*numLeaders);
	s->numActors = numActorsPerLeader*numLeaders;
	s->numLeaders = numLeaders;
	for(i=0; i<numLeaders; i++){
		genX = spread - ((double)rand() / RAND_MAX) * 2.0 * spread;
		genY = spread - ((double)rand() / RAND_MAX) * 2.0 * spread;
		genZ = spread - ((double)rand() / RAND_MAX) * 2.0 * spread;
		leader_init(&(s->leaders[i]), shape);
		leader_setLocation(&(s->leaders[i]), 
							start->val[0] + genX, 
							start->val[1] + genY, 
						   	start->val[2] + genZ);
		leader_setVelocity(&(s->leaders[i]), initVel);
		for(j=0; j<numActorsPerLeader; j++){
			genX = spread - ((double)rand() / RAND_MAX) * 2.0 * spread;
			genY = spread - ((double)rand() / RAND_MAX) * 2.0 * spread;
			genZ = spread - ((double)rand() / RAND_MAX) * 2.0 * spread;
			actor_init(&(s->actors[j+(i*numActorsPerLeader)]), &(s->leaders[i]), shape);
			actor_setLocation(&(s->actors[j+(i*numActorsPerLeader)]), 
								start->val[0] + genX, 
								start->val[1] + genY, 
				 				start->val[2] + genZ);
			actor_setID(&(s->actors[j+(i*numActorsPerLeader)]), id++);
		}
	}
	return s;
}