Subversion Repositories Kolibri OS

Rev

Rev 5316 | 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
5316 alpine 113
#define     OBJ_HUGE_EXPLOSION  7
5291 alpine 114
 
115
typedef struct game_obj_t {
116
    int obj_type;
117
    int flags;
118
    int tag;
119
    int radius;
120
 
121
    float x;
122
    float y;
123
    int t;
124
    float f;
5322 alpine 125
 
5291 alpine 126
} game_obj_t;
127
 
128
#define OBJ_FLAG_DESTROYED      0x01
129
#define OBJ_FLAG_ENEMY          0x02
130
#define OBJ_FLAG_SIN            0x04
131
#define OBJ_FLAG_BOSS           0x08 // draw health-bar above
132
 
133
game_obj_t game_obj(int obj_type, int flags, int tag, int radius, float x, float y, int t, float f);
134
 
135
int game_obj_add(game_obj_t obj);
136
void game_obj_remove(int index);
137
 
138
 
139
 
5225 alpine 140
// Game Registry
141
 
5291 alpine 142
#define ROCKS_COUNT 8
143
#define MINIROCKS_COUNT ROCKS_COUNT // must equal
5225 alpine 144
#define FONTS_COUNT 4
5291 alpine 145
#define EXPLOSIONS_COUNT    8
146
#define EXPLOSION_RADIUS    16
5225 alpine 147
 
5316 alpine 148
#define HUGE_EXPLOSIONS_COUNT    24
149
#define HUGE_EXPLOSION_RADIUS    32
150
 
151
 
5225 alpine 152
#define STATUS_MENU     0
153
#define STATUS_PLAYING  1
154
#define STATUS_PAUSED   2
155
 
156
 
157
#define RS_ARROW_LEFT_MASK	0x01
158
#define RS_ARROW_DOWN_MASK	0x02
159
#define RS_ARROW_UP_MASK	0x04
160
#define RS_ARROW_RIGHT_MASK	0x08
161
#define RS_ATTACK_KEY_MASK  0x10
162
 
163
 
164
#define GAME_SHOOT_PERIOD   3
165
 
5291 alpine 166
#define GAME_FLAG_BOSS_DESTROYED    0x01
5315 alpine 167
#define GAME_FLAG_INSTRUCTIONS_PASSED   0x02
5291 alpine 168
 
5298 alpine 169
#define SOUND_EXPLOSIONS_COUNT      8
170
 
5225 alpine 171
typedef struct rs_game_t {
172
    rs_texture_t framebuffer;
173
    unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
174
 
175
    rs_texture_t tex;
176
 
177
    rs_texture_t tex_clouds;
178
    rs_texture_t tex_ground;
179
 
180
    rs_texture_t tex_ship[4];
181
    rs_texture_t tex_rocks[ROCKS_COUNT];
5291 alpine 182
    rs_texture_t tex_minirocks[MINIROCKS_COUNT];
5225 alpine 183
 
5291 alpine 184
    rs_texture_t tex_explosions[EXPLOSIONS_COUNT];
5316 alpine 185
    rs_texture_t tex_huge_explosions[HUGE_EXPLOSIONS_COUNT];
5291 alpine 186
 
5225 alpine 187
    rs_texture_t tex_font[64*FONTS_COUNT];
188
 
189
    rs_texture_t tex_gui_line;
190
 
5298 alpine 191
    int bg_color;
5225 alpine 192
 
5315 alpine 193
    rs_soundbuf_t sound_shoot;
194
    rs_soundbuf_t sound_turret_shoot;
195
 
5225 alpine 196
    rs_soundbuf_t sound_test2;
197
    rs_soundbuf_t sound_test3;
198
 
5298 alpine 199
    rs_soundbuf_t sound_explosions[SOUND_EXPLOSIONS_COUNT];
200
    rs_soundbuf_t sound_hit;
5316 alpine 201
    rs_soundbuf_t sound_huge_explosion;
5298 alpine 202
 
5302 alpine 203
    rs_soundbuf_t sound_music;
5315 alpine 204
//    rs_soundbuf_t sound_music2;
5302 alpine 205
 
5225 alpine 206
    int status;
5291 alpine 207
    int flags;
5225 alpine 208
 
209
    unsigned int keyboard_state;
210
 
211
    int menu_index;
212
    int menu_item_index;
213
 
214
    int window_scale;
215
 
216
    int tz;
217
 
5291 alpine 218
    int player_x;
219
    int player_y;
5322 alpine 220
 
5225 alpine 221
    int shoot_delay;
222
    int shoot_keypressed;
5291 alpine 223
    int shoot_restore_delay;
5225 alpine 224
 
5291 alpine 225
    int health;
226
    int ammo;
227
    int score;
228
 
229
//    int ammo_max;
230
 
5315 alpine 231
    int stage; // (wave)
5291 alpine 232
    int stage_timer;
233
 
5315 alpine 234
    int stage_level; // (stage)
235
 
5291 alpine 236
    game_obj_t *objs;
237
    int objs_count;
238
 
5225 alpine 239
} rs_game_t;
240
 
5291 alpine 241
#define GAME_HEALTH_MAX     8
242
#define GAME_AMMO_MAX       24
243
 
5225 alpine 244
extern rs_game_t game;
245
void game_reg_init();
246
 
5298 alpine 247
 
248
 
249
 
250
 
251
 
252
 
253
 
254
 
5225 alpine 255
/*  __
256
   /cc\
257
  /aaaa\
258
 |kkkkkk|  <-- Easter Egg
259
  \eeee/
260
------------------------------- */
261
 
262
 
5298 alpine 263
 
264
 
265
 
266
 
267
 
268
 
269
 
5225 alpine 270
void game_ding(int i);
271
 
272
void GameInit();
273
void GameTerm();
274
 
5298 alpine 275
void GameKeyDown(int key);
5225 alpine 276
void GameKeyUp(int key);
277
 
5243 alpine 278
void GameMouseDown(int x, int y);
279
void GameMouseUp(int x, int y);
280
 
5225 alpine 281
void game_change_window_scale(int d);
282
 
5291 alpine 283
int is_key_pressed(int mask);
284
unsigned short rs_rand();
285
 
5225 alpine 286
#endif // RSGAME_H_INCLUDED