Subversion Repositories Kolibri OS

Rev

Rev 5298 | Rev 5315 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5225 alpine 1
#ifndef RSGAME_H_INCLUDED
2
#define RSGAME_H_INCLUDED
3
 
4
/*
5
 
6
    Heliothryx
7
    Game by Roman Shuvalov
8
 
9
*/
10
 
5243 alpine 11
#ifndef RS_LINUX
12
    #ifndef RS_WIN32
13
        #ifndef RS_KOS
14
            #error Please specify platform
15
        #endif
16
    #endif
17
#endif
5225 alpine 18
 
5243 alpine 19
 
5225 alpine 20
#include "rskos.h"
21
#include "rs/rsplatform.h"
5298 alpine 22
 
5225 alpine 23
#include "rs/rsdebug.h"
24
#include "rs/rsbits.h"
25
 
5298 alpine 26
#include "rsgamelogic.h"
5225 alpine 27
 
28
 
29
#include "rs/rsmx.h"
30
 
31
 
32
 
33
 
34
#define GAME_LANG_EN    0
35
#define GAME_LANG_RU    1
36
 
37
#define GAME_WIDTH  320
38
#define GAME_HEIGHT 180
39
 
40
 
41
typedef struct {
42
    unsigned int status;
43
    int w;
44
    int h;
45
    unsigned char *data; // BGRA BGRA
46
} rs_texture_t;
47
 
48
 
49
// for little-endian
50
typedef union color_t {
51
    int d;                 // 0x44332211 (ARGB)
52
    struct {
53
        unsigned char b; // 0x11
54
        unsigned char g; // 0x22
55
        unsigned char r; // 0x33
56
        unsigned char a; // 0x44
57
    };
58
} color_t;
59
 
60
// for little-endian (ARGB)
61
#define COLOR_BLACK     0xFF000000
62
#define COLOR_TRANSPARENT   0x00000000
5298 alpine 63
#define COLOR_DARK_RED  0xFF401000
5225 alpine 64
 
65
 
66
 
67
void texture_init(rs_texture_t *tex, int w, int h);
68
void texture_free(rs_texture_t *tex);
69
void texture_clear(rs_texture_t *tex, unsigned int color);
70
void texture_draw(rs_texture_t *dest, rs_texture_t *src, int x, int y, int mode);
71
void texture_draw_vline(rs_texture_t *tex, int x, int y, int l, unsigned int color);
72
void texture_draw_hline(rs_texture_t *tex, int x, int y, int l, unsigned int color);
73
void texture_set_pixel(rs_texture_t *tex, int x, int y, unsigned int color);
74
 
75
unsigned char clamp_byte(int value);
76
 
77
#define DRAW_MODE_REPLACE   0
78
#define DRAW_MODE_ADDITIVE  1
79
#define DRAW_MODE_ALPHA     2
80
 
81
#define DRAW_MODE_MASK      0x0000FFFF
82
#define DRAW_TILED_FLAG     0x00010000
83
 
84
 
85
 
86
typedef struct {
87
    unsigned int status;
88
    int length_samples;
89
    SNDBUF hbuf;
90
    signed short *data;
91
} rs_soundbuf_t;
92
 
93
void soundbuf_init(rs_soundbuf_t *snd, int length);
94
void soundbuf_free(rs_soundbuf_t *snd);
95
void soundbuf_fill(rs_soundbuf_t *snd, int amp, int freq_div);
96
void soundbuf_sin(rs_soundbuf_t *snd, float freq);
97
void soundbuf_sin_fade(rs_soundbuf_t *snd, float freq);
5302 alpine 98
void soundbuf_play(rs_soundbuf_t *snd, int mode);
99
void soundbuf_loop_check(rs_soundbuf_t *snd);
5225 alpine 100
void soundbuf_stop(rs_soundbuf_t *snd);
101
 
5291 alpine 102
// Game Objects
103
 
104
#define     GAME_OBJS_MAX_COUNT     1024
105
 
106
#define     OBJ_PLAYER      0
107
#define     OBJ_BULLET      1
108
#define     OBJ_EXPLOSION   2
109
#define     OBJ_ROCK        3
110
#define     OBJ_MINIROCK    4
111
#define     OBJ_TURRET      5
112
#define     OBJ_RED_BULLET  6
113
 
114
typedef struct game_obj_t {
115
    int obj_type;
116
    int flags;
117
    int tag;
118
    int radius;
119
 
120
    float x;
121
    float y;
122
    int t;
123
    float f;
124
 
125
//    int health;
126
//    int reserved0;
127
//    int reserved1;
128
//    int reserved2;
129
} game_obj_t;
130
 
131
#define OBJ_FLAG_DESTROYED      0x01
132
#define OBJ_FLAG_ENEMY          0x02
133
#define OBJ_FLAG_SIN            0x04
134
#define OBJ_FLAG_BOSS           0x08 // draw health-bar above
135
 
136
game_obj_t game_obj(int obj_type, int flags, int tag, int radius, float x, float y, int t, float f);
137
 
