Blob Blame Raw

#include <math.h>

#include <helianthus.h>

#include "sprites.h"


static Group pulse;


void spritesInit() {
	pulse = createGroup();
	
	Sprite s;
	double x = 1024 - 6*64 + 48/2;
	double y = 16 + 48/2;
	
	// normal
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
	groupAdd(pulse, s);
	x += 64;
	
	// indexed colors
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/snail-indexed.png"));
	groupAdd(pulse, s);
	x += 64;
	
	// without alpha
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	groupAdd(pulse, s);
	x += 64;
	
	// without texture
	s = createSpriteEx(x, y, 48, 48);
	spriteSetShapeColor(s, colorByName("blue"));
	groupAdd(pulse, s);
	x += 64;
	
	// with tint color
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
	spriteSetTintColor(s, colorByName("red"));
	groupAdd(pulse, s);
	x += 64;
	
	// semi-transparent
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
	spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
	groupAdd(pulse, s);
	x += 64;
	
	x = 1024 - 16 - 48/2;
	y += 64;
	
	// tiles
	s = createSpriteEx(x - 48/2, y + 48/2, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
	groupAdd(pulse, s);
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	s = createSpriteEx(x, y + 48, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	x -= 48;
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	s = createSpriteEx(x, y + 48, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	x -= 64;
	
	// blend two sprites
	s = createSpriteEx(x, y, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
	groupAdd(pulse, s);
	x -= 16;
	s = createSpriteEx(x, y + 16, 48, 48);
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
	spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
	groupAdd(pulse, s);
	x -= 64;
	
	// texture size is not power of two
	double k = 0.25, w = 343*k, h = 221*k;
	x += 48/2 - w/2;
	s = createSpriteEx(x, y, w, h);
	spriteSetAnimation(s, createAnimation("data/sprite/snake.png"));
	spriteSetDebug(s, TRUE);
	groupAdd(pulse, s);
}


void spritesDraw() {
	const double shift = PI/4;
	const double scalePeriod = 1;
	const double scaleAmplitude = 0.1;
	const double rotatePeriod = 2;
	const double rotateAmplitude = 30;
	
	double time = worldGetSeconds();
	for(int i = 0; i < groupGetCount(pulse); ++i) {
		double scale = exp( scaleAmplitude * sin(shift*i + time/scalePeriod*2*PI) );
		double rotation = rotateAmplitude * sin(shift*i + time/rotatePeriod*2*PI);
		
		Sprite s = groupGet(pulse, i);
		spriteSetScale(s, scale);
		spriteSetRotation(s, rotation);
	}
}