src/map/sky.cpp

Go to the documentation of this file.
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  * Sky: background of the map
00020  *****************************************************************************/
00021 
00022 #include "sky.h"
00023 #include "camera.h"
00024 #include "map.h"
00025 #include "maps_list.h"
00026 #include "../graphic/surface.h"
00027 #include "../include/app.h"
00028 
00029 // Vitesse (comprise entre 0 et 0.5)
00030 const Point2d SKY_SPEED( 0.3, 1);
00031 
00032 Sky::Sky(){
00033 }
00034 
00035 void Sky::Init(){
00036         // That is temporary -> image will be loaded directly without alpha chanel
00037         Surface tmp_image = ActiveMap().ReadImgSky();
00038         tmp_image.SetAlpha( 0, 0);
00039         image = tmp_image.DisplayFormat();
00040 
00041         tstVect = image.GetSize().inf( camera.GetSize() );
00042         margin = tstVect * (camera.GetSize() - image.GetSize())/2;
00043 }
00044 
00045 void Sky::Reset(){
00046         Init();
00047         lastPos.SetValues(INT_MAX, INT_MAX);
00048 }
00049 
00050 void Sky::Free(){
00051         image.Free();
00052 }
00053 
00054 void Sky::Draw()
00055 {
00056   if( lastPos != camera.GetPosition() ){
00057         lastPos = camera.GetPosition();
00058         RedrawParticle(camera);
00059     return;
00060   }
00061   
00062   RedrawParticleList(*world.to_redraw_now);
00063   RedrawParticleList(*world.to_redraw_particles_now);
00064 }
00065 
00066 void Sky::RedrawParticleList(std::list<Rectanglei> &list){
00067   std::list<Rectanglei>::iterator it;
00068 
00069   for( it = list.begin(); it != list.end(); ++it )
00070           RedrawParticle(*it);
00071 }
00072 
00073 void Sky::RedrawParticle(const Rectanglei &particle) const{
00074     Rectanglei ds(GetSkyPos() + particle.GetPosition() - camera.GetPosition() - margin, 
00075                     particle.GetSize() );
00076     AppWormux::GetInstance()->video.window.Blit(image, ds, particle.GetPosition() - camera.GetPosition());
00077 }
00078 
00079 Point2i Sky::GetSkyPos() const{
00080         return (Point2i(1, 1) - tstVect) * camera.GetPosition() * SKY_SPEED;
00081 }

Generated on Mon Jan 1 13:10:58 2007 for Wormux by  doxygen 1.4.7