Split SOL data structures into base, varying and rendering parts
[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
34     case ITEM_COIN:
35
36         if (hp->n >= 1)
37         {
38             c[0] = 1.0f;
39             c[1] = 1.0f;
40             c[2] = 0.2f;
41         }
42         if (hp->n >= 5)
43         {
44             c[0] = 1.0f;
45             c[1] = 0.2f;
46             c[2] = 0.2f;
47         }
48         if (hp->n >= 10)
49         {
50             c[0] = 0.2f;
51             c[1] = 0.2f;
52             c[2] = 1.0f;
53         }
54         break;
55
56     case ITEM_GROW:
57
58         c[0] = 0.00f;
59         c[1] = 0.51f;
60         c[2] = 0.80f;
61
62         break;
63
64     case ITEM_SHRINK:
65
66         c[0] = 1.00f;
67         c[1] = 0.76f;
68         c[2] = 0.00f;
69
70         break;
71
72     default:
73
74         c[0] = 1.0f;
75         c[1] = 1.0f;
76         c[2] = 1.0f;
77
78         break;
79     }
80 }
81
82 void item_init(void)
83 {
84     sol_load_full(&item_coin_file,   "item/coin/coin.sol",     0);
85     sol_load_full(&item_grow_file,   "item/grow/grow.sol",     0);
86     sol_load_full(&item_shrink_file, "item/shrink/shrink.sol", 0);
87 }
88
89 void item_free(void)
90 {
91     sol_free_full(&item_coin_file);
92     sol_free_full(&item_grow_file);
93     sol_free_full(&item_shrink_file);
94 }
95
96 void item_push(int type)
97 {
98     glEnable(GL_COLOR_MATERIAL);
99 }
100
101 void item_draw(const struct v_item *hp, float r)
102 {
103     struct s_draw *draw = NULL;
104     float c[3];
105
106     switch (hp->t)
107     {
108     case ITEM_COIN:   draw = &item_coin_file.draw;   break;
109     case ITEM_GROW:   draw = &item_grow_file.draw;   break;
110     case ITEM_SHRINK: draw = &item_shrink_file.draw; break;
111     }
112
113     item_color(hp, c);
114
115     glColor3fv(c);
116     sol_draw(draw, 0, 1);
117 }
118
119 void item_pull(void)
120 {
121     glColor3f(1.0f, 1.0f, 1.0f);
122     glDisable(GL_COLOR_MATERIAL);
123 }
124
125 /*---------------------------------------------------------------------------*/
126