// $Id: getreadydisplay.cc,v 1.8 2006/08/26 19:40:49 matthew Exp $ // Fish Supper // Copyright (C) 2006 Matthew Clarke // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. #include "getreadydisplay.h" #include "SDL_image.h" #include "fontrepository.h" #include #include #include extern FS::FontRepository * font_rep; // ******************* // *** CONSTRUCTOR *** // ******************* FS::GetReadyDisplay::GetReadyDisplay(SDL_Surface * s) : my_font(font_rep->get_SFont(FontRepository::SMALL_FONT)) { screen = s; // load background background = SDL_DisplayFormat(IMG_Load( PKG_DATA_DIR "/images/getready/get_ready_bg.png" )); // load arrow gfx arrows[LOWER_LIMIT] = SDL_DisplayFormatAlpha( IMG_Load( PKG_DATA_DIR "/images/getready/lower_limit.png" )); SDL_SetAlpha(arrows[LOWER_LIMIT], SDL_SRCALPHA|SDL_RLEACCEL, 0); arrows[MIDDLE] = SDL_DisplayFormatAlpha( IMG_Load( PKG_DATA_DIR "/images/getready/middle.png" )); SDL_SetAlpha(arrows[MIDDLE], SDL_SRCALPHA|SDL_RLEACCEL, 0); arrows[UPPER_LIMIT] = SDL_DisplayFormatAlpha( IMG_Load( PKG_DATA_DIR "/images/getready/upper_limit.png" )); SDL_SetAlpha(arrows[UPPER_LIMIT], SDL_SRCALPHA|SDL_RLEACCEL, 0); dest_rect.x = 355; dest_rect.y = 90; erase_rect.x = 355; erase_rect.y = 90; erase_rect.w = 90; erase_rect.h = 50; } // FS::GetReadyDisplay::GetReadyDisplay() // ****************** // *** DESTRUCTOR *** // ****************** FS::GetReadyDisplay::~GetReadyDisplay() { for (int i = 0; i < 3; ++i) { SDL_FreeSurface(arrows[i]); } // for SDL_FreeSurface(background); } // FS::GetReadyDisplay::~GetReadyDisplay() // ************************ // *** MEMBER FUNCTIONS *** // ************************ // ************************************************** void FS::GetReadyDisplay::start_draw(int gt, int lev) { start_time = gt; SDL_BlitSurface(background, NULL, screen, NULL); std::string message; char digits[4]; // allows for 999 levels! sprintf(digits, "%d", lev); message = "About to start level "; message += digits; message += " . . ."; my_font.writeCenter(screen, message.c_str(), 50); my_font.writeCenter(screen, "Get Ready!",90); // FIXME: second arg shouldn't be hard-coded. my_font.writeCenter(screen, "10", 130); SDL_UpdateRect(screen, 0, 0, 0, 0); } // FS::GetReadyDisplay::start_draw() // ************************************************** bool FS::GetReadyDisplay::redraw(int gt, KeyboardEvent * events, int n) { int seconds_passed = (gt - start_time) / 1000; bool jump_pressed = false; int i = 0; while (i < n) { if ( events[i] == JUMP_KEY_PRESSED ) { jump_pressed = true; break; } // if ++i; } // while if ( (seconds_passed == SECONDS_TO_WAIT) || jump_pressed ) { //finished = true; //return; return true; } // if SDL_Rect erase_rect = { 390, 130, 50, 50 }; SDL_Rect dest_rect = { 390, 130 }; SDL_BlitSurface(background, &erase_rect, screen, &dest_rect); char seconds[3]; sprintf(seconds, "%d", (SECONDS_TO_WAIT - seconds_passed)); my_font.writeCenter(screen, seconds, 130); SDL_UpdateRect(screen, 390, 130, 50, 50); return false; } // FS::GetReadyDisplay::redraw() // ************************************************** void FS::GetReadyDisplay::start_draw_level_select(int furthest_lev) { current_start_level = furthest_lev; SDL_BlitSurface(background, NULL, screen, NULL); char lev_string[4]; sprintf(lev_string, "%d", current_start_level); my_font.writeCenter(screen, "Please select start level . . .", 50); my_font.writeCenter(screen, lev_string ,90); SDL_BlitSurface(arrows[UPPER_LIMIT], NULL, screen, &dest_rect); SDL_UpdateRect(screen, 0, 0, 0, 0); } // FS::GetReadyDisplay::start_draw_level_select() // ************************************************** int FS::GetReadyDisplay::redraw_level_select(KeyboardEvent * events, int n, int furthest_lev) { bool changed = false; int selection = 0; int i = 0; while (i < n) { if ( events[i] == JUMP_KEY_PRESSED ) { selection = current_start_level; break; } else if ( events[i] == LEFT_KEY_PRESSED ) { if ( current_start_level > 1 ) { --current_start_level; changed = true; } // if } else if ( events[i] == RIGHT_KEY_PRESSED ) { if ( current_start_level < furthest_lev ) { ++current_start_level; changed = true; } // if } // if ... else ++i; } // while if (changed) { char lev_string[4]; sprintf(lev_string, "%d", current_start_level); SDL_BlitSurface(background, &erase_rect, screen, &erase_rect); SDL_BlitSurface( ((current_start_level == 1) ? arrows[LOWER_LIMIT] : ((current_start_level == furthest_lev) ? arrows[UPPER_LIMIT] : arrows[MIDDLE])), NULL, screen, &dest_rect ); my_font.writeCenter(screen, lev_string ,90); SDL_UpdateRect(screen, erase_rect.x, erase_rect.y, erase_rect.w, erase_rect.h); } // if return selection; } // FS::GetReadyDisplay::redraw_level_select() // ************************************************** // **************************************************