?login_element?

Subversion Repositories NedoOS

Rev

Rev 962 | Blame | Compare with Previous | Last modification | View Log | Download

  1. #ifndef GAMELOOPC
  2. #define GAMELOOPC
  3. //#include "sprite_pool.c"
  4. //#include "engine.c"
  5. //#include <evo.h>
  6. //#include "dialogs.c"
  7. #include "bytecode.h"
  8. #include "level1.c"
  9. #include "level3.c"
  10. #include "level4.c"
  11. #include "interpreter.c"
  12.  
  13. #define LEFT KEY_5
  14. #define RIGHT KEY_8
  15. #define DOWN KEY_6
  16. #define UP KEY_7
  17. #define FIRE KEY_SPACE
  18.  
  19. static u8 i, j;
  20. static void init_level(u8 pal, char *fn);
  21.  
  22. void game_loop();
  23.  
  24. static void start_level(u8 pal, char *fn, u8 *name)
  25. {
  26.     u8 c;
  27.     music_stop();
  28.     player.y = STARTY/*321*/;
  29.     flush_sprites();
  30.     init_text();
  31.     swap_screen();
  32.     text_y = 24/*29*/;
  33.     text_x = 20;
  34.     put_str("Girls are praying...");
  35.  
  36.     text_y = 10;
  37.     text_x = 3;
  38.     put_str("Lives: ");
  39.     put_num(hp);
  40.     text_y = 11;
  41.     text_x = 3;
  42.     put_str("Score: ");
  43.     put_num(score);
  44.  
  45.     text_y = 2;
  46.     text_x = 20 - strlen(name) / 2;
  47.     put_slow_str(name);
  48.  
  49.     text_x = 10;
  50.     text_y = 5;
  51.     draw_face(REIMU_FACE);
  52.     text_y--;
  53.     text_x += 5;
  54. //swap_screen();
  55.  
  56.     for (c = 0; c < 50; c++)
  57.         swap_screen();
  58. //swap_screen();
  59.     draw_face(MARISA_FACE);
  60. //swap_screen();
  61.     text_y--;
  62.     text_x += 5;
  63.     for (c = 0; c < 50; c++)
  64.         swap_screen();
  65. //swap_screen();
  66.     draw_face(CIRNO_FACE);
  67. //swap_screen();
  68.     for (c = 0; c < 100; c++)
  69.         swap_screen();
  70.     //init_level(image);
  71. init_level(pal, fn);
  72. }
  73.  
  74. static void init_level(u8 pal, char *fn)
  75. {
  76.     pal_bright(BRIGHT_MIN);
  77. if (pal) preparescroll(fn);
  78. /*    if (image == IMG256_BG8)
  79.         unpack_pal256(PAL256_BG8, 0);
  80.     else
  81.         unpack_pal256(PAL256_BG1, 0);*/
  82. unpack_pal256(pal, 0);
  83.  
  84.     //unpack_pal16(PAL16_SPRITES, 15, 0);
  85.     //draw_image_g256(0, 0, image);
  86. scroll(0, 0);
  87. //drawscroll();
  88.     pal_bright(BRIGHT_MID);
  89.     player.x = 120;
  90.     player.y = 168;
  91.     flush_sprites();
  92.     swap_screen();
  93.     scroll_pos = 0;
  94.     hor_scroll_pos = 0;
  95.     hor_scroll_speed = 0;
  96.     level_loop = 0;
  97.     schedule = 0;
  98.     add_cnt = 0;
  99. //sprites_start();
  100. }
  101.  
  102.  
  103.  
  104. void start_game_loop()
  105. {
  106.     int i;
  107.     hp = 3;
  108.     score = 0;
  109.  
  110.     process_level = process_level1;
  111.     //process_level = process_flandre;
  112.     //process_level = process_level2;
  113.     scroll_pos = 0;
  114.     bullet_sprite = DEFAULT_BULLET;
  115.     //start_level(IMG256_BG1, "Day before festival");
  116. start_level(PAL256_BG1, "bg1-16.bmp", "Day before festival");
  117. //start_level(PAL256_BG8, "bg8-16.bmp", "Day before festival");
  118.     init_vm(level1_bytecode);
  119.     //init_vm(level2_bc);
  120. //init_vm(level4_2);
  121.     music_play(MUS_TH0EA1);
  122.     sprites_start();
  123.     immortality = 20;
  124.     game_loop();
  125. }
  126.  
  127. static void player_control()
  128. {
  129.     if (keys[LEFT])
  130.         player.x -= 4;
  131.     if (keys[RIGHT])
  132.         player.x += 4;
  133.     if (keys[UP])
  134.         player.y -= 4;
  135.     if (keys[DOWN])
  136.         player.y += 4;
  137.     if (keys[FIRE])
  138.         user_fire();
  139. #ifdef CHEAT
  140.     if (keys[KEY_C]&&keys[KEY_CAPS])
  141.         cheat_on = 1;
  142. #endif
  143.  
  144.     if (player.x < MIN_X_RES/*0*/)
  145.         player.x = MIN_X_RES/*0*/;
  146.     if (player.x > MAX_X_RES/*300*/)
  147.         player.x = MAX_X_RES/*300*/;
  148.     if (player.y < MIN_Y_RES/*0*/)
  149.         player.y = MIN_Y_RES/*0*/;
  150.     if (player.y > MAX_Y_RES - 32)
  151.         player.y = MAX_Y_RES - 32;
  152. }
  153.  
  154. static void bg_scroll()
  155. {
  156.     scroll_pos -= scroll_speed;
  157.     scroll_pos &= 511;
  158.     hor_scroll_pos += hor_scroll_speed;
  159.     hor_scroll_pos &= 511;
  160.  
  161.     scroll(hor_scroll_pos, scroll_pos);
  162. }
  163.  
  164. static void process_events()
  165. {
  166.     if ((schedule & 7) == 0)
  167.     {
  168.         level_loop++;
  169.         process_level();
  170.         if (immortality)
  171.         {
  172.             immortality--;
  173.         }
  174.     }
  175. }
  176.  
  177. static void player_collisions()
  178. {
  179.     static MovableSprite *b;
  180.     if (!immortality && is_player_collide())
  181.     {
  182.         immortality = 20;
  183.         player.x = 160;
  184.         player.y = 168;
  185.         cards = 3;
  186.         hp--;
  187.         sfx_play(1, 0);
  188.         for (push_counter = 0; push_counter < BULLETS_count; push_counter++)
  189.             bullets[push_counter].dy = 10;
  190.     }
  191.     b = is_player_collide_with_pups();
  192.     if (b)
  193.     {
  194.         switch (b->tile)
  195.         {
  196.         case BONUS_CARD:
  197.             if (cards < MY_BULLETS_max)
  198.                 cards++;
  199.             break;
  200.         case HEALTH_CARD:
  201.             hp++;
  202.             break;
  203.         default:
  204.             break;
  205.         }
  206.     }
  207. }
  208.  
  209. void game_loop()
  210. {
  211.     scroll_speed = 1;
  212.     immortality = 10;
  213.     while (state == STATE_PLAY)
  214.     {
  215.         schedule++;
  216.  
  217.         if ((schedule & 3) == 0)
  218.             anim_frame++;
  219.         anim_frame &= 3;
  220.  
  221.         player.tile = (immortality & 1) ? 1072/*2560*/ : 0;
  222.         if (schedule & 1)
  223.         {
  224.             keyboard(keys);
  225.             player_control();
  226.             player_collisions();
  227.         }
  228.         else
  229.         {
  230.             enemy_collision();
  231.             process_events();
  232.         }
  233.         if (hp < 1)
  234.         {
  235.             state = STATE_GAMEOVER;
  236.         }
  237. //begin_set_sprites();
  238.         update_sprites(schedule & 1);
  239.         //update_sprites(0);
  240.         //update_sprites(1);
  241.         if ((schedule & 3) == 0)
  242.             bg_scroll();
  243.         //swap_screen();
  244.    
  245. if (schedule & 1) {
  246. end_set_sprites();
  247. drawscroll();
  248. swap_screen_scroll();
  249. }
  250.     }
  251. }
  252.  
  253. #endif