Subversion Repositories Kolibri OS

Rev

Rev 5237 | 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.  
  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.  
  119. #define FIELD_WIDTH     12
  120. #define FIELD_HEIGHT    9
  121. #define FIELD_LENGTH    (FIELD_WIDTH * FIELD_HEIGHT)
  122. #define CRYSTAL_SIZE    32
  123. #define FIELD_X0     64
  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.  
  132. #define EXPLOSION_FRAMES_COUNT      19
  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.  
  138. typedef struct rs_game_t {
  139.     rs_texture_t framebuffer;
  140.     unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
  141.    
  142.     int loader_counter;
  143.    
  144.     rs_texture_t tex_bg;
  145.    
  146.     rs_texture_t tex_logo;
  147.     rs_texture_t tex_clouds;
  148.    
  149.     rs_texture_t tex_crystals[CRYSTALS_COUNT];
  150.     rs_texture_t tex_cursor;
  151.     rs_texture_t tex_explosion[EXPLOSION_FRAMES_COUNT];
  152.    
  153.     rs_texture_t tex_font[64*FONTS_COUNT];
  154.    
  155.     rs_soundbuf_t sound_test1;
  156.     rs_soundbuf_t sound_test2;
  157.     rs_soundbuf_t sound_test3;
  158.    
  159.     int status;
  160.    
  161.     unsigned int keyboard_state;
  162.    
  163.     int menu_index;
  164.     int menu_item_index;
  165.    
  166.     int window_scale;
  167.    
  168.     int tx;
  169.     int ty;
  170.     int tz;
  171.    
  172.     unsigned char *field;
  173.    
  174.     int selected;
  175.     unsigned char selected_x;
  176.     unsigned char selected_y;
  177.    
  178.     unsigned int explosions_count;
  179.     unsigned int explosions[EXPLOSIONS_MAX_COUNT]; //0x00TTYYXX, TT = frame, YY = fieldY, XX = fieldX
  180.    
  181.     int score;
  182.     int time;
  183.    
  184.    
  185. } rs_game_t;
  186.  
  187. extern rs_game_t game;
  188. void game_reg_init();
  189.  
  190. /*  __
  191.    /cc\
  192.   /aaaa\
  193.  |kkkkkk|  <-- Easter Egg
  194.   \eeee/
  195. ------------------------------- */
  196.  
  197. void GameProcess();
  198.  
  199. void game_ding(int i);
  200.  
  201. void GameInit();
  202. void GameTerm();
  203.  
  204. void GameKeyDown(int key, int first);
  205. void GameKeyUp(int key);
  206.  
  207. void GameMouseDown(int x, int y);
  208. void GameMouseUp(int x, int y);
  209.  
  210.  
  211. #endif // RSGAME_H_INCLUDED
  212.