Subversion Repositories Kolibri OS

Rev

Rev 5302 | Rev 5316 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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. #include "rsgamelogic.h"
  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
  63. #define COLOR_DARK_RED  0xFF401000
  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);
  98. void soundbuf_play(rs_soundbuf_t *snd, int mode);
  99. void soundbuf_loop_check(rs_soundbuf_t *snd);
  100. void soundbuf_stop(rs_soundbuf_t *snd);
  101.  
  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.  
  143. // Game Registry
  144.  
  145. #define ROCKS_COUNT 8
  146. #define MINIROCKS_COUNT ROCKS_COUNT // must equal
  147. #define FONTS_COUNT 4
  148. #define EXPLOSIONS_COUNT    8
  149. #define EXPLOSION_RADIUS    16
  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.  
  162. //#define BULLETS_COUNT   8
  163.  
  164. #define GAME_SHOOT_PERIOD   3
  165.  
  166. #define GAME_FLAG_BOSS_DESTROYED    0x01
  167. #define GAME_FLAG_INSTRUCTIONS_PASSED   0x02
  168.  
  169. #define SOUND_EXPLOSIONS_COUNT      8
  170.  
  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];
  182.     rs_texture_t tex_minirocks[MINIROCKS_COUNT];
  183.    
  184.     rs_texture_t tex_explosions[EXPLOSIONS_COUNT];
  185.    
  186.     rs_texture_t tex_font[64*FONTS_COUNT];
  187.    
  188.     rs_texture_t tex_gui_line;
  189.    
  190.     int bg_color;
  191.    
  192.     rs_soundbuf_t sound_shoot;
  193.     rs_soundbuf_t sound_turret_shoot;
  194.    
  195.     rs_soundbuf_t sound_test2;
  196.     rs_soundbuf_t sound_test3;
  197.    
  198.     rs_soundbuf_t sound_explosions[SOUND_EXPLOSIONS_COUNT];
  199.     rs_soundbuf_t sound_hit;
  200.    
  201.     rs_soundbuf_t sound_music;
  202. //    rs_soundbuf_t sound_music2;
  203.    
  204.     int status;
  205.     int flags;
  206.    
  207.     unsigned int keyboard_state;
  208.    
  209.     int menu_index;
  210.     int menu_item_index;
  211.    
  212.     int window_scale;
  213.    
  214. //    int tx1;
  215. //    int ty1;
  216.     int tz;
  217.    
  218.     int player_x;
  219.     int player_y;
  220. //    int player_z;
  221.    
  222. //    int bullet_x[BULLETS_COUNT];
  223. //    int bullet_y[BULLETS_COUNT];
  224. //    int bullet_index;
  225.     int shoot_delay;
  226.     int shoot_keypressed;
  227.     int shoot_restore_delay;
  228.    
  229.     int health;
  230.     int ammo;
  231.     int score;
  232.    
  233. //    int ammo_max;
  234.    
  235.     int stage; // (wave)
  236.     int stage_timer;
  237.    
  238.     int stage_level; // (stage)
  239.    
  240.     game_obj_t *objs;
  241.     int objs_count;
  242.    
  243. } rs_game_t;
  244.  
  245. #define GAME_HEALTH_MAX     8
  246. #define GAME_AMMO_MAX       24
  247.  
  248. extern rs_game_t game;
  249. void game_reg_init();
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259. /*  __
  260.    /cc\
  261.   /aaaa\
  262.  |kkkkkk|  <-- Easter Egg
  263.   \eeee/
  264. ------------------------------- */
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. void game_ding(int i);
  275.  
  276. void GameInit();
  277. void GameTerm();
  278.  
  279. void GameKeyDown(int key);
  280. void GameKeyUp(int key);
  281.  
  282. void GameMouseDown(int x, int y);
  283. void GameMouseUp(int x, int y);
  284.  
  285. void game_change_window_scale(int d);
  286.  
  287. int is_key_pressed(int mask);
  288. unsigned short rs_rand();
  289.  
  290. #endif // RSGAME_H_INCLUDED
  291.