138
int game_obj_add(game_obj_t obj);
139
void game_obj_remove(int index);
140
 
141
 
142
 
5225 alpine 143
// Game Registry
144
 
5291 alpine 145
#define ROCKS_COUNT 8
146
#define MINIROCKS_COUNT ROCKS_COUNT // must equal
5225 alpine 147
#define FONTS_COUNT 4
5291 alpine 148
#define EXPLOSIONS_COUNT    8
149
#define EXPLOSION_RADIUS    16
5225 alpine 150
 
151
#define STATUS_MENU     0
152
#define STATUS_PLAYING  1
153
#define STATUS_PAUSED   2
154
 
155
 
156
#define RS_ARROW_LEFT_MASK	0x01
157
#define RS_ARROW_DOWN_MASK	0x02
158
#define RS_ARROW_UP_MASK	0x04
159
#define RS_ARROW_RIGHT_MASK	0x08
160
#define RS_ATTACK_KEY_MASK  0x10
161
 
5291 alpine 162
//#define BULLETS_COUNT   8
5225 alpine 163
 
164
#define GAME_SHOOT_PERIOD   3
165
 
5291 alpine 166
#define GAME_FLAG_BOSS_DESTROYED    0x01
167
 
5298 alpine 168
#define SOUND_EXPLOSIONS_COUNT      8
169
 
5225 alpine 170
typedef struct rs_game_t {
171
    rs_texture_t framebuffer;
172
    unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
173
 
174
    rs_texture_t tex;
175
 
176
    rs_texture_t tex_clouds;
177
    rs_texture_t tex_ground;
178
 
179
    rs_texture_t tex_ship[4];
180
    rs_texture_t tex_rocks[ROCKS_COUNT];
5291 alpine 181
    rs_texture_t tex_minirocks[MINIROCKS_COUNT];
5225 alpine 182
 
5291 alpine 183
    rs_texture_t tex_explosions[EXPLOSIONS_COUNT];
184
 
5225 alpine 185
    rs_texture_t tex_font[64*FONTS_COUNT];
186
 
187
    rs_texture_t tex_gui_line;
188
 
5298 alpine 189
    int bg_color;
5225 alpine 190
 
191
    rs_soundbuf_t sound_test1;
192
    rs_soundbuf_t sound_test2;
193
    rs_soundbuf_t sound_test3;
194
 
5298 alpine 195
    rs_soundbuf_t sound_explosions[SOUND_EXPLOSIONS_COUNT];
196
    rs_soundbuf_t sound_hit;
197
 
5302 alpine 198
    rs_soundbuf_t sound_music;
199
    rs_soundbuf_t sound_music2;
200
 
5225 alpine 201
    int status;
5291 alpine 202
    int flags;
5225 alpine 203
 
204
    unsigned int keyboard_state;
205
 
206
    int menu_index;
207
    int menu_item_index;
208
 
209
    int window_scale;
210
 
5291 alpine 211
//    int tx1;
212
//    int ty1;
5225 alpine 213
    int tz;
214
 
5291 alpine 215
    int player_x;
216
    int player_y;
217
//    int player_z;
218
 
219
//    int bullet_x[BULLETS_COUNT];
220
//    int bullet_y[BULLETS_COUNT];
221
//    int bullet_index;
5225 alpine 222
    int shoot_delay;
223
    int shoot_keypressed;
5291 alpine 224
    int shoot_restore_delay;
5225 alpine 225
 
5291 alpine 226
    int health;
227
    int ammo;
228
    int score;
229
 
230
//    int ammo_max;
231
 
232
    int stage;
233
    int stage_timer;
234
 
235
    game_obj_t *objs;
236
    int objs_count;
237
 
5225 alpine 238
} rs_game_t;
239
 
5291 alpine 240
#define GAME_HEALTH_MAX     8
241
#define GAME_AMMO_MAX       24
242
 
5225 alpine 243
extern rs_game_t game;
244
void game_reg_init();
245
 
5298 alpine 246
 
247
 
248
 
249
 
250
 
251
 
252
 
253
 
5225 alpine 254
/*  __
255
   /cc\
256
  /aaaa\
257
 |kkkkkk|  <-- Easter Egg
258
  \eeee/
259
------------------------------- */
260
 
261
 
5298 alpine 262
 
263
 
264
 
265
 
266
 
267
 
268
 
5225 alpine 269
void game_ding(int i);
270
 
271
void GameInit();
272
void GameTerm();
273
 
5298 alpine 274
void GameKeyDown(int key);
5225 alpine 275
void GameKeyUp(int key);
276
 
5243 alpine 277
void GameMouseDown(int x, int y);
278
void GameMouseUp(int x, int y);
279
 
5225 alpine 280
void game_change_window_scale(int d);
281
 
5291 alpine 282
int is_key_pressed(int mask);
283
unsigned short rs_rand();
284
 
5225 alpine 285
#endif // RSGAME_H_INCLUDED