1 /*****************************************************************************
2 *
3 * Copyright (C) 2003 C�dric Br�gardis <cedric.bregardis@free.fr>
4 *
5 * This file is part of BRIQUOLO
6 *
7 * BRIQUOLO is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * BRIQUOLO is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with BRIQUOLO; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 *****************************************************************************/
22 #include "BonusDoubleBalle.h"
23 #include "TableauJeu.h"
24 #include <MOGL_GestionnaireObjet.h>
25 #include "Constante.h"
26
27 #ifndef M_PI
28 #define M_PI 3.14159265359
29 #endif
30
31 MOGL_Objet * BonusDoubleBalle::_ObjetSource=NULL;
32
BonusDoubleBalle()33 BonusDoubleBalle::BonusDoubleBalle(): Bonus()
34 {
35 if (_ObjetSource==NULL)
36 {
37 PreCharger(Texture::GetGestionnaireTexture());
38 }
39 _ElementArbre=new MOGL_Objet(*_ObjetSource);
40 }
41
42
BonusDoubleBalle(const BonusDoubleBalle & p_Bonus)43 BonusDoubleBalle::BonusDoubleBalle(const BonusDoubleBalle & p_Bonus): Bonus(p_Bonus)
44 {
45 _ElementArbre=new MOGL_Objet(*_ObjetSource);
46 }
47
~BonusDoubleBalle()48 BonusDoubleBalle::~BonusDoubleBalle()
49 {
50 delete _ElementArbre;
51 }
52
PreCharger(MOGL_GestionnaireTexture * p_GestionnaireTexture)53 void BonusDoubleBalle::PreCharger(MOGL_GestionnaireTexture * p_GestionnaireTexture)
54 {
55 _ObjetSource=new MOGL_Objet;
56 MOGL_GestionnaireObjet::ChargerObjetASCTriangle((Constante::GetGlobalDir()+Constante::GetDataDir()+"/bonus_doubleballe.tri").c_str(),
57 *p_GestionnaireTexture, *_ObjetSource);
58 }
59
Mouvement(Plateau * p_Plateau,TableauJeu * p_Tableau)60 bool BonusDoubleBalle::Mouvement(Plateau * p_Plateau, TableauJeu * p_Tableau)
61 {
62 if (CollisionPlateau(p_Plateau))
63 {
64 unsigned int i=0;
65 Balle ** tabBalle;
66 tabBalle=new Balle*[p_Tableau->GetSetBalle()->size()];
67
68 for(TableauJeu::Set_Balle::iterator itBalle=p_Tableau->GetSetBalle()->begin(); itBalle!=p_Tableau->GetSetBalle()->end(); itBalle++)
69 {
70 float dirX=(*itBalle)->GetDirectionX();
71 float dirY=(*itBalle)->GetDirectionY();
72 //float vitesse=sqrt(vitX*vitX + vitY*vitY);
73 float angle=atan2(dirY, dirX);
74
75 tabBalle[i]=new Balle(*(*itBalle));
76
77 (*itBalle)->SetDirection(cos(angle-20*M_PI/180), sin(angle-20*M_PI/180));
78 tabBalle[i]->SetDirection(cos(angle+20*M_PI/180), sin(angle+20*M_PI/180));
79 i++;
80 }
81
82 unsigned int total=p_Tableau->GetSetBalle()->size();
83 for(i=0; i<total; i++)
84 {
85 p_Tableau->AjouterBalle(tabBalle[i]);
86 }
87 delete [] tabBalle;
88 return true;
89 }
90 return false;
91 }
92
93