00001 /****************************************************************************** 00002 * Wormux is a convivial mass murder game. 00003 * Copyright (C) 2001-2004 Lawrence Azzoug. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00018 ****************************************************************************** 00019 * Weapon's crosshair 00020 *****************************************************************************/ 00021 00022 #include "crosshair.h" 00023 #include "weapon.h" 00024 #include "../game/game_loop.h" 00025 #include "../graphic/surface.h" 00026 #include "../include/app.h" 00027 #include "../map/camera.h" 00028 #include "../map/map.h" 00029 #include "../team/teams_list.h" 00030 #include "../tool/math_tools.h" 00031 00032 // Distance between crosshair and character 00033 #define RAY 40 // pixels 00034 00035 CrossHair::CrossHair() 00036 { 00037 enable = false; 00038 Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false); 00039 image = resource_manager.LoadImage(res, "gfx/pointeur1"); 00040 resource_manager.UnLoadXMLProfile(res); 00041 } 00042 00043 void CrossHair::Reset() 00044 { 00045 ActiveCharacter().SetFiringAngle(0.0); 00046 } 00047 00048 // Compute crosshair position 00049 void CrossHair::Refresh(double angle) 00050 { 00051 crosshair_position = Point2i(RAY, RAY) * Point2d(cos(angle), sin(angle)) - image.GetSize() / 2; 00052 } 00053 00054 void CrossHair::Draw() 00055 { 00056 if( !enable ) 00057 return; 00058 if( ActiveCharacter().IsDead() ) 00059 return; 00060 if( GameLoop::GetInstance()->ReadState() != GameLoop::PLAYING ) 00061 return; 00062 Point2i tmp = ActiveCharacter().GetHandPosition() + crosshair_position; 00063 AppWormux::GetInstance()->video.window.Blit(image, tmp - camera.GetPosition()); 00064 world.ToRedrawOnMap(Rectanglei(tmp, image.GetSize())); 00065 }