1 /* 2 * enemy.h - baddies 3 * Copyright (C) 2008-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 21 #ifndef _ENEMY_H 22 #define _ENEMY_H 23 24 #include "../core/v2d.h" 25 26 /* forward declarations */ 27 struct actor_t; 28 struct player_t; 29 struct brick_list_t; 30 struct item_list_t; 31 struct objectvm_t; 32 struct object_child_list_t; 33 typedef struct enemy_t enemy_t; 34 typedef struct enemy_list_t enemy_list_t; 35 typedef enum enemystate_t enemystate_t; 36 37 /* enemy state */ 38 enum enemystate_t { 39 ES_IDLE, /* idle: default state */ 40 ES_DEAD /* dead objects are automatically removed from the object list */ 41 }; 42 43 /* enemy class */ 44 struct enemy_t { 45 /* public attributes */ 46 char *name; /* name */ 47 struct actor_t *actor; /* actor */ 48 enemystate_t state; /* state */ 49 int created_from_editor; /* was this created from the level editor? */ 50 51 int preserve; /* should not be removed if far from play area? */ 52 int obstacle; /* does this behave like an obstacle brick? */ 53 int obstacle_angle; /* if this is an obstacle, what is my angle a, 0 <= a < 360? */ 54 int always_active; /* is this object always active, even if it's far away from the camera? */ 55 int hide_unless_in_editor_mode; /* this object will be displayed only in the level editor */ 56 struct objectvm_t *vm; /* virtual machine (programming related to objects) */ 57 58 /* private attributes */ 59 enemy_t *parent; /* if someone has created me, who is that? */ 60 struct object_children_t *children; /* I have created my children */ 61 struct player_t *observed_player; /* NULL iff I'm observing the active player */ 62 }; 63 64 /* linked list of enemies */ 65 struct enemy_list_t { 66 enemy_t *data; 67 enemy_list_t *next; 68 }; 69 70 71 /* ------ public class methods ---------- */ 72 73 /* initializes this module */ 74 void objects_init(); 75 76 /* releases this module */ 77 void objects_release(); 78 79 /* returns an array v[0..n-1] of available object names */ 80 const char** objects_get_list_of_names(int *n); 81 82 83 84 85 /* ------ public instance methods: generic routines ------- */ 86 87 /* creates a new enemy instance */ 88 enemy_t *enemy_create(const char *name); 89 90 /* destroys an existing enemy instance */ 91 enemy_t *enemy_destroy(enemy_t *enemy); 92 93 /* updates an enemy */ 94 void enemy_update(enemy_t *enemy, struct player_t **team, int team_size, struct brick_list_t *brick_list, struct item_list_t *item_list, struct enemy_list_t *object_list); 95 96 /* renders an enemy */ 97 void enemy_render(enemy_t *enemy, v2d_t camera_position); 98 99 100 101 102 103 /* ------ public instance methods: programming-specific routines ------- */ 104 105 /* finds the parent */ 106 enemy_t *enemy_get_parent(enemy_t *enemy); 107 108 /* finds a child */ 109 enemy_t *enemy_get_child(enemy_t *enemy, const char *child_name); 110 111 /* adds a child */ 112 void enemy_add_child(enemy_t *enemy, const char *child_name, enemy_t *child); 113 114 /* removes a child from this object (the child is not deleted, though) */ 115 void enemy_remove_child(enemy_t *enemy, enemy_t *child); 116 117 /* returns the observed player */ 118 struct player_t *enemy_get_observed_player(enemy_t *enemy); 119 120 /* observes a new player */ 121 void enemy_observe_player(enemy_t *enemy, struct player_t *player); 122 123 /* observes the current player */ 124 void enemy_observe_current_player(enemy_t *enemy); 125 126 /* observes the active player */ 127 void enemy_observe_active_player(enemy_t *enemy); 128 129 #endif 130