Subversion Repositories Kolibri OS

Rev

Rev 5315 | 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. #define     OBJ_HUGE_EXPLOSION  7
  114.  
  115. typedef struct game_obj_t {
  116.     int obj_type;
  117.     int flags;
  118.     int tag;
  119.     int radius;
  120.    
  121.     float x;
  122.     float y;
  123.     int t;
  124.     float f;
  125.    
  126. //    int health;
  127. //    int reserved0;
  128. //    int reserved1;
  129. //    int reserved2;
  130. } game_obj_t;
  131.  
  132. #define OBJ_FLAG_DESTROYED      0x01
  133. #define OBJ_FLAG_ENEMY          0x02
  134. #define OBJ_FLAG_SIN            0x04
  135. #define OBJ_FLAG_BOSS           0x08 // draw health-bar above
  136.  
  137. game_obj_t game_obj(int obj_type, int flags, int tag, int radius, float x, float y, int t, float f);
  138.  
  139. int game_obj_add(game_obj_t obj);
  140. void game_obj_remove(int index);
  141.  
  142.  
  143.  
  144. // Game Registry
  145.  
  146. #define ROCKS_COUNT 8
  147. #define MINIROCKS_COUNT ROCKS_COUNT // must equal
  148. #define FONTS_COUNT 4
  149. #define EXPLOSIONS_COUNT    8
  150. #define EXPLOSION_RADIUS    16
  151.  
  152. #define HUGE_EXPLOSIONS_COUNT    24
  153. #define HUGE_EXPLOSION_RADIUS    32
  154.  
  155.  
  156. #define STATUS_MENU     0
  157. #define STATUS_PLAYING  1
  158. #define STATUS_PAUSED   2
  159.  
  160.  
  161. #define RS_ARROW_LEFT_MASK      0x01
  162. #define RS_ARROW_DOWN_MASK      0x02
  163. #define RS_ARROW_UP_MASK        0x04
  164. #define RS_ARROW_RIGHT_MASK     0x08
  165. #define RS_ATTACK_KEY_MASK  0x10
  166.  
  167. //#define BULLETS_COUNT   8
  168.  
  169. #define GAME_SHOOT_PERIOD   3
  170.  
  171. #define GAME_FLAG_BOSS_DESTROYED    0x01
  172. #define GAME_FLAG_INSTRUCTIONS_PASSED   0x02
  173.  
  174. #define SOUND_EXPLOSIONS_COUNT      8
  175.  
  176. typedef struct rs_game_t {
  177.     rs_texture_t framebuffer;
  178.     unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
  179.    
  180.     rs_texture_t tex;
  181.    
  182.     rs_texture_t tex_clouds;
  183.     rs_texture_t tex_ground;
  184.    
  185.     rs_texture_t tex_ship[4];
  186.     rs_texture_t tex_rocks[ROCKS_COUNT];
  187.     rs_texture_t tex_minirocks[MINIROCKS_COUNT];
  188.    
  189.     rs_texture_t tex_explosions[EXPLOSIONS_COUNT];
  190.     rs_texture_t tex_huge_explosions[HUGE_EXPLOSIONS_COUNT];
  191.    
  192.     rs_texture_t tex_font[64*FONTS_COUNT];
  193.    
  194.     rs_texture_t tex_gui_line;
  195.    
  196.     int bg_color;
  197.    
  198.     rs_soundbuf_t sound_shoot;
  199.     rs_soundbuf_t sound_turret_shoot;
  200.    
  201.     rs_soundbuf_t sound_test2;
  202.     rs_soundbuf_t sound_test3;
  203.    
  204.     rs_soundbuf_t sound_explosions[SOUND_EXPLOSIONS_COUNT];
  205.     rs_soundbuf_t sound_hit;
  206.     rs_soundbuf_t sound_huge_explosion;
  207.    
  208.     rs_soundbuf_t sound_music;
  209. //    rs_soundbuf_t sound_music2;
  210.    
  211.     int status;
  212.     int flags;
  213.    
  214.     unsigned int keyboard_state;
  215.    
  216.     int menu_index;
  217.     int menu_item_index;
  218.    
  219.     int window_scale;
  220.    
  221. //    int tx1;
  222. //    int ty1;
  223.     int tz;
  224.    
  225.     int player_x;
  226.     int player_y;
  227. //    int player_z;
  228.    
  229. //    int bullet_x[BULLETS_COUNT];
  230. //    int bullet_y[BULLETS_COUNT];
  231. //    int bullet_index;
  232.     int shoot_delay;
  233.     int shoot_keypressed;
  234.     int shoot_restore_delay;
  235.    
  236.     int health;
  237.     int ammo;
  238.     int score;
  239.    
  240. //    int ammo_max;
  241.    
  242.     int stage; // (wave)
  243.     int stage_timer;
  244.    
  245.     int stage_level; // (stage)
  246.    
  247.     game_obj_t *objs;
  248.     int objs_count;
  249.    
  250. } rs_game_t;
  251.  
  252. #define GAME_HEALTH_MAX     8
  253. #define GAME_AMMO_MAX       24
  254.  
  255. extern rs_game_t game;
  256. void game_reg_init();
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. /*  __
  267.    /cc\
  268.   /aaaa\
  269.  |kkkkkk|  <-- Easter Egg
  270.   \eeee/
  271. ------------------------------- */
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281. void game_ding(int i);
  282.  
  283. void GameInit();
  284. void GameTerm();
  285.  
  286. void GameKeyDown(int key);
  287. void GameKeyUp(int key);
  288.  
  289. void GameMouseDown(int x, int y);
  290. void GameMouseUp(int x, int y);
  291.  
  292. void game_change_window_scale(int d);
  293.  
  294. int is_key_pressed(int mask);
  295. unsigned short rs_rand();
  296.  
  297. #endif // RSGAME_H_INCLUDED
  298.