2 * $Logfile: /Freespace2/code/MenuUI/fishtank.cpp $
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 3 9/01/99 10:09a Dave
17 * 2 8/26/99 9:45a Dave
18 * First pass at easter eggs and cheats.
25 #include "packunpack.h"
28 #include "freespace.h"
29 #include "gamesequence.h"
33 float x, y; // x and y coords
34 float x_speed, y_speed; // x and y speed
35 int left; // left or right
36 anim_instance *a; // tha animation
44 #define FISH_LEFT_ANIM_NAME "f_left.ani"
45 #define FISH_RIGHT_ANIM_NAME "f_right.ani"
47 #define FISH_ANIM_WIDTH 100
48 #define FISH_ANIM_HEIGHT 30
50 anim *Fish_left_anim = NULL;
51 anim *Fish_right_anim = NULL;
65 if((Fish_left_anim == NULL) || (Fish_right_anim == NULL)){
71 for(idx=0; idx<MAX_FISH; idx++){
72 if(!Fish[idx].swimming){
83 f->left = frand_range(0.0f, 1.0f) < 0.5f ? 0 : 1;
87 f->x = gr_screen.max_w + frand_range(0.0f, 50.0f);
89 f->x = frand_range(0.0f, -50.0f) - FISH_ANIM_WIDTH;
91 f->y = frand_range(-40.0f, (float)gr_screen.max_h + 40.0f);
95 f->x_speed = frand_range(-1.0f, -15.0f);
97 f->x_speed = frand_range(1.0f, 15.0f);
99 f->y_speed = frand_range(0.0f, 1.0f) < 0.5f ? frand_range(1.0f, 4.0f) : frand_range(-1.0f, -4.0f);
101 // all fish start out offscreen
108 anim_play_struct aps;
111 anim_play_init(&aps, Fish_left_anim, (int)f->x, (int)f->y);
112 f->a = anim_play(&aps);
118 f->a->screen_id = GS_STATE_MAIN_MENU;
120 f->a->framerate_independent = 1;
123 anim_play_init(&aps, Fish_right_anim, (int)f->x, (int)f->y);
124 f->a = anim_play(&aps);
130 f->a->screen_id = GS_STATE_MAIN_MENU;
132 f->a->framerate_independent = 1;
137 void fish_flush(fish *f)
144 // release his render instance
146 anim_release_render_instance(f->a);
150 // no longer swimming
154 void fishtank_start()
162 // try and load the fish anim
163 Fish_left_anim = anim_load(FISH_LEFT_ANIM_NAME);
164 if(Fish_left_anim == NULL){
167 Fish_right_anim = anim_load(FISH_RIGHT_ANIM_NAME);
168 if(Fish_right_anim == NULL){
173 for(idx=0; idx<MAX_FISH; idx++){
175 Fish[idx].swimming = 0;
180 // generate a random # of fish
181 int count = (int)frand_range(1.0f, (float)(MAX_FISH - 1));
182 for(idx=0; idx<count; idx++){
196 for(idx=0; idx<MAX_FISH; idx++){
197 if(Fish[idx].a != NULL){
198 anim_release_render_instance(Fish[idx].a);
201 Fish[idx].swimming = 0;
203 if(Fish_left_anim != NULL){
204 anim_free(Fish_left_anim);
205 Fish_left_anim = NULL;
207 if(Fish_right_anim != NULL){
208 anim_free(Fish_right_anim);
209 Fish_right_anim = NULL;
215 void fishtank_process()
225 for(idx=0; idx<MAX_FISH; idx++){
234 f->x += f->x_speed * flFrametime;
235 f->y += f->y_speed * flFrametime;
237 // is he currently onscreen ?
239 if( (f->x < (float)gr_screen.max_w) && ((f->x + FISH_ANIM_WIDTH) >= 0.0f) &&
240 (f->y < (float)gr_screen.max_h) && ((f->y + FISH_ANIM_HEIGHT) >= 0.0f) ){
244 // if he was onscreen before, but is no longer, flush him and make a new fish
245 if(f->onscreen && !onscreen){
252 // otherwise just mark his current status
253 f->onscreen = onscreen;
261 anim_render_one(GS_STATE_MAIN_MENU, f->a, flFrametime);