1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3
4 This file is part of Aquaria.
5
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 #include "DSQ.h"
22 #include "Game.h"
23
Emote()24 Emote::Emote()
25 {
26 // blah
27 emoteTimer = 0;
28 lastVariation = -1;
29 }
30
load(const std::string & file)31 void Emote::load(const std::string &file)
32 {
33 emotes.clear();
34 InStream in(file.c_str());
35 std::string line;
36
37 while (std::getline(in, line))
38 {
39 std::istringstream is(line);
40 EmoteData e;
41 is >> e.index >> e.name >> e.variations;
42 emotes.push_back(e);
43 }
44 emoteTimer = 0;
45 }
46
playSfx(int index)47 void Emote::playSfx(int index)
48 {
49 if (index < 0 || index >= emotes.size()) return;
50 if (emoteTimer > 0) return;
51
52 int r = 0;
53
54 if (emotes[index].variations > 1)
55 {
56 r = (rand()%emotes[index].variations)+1;
57 if (r == lastVariation)
58 {
59 r++;
60 if (r > emotes[index].variations)
61 {
62 r = 1;
63 }
64 }
65 }
66
67 std::ostringstream os;
68 os << emotes[index].name << r;
69
70 lastVariation = r;
71
72 PlaySfx play;
73 play.name = os.str();
74
75 dsq->sound->playSfx(play);
76 emoteTimer = 0.5;
77 }
78
update(float dt)79 void Emote::update(float dt)
80 {
81 if (!dsq->game->isPaused())
82 {
83 if (emoteTimer > 0)
84 {
85 emoteTimer -= dt;
86 if (emoteTimer <= 0)
87 {
88 emoteTimer = 0;
89 }
90 }
91 }
92 }
93