1 #ifndef __YELLIFISH_H_2014__ 2 #define __YELLIFISH_H_2014__ 3 #include <SDL/SDL.h> 4 #include "u-iff.h" 5 #include "sprite.h" 6 7 #define YELLIFISH_TENTACLESEGMENTS 16 8 #define YELLIFISH_TENTACLENO 4 9 #define YELLIFISH_MAXNUM 3 //!< maximum number of yellifish 10 11 typedef struct Yellifish { 12 float posx, posy; 13 float velx, vely; 14 float offset[YELLIFISH_TENTACLENO]; //!< offset in pixel for the tentacle animation 15 unsigned char tentacleparts[YELLIFISH_TENTACLENO][YELLIFISH_TENTACLESEGMENTS]; //!< which tentaclepart 16 float tspeed[YELLIFISH_TENTACLENO]; //!< speed for each tentacle 17 float length; //!< length is the total length of the long tentacle 18 short tentacle_active; //!< is the tentacle active? 0=no, 1=tentacle moving down, -1=tentacle moving up 19 unsigned short partoffset[YELLIFISH_TENTACLENO]; //!< offset in the tentacleparts table 20 short active; //!< this is > 0 if the yellifish is active, < 0 the yellifish is dying 21 struct sprite ysprite; //!< yellifish sprite 22 } yellifish_t; 23 24 25 typedef struct Yellifishsubsystem { 26 struct Yellifish yellifishs[YELLIFISH_MAXNUM]; 27 int minimum_level; //!< minimum level before yellifish appear 28 int level_modulo; //!< for checking level % level_modulo == 0 (only then yellifish do appear) 29 float minimum_length; //!< minimum tentacle length 30 float maximum_length; //!< maximum tentacle length 31 float maximum_velocity; //!< maximum velovity component of yellifish 32 float attack_distance; //!< if X-Distance smaller then attack prey 33 float delta_velocity; //!< delta velocity per update 34 float yelliprobability; //!< probability that a yellifish appears 35 short headoffsetx, headoffsety; //!< offset between head image and tentacle images 36 } yellifishsubsystem_t; 37 38 39 /*! \brief initialise yellifish subsystem 40 * 41 * This loads the animation graphics, etc. After calling this function 42 * init_yellifish() may be called. 43 * 44 * \return 0 on OK, != 0 on error 45 */ 46 yellifishsubsystem_t *init_yellifish_subsystem(uiff_ctx_t iff); 47 48 /*! \brief Shutdown yellifish subsystem 49 * 50 * Shutdown subsystem and free system resources. 51 * 52 * \param yellifishs pointer to subsystem structure 53 */ 54 void shutdown_yellifish_subsystem(yellifishsubsystem_t *yellifishs); 55 56 /*! \brief initialise a single yellifish 57 * 58 * Yellifish is initialised with some default values. Uses the random 59 * number generator. 60 * 61 * \param ysys pointer to yellifish subsystem structure 62 * \param yelli pointer to a yellifish structure 63 * \param posx starting X-position 64 * \param posy starting Y-position 65 */ 66 void init_yellifish(yellifishsubsystem_t *ysys, yellifish_t *yelli, int posx, int posy); 67 68 69 /*! \brief activate a yellifish if conditions are right 70 * 71 * This function will create a new yellifish if there is a free slot 72 * available and if the level modulo the level module is zero and a 73 * random number is below the random number threshold. Of course the 74 * minimum level needed is also taken into account. 75 * 76 * \param yelli pointer to yellifish subsystem 77 * \param level current level as an int 78 * \param x x-position of newly created yellfish 79 * \param y y-position of newly created yellfish 80 * \return NULL if no yellfish created or no more yellifish slots available, pointer to yellifish_t struct on success 81 */ 82 yellifish_t *maybe_activate_yellifish(yellifishsubsystem_t *yelli, int level, int x, int y); 83 84 yellifish_t *activate_yellifish(yellifishsubsystem_t *yelli, int x, int y); 85 86 /*! \brief yellifish display function 87 * 88 * This will also update the animation. 89 * 90 * \param ysys pointer to the yellifish subsystem struct 91 * \param yelli pointer to a single yellifish 92 * \param surf_screen display on which the yellifish is displayed 93 */ 94 void display_yellifish(yellifishsubsystem_t *ysys, yellifish_t *yelli, SDL_Surface *surf_screen); 95 96 void display_yellifishs(yellifishsubsystem_t *yelli, SDL_Surface *surf_screen); 97 98 /*! \brief update yellifish 99 * 100 * Update the yellifish positions. This means that the yellifish will follow its prey. 101 * \param yelli Yellifish subsystem pointer 102 * \param preyx x-position of prey 103 * \param preyy y-position of prey 104 */ 105 void update_yellifishs(yellifishsubsystem_t *yelli, float preyx, float preyy); 106 107 yellifish_t *check_yellifish_hit(yellifishsubsystem_t *yelli, float minlaserx, float maxlaserx, float lasery); 108 109 void kill_yellifish(yellifish_t *yptr); 110 111 void deactivate_all_yellifish(yellifishsubsystem_t *yelli); 112 113 #endif 114