|
|
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
|
|
|
e8cb52 |
s = createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/bricks.png"));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
59dae5 |
x += 64;
|
|
|
59dae5 |
|
|
|
59dae5 |
// indexed colors
|
|
|
e8cb52 |
s = createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/snail-indexed.png"));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
59dae5 |
x += 64;
|
|
|
59dae5 |
|
|
|
59dae5 |
// without alpha
|
|
|
e8cb52 |
s = createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/bricks-tile.png"));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
59dae5 |
x += 64;
|
|
|
59dae5 |
|
|
|
59dae5 |
// without texture
|
|
|
e8cb52 |
s = createSprite(x, y, 48, 48);
|
|
|
d4e89f |
spriteSetShapeColor(s, colorByName("blue"));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
59dae5 |
x += 64;
|
|
|
59dae5 |
|
|
|
59dae5 |
// with tint color
|
|
|
e8cb52 |
s = createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/bricks.png"));
|
|
|
d4e89f |
spriteSetTintColor(s, colorByName("red"));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
59dae5 |
x += 64;
|
|
|
59dae5 |
|
|
|
59dae5 |
// semi-transparent
|
|
|
e8cb52 |
s = createSpriteEx(x, y, 48, 48, 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
|
|
|
e8cb52 |
s = createSpriteEx(x - 48/2, y + 48/2, 48, 48, createAnimation("data/sprite/bricks.png"));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
e8cb52 |
createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/bricks-tile.png"));
|
|
|
e8cb52 |
createSpriteEx(x, y + 48, 48, 48, createAnimation("data/sprite/bricks-tile.png"));
|
|
|
59dae5 |
x -= 48;
|
|
|
e8cb52 |
createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/bricks-tile.png"));
|
|
|
e8cb52 |
createSpriteEx(x, y + 48, 48, 48, createAnimation("data/sprite/bricks-tile.png"));
|
|
|
59dae5 |
x -= 64;
|
|
|
59dae5 |
|
|
|
59dae5 |
// blend two sprites
|
|
|
e8cb52 |
s = createSpriteEx(x, y, 48, 48, createAnimation("data/sprite/bricks-tile.png"));
|
|
|
d4e89f |
spriteSetTintColor(s, colorByRGBA(1, 1, 1, 0.5));
|
|
|
59dae5 |
groupAdd(pulse, s);
|
|
|
59dae5 |
x -= 16;
|
|
|
e8cb52 |
s = createSpriteEx(x, y + 16, 48, 48, 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;
|
|
|
e8cb52 |
s = createSpriteEx(x, y, w, h, 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 |
|
|
|
d7d433 |
double time = windowGetSeconds();
|
|
|
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 |
}
|