breakhack/src/actiontext.c

68 lines
1.6 KiB
C
Raw Normal View History

2018-02-16 18:11:26 +01:00
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2017-12-21 12:35:52 +01:00
#include <stdlib.h>
2017-12-15 15:03:29 +01:00
#include "actiontext.h"
#include "util.h"
2018-05-15 11:16:56 +02:00
#include "update_data.h"
2017-12-15 15:03:29 +01:00
ActionText*
2018-05-15 11:16:56 +02:00
actiontext_create(Sprite *sprite)
2017-12-15 15:03:29 +01:00
{
ActionText *t = ec_malloc(sizeof(ActionText));
t->pos = (Position) { 0, 0 };
2018-05-15 11:16:56 +02:00
t->sprite = sprite;
2017-12-15 15:03:29 +01:00
t->timer = timer_create();
2018-05-15 11:16:56 +02:00
t->dead = false;
2018-05-15 14:12:38 +02:00
t->velocity = (Vector2d) { 0, -100 };
2018-05-22 15:48:09 +02:00
t->color = C_WHITE;
2017-12-15 15:03:29 +01:00
return t;
}
void
2018-05-15 11:16:56 +02:00
actiontext_update(ActionText *t, UpdateData *data)
2017-12-15 15:03:29 +01:00
{
2018-05-15 11:16:56 +02:00
t->sprite->pos.x += (int) (t->velocity.x * data->deltatime);
t->sprite->pos.y += (int) (t->velocity.y * data->deltatime);
2017-12-15 15:03:29 +01:00
}
void
actiontext_render(ActionText *t, Camera *cam)
{
2018-05-15 11:16:56 +02:00
if (t->dead)
2017-12-15 15:03:29 +01:00
return;
2018-05-15 11:16:56 +02:00
if (!t->dead && !timer_started(t->timer))
2017-12-15 15:03:29 +01:00
timer_start(t->timer);
2018-05-15 11:16:56 +02:00
if (timer_get_ticks(t->timer) < 500) {
sprite_render(t->sprite, cam);
2017-12-15 15:03:29 +01:00
} else {
timer_stop(t->timer);
2018-05-15 11:16:56 +02:00
t->dead = true;
2017-12-15 15:03:29 +01:00
}
}
void
actiontext_destroy(ActionText *t)
{
2018-05-15 11:16:56 +02:00
sprite_destroy(t->sprite);
2017-12-15 15:03:29 +01:00
timer_destroy(t->timer);
free(t);
}