1 /******************************************************************************************
2  *
3  * HighNoon - Duell im All
4  * Copyright (c) 2005, 2006 Patrick Gerdsmeier <patrick@gerdsmeier.net>
5  *
6  * "graphics.hpp"
7  *
8  * Font - use Font to print Text on the Screen
9  *
10  * Sprite - Sprites are initialised with a Filename of a
11  * Picture. Use Sprites to draw Graphics on the Screen.
12  * Sprite has a static Function called putpixel().
13  *
14  * Star, Goldrain - Pixel-Classes. Used for Background
15  * and winner Animation
16  *
17  *
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 2, or (at your option)
22  * any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32  *
33  ******************************************************************************************/
34 
35 #ifndef __GRAPHICS_HPP__
36 #define __GRAPHICS_HPP__
37 
38 #include <SDL.h>
39 
40 #include "constants.hpp"
41 
42 const double SCREENFACTOR = (double)SCREENWIDTH/1024;
43 
44 extern SDL_Surface* MYSDLSCREEN;
45 
46 /******************************************************************************************
47  *
48  * Font
49  *
50  * Font is a class that manages a GIF (Background=0xff00ff) proportional Font.
51  *
52  ******************************************************************************************/
53 class Font
54 {
55 public:
56 	Font();
57 
58 	~Font();
59 
60 	void print( int x, int y, std::string txt, int alpha=255 );
61 
62 	int getLineHeight() const;
63 
64 	int getWidth( std::string txt );
65 
66 private:
67 	SDL_Surface *font_image;
68 	SDL_Rect src, dst;
69 
70 	int font_pos[96];
71 	int font_width[96];
72 };
73 
74 /******************************************************************************************
75  *
76  * Sprite
77  *
78  * Sprite manages a GIF (Background=0xff00ff) as a screen sprite
79  * If Constructed with frames-parameter, Sprite uses serialised
80  * Pictures as Anim with size: Sprite-size / frames;
81  *
82  ******************************************************************************************/
83 class Sprite
84 {
85 public:
86 	static int x_offset, y_offset;
87 
88 	Sprite( char* filename, int frames=1 );
89 
90 	~Sprite();
91 
92 	static void setOffset( int x, int y );
93 
94 	bool is_onLastFrame();
95 
96 	int getWidth();
97 
98 	void setFramerate( int rate );
99 
100 	void setRepeatmode( bool mode );
101 
102 	void resetFrames();
103 
104  	void setPos( int x, int y );
105 
106 	void setAlpha( int a );
107 
108 	void draw();
109 
110 	static void putpixel( int x, int y, Uint32 pixel, SDL_Surface *screen=MYSDLSCREEN );
111 
112 	static SDL_Surface *zoom( SDL_Surface *surface, double factor = SCREENFACTOR );
113 
114 private:
115 	SDL_Surface *sprite_image;
116 	SDL_Rect sprite_rect, rect;
117 	int x, y, width, height, alpha;
118 	bool repeat_mode;
119 	int frames,
120 		actual_frame,
121 		frame_delay,
122 		frame_rate;
123 };
124 
125 /******************************************************************************************
126  *
127  * Star
128  *
129  * Star contains a Star-Structure (for the background)
130  * Lock Surface before Drawing!
131  *
132  ******************************************************************************************/
133 class Star
134 {
135 public:
136 	Star();
137 
138 	void draw();
139 
140 private:
141 	int x, y, b, c;
142 
143 	int rx();
144 
145 	int ry();
146 
147 	int color();
148 
149 	int blink();
150 
151 };
152 
153 /******************************************************************************************
154  *
155  * Shootingstar
156  *
157  * A little Backgroud-Effect
158  * Lock Surface before Drawing!
159  *
160  ******************************************************************************************/
161 class Shootingstar
162 {
163 public:
164 	Shootingstar();
165 
166 	void draw();
167 
168 private:
169 	double x, y, s;
170 	int w;
171 
172 	double rx();
173 
174 	double ry();
175 
176 	double speed();
177 
178 	int wait();
179 
180 };
181 
182 /******************************************************************************************
183  *
184  * Goldrain
185  *
186  * Goldrain is a winner goldrain pixel
187  * Lock Surface before Drawing!
188  *
189  ******************************************************************************************/
190 class Goldrain
191 {
192 public:
193 	Goldrain();
194 
195 	void setOffset(int x, int y);
196 
197 	void draw();
198 
199 private:
200 	double x, y, sp, xoffset, yoffset;
201 	int b, cr, cg, cb ;
202 
203 	double rx();
204 
205 	double ry();
206 
207 	double speed();
208 
209 	int color();
210 
211 	int blink();
212 
213 };
214 
215 #endif
216 
217