-
Notifications
You must be signed in to change notification settings - Fork 0
/
Y_Wolf.cpp
140 lines (119 loc) · 3.53 KB
/
Y_Wolf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Y_Wolf.cpp
*
* Copyright 2009 jmimu
*
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "Y_Wolf.h"
Animation *Y_Wolf::anim_wolf;
std::list <Y_Wolf*> Y_Wolf::wolves;
sf::SoundBuffer Y_Wolf::w_yell_buffer;
sf::Sound Y_Wolf::w_yell_sound;
sf::SoundBuffer Y_Wolf::w_stress_buffer;
sf::Sound Y_Wolf::w_stress_sound;
Y_Wolf::Y_Wolf(int size_x,int size_y,Y_Perso * _perso,Y_Fire * _fire1,Y_Fire * _fire2)
: Actor(size_x,size_y),stress(0),perso(_perso),fire1(_fire1),fire2(_fire2)
{
if (wolves.empty())
{
anim_wolf=new Animation();
anim_wolf->load_animation("data/wolf2.png",54,45);
w_yell_buffer.LoadFromFile("data/sound/grrB2.ogg");
w_yell_sound.SetBuffer(w_yell_buffer);
w_stress_buffer.LoadFromFile("data/sound/grr2.ogg");
w_stress_sound.SetBuffer(w_stress_buffer);
}
add_anim(anim_wolf);
x=-200;
y=180;
mass=0;
//wolf.SetScale(2.0,2.0);
wolves.push_back(this);
number=wolves.size();
}
Y_Wolf::~Y_Wolf()
{
wolves.remove(this);
//if (wolves.empty()) delete_all_anims();
}
bool Y_Wolf::update()//return true if object is deleted
{
if (rand()%2000==3) w_yell_sound.Play();
bool ret;
ret=Phys_Object::update();
float wolves_close=0;//nbr of wolves close
std::list <Y_Wolf*>::iterator wolf_iterator;
wolf_iterator = wolves.begin();
while( wolf_iterator != wolves.end() ) {
wolves_close+=1/(fabs(x-(*wolf_iterator)->x)+1);
++wolf_iterator;
}
float previous_stress=stress;
if (x<0)
{
stress=(stress*10+ //previous
//(400-fabs(x)) //position
+perso->get_yelling()*1000 //yell
+1*(fire1->get_intensity()+fire1->get_intensity_increase()*100)/ sqrtf(fabs(x-fire1->get_pos_x()))
+10*(fire2->get_intensity()+fire2->get_intensity_increase()*1000)/ sqrtf(fabs(x-fire2->get_pos_x()))
-10*wolves_close
+ rand() % 400 - 200
)/11;
if (stress<0) stress=0;
target_x=-stress;
}else{
stress=(stress*10+ //previous
//(400-fabs(x)) //position
+perso->get_yelling()*1000 //yell
+10*(fire1->get_intensity()+fire1->get_intensity_increase()*100)/ sqrtf(fabs(x-fire1->get_pos_x()))
+1*(fire2->get_intensity()+fire2->get_intensity_increase()*1000)/ sqrtf(fabs(x-fire2->get_pos_x()))
-10*wolves_close
+ rand() % 400 - 200
)/11;
if (stress<0) stress=0;
target_x=+stress;
}
if ((target_x-x)>1)
{
if (speed_x<0.01)
{
speed_x=0;
set_flipX(false);
}
speed_x+=5;
speed_x/=1.3;
}
else if ((target_x-x)<-1)
{
if (speed_x>-0.01)
{
speed_x=0;
set_flipX(true);
}
speed_x+=-5;
speed_x/=1.3;
}else
{
speed_x=0;
}
if ((previous_stress*2<stress)&&(stress>100)) w_stress_sound.Play();
return ret;
}
void Y_Wolf::draw_infos(sf::RenderWindow & App,int x2,int y2)
{
//App.Draw(sf::Shape::Rectangle(x2-20, y2-59-number, x2-20+stress/2.5, y2-58-number, sf::Color::Color(255,0,0,255) ));
}