Subversion Repositories Kolibri OS

Rev

Rev 5260 | 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     11
  120. #define FIELD_HEIGHT    8
  121. #define FIELD_LENGTH    (FIELD_WIDTH * FIELD_HEIGHT)
  122. #define CRYSTAL_SIZE    40
  123. #define FIELD_X0     36
  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      10
  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. #define ANIMATION_PROCESS_TIMER_LIMIT   3
  139.  
  140. #define SOUND_EXPLOSION_COUNT   8
  141.  
  142. //#define GAME_MODE_MATCH3    0
  143. //#define GAME_MODE_RAMPAGE   1
  144.  
  145. #ifdef RS_KOS
  146.     #define HISCORE_FILENAME    "/sys/games/marble-hiscore.dat"
  147. #else
  148.     #define HISCORE_FILENAME    "marble-hiscore.dat"
  149. #endif
  150.  
  151. typedef struct rs_game_t {
  152.     rs_texture_t framebuffer;
  153.     unsigned char *bgr_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
  154.    
  155.     int loader_counter;
  156.    
  157.     rs_texture_t tex_bg;
  158.     rs_texture_t tex_bg_gameplay;
  159.     rs_texture_t tex_field;
  160.    
  161.     rs_texture_t tex_logo;
  162.     rs_texture_t tex_clouds;
  163.    
  164.     rs_texture_t tex_crystals[CRYSTALS_COUNT];
  165.     rs_texture_t tex_cursor;
  166.     rs_texture_t tex_explosion[EXPLOSION_FRAMES_COUNT];
  167.    
  168.     rs_texture_t tex_font[64*FONTS_COUNT];
  169.    
  170.     int sound_index;
  171.     rs_soundbuf_t sound_explosion[SOUND_EXPLOSION_COUNT];
  172.     rs_soundbuf_t sound_tick;
  173. //    rs_soundbuf_t sound_tack;
  174.     rs_soundbuf_t sound_click;
  175.     rs_soundbuf_t sound_bang;
  176.    
  177.     int status;
  178. //    int game_mode;
  179.     int menu_replay_timeout;
  180.    
  181.     unsigned int keyboard_state;
  182.    
  183. //    int menu_index;
  184. //    int menu_item_index;
  185.    
  186.     int process_timer;
  187.    
  188.     int hiscore;
  189.    
  190. //    int tx;
  191. //    int ty;
  192. //    int tz;
  193.    
  194.     unsigned char *field;
  195.    
  196.     int selected;
  197.     unsigned char selected_x;
  198.     unsigned char selected_y;
  199.    
  200.     unsigned int explosions_count;
  201.     unsigned int explosions[EXPLOSIONS_MAX_COUNT]; //0x00TTYYXX, TT = frame, YY = fieldY, XX = fieldX
  202.    
  203.     int need_redraw;
  204.    
  205.     int score;
  206.     int time;
  207.    
  208.    
  209. } rs_game_t;
  210.  
  211. extern rs_game_t game;
  212. void game_reg_init();
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222. /*  __
  223.    /cc\
  224.   /aaaa\
  225.  |kkkkkk|  <-- Easter Egg
  226.   \eeee/
  227. ------------------------------- */
  228.  
  229.  
  230.  
  231.  
  232.  
  233. void GameProcess();
  234.  
  235. void game_ding(int i);
  236.  
  237. void GameInit();
  238. void GameTerm();
  239.  
  240. void GameKeyDown(int key, int first);
  241. void GameKeyUp(int key);
  242.  
  243. void GameMouseDown(int x, int y);
  244. void GameMouseUp(int x, int y);
  245.  
  246.  
  247. #endif // RSGAME_H_INCLUDED
  248.