Subversion Repositories Kolibri OS

Rev

Rev 5225 | Rev 5291 | 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"
22
//#include "rs/rstexture.h"
23
//#include "rs/rsshader.h"
24
//#include "rs/rsgl.h"
25
#include "rs/rsdebug.h"
26
#include "rs/rsbits.h"
27
 
28
//#include "rs/rskeyboard.h"
29
 
30
//#include "rs/rsaudio.h"
31
 
32
//#include "rs/rsfile.h"
33
 
34
//#include "rs/rsvbo.h"
35
//#include "rs/rsfbo.h"
36
 
37
//#include "rs/rsthread.h"
38
 
39
#include "rs/rsmx.h"
40
 
41
 
42
 
43
 
44
#define GAME_LANG_EN    0
45
#define GAME_LANG_RU    1
46
 
47
#define GAME_WIDTH  320
48
#define GAME_HEIGHT 180
49
 
50
 
51
typedef struct {
52
    unsigned int status;
53
    int w;
54
    int h;
55
    unsigned char *data; // BGRA BGRA
56
} rs_texture_t;
57
 
58
 
59
// for little-endian
60
typedef union color_t {
61
    int d;                 // 0x44332211 (ARGB)
62
    struct {
63
        unsigned char b; // 0x11
64
        unsigned char g; // 0x22
65
        unsigned char r; // 0x33
66
        unsigned char a; // 0x44
67
    };
68
} color_t;
69
 
70
// for little-endian (ARGB)
71
#define COLOR_BLACK     0xFF000000
72
#define COLOR_TRANSPARENT   0x00000000
73
#define COLOR_DARK_RED  0xFF660000
74
 
75
 
76
 
77
void texture_init(rs_texture_t *tex, int w, int h);
78
void texture_free(rs_texture_t *tex);
79
void texture_clear(rs_texture_t *tex, unsigned int color);
80
void texture_draw(rs_texture_t *dest, rs_texture_t *src, int x, int y, int mode);
81
void texture_draw_vline(rs_texture_t *tex, int x, int y, int l, unsigned int color);
82
void texture_draw_hline(rs_texture_t *tex, int x, int y, int l, unsigned int color);
83
void texture_set_pixel(rs_texture_t *tex, int x, int y, unsigned int color);
84
 
85
unsigned char clamp_byte(int value);
86
 
87
#define DRAW_MODE_REPLACE   0
88
#define DRAW_MODE_ADDITIVE  1
89
#define DRAW_MODE_ALPHA     2
90
 
91
#define DRAW_MODE_MASK      0x0000FFFF
92
#define DRAW_TILED_FLAG     0x00010000
93
 
94
 
95
 
96
typedef struct {
97
    unsigned int status;
98
    int length_samples;
99
    SNDBUF hbuf;
100
    signed short *data;
101
} rs_soundbuf_t;
102
 
103
void soundbuf_init(rs_soundbuf_t *snd, int length);
104
void soundbuf_free(rs_soundbuf_t *snd);
105
void soundbuf_fill(rs_soundbuf_t *snd, int amp, int freq_div);
106
void soundbuf_sin(rs_soundbuf_t *snd, float freq);
107
void soundbuf_sin_fade(rs_soundbuf_t *snd, float freq);
108
void soundbuf_play(rs_soundbuf_t *snd);
109
void soundbuf_stop(rs_soundbuf_t *snd);
110
 
111
// Game Registry
112
 
113
#define ROCKS_COUNT 3
114
#define FONTS_COUNT 4
115
 
116
#define STATUS_MENU     0
117
#define STATUS_PLAYING  1
118
#define STATUS_PAUSED   2
119
 
120
 
121
#define RS_ARROW_LEFT_MASK	0x01
122
#define RS_ARROW_DOWN_MASK	0x02
123
#define RS_ARROW_UP_MASK	0x04
124
#define RS_ARROW_RIGHT_MASK	0x08
125
#define RS_ATTACK_KEY_MASK  0x10
126
 
127
#define BULLETS_COUNT   8
128
 
129
#define GAME_SHOOT_PERIOD   3
130
 
131
typedef struct rs_game_t {
132
    rs_texture_t framebuffer;
133
    unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
134
 
135
    rs_texture_t tex;
136
 
137
    rs_texture_t tex_clouds;
138
    rs_texture_t tex_ground;
139
 
140
    rs_texture_t tex_ship[4];
141
    rs_texture_t tex_rocks[ROCKS_COUNT];
142
 
143
    rs_texture_t tex_font[64*FONTS_COUNT];
144
 
145
    rs_texture_t tex_gui_line;
146
 
147
 
148
    rs_soundbuf_t sound_test1;
149
    rs_soundbuf_t sound_test2;
150
    rs_soundbuf_t sound_test3;
151
 
152
    int status;
153
 
154
    unsigned int keyboard_state;
155
 
156
    int menu_index;
157
    int menu_item_index;
158
 
159
    int window_scale;
160
 
161
    int tx;
162
    int ty;
163
    int tz;
164
 
165
    int bullet_x[BULLETS_COUNT];
166
    int bullet_y[BULLETS_COUNT];
167
    int bullet_index;
168
    int shoot_delay;
169
    int shoot_keypressed;
170
 
171
} rs_game_t;
172
 
173
extern rs_game_t game;
174
void game_reg_init();
175
 
176
/*  __
177
   /cc\
178
  /aaaa\
179
 |kkkkkk|  <-- Easter Egg
180
  \eeee/
181
------------------------------- */
182
 
183
void GameProcess();
184
 
185
void game_ding(int i);
186
 
187
void GameInit();
188
void GameTerm();
189
 
190
void GameKeyDown(int key, int first);
191
void GameKeyUp(int key);
192
 
5243 alpine 193
void GameMouseDown(int x, int y);
194
void GameMouseUp(int x, int y);
195
 
5225 alpine 196
void game_change_window_scale(int d);
197
 
198
#endif // RSGAME_H_INCLUDED