Beispiel #1
0
void sat_render(Satellite* sat, SDL_Surface* canvas) {
	Node* current = sat->parts;

	// render every part separately
	while(current != NULL) {
		SatPart* part = (SatPart*)current->data;

		// calculate offset by following tree to root part
		int dx = 0;
		int dy = 0;

		SatPart* child = part;
		SatPart* parent = child->parent;

		while(parent != NULL) {
			// gather connection information
			Connector* connChild = child->connection->child;
			Connector* connParent = child->connection->parent;

			// offset based on connector location
			dx += rot_x_pt(&connParent->position, parent->rotation) -
				rot_x_pt(&connChild->position, child->rotation);
			dy += rot_y_pt(&connParent->position, parent->rotation) -
				rot_y_pt(&connChild->position, child->rotation);

			// offset based on connector directions
			Dir dc = (connChild->direction + child->rotation)%4;
			Dir dp = (connParent->direction + parent->rotation)%4;

			if(dc == UP && dp == DOWN) {
				dy += 1;
			} else if(dc == DOWN && dp == UP) {
				dy -= 1;
			} else if(dc == LEFT && dp == RIGHT) {
				dx += 1;
			} else if(dc == RIGHT && dp == LEFT) {
				dx -= 1;
			} else {
				printf("error: invalid connection - %d to %d\n", dc, dp);
				exit(0);
			}

			child = parent;
			parent = child->parent;
		}

		// render sprite at offset
		sprite_render(canvas, part, sat->x + dx, sat->y + dy, part->rotation);

		current = current->next;
	}
}
Beispiel #2
0
void background_render_handler(actor *a)
{
    background_actor *bg = (background_actor *)a;

    sprite_render(&(bg->background_sprite));
}