Subversion Repositories Kolibri OS

Rev

Rev 5239 | Rev 5251 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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