Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

224 Zeilen
6.7 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id: main.c,v 1.7 2002/12/22 18:44:12 sam Exp $
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <unistd.h>
  26. #include "common.h"
  27. static void start_game (game *);
  28. int main (int argc, char **argv)
  29. {
  30. game *g = malloc(sizeof(game));
  31. //srand(time(NULL));
  32. if( init_graphics() )
  33. {
  34. return 1;
  35. }
  36. /* Initialize our program */
  37. init_game(g);
  38. /* Go ! */
  39. start_game(g);
  40. /* Clean up */
  41. end_graphics();
  42. return 0;
  43. }
  44. static void start_game (game *g)
  45. {
  46. int i;
  47. int quit = 0;
  48. int poz = 0;
  49. int skip = 0;
  50. int purcompteur = 0;
  51. g->sf = malloc(sizeof(starfield));
  52. g->wp = malloc(sizeof(weapons));
  53. g->ex = malloc(sizeof(explosions));
  54. g->bo = malloc(sizeof(bonus));
  55. g->t = create_tunnel( g, g->w, g->h );
  56. g->p = create_player( g );
  57. g->al = malloc(sizeof(aliens));
  58. init_starfield( g, g->sf );
  59. init_weapons( g, g->wp );
  60. init_explosions( g, g->ex );
  61. init_aliens( g, g->al );
  62. /* Temporary stuff */
  63. for( i = 0; i < 5; i++ )
  64. {
  65. add_alien( g, g->al, rand() % g->w, rand() % g->h / 2, ALIEN_POOLP );
  66. }
  67. g->t->w = 25;
  68. while( !quit )
  69. {
  70. char key;
  71. while( ( key = get_key() ) )
  72. {
  73. switch( key )
  74. {
  75. case 'q':
  76. quit = 1;
  77. break;
  78. case 'p':
  79. poz = !poz;
  80. break;
  81. case '\t':
  82. ceo_alert();
  83. poz = 1;
  84. break;
  85. case 's':
  86. skip = 1;
  87. break;
  88. case 'h':
  89. g->p->dir = -3;
  90. break;
  91. case 'j':
  92. if( g->p->y < g->h - 2 ) g->p->y += 1;
  93. break;
  94. case 'k':
  95. if( g->p->y > 1 ) g->p->y -= 1;
  96. break;
  97. case 'l':
  98. g->p->dir = 3;
  99. break;
  100. case 'n':
  101. if( g->p->nuke == 0 )
  102. {
  103. g->p->nuke = 40;
  104. add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE );
  105. }
  106. break;
  107. case '\r':
  108. if( g->p->nuke == 0 )
  109. {
  110. g->p->nuke = 40;
  111. add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM );
  112. }
  113. break;
  114. case 'b':
  115. if( g->p->weapon == 0 )
  116. {
  117. g->p->weapon = 4;
  118. add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB );
  119. }
  120. case ' ':
  121. if( g->p->weapon == 0 )
  122. {
  123. g->p->weapon = 4;
  124. add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, 0, -16, WEAPON_LASER );
  125. add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -16, WEAPON_LASER );
  126. /* Extra shtuph */
  127. add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER );
  128. add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER );
  129. /* More shtuph */
  130. add_weapon( g, g->wp, (g->p->x + 1) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER );
  131. add_weapon( g, g->wp, (g->p->x + 4) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER );
  132. /* Even more shtuph */
  133. add_weapon( g, g->wp, (g->p->x + 2) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER );
  134. add_weapon( g, g->wp, (g->p->x + 3) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER );
  135. /* Extra shtuph */
  136. add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -32, 0, WEAPON_SEEKER );
  137. add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 32, 0, WEAPON_SEEKER );
  138. }
  139. break;
  140. }
  141. }
  142. usleep(40000);
  143. if( !poz || skip )
  144. {
  145. skip = 0;
  146. /* XXX: to be removed */
  147. if( GET_RAND(0,10) == 0 )
  148. {
  149. int list[3] = { ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH };
  150. add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)] );
  151. }
  152. /* Update game rules */
  153. if( g->t->right[1] - g->t->left[1] == g->t->w )
  154. {
  155. g->t->w = 85 - g->t->w;
  156. }
  157. /* Scroll and update positions */
  158. collide_player_tunnel( g, g->p, g->t, g->ex );
  159. update_player( g, g->p );
  160. collide_player_tunnel( g, g->p, g->t, g->ex );
  161. update_starfield( g, g->sf );
  162. update_bonus( g, g->bo );
  163. update_aliens( g, g->al );
  164. collide_weapons_tunnel( g, g->wp, g->t, g->ex );
  165. collide_weapons_aliens( g, g->wp, g->al, g->ex );
  166. update_weapons( g, g->wp );
  167. collide_weapons_tunnel( g, g->wp, g->t, g->ex );
  168. collide_weapons_aliens( g, g->wp, g->al, g->ex );
  169. update_explosions( g, g->ex );
  170. /*if(purcompteur%2)*/ update_tunnel( g, g->t );
  171. }
  172. /* Clear screen */
  173. clear_graphics();
  174. /* Print starfield, tunnel, aliens, player and explosions */
  175. draw_starfield( g, g->sf );
  176. draw_tunnel( g, g->t );
  177. draw_bonus( g, g->bo );
  178. draw_aliens( g, g->al );
  179. draw_player( g, g->p );
  180. draw_explosions( g, g->ex );
  181. draw_weapons( g, g->wp );
  182. /* Refresh */
  183. refresh_graphics();
  184. purcompteur++;
  185. }
  186. #if 0
  187. free_player( p );
  188. free_tunnel( g->t );
  189. #endif
  190. }