Merge branch 'gles'
[neverball] / share / item.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #include "item.h"
16 #include "glext.h"
17 #include "vec3.h"
18 #include "image.h"
19 #include "config.h"
20
21 #include "solid_draw.h"
22
23 /*---------------------------------------------------------------------------*/
24
25 static struct s_full item_coin_file;
26 static struct s_full item_grow_file;
27 static struct s_full item_shrink_file;
28
29 void item_color(const struct v_item *hp, float *c)
30 {
31     switch (hp->t)
32     {
33     case ITEM_COIN:
34
35         if (hp->n >= 1)
36         {
37             c[0] = 1.0f;
38             c[1] = 1.0f;
39             c[2] = 0.2f;
40             c[3] = 1.0f;
41         }
42         if (hp->n >= 5)
43         {
44             c[0] = 1.0f;
45             c[1] = 0.2f;
46             c[2] = 0.2f;
47             c[3] = 1.0f;
48         }
49         if (hp->n >= 10)
50         {
51             c[0] = 0.2f;
52             c[1] = 0.2f;
53             c[2] = 1.0f;
54             c[3] = 1.0f;
55         }
56         break;
57
58     case ITEM_GROW:
59
60         c[0] = 0.00f;
61         c[1] = 0.51f;
62         c[2] = 0.80f;
63         c[3] = 1.00f;
64
65         break;
66
67     case ITEM_SHRINK:
68
69         c[0] = 1.00f;
70         c[1] = 0.76f;
71         c[2] = 0.00f;
72         c[3] = 1.00f;
73
74         break;
75
76     default:
77
78         c[0] = 1.0f;
79         c[1] = 1.0f;
80         c[2] = 1.0f;
81         c[3] = 1.0f;
82
83         break;
84     }
85 }
86
87 void item_init(void)
88 {
89     sol_load_full(&item_coin_file,   "item/coin/coin.sol",     0);
90     sol_load_full(&item_grow_file,   "item/grow/grow.sol",     0);
91     sol_load_full(&item_shrink_file, "item/shrink/shrink.sol", 0);
92 }
93
94 void item_free(void)
95 {
96     sol_free_full(&item_coin_file);
97     sol_free_full(&item_grow_file);
98     sol_free_full(&item_shrink_file);
99 }
100
101 void item_draw(struct s_rend *rend,
102                const struct v_item *hp,
103                const GLfloat *M, float t)
104 {
105     struct s_draw *draw = NULL;
106     float c[4];
107
108     switch (hp->t)
109     {
110     case ITEM_COIN:   draw = &item_coin_file.draw;   break;
111     case ITEM_GROW:   draw = &item_grow_file.draw;   break;
112     case ITEM_SHRINK: draw = &item_shrink_file.draw; break;
113     }
114
115     item_color(hp, c);
116
117     glColor4f(c[0], c[1], c[2], c[3]);
118
119     glDepthMask(GL_FALSE);
120     {
121         sol_bill(draw, rend, M, t);
122     }
123     glDepthMask(GL_TRUE);
124
125     glPushMatrix();
126     {
127         glRotatef(360.0f * t, 0.0f, 1.0f, 0.0f);
128         sol_draw(draw, rend, 0, 1);
129     }
130     glPopMatrix();
131 }
132
133 /*---------------------------------------------------------------------------*/
134