|
From: Matti K. <mpk...@us...> - 2009-11-23 18:06:38
|
Module: performous
Branch: dance
Commit: 814db5c8acf71bdcc03025c2c6a97fe92a347196
Author: Matti Kemppainen <mpk...@us...>
Date: Mon Nov 23 20:06:16 2009 +0200
Added simple score counting.
---
game/dancegraph.cc | 40 ++++++++++++++++++++++------------------
game/dancegraph.hh | 5 +++--
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index 0c5dfe2..99e489c 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -21,11 +21,12 @@ namespace {
// TODO: Use this or something else?
double points(double error) {
+ error = (error < 0.0) ? -error : error;
double score = 0.0;
if (error < maxTolerance) score += 15;
- if (error < 0.1) score += 15;
- if (error < 0.05) score += 15;
- if (error < 0.03) score += 5;
+ if (error < maxTolerance / 2) score += 15;
+ if (error < maxTolerance / 4) score += 15;
+ if (error < maxTolerance / 6) score += 5;
return score;
}
}
@@ -55,10 +56,6 @@ DanceGraph::DanceGraph(Audio& audio, Song const& song):
for(size_t i = 0; i < 4; i++) m_pressed[i] = AnimValue(0.0, 8.0);
- /**
- * TODO: Skype 17.11.
- * - trackien etsintä
- **/
DanceTracks::const_iterator it = m_song.danceTracks.find(m_gamingMode);
if(it == m_song.danceTracks.end())
throw std::runtime_error("Could not find any dance tracks.");
@@ -84,7 +81,8 @@ void DanceGraph::difficulty(DanceDifficulty level) {
DanceTrack const& track = m_song.danceTracks.find(m_gamingMode)->second.find(level)->second;
for(Notes::const_iterator it = track.notes.begin(); it != track.notes.end(); it++)
m_notes.push_back(DanceNote(*it));
- std::cout << "Difficulty set to: " << level << std::endl;
+ m_notesIt = m_notes.begin();
+// std::cout << "Difficulty set to: " << level << std::endl;
m_level = level;
}
@@ -104,8 +102,13 @@ void DanceGraph::engine() {
else if (ev.pressed[STEP_DOWN]) difficultyDelta(-1);
}
}
- if (ev.type == input::Event::RELEASE) m_pressed[ev.button].setTarget(0.0, false);
- else if (ev.type == input::Event::PRESS) m_pressed[ev.button].setTarget(1.0, true);
+ if (ev.type == input::Event::RELEASE) {
+ m_pressed[ev.button].setTarget(0.0, false);
+ }
+ else if (ev.type == input::Event::PRESS) {
+ dance(time, ev);
+ m_pressed[ev.button].setTarget(1.0, true);
+ }
}
@@ -114,8 +117,14 @@ void DanceGraph::engine() {
/// Handles scoring and such
void DanceGraph::dance(double time, input::Event const& ev) {
- //TODO - Kemppi
-
+ for (DanceNotes::iterator& it = m_notesIt; it != m_notes.end() && it->note.begin <= time + maxTolerance; ++it) {
+ if(!it->isHit) {
+ it->isHit = true;
+ double p = points(it->note.begin - time);
+ it->score = p;
+ m_score += p;
+ }
+ }
}
@@ -190,12 +199,7 @@ void DanceGraph::draw(double time) {
tEnd = it->note.end - time;
if (tEnd < past) continue;
if (tBeg > future) break;
-
- // TODO: Remove me (temporary hack to test hitAnim)
- if (tBeg <= 0.0 && !it->isHit) {
- it->isHit = true; it->hitAnim.setTarget(1.0, false);
- }
-
+
int arrow_i = it->note.note;
float x = -1.5f + arrow_i;
float s = 0.6f;
diff --git a/game/dancegraph.hh b/game/dancegraph.hh
index 2b90517..83095d1 100644
--- a/game/dancegraph.hh
+++ b/game/dancegraph.hh
@@ -15,11 +15,11 @@ class Song;
struct DanceNote {
DanceNote(Note note) :
- note(note), isHit(false), hitAnim(0.0, 5.0), score(0) {}
+ note(note), hitAnim(0.0, 5.0), score(0), isHit(false) {}
Note note;
- bool isHit;
AnimValue hitAnim;
int score;
+ bool isHit;
};
@@ -58,6 +58,7 @@ class DanceGraph {
Song const& m_song;
input::InputDev m_input;
DanceNotes m_notes;
+ DanceNotes::iterator m_notesIt;
Surface m_arrow;
AnimValue m_cx, m_width;
std::size_t m_stream;
|