1 //
2 //  Asteroid.hpp -- Randomly generated asteroid.
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_ASTEROID_HPP
20 #define INC_ASTEROID_HPP
21 
22 #include "GameObjFwd.hpp"
23 #include "GraphicsFwd.hpp"
24 #include "Surface.hpp"
25 #include "ObjectGrid.hpp"
26 #include <memory>
27 
28 class Asteroid : public StaticObject {
29 public:
30    Asteroid(int x, int y, int width, int surftex);
31    Asteroid(const Asteroid& other);
32    ~Asteroid();
33 
34    void Draw(int viewadjust_x, int viewadjust_y) const;
35    bool CheckCollision(const Ship& ship) const;
36    LineSegment GetUpBoundary(int poly) const;
37    LineSegment GetDownBoundary(int poly) const;
38 
39    static const int MAX_ASTEROID_WIDTH = 15;
40 
41 private:
42    static const int AS_VARIANCE = 64;
43 
44    void GenerateDisplayList(int texidx);
45    static string SurfaceFileName(int textureId);
46 
47    Texture* surfaceTexture;
48    std::shared_ptr<GLuint> displayList;
49 
50    struct AsteroidSection {
51       double texX, texwidth;
52       Point points[4];
53    };
54    AsteroidSection uppolys[MAX_ASTEROID_WIDTH], downpolys[MAX_ASTEROID_WIDTH];
55 };
56 
57 
58 #endif
59