1 /*
2 * explosion.c - explosion
3 * Copyright (C) 2010 Alexandre Martins <alemartf(at)gmail(dot)com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "explosion.h"
21 #include "../../core/util.h"
22 #include "../player.h"
23 #include "../enemy.h"
24
25 /* explosion class */
26 typedef struct explosion_t explosion_t;
27 struct explosion_t {
28 item_t item; /* base class */
29 };
30
31 static void explosion_init(item_t *item);
32 static void explosion_release(item_t* item);
33 static void explosion_update(item_t* item, player_t** team, int team_size, brick_list_t* brick_list, item_list_t* item_list, enemy_list_t* enemy_list);
34 static void explosion_render(item_t* item, v2d_t camera_position);
35
36
37
38 /* public methods */
explosion_create()39 item_t* explosion_create()
40 {
41 item_t *item = mallocx(sizeof(explosion_t));
42
43 item->init = explosion_init;
44 item->release = explosion_release;
45 item->update = explosion_update;
46 item->render = explosion_render;
47
48 return item;
49 }
50
51
52 /* private methods */
explosion_init(item_t * item)53 void explosion_init(item_t *item)
54 {
55 item->obstacle = FALSE;
56 item->bring_to_back = FALSE;
57 item->preserve = FALSE;
58 item->actor = actor_create();
59
60 actor_change_animation(item->actor, sprite_get_animation("SD_EXPLOSION", random(2)));
61 }
62
63
64
explosion_release(item_t * item)65 void explosion_release(item_t* item)
66 {
67 actor_destroy(item->actor);
68 }
69
70
71
explosion_update(item_t * item,player_t ** team,int team_size,brick_list_t * brick_list,item_list_t * item_list,enemy_list_t * enemy_list)72 void explosion_update(item_t* item, player_t** team, int team_size, brick_list_t* brick_list, item_list_t* item_list, enemy_list_t* enemy_list)
73 {
74 if(actor_animation_finished(item->actor))
75 item->state = IS_DEAD;
76 }
77
78
explosion_render(item_t * item,v2d_t camera_position)79 void explosion_render(item_t* item, v2d_t camera_position)
80 {
81 actor_render(item->actor, camera_position);
82 }
83
84