00001 /************************************************************************* 00002 character.cpp 00003 Project Piedmont game 00004 ------------------------- 00005 00006 Date Created: 10/18/00 Last Modified: 05/07/08 00007 Programmer: David Foster 00008 Copyright: (C) 2000 David Foster (see file COPYING) 00009 E-mail: dfoster@computer.org 00010 00011 Description: main character class from which enemies character 00012 classes will be derived. 00013 00014 This program is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License as published by 00016 the Free Software Foundation; either version 2 of the License, or 00017 (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00027 00028 ************************************************************************/ 00029 00030 #include "character.h" 00031 00032 Character::Character(){ 00033 num_frames = 24; 00034 onscreen = 0; 00035 animate = 0; 00036 walkable = 0; 00037 } 00038 00039 Character::~Character(){ 00040 } 00041 00042 void Character::set_paul_info(paul_info *p){ 00043 pinfo = p; 00044 } 00045 00046 void Character::set_tileinfo(int first_prop, int second_prop, int third_prop){ 00047 ranged = first_prop; 00048 hitpoints = second_prop; 00049 damage = third_prop; 00050 stationary = 0; 00051 } 00052 00053 void Character::update(){ 00054 if(CHARACTER_DEBUG) printf("character update (%d, %d)\n", box.x, box.y); 00055 // Because box is a tile location and tile_start|stop are tile locations, we can 00056 // do a simple compare to figure out if any part of this FGE is onscreen 00057 if((box.x >= pinfo->tile_start_x) && (box.x <= pinfo->tile_stop_x) && 00058 (box.y >= pinfo->tile_start_y) && (box.y <= pinfo->tile_stop_y)){ 00059 onscreen = 1; 00060 // This is not a particularly intuitive calculation 00061 // box - tile_start gives us the relative location of the tile (in t units) in the window 00062 // Multiply by tilesize to get the pixel location 00063 // Add tile_aN_in_win to get the tile offset if the window isn't aligned on tile borders 00064 current_box.x = pinfo->tile_ax_in_win + (box.x - pinfo->tile_start_x)*pinfo->tilesize; 00065 current_box.y = pinfo->tile_ay_in_win + (box.y - pinfo->tile_start_y)*pinfo->tilesize; 00066 }else{ 00067 onscreen = 0; 00068 } 00069 } 00070