From ee2875d4029935247709a661a73f706e389bd035 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 30 Aug 2008 17:52:45 +0100 Subject: [PATCH] Draw while line between gates --- src/Asteroid.cpp | 1 - src/ElectricGate.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- src/ElectricGate.hpp | 26 ++++++++++++++++++++++++++ src/Game.cpp | 2 +- src/Platform.hpp | 1 + 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/Asteroid.cpp b/src/Asteroid.cpp index 76d502c..a2566c9 100644 --- a/src/Asteroid.cpp +++ b/src/Asteroid.cpp @@ -24,7 +24,6 @@ Texture *Asteroid::surfTexture[Surface::NUM_SURF_TEX]; Asteroid::Asteroid() { LOAD_ONCE { - cout << "Loading asteroids..." << endl; surfTexture[0] = new Texture("images/dirt_surface2.png"); surfTexture[1] = new Texture("images/snow_surface2.png"); surfTexture[2] = new Texture("images/red_rock_surface2.png"); diff --git a/src/ElectricGate.cpp b/src/ElectricGate.cpp index 776da40..307a14d 100644 --- a/src/ElectricGate.cpp +++ b/src/ElectricGate.cpp @@ -26,6 +26,8 @@ ElectricGate::ElectricGate(Viewport *v, int length, bool vertical, int x, int y) LOAD_ONCE { gateImage = new Image("images/gateway.png"); } + + lightning.Build(length * OBJ_GRID_SIZE, vertical); timer = rand() % 70 + 10; } @@ -78,9 +80,14 @@ void ElectricGate::Draw() // Draw the electricity stuff if (--timer < GATEWAY_ACTIVE) { - int x, y, deviation; + double x = xpos*OBJ_GRID_SIZE + 16 - viewport->GetXAdjust(); + double y = ypos*OBJ_GRID_SIZE + OBJ_GRID_TOP + 16 - viewport->GetYAdjust(); + + glLoadIdentity(); + glTranslated(x, y, 0.0); + lightning.Draw(); - glDisable(GL_TEXTURE_2D); + /*glDisable(GL_TEXTURE_2D); for (int j = 0; j < 10; j++) { deviation = 0; @@ -121,7 +128,7 @@ void ElectricGate::Draw() } glEnd(); } - } + }*/ // Reset timer if (timer < 0) @@ -129,4 +136,35 @@ void ElectricGate::Draw() } } +void Lightning::Build(int length, bool vertical) +{ + line.SwapXandY(vertical); + + line.AddPoint(0, 0); + line.AddPoint(length, 0); +} + +void Lightning::Draw() const +{ + glDisable(GL_TEXTURE_2D); + line.Draw(); +} +void LightLineStrip::AddPoint(double x, double y) +{ + if (swapXandY) + points.push_back(Point_t(y, x)); + else + points.push_back(Point_t(x, y)); +} + +void LightLineStrip::Draw() const +{ + glBegin(GL_LINE_STRIP); + + list::const_iterator it; + for (it = points.begin(); it != points.end(); ++it) + glVertex2d((*it).first, (*it).second); + + glEnd(); +} diff --git a/src/ElectricGate.hpp b/src/ElectricGate.hpp index 25d9909..2d0b9c0 100644 --- a/src/ElectricGate.hpp +++ b/src/ElectricGate.hpp @@ -23,6 +23,31 @@ #include "Viewport.hpp" #include "Image.hpp" +/* + * A line strip used for rendering lightning. + */ +class LightLineStrip { +public: + LightLineStrip() : swapXandY(false) {} + + void AddPoint(double x, double y); + void Draw() const; + void SwapXandY(int b) { swapXandY = b; } +private: + typedef pair Point_t; + list points; + bool swapXandY; +}; + +class Lightning { +public: + void Build(int length, bool vertical); + void Draw() const; +private: + LightLineStrip line; +}; + + class ElectricGate : public StaticObject { public: ElectricGate(Viewport *v, int length, bool vertical, int x, int y); @@ -36,6 +61,7 @@ private: int length, timer; bool vertical; Viewport *viewport; + Lightning lightning; static Image *gateImage; }; diff --git a/src/Game.cpp b/src/Game.cpp index 9e31cca..7d64d22 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -447,7 +447,7 @@ void Game::StartLevel(int level) } // Create gateways - int gatewaycount = level/3 + rand()%level - 2; + int gatewaycount = 10 /* DEBUG */ + level/3 + rand()%level - 2; gateways.clear(); if (gatewaycount > MAX_GATEWAYS) gatewaycount = MAX_GATEWAYS; diff --git a/src/Platform.hpp b/src/Platform.hpp index 01108fb..d49537b 100644 --- a/src/Platform.hpp +++ b/src/Platform.hpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include -- 2.39.2