|
From: Tapio V. <aa...@us...> - 2009-12-11 12:43:10
|
Module: performous
Branch: dance
Commit: aceb82c7858f9da22620bca798e1a91f3e70c947
Author: Tapio Vierros <tap...@gm...>
Date: Sun Nov 29 20:19:27 2009 +0200
Some quick test for a starpower / overdrive effect.
Tilt guitar or press F6 to active.
Colors are made uniform and then they slowly fade back to normal.
---
game/guitargraph.cc | 22 +++++++++++++++++++---
game/guitargraph.hh | 1 +
game/joystick.cc | 40 +++++++++++++++++++++++++++++++---------
game/joystick.hh | 2 +-
4 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 9f19f97..2661353 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -40,6 +40,18 @@ namespace {
if (error < 0.03) score += 5;
return score;
}
+
+ inline float blend(float a, float b, float f) { return a*f + b*(1.0f-f); }
+
+ glutil::Color starpowerColorize(glutil::Color c, float f) {
+ static glutil::Color starpowerC(0.5f, 0.5f, 1.0f);
+ if ( f < 0.001 ) return c;
+ f = std::sqrt(std::sqrt(f));
+ c.r = blend(starpowerC.r, c.r, f);
+ c.g = blend(starpowerC.g, c.g, f);
+ c.b = blend(starpowerC.b, c.b, f);
+ return c;
+ }
}
@@ -52,6 +64,7 @@ GuitarGraph::GuitarGraph(Audio& audio, Song const& song, std::string track):
m_tap(getThemePath("tap.svg")),
m_drums(track=="drums"),
m_use3d(config["graphic/3d_notes"].b()),
+ m_starpower(0.0, 0.1),
m_cx(0.0, 0.2),
m_width(0.5, 0.4),
m_stream(),
@@ -128,6 +141,7 @@ void GuitarGraph::engine() {
}
if (!m_drums && ev.type == input::Event::WHAMMY)
whammy = (1.0 + ev.button + 2.0*(rand()/double(RAND_MAX))) / 4.0;
+ if (!m_drums && ev.type == input::Event::STARPOWER) m_starpower.setValue(1.0);
if (ev.type == input::Event::PRESS) m_hit[!m_drums + ev.button].setValue(1.0);
else if (ev.type == input::Event::PICK) m_hit[0].setValue(1.0);
if (time < -0.5) {
@@ -400,7 +414,8 @@ void GuitarGraph::draw(double time) {
texCoord -= texCoordStep * (tEnd - future) / (tEnd - tBeg);
tEnd = future;
}
- glColor4f(1.0f, 1.0f, 1.0f, time2a(tEnd));
+ glutil::Color c(1.0f, 1.0f, 1.0f, time2a(tEnd));
+ glColor4fv(starpowerColorize(c, m_starpower.get()));
glNormal3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, texCoord); glVertex2f(-w, time2y(tEnd));
glNormal3f(0.0f, 1.0f, 0.0f);
@@ -415,7 +430,8 @@ void GuitarGraph::draw(double time) {
for (int fret = m_drums; fret < 5; ++fret) {
float x = -2.0f + fret - 0.5f * m_drums;
float l = m_hit[fret + !m_drums].get();
- glColor4fv(color(fret));
+ glColor4fv(starpowerColorize(color(fret), m_starpower.get()));
+ //glColor4fv(c);
m_button.dimensions.center(time2y(0.0)).middle(x);
m_button.draw();
glColor3f(l, l, l);
@@ -440,7 +456,7 @@ void GuitarGraph::draw(double time) {
glow = m_events[event - 1].glow.get();
whammy = m_events[event - 1].whammy.get();
}
- glutil::Color c = color(fret);
+ glutil::Color c = starpowerColorize(color(fret), m_starpower.get());
c.r += glow;
c.g += glow;
c.b += glow;
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index b4a6a15..eaa9406 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -77,6 +77,7 @@ class GuitarGraph {
boost::scoped_ptr<Texture> m_neck;
bool m_drums;
bool m_use3d;
+ AnimValue m_starpower;
AnimValue m_cx, m_width;
std::size_t m_stream;
TrackMapConstPtr m_track_map;
diff --git a/game/joystick.cc b/game/joystick.cc
index 3b0e42e..30eeaba 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -27,9 +27,9 @@ static const unsigned SDL_BUTTONS = 6;
int buttonFromSDL(input::Private::Type _type, unsigned int _sdl_button) {
static const int inputmap[4][SDL_BUTTONS] = {
- //G R Y B O // for guitars
- { 2, 0, 1, 3, 4, -1 }, // Guitar Hero guitar
- { 3, 0, 1, 2, 4, -1 }, // Rock Band guitar
+ //G R Y B O S // for guitars (S=starpower)
+ { 2, 0, 1, 3, 4, 5 }, // Guitar Hero guitar
+ { 3, 0, 1, 2, 4, 5 }, // Rock Band guitar
//K R Y B G O // for drums
{ 3, 4, 1, 2, 0, 4 }, // Guitar Hero drums
{ 3, 4, 1, 2, 0, -1 } // Rock Band drums
@@ -215,6 +215,14 @@ bool input::SDL::pushEvent(SDL_Event _e) {
}
devices[joy_id].addEvent(event);
return true;
+ case SDLK_F6:
+ event.type = input::Event::STARPOWER;
+ event.button = 1;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ devices[joy_id].addEvent(event);
+ return true;
case SDLK_F5: case SDLK_5:
button++;
case SDLK_F4: case SDLK_4:
@@ -254,6 +262,14 @@ bool input::SDL::pushEvent(SDL_Event _e) {
}
devices[joy_id].addEvent(event);
return true;
+ case SDLK_F6:
+ event.type = input::Event::STARPOWER;
+ event.button = 0;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ devices[joy_id].addEvent(event);
+ return true;
case SDLK_F5: case SDLK_5:
button++;
case SDLK_F4: case SDLK_4:
@@ -318,10 +334,14 @@ bool input::SDL::pushEvent(SDL_Event _e) {
if(!devices[joy_id].assigned()) return false;
button = buttonFromSDL(devices[joy_id].type(),_e.jbutton.button);
if( button == -1 ) return false;
- for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
- event.pressed[i] = devices[joy_id].pressed(i);
+ if( button == 5) {
+ event.type = input::Event::STARPOWER;
+ } else {
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ event.type = input::Event::PRESS;
}
- event.type = input::Event::PRESS;
event.button = button;
event.pressed[button] = true;
devices[joy_id].addEvent(event);
@@ -331,10 +351,12 @@ bool input::SDL::pushEvent(SDL_Event _e) {
if(!devices[joy_id].assigned()) return false;
button = buttonFromSDL(devices[joy_id].type(),_e.jbutton.button);
if( button == -1 ) return false;
- for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
- event.pressed[i] = devices[joy_id].pressed(i);
+ if( button != 5) {
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ event.type = input::Event::RELEASE;
}
- event.type = input::Event::RELEASE;
event.button = button;
event.pressed[button] = false;
devices[joy_id].addEvent(event);
diff --git a/game/joystick.hh b/game/joystick.hh
index f3ee06b..23f5da4 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -21,7 +21,7 @@ namespace input {
static const std::size_t BUTTONS = 6;
struct Event {
- enum Type { PRESS, RELEASE, PICK, WHAMMY };
+ enum Type { PRESS, RELEASE, PICK, WHAMMY, STARPOWER };
Type type;
int button; // Translated button number for press/release events. 0 for pick down, 1 for pick up (NOTE: these are NOT pick press/release events but rather different directions)
bool pressed[BUTTONS]; // All events tell the button state right after the event happened
|