File: Ice.hpp

package info (click to toggle)
marsshooter 0.7.6-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,812 kB
  • sloc: cpp: 20,216; xml: 29; makefile: 8
file content (100 lines) | stat: -rw-r--r-- 3,386 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Ice.hpp

Copyright (c) 2010 - 2011 by Felix Lauer and Simon Schneegans

This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along with
this program.  If not, see <http://www.gnu.org/licenses/>. */

# ifndef ICE_HPP_INCLUDED
# define ICE_HPP_INCLUDED

# include "DecoObjects/DecoObject.hpp"

# include "DecoObjects/decoObjects.hpp"
# include "SpaceObjects/Ball.hpp"
# include "SpaceObjects/Ship.hpp"
# include "Particles/AmmoRocket.hpp"


/// An ice block drawn over frozen SpaceObjects.


template <typename Object>
class Ice: public DecoObject {
    public:
        Ice(Object* object): object_(object) {}

        void draw() const {
            if (object_->visible_ && object_->frozen_ > 0.f) {
                glEnable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D, texture::getTexture(texture::Ice));
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

                glPushMatrix();
                glLoadIdentity();
                glTranslatef(object_->location_.x_, object_->location_.y_, 0.f);
                glRotatef(object_->rotation_, 0.f, 0.f, 1.f);
                if (object_->frozen_ > 0) {
                    int posX;
                    int posY;

                    if (object_->frozen_ >= 30) {
                        posX = 0;
                        posY = 0;
                    }
                    else if (object_->frozen_ >= 20) {
                        posX = 1;
                        posY = 0;
                    }
                    else if (object_->frozen_ >= 10) {
                        posX = 0;
                        posY = 1;
                    }
                    else if (object_->frozen_ > 0) {
                        posX = 1;
                        posY = 1;
                    }

                    else {
                        decoObjects::removeIce(this);
                        return;
                    }

                    glColor3f(1.f, 1.f, 1.f);
                    glBegin(GL_QUADS);
                        glTexCoord2f( posX*0.5f,    posY*0.5f);    glVertex2f(-object_->radius_*1.5f,-object_->radius_*1.5f);
                        glTexCoord2f( posX*0.5f,   (posY+1)*0.5f); glVertex2f(-object_->radius_*1.5f, object_->radius_*1.5f);
                        glTexCoord2f((posX+1)*0.5f,(posY+1)*0.5f); glVertex2f( object_->radius_*1.5f, object_->radius_*1.5f);
                        glTexCoord2f((posX+1)*0.5f, posY*0.5f);    glVertex2f( object_->radius_*1.5f,-object_->radius_*1.5f);
                    glEnd();

                }

                glPopMatrix();

                glDisable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D, 0);
            }
            else {
                decoObjects::removeIce(this);
            }
        }

    private:
        Object* object_;
};

# endif // ICE_HPP_INCLUDED