1 // 2 // ElectricGate.hpp -- Electric gateway thingys. 3 // Copyright (C) 2008 Nick Gasson 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 // 18 19 #ifndef INC_ELECTRICGATE_HPP 20 #define INC_ELECTRICGATE_HPP 21 22 #include "ObjectGrid.hpp" 23 #include "Viewport.hpp" 24 #include "Image.hpp" 25 #include "GameObjFwd.hpp" 26 27 #include <list> 28 29 // 30 // A line strip used for rendering lightning. 31 // 32 class LightLineStrip { 33 public: LightLineStrip()34 LightLineStrip() : swapXandY(false) {} 35 36 void AddPoint(double x, double y); 37 void Draw() const; SwapXandY(bool b)38 void SwapXandY(bool b) { swapXandY = b; } Clear()39 void Clear() { points.clear(); } 40 private: 41 void DrawWithOffset(double off, double r, double g, double b, 42 double a) const; 43 44 typedef pair<double, double> Point_t; 45 list<Point_t> points; 46 bool swapXandY; 47 }; 48 49 class Lightning { 50 public: 51 void Build(int length, bool vertical); 52 void Draw() const; 53 private: 54 LightLineStrip line; 55 }; 56 57 58 class ElectricGate : public StaticObject { 59 public: 60 ElectricGate(Viewport* v, int length, bool vertical, int x, int y); 61 62 bool CheckCollision(Ship& ship); 63 void Draw(); 64 65 private: 66 static const int GATEWAY_ACTIVE = 30; 67 68 int length, timer; 69 bool vertical; 70 Viewport* viewport; 71 Lightning lightning; 72 Image gateImage; 73 }; 74 75 #endif 76