Fix accidental switch/teleporter behavior changes
[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 "solid_gl.h"
19 #include "image.h"
20 #include "config.h"
21
22 /*---------------------------------------------------------------------------*/
23
24 static struct s_file item_coin_file;
25 static struct s_file item_grow_file;
26 static struct s_file item_shrink_file;
27
28 void item_color(const struct s_item *hp, float *c)
29 {
30     switch (hp->t)
31     {
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         }
41         if (hp->n >= 5)
42         {
43             c[0] = 1.0f;
44             c[1] = 0.2f;
45             c[2] = 0.2f;
46         }
47         if (hp->n >= 10)
48         {
49             c[0] = 0.2f;
50             c[1] = 0.2f;
51             c[2] = 1.0f;
52         }
53         break;
54
55     case ITEM_GROW:
56
57         c[0] = 0.00f;
58         c[1] = 0.51f;
59         c[2] = 0.80f;
60
61         break;
62
63     case ITEM_SHRINK:
64
65         c[0] = 1.00f;
66         c[1] = 0.76f;
67         c[2] = 0.00f;
68
69         break;
70
71     default:
72
73         c[0] = 1.0f;
74         c[1] = 1.0f;
75         c[2] = 1.0f;
76
77         break;
78     }
79 }
80
81 void item_init(void)
82 {
83     sol_load_gl(&item_coin_file,   "item/coin/coin.sol",     0);
84     sol_load_gl(&item_grow_file,   "item/grow/grow.sol",     0);
85     sol_load_gl(&item_shrink_file, "item/shrink/shrink.sol", 0);
86 }
87
88 void item_free(void)
89 {
90     sol_free_gl(&item_coin_file);
91     sol_free_gl(&item_grow_file);
92     sol_free_gl(&item_shrink_file);
93 }
94
95 void item_push(int type)
96 {
97     glEnable(GL_COLOR_MATERIAL);
98 }
99
100 void item_draw(const struct s_item *hp, float r)
101 {
102     float c[3];
103     struct s_file *fp = NULL;
104
105     switch (hp->t)
106     {
107     case ITEM_COIN:   fp = &item_coin_file;   break;
108     case ITEM_GROW:   fp = &item_grow_file;   break;
109     case ITEM_SHRINK: fp = &item_shrink_file; break;
110     }
111
112     item_color(hp, c);
113
114     glColor3fv(c);
115     sol_draw(fp, 0, 1);
116 }
117
118 void item_pull(void)
119 {
120     glColor3f(1.0f, 1.0f, 1.0f);
121     glDisable(GL_COLOR_MATERIAL);
122 }
123
124 /*---------------------------------------------------------------------------*/
125