2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/MenuUI/fishtank.cpp $
18 * Revision 1.2 2002/06/09 04:41:22 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:09 root
25 * 3 9/01/99 10:09a Dave
28 * 2 8/26/99 9:45a Dave
29 * First pass at easter eggs and cheats.
36 #include "packunpack.h"
39 #include "freespace.h"
40 #include "gamesequence.h"
44 float x, y; // x and y coords
45 float x_speed, y_speed; // x and y speed
46 int left; // left or right
47 anim_instance *a; // tha animation
55 static const char *FISH_LEFT_ANIM_NAME = "f_left.ani";
56 static const char *FISH_RIGHT_ANIM_NAME = "f_right.ani";
58 #define FISH_ANIM_WIDTH 100
59 #define FISH_ANIM_HEIGHT 30
61 anim *Fish_left_anim = NULL;
62 anim *Fish_right_anim = NULL;
76 if((Fish_left_anim == NULL) || (Fish_right_anim == NULL)){
82 for(idx=0; idx<MAX_FISH; idx++){
83 if(!Fish[idx].swimming){
94 f->left = frand_range(0.0f, 1.0f) < 0.5f ? 0 : 1;
98 f->x = gr_screen.max_w + frand_range(0.0f, 50.0f);
100 f->x = frand_range(0.0f, -50.0f) - FISH_ANIM_WIDTH;
102 f->y = frand_range(-40.0f, (float)gr_screen.max_h + 40.0f);
106 f->x_speed = frand_range(-1.0f, -15.0f);
108 f->x_speed = frand_range(1.0f, 15.0f);
110 f->y_speed = frand_range(0.0f, 1.0f) < 0.5f ? frand_range(1.0f, 4.0f) : frand_range(-1.0f, -4.0f);
112 // all fish start out offscreen
119 anim_play_struct aps;
122 anim_play_init(&aps, Fish_left_anim, (int)f->x, (int)f->y);
123 f->a = anim_play(&aps);
129 f->a->screen_id = GS_STATE_MAIN_MENU;
131 f->a->framerate_independent = 1;
134 anim_play_init(&aps, Fish_right_anim, (int)f->x, (int)f->y);
135 f->a = anim_play(&aps);
141 f->a->screen_id = GS_STATE_MAIN_MENU;
143 f->a->framerate_independent = 1;
148 void fish_flush(fish *f)
155 // release his render instance
157 anim_release_render_instance(f->a);
161 // no longer swimming
165 void fishtank_start()
173 // try and load the fish anim
174 Fish_left_anim = anim_load(FISH_LEFT_ANIM_NAME);
175 if(Fish_left_anim == NULL){
178 Fish_right_anim = anim_load(FISH_RIGHT_ANIM_NAME);
179 if(Fish_right_anim == NULL){
184 for(idx=0; idx<MAX_FISH; idx++){
186 Fish[idx].swimming = 0;
191 // generate a random # of fish
192 int count = (int)frand_range(1.0f, (float)(MAX_FISH - 1));
193 for(idx=0; idx<count; idx++){
207 for(idx=0; idx<MAX_FISH; idx++){
208 if(Fish[idx].a != NULL){
209 anim_release_render_instance(Fish[idx].a);
212 Fish[idx].swimming = 0;
214 if(Fish_left_anim != NULL){
215 anim_free(Fish_left_anim);
216 Fish_left_anim = NULL;
218 if(Fish_right_anim != NULL){
219 anim_free(Fish_right_anim);
220 Fish_right_anim = NULL;
226 void fishtank_process()
236 for(idx=0; idx<MAX_FISH; idx++){
245 f->x += f->x_speed * flFrametime;
246 f->y += f->y_speed * flFrametime;
248 // is he currently onscreen ?
250 if( (f->x < (float)gr_screen.max_w) && ((f->x + FISH_ANIM_WIDTH) >= 0.0f) &&
251 (f->y < (float)gr_screen.max_h) && ((f->y + FISH_ANIM_HEIGHT) >= 0.0f) ){
255 // if he was onscreen before, but is no longer, flush him and make a new fish
256 if(f->onscreen && !onscreen){
263 // otherwise just mark his current status
264 f->onscreen = onscreen;
272 anim_render_one(GS_STATE_MAIN_MENU, f->a, flFrametime);