Rotate daggers instead of using spritesheet

Don't know if this is bad for performance but it does make things
simpler.
This commit is contained in:
Linus Probert 2018-05-05 21:29:08 +02:00
parent 677a7d8b69
commit 3665c7ff66
3 changed files with 18 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 419 B

View File

@ -31,25 +31,22 @@
static void static void
onDaggerRender(Sprite *s) onDaggerRender(Sprite *s)
{ {
if (!timer_started(s->renderTimer)) if (s->angle >= 0)
timer_start(s->renderTimer); s->angle += 30;
else
if (timer_get_ticks(s->renderTimer) > 60) { s->angle -= 30;
timer_start(s->renderTimer);
s->clip.x += 16;
s->clip.x = s->clip.x % 64;
}
} }
Projectile * Projectile *
projectile_dagger_create(void) projectile_dagger_create(void)
{ {
Projectile *p = projectile_create(); Projectile *p = projectile_create();
sprite_set_texture(p->sprite, texturecache_add("Extras/Dagger.png"), 0); sprite_set_texture(p->sprite, texturecache_add("Items/ShortWep.png"), 0);
p->sprite->onRender = onDaggerRender; p->sprite->onRender = onDaggerRender;
p->sprite->animate = false; p->sprite->animate = false;
p->sprite->clip = CLIP16(0, 0); p->sprite->clip = CLIP16(0, 0);
p->sprite->dim = (Dimension) { 32, 32 }; p->sprite->dim = (Dimension) { 32, 32 };
p->sprite->rotationPoint = (SDL_Point) { 16, 16 };
return p; return p;
} }

View File

@ -143,14 +143,22 @@ skill_throw_dagger(Skill *skill, SkillData *data)
data->player->daggers--; data->player->daggers--;
Projectile *p = projectile_dagger_create(); Projectile *p = projectile_dagger_create();
if (vector2d_equals(VECTOR2D_UP, data->direction)) if (vector2d_equals(VECTOR2D_UP, data->direction)) {
p->velocity = (Vector2d) { 0, -DAGGER_VELOCITY }; p->velocity = (Vector2d) { 0, -DAGGER_VELOCITY };
else if (vector2d_equals(VECTOR2D_DOWN, data->direction)) p->sprite->flip = SDL_FLIP_VERTICAL;
}
else if (vector2d_equals(VECTOR2D_DOWN, data->direction)) {
p->velocity = (Vector2d) { 0, DAGGER_VELOCITY }; p->velocity = (Vector2d) { 0, DAGGER_VELOCITY };
else if (vector2d_equals(VECTOR2D_RIGHT, data->direction)) p->sprite->flip = SDL_FLIP_HORIZONTAL;
}
else if (vector2d_equals(VECTOR2D_RIGHT, data->direction)) {
p->velocity = (Vector2d) { DAGGER_VELOCITY, 0 }; p->velocity = (Vector2d) { DAGGER_VELOCITY, 0 };
else p->sprite->flip = SDL_FLIP_HORIZONTAL;
}
else {
p->velocity = (Vector2d) { -DAGGER_VELOCITY, 0 }; p->velocity = (Vector2d) { -DAGGER_VELOCITY, 0 };
p->sprite->angle = -270;
}
set_player_clip_for_direction(data->player, &data->direction); set_player_clip_for_direction(data->player, &data->direction);