Blame demo/src/sprites.c

59dae5
59dae5
#include <math.h></math.h>
59dae5
59dae5
#include <helianthus.h></helianthus.h>
59dae5
59dae5
#include "sprites.h"
59dae5
59dae5
28a314
static Group pulse;
59dae5
59dae5
59dae5
void spritesInit() {
59dae5
	pulse = createGroup();
59dae5
	
59dae5
	Sprite s;
59dae5
	double x = 1024 - 6*64 + 48/2;
59dae5
	double y = 16 + 48/2;
59dae5
	
59dae5
	// normal
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
59dae5
	groupAdd(pulse, s);
59dae5
	x += 64;
59dae5
	
59dae5
	// indexed colors
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/snail-indexed.png"));
59dae5
	groupAdd(pulse, s);
59dae5
	x += 64;
59dae5
	
59dae5
	// without alpha
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
59dae5
	groupAdd(pulse, s);
59dae5
	x += 64;
59dae5
	
59dae5
	// without texture
59dae5
	s = createSpriteEx(x, y, 48, 48);
d4e89f
	spriteSetShapeColor(s, colorByName("blue"));
59dae5
	groupAdd(pulse, s);
59dae5
	x += 64;
59dae5
	
59dae5
	// with tint color
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
d4e89f
	spriteSetTintColor(s, colorByName("red"));
59dae5
	groupAdd(pulse, s);
59dae5
	x += 64;
59dae5
	
59dae5
	// semi-transparent
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
d4e89f
	spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
59dae5
	groupAdd(pulse, s);
59dae5
	x += 64;
59dae5
	
59dae5
	x = 1024 - 16 - 48/2;
59dae5
	y += 64;
59dae5
	
59dae5
	// tiles
59dae5
	s = createSpriteEx(x - 48/2, y + 48/2, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks.png"));
59dae5
	groupAdd(pulse, s);
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
59dae5
	s = createSpriteEx(x, y + 48, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
59dae5
	x -= 48;
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
59dae5
	s = createSpriteEx(x, y + 48, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
59dae5
	x -= 64;
59dae5
	
59dae5
	// blend two sprites
59dae5
	s = createSpriteEx(x, y, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
d4e89f
	spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
59dae5
	groupAdd(pulse, s);
59dae5
	x -= 16;
59dae5
	s = createSpriteEx(x, y + 16, 48, 48);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/bricks-tile.png"));
d4e89f
	spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
59dae5
	groupAdd(pulse, s);
59dae5
	x -= 64;
59dae5
	
59dae5
	// texture size is not power of two
59dae5
	double k = 0.25, w = 343*k, h = 221*k;
59dae5
	x += 48/2 - w/2;
59dae5
	s = createSpriteEx(x, y, w, h);
dba3fc
	spriteSetAnimation(s, createAnimation("data/sprite/snake.png"));
3954ba
	spriteSetDebug(s, TRUE);
59dae5
	groupAdd(pulse, s);
59dae5
}
59dae5
59dae5
59dae5
void spritesDraw() {
59dae5
	const double shift = PI/4;
59dae5
	const double scalePeriod = 1;
59dae5
	const double scaleAmplitude = 0.1;
59dae5
	const double rotatePeriod = 2;
59dae5
	const double rotateAmplitude = 30;
59dae5
	
59dae5
	double time = worldGetSeconds();
59dae5
	for(int i = 0; i < groupGetCount(pulse); ++i) {
b9c036
		double scale = exp( scaleAmplitude * sin(shift*i + time/scalePeriod*2*PI) );
b9c036
		double rotation = rotateAmplitude * sin(shift*i + time/rotatePeriod*2*PI);
59dae5
		
59dae5
		Sprite s = groupGet(pulse, i);
59dae5
		spriteSetScale(s, scale);
59dae5
		spriteSetRotation(s, rotation);
59dae5
	}
59dae5
}