Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5235 alpine 1
#ifndef RSGAME_H_INCLUDED
2
#define RSGAME_H_INCLUDED
3
 
4
/*
5
 
6
    Heliothryx
7
    Game by Roman Shuvalov
8
 
9
*/
10
 
11
#ifndef RS_LINUX
12
    #ifndef RS_WIN32
13
        #ifndef RS_KOS
14
            #error Please specify platform
15
        #endif
16
    #endif
17
#endif
18
 
19
 
20
#include "rskos.h"
21
#include "rs/rsplatform.h"
22
 
23
#include "rs/rsdebug.h"
24
#include "rs/rsbits.h"
25
 
26
 
27
#include "rs/rsmx.h"
28
 
29
 
30
 
31
 
32
#define GAME_WIDTH  512
33
#define GAME_HEIGHT 512
34
 
35
 
36
typedef struct {
37
    unsigned int status;
38
    int w;
39
    int h;
40
    unsigned char *data; // BGRA BGRA
41
} rs_texture_t;
42
 
43
 
44
// for little-endian
45
typedef union color_t {
46
    int d;                 // 0x44332211 (ARGB)
47
    struct {
48
        unsigned char b; // 0x11
49
        unsigned char g; // 0x22
50
        unsigned char r; // 0x33
51
        unsigned char a; // 0x44
52
    };
53
} color_t;
54
 
55
// for little-endian (ARGB)
56
#define COLOR_BLACK     0xFF000000
57
#define COLOR_TRANSPARENT   0x00000000
58
#define COLOR_DARK_RED  0xFF660000
59
#define COLOR_DARK_GRAY 0xFF333344
60
#define COLOR_SILVER    0xFFCCCCDD
61
#define COLOR_SEMI_TRANSPARENT      0x80808080
62
 
63
void texture_init(rs_texture_t *tex, int w, int h);
64
void texture_free(rs_texture_t *tex);
65
void texture_clear(rs_texture_t *tex, unsigned int color);
66
void texture_draw(rs_texture_t *dest, rs_texture_t *src, int x, int y, int mode);
67
void texture_draw_vline(rs_texture_t *tex, int x, int y, int l, unsigned int color);
68
void texture_draw_hline(rs_texture_t *tex, int x, int y, int l, unsigned int color);
69
void texture_set_pixel(rs_texture_t *tex, int x, int y, unsigned int color);
70
 
71
unsigned char clamp_byte(int value);
72
 
73
#define DRAW_MODE_REPLACE   0
74
#define DRAW_MODE_ADDITIVE  1
75
#define DRAW_MODE_ALPHA     2
76
#define DRAW_MODE_MULT      3
77
 
78
#define DRAW_MODE_MASK      0x0000FFFF
79
#define DRAW_TILED_FLAG     0x00010000
80
 
81
 
82
 
83
typedef struct {
84
    unsigned int status;
85
    int length_samples;
86
    SNDBUF hbuf;
87
    signed short *data;
88
} rs_soundbuf_t;
89
 
90
void soundbuf_init(rs_soundbuf_t *snd, int length);
91
void soundbuf_free(rs_soundbuf_t *snd);
92
void soundbuf_fill(rs_soundbuf_t *snd, int amp, int freq_div);
93
void soundbuf_sin(rs_soundbuf_t *snd, float freq);
94
void soundbuf_sin_fade(rs_soundbuf_t *snd, float freq);
95
void soundbuf_play(rs_soundbuf_t *snd);
96
void soundbuf_stop(rs_soundbuf_t *snd);
97
 
98
// Game Registry
99
 
100
#define FONTS_COUNT 4
101
#define CRYSTALS_COUNT  7
102
 
103
#define STATUS_LOADING  0
104
#define STATUS_MENU     1
105
#define STATUS_PLAYING  2
106
#define STATUS_PAUSED   3
107
 
108
 
