// $Id: mapsprite.cc,v 1.4 2006/08/05 09:08:59 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 "mapsprite.h" // ************************ // *** MEMBER FUNCTIONS *** // ************************ // ************************************************** bool FS::MapSprite::adjust_rect(SDL_Rect * rect) { if (rect->x >= SCREEN_WIDTH) // SCREEN_WIDTH defined in enums.h { if ((rect->x + rect->w) > row_length_pixels) { rect->w = (rect->x + rect->w) - row_length_pixels; rect->x = 0; } else { return false; } // if ... else } else if ((rect->x + rect->w) > SCREEN_WIDTH) { rect->w = SCREEN_WIDTH - rect->x; } // if ... else return true; } // FS::MapSprite::adjust_rect() // ************************************************** // Assigns 'screen' x to the sprite's x variable. N.B. This value // will always be >= 0. void FS::MapSprite::calc_x(int current_start_pixel) { if (current_start_pixel <= map_x) { x = map_x - current_start_pixel; } else { x = (row_length_pixels - current_start_pixel) + map_x; } // if ... else } // FS::MapSprite::calc_screen_x() // ************************************************** void FS::MapSprite::calc_sprite_rect() { sprite_rect.x = x; sprite_rect.w = width; if (((sprite_rect.x + width) > row_length_pixels) || (sprite_rect.x < SCREEN_WIDTH)) { sprite_visible = true; // If sprite's x is off-screen, adjust this value so that it's // negative. It can then be used by SDL_BlitSurface(). if (sprite_rect.x >= SCREEN_WIDTH) { sprite_rect.x -= row_length_pixels; } // if } else { sprite_visible = false; } // if ... else } // FS::MapSprite::calc_sprite_rect() // ************************************************** // ************************************************** // ************************************************** // **************************************************