109
#define RS_ARROW_LEFT_MASK	0x01
110
#define RS_ARROW_DOWN_MASK	0x02
111
#define RS_ARROW_UP_MASK	0x04
112
#define RS_ARROW_RIGHT_MASK	0x08
113
#define RS_ATTACK_KEY_MASK  0x10
114
 
115
#define BULLETS_COUNT   8
116
 
117
#define GAME_SHOOT_PERIOD   3
118
 
5237 alpine 119
#define FIELD_WIDTH     10
120
#define FIELD_HEIGHT    8
5235 alpine 121
#define FIELD_LENGTH    (FIELD_WIDTH * FIELD_HEIGHT)
5237 alpine 122
#define CRYSTAL_SIZE    40
123
#define FIELD_X0     56
5235 alpine 124
#define FIELD_Y0     128
125
#define FIELD_ITEM(x,y)     (game.field[(y)*FIELD_WIDTH+(x)])
126
 
127
#define CRYSTAL_INDEX_MASK      0x0F
128
#define CRYSTAL_VISIBLE_BIT     0x10
129
#define CRYSTAL_EXPLODED_BIT    0x20
130
#define CRYSTAL_MOVING_BIT      0x40
131
 
5237 alpine 132
#define EXPLOSION_FRAMES_COUNT      10
5235 alpine 133
#define EXPLOSION_SIZE      64
134
 
135
#define EXPLOSIONS_MAX_COUNT        16
136
//#define EXPLOSION_PACK(x,y,frame)   ( (x) | ( (y)<<8 ) |  (frame)<<16 )
137
 
5239 alpine 138
#define ANIMATION_PROCESS_TIMER_LIMIT   3
139
 
5235 alpine 140
typedef struct rs_game_t {
141
    rs_texture_t framebuffer;
5243 alpine 142
    unsigned char *bgr_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
5235 alpine 143
 
144
    int loader_counter;
145
 
146
    rs_texture_t tex_bg;
5237 alpine 147
    rs_texture_t tex_bg_gameplay;
148
    rs_texture_t tex_field;
5235 alpine 149
 
150
    rs_texture_t tex_logo;
151
    rs_texture_t tex_clouds;
152
 
153
    rs_texture_t tex_crystals[CRYSTALS_COUNT];
154
    rs_texture_t tex_cursor;
155
    rs_texture_t tex_explosion[EXPLOSION_FRAMES_COUNT];
156
 
157
    rs_texture_t tex_font[64*FONTS_COUNT];
158
 
159
    rs_soundbuf_t sound_test1;
160
    rs_soundbuf_t sound_test2;
161
    rs_soundbuf_t sound_test3;
162
 
163
    int status;
164
 
165
    unsigned int keyboard_state;
166
 
167
    int menu_index;
168
    int menu_item_index;
169
 
5243 alpine 170
//    int window_scale;
5235 alpine 171
 
5239 alpine 172
    int process_timer;
173
 
5235 alpine 174
    int tx;
175
    int ty;
176
    int tz;
177
 
178
    unsigned char *field;
179
 
180
    int selected;
181
    unsigned char selected_x;
182
    unsigned char selected_y;
183
 
184
    unsigned int explosions_count;
185
    unsigned int explosions[EXPLOSIONS_MAX_COUNT]; //0x00TTYYXX, TT = frame, YY = fieldY, XX = fieldX
186
 
5237 alpine 187
    int need_redraw;
188
 
5235 alpine 189
    int score;
190
    int time;
191
 
192
 
193
} rs_game_t;
194
 
195
extern rs_game_t game;
196
void game_reg_init();
197
 
198
/*  __
199
   /cc\
200
  /aaaa\
201
 |kkkkkk|  <-- Easter Egg
202
  \eeee/
203
------------------------------- */
204
 
205
void GameProcess();
206
 
207
void game_ding(int i);
208
 
209
void GameInit();
210
void GameTerm();
211
 
212
void GameKeyDown(int key, int first);
213
void GameKeyUp(int key);
214
 
215
void GameMouseDown(int x, int y);
216
void GameMouseUp(int x, int y);
217
 
218
 
219
#endif // RSGAME_H_INCLUDED