Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

262 lignes
5.9 KiB

  1. /*
  2. * ttyvaders Textmode shoot'em up
  3. * Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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 "config.h"
  23. #include <stdlib.h>
  24. #include "common.h"
  25. static void draw_alien_foo(game *, int, int, int);
  26. static void draw_alien_bar(game *, int, int, int);
  27. static void draw_alien_baz(game *, int, int, int);
  28. void init_aliens(game *g, aliens *al)
  29. {
  30. int i;
  31. for(i = 0; i < ALIENS; i++)
  32. {
  33. al->type[i] = ALIEN_NONE;
  34. }
  35. }
  36. void draw_aliens(game *g, aliens *al)
  37. {
  38. int i;
  39. for(i = 0; i < ALIENS; i++)
  40. {
  41. switch(al->type[i])
  42. {
  43. case ALIEN_FOO:
  44. draw_alien_foo(g, al->x[i], al->y[i], al->img[i] % 8);
  45. break;
  46. case ALIEN_BAR:
  47. draw_alien_bar(g, al->x[i], al->y[i], al->img[i] % 2);
  48. break;
  49. case ALIEN_BAZ:
  50. draw_alien_baz(g, al->x[i], al->y[i], al->img[i] % 6);
  51. break;
  52. case ALIEN_NONE:
  53. break;
  54. }
  55. }
  56. }
  57. void update_aliens(game *g, aliens *al)
  58. {
  59. int i;
  60. for(i = 0; i < ALIENS; i++)
  61. {
  62. /* If alien died, make it explode */
  63. if(al->type[i] != ALIEN_NONE && al->life[i] < 0)
  64. {
  65. add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM);
  66. al->type[i] = ALIEN_NONE;
  67. add_bonus(g, g->bo, al->x[i], al->y[i], ee_rand(0,4) ? BONUS_GREEN : BONUS_LIFE);
  68. }
  69. /* Update coordinates */
  70. switch(al->type[i])
  71. {
  72. case ALIEN_FOO:
  73. case ALIEN_BAR:
  74. case ALIEN_BAZ:
  75. al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
  76. al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
  77. al->img[i] = al->img[i] + 1;
  78. /* Check bounds */
  79. if(al->y[i] < 0 ) al->y[i] = 0;
  80. if(al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
  81. break;
  82. case ALIEN_NONE:
  83. break;
  84. }
  85. }
  86. }
  87. void add_alien(game *g, aliens *al, int x, int y, int type)
  88. {
  89. int i;
  90. for(i = 0; i < ALIENS; i++)
  91. {
  92. if(al->type[i] == ALIEN_NONE)
  93. {
  94. al->type[i] = type;
  95. al->x[i] = x;
  96. al->y[i] = y;
  97. al->img[i] = 0;
  98. switch(al->type[i])
  99. {
  100. case ALIEN_FOO:
  101. al->life[i] = 3;
  102. break;
  103. case ALIEN_BAR:
  104. al->life[i] = 3;
  105. break;
  106. case ALIEN_BAZ:
  107. al->life[i] = 3;
  108. break;
  109. case ALIEN_NONE:
  110. break;
  111. }
  112. break;
  113. }
  114. }
  115. }
  116. static void draw_alien_bar(game *g, int x, int y, int frame)
  117. {
  118. switch(frame)
  119. {
  120. case 0:
  121. ee_color(EE_MAGENTA);
  122. ee_goto(x, y);
  123. ee_putstr(",---.");
  124. ee_goto(x, y+1);
  125. ee_putchar('\\');
  126. ee_color(EE_WHITE);
  127. ee_putstr("o O");
  128. ee_color(EE_MAGENTA);
  129. ee_putchar('/');
  130. ee_goto(x, y+2);
  131. ee_putstr("^^^^^");
  132. break;
  133. case 1:
  134. ee_color(EE_MAGENTA);
  135. ee_goto(x, y);
  136. ee_putstr(",---.");
  137. ee_goto(x, y+1);
  138. ee_putchar('\\');
  139. ee_color(EE_WHITE);
  140. ee_putstr("O o");
  141. ee_color(EE_MAGENTA);
  142. ee_putchar('/');
  143. ee_goto(x, y+2);
  144. ee_putstr("^^^^^");
  145. break;
  146. }
  147. }
  148. static void draw_alien_baz(game *g, int x, int y, int frame)
  149. {
  150. ee_color(EE_GREEN);
  151. ee_goto(x, y-1);
  152. ee_putstr("__");
  153. ee_goto(x-1, y);
  154. ee_putchar('/');
  155. ee_goto(x+2, y);
  156. ee_putchar('\\');
  157. switch(frame)
  158. {
  159. case 3:
  160. ee_goto(x-2, y+1);
  161. ee_putstr("//'`\\\\");
  162. break;
  163. case 4:
  164. case 2:
  165. ee_goto(x-2, y+1);
  166. ee_putstr("/(~~)\\");
  167. break;
  168. case 5:
  169. case 1:
  170. ee_goto(x-2, y+1);
  171. ee_putstr("((^^))");
  172. break;
  173. case 0:
  174. ee_goto(x-1, y+1);
  175. ee_putstr("\\\\//");
  176. break;
  177. }
  178. ee_color(EE_WHITE);
  179. ee_goto(x, y);
  180. ee_putstr("oo");
  181. }
  182. static void draw_alien_foo(game *g, int x, int y, int frame)
  183. {
  184. ee_color(EE_YELLOW);
  185. switch(frame)
  186. {
  187. case 0:
  188. ee_goto(x, y);
  189. ee_putchar('.');
  190. ee_goto(x+6, y);
  191. ee_putchar(',');
  192. ee_goto(x+1, y+1);
  193. ee_putstr("\\ X /");
  194. break;
  195. case 7:
  196. case 1:
  197. ee_goto(x-1, y);
  198. ee_putchar('.');
  199. ee_goto(x+7, y);
  200. ee_putchar(',');
  201. ee_goto(x, y+1);
  202. ee_putstr("`- X -'");
  203. break;
  204. case 6:
  205. case 2:
  206. ee_goto(x-1, y+1);
  207. ee_putstr("`-- X --'");
  208. break;
  209. case 5:
  210. case 3:
  211. ee_goto(x, y+1);
  212. ee_putstr(",- X -.");
  213. ee_goto(x-1, y+2);
  214. ee_putchar('\'');
  215. ee_goto(x+7, y+2);
  216. ee_putchar('`');
  217. break;
  218. case 4:
  219. ee_goto(x+1, y+1);
  220. ee_putstr(", X .");
  221. ee_goto(x, y+2);
  222. ee_putchar('/');
  223. ee_goto(x+6, y+2);
  224. ee_putchar('\\');
  225. break;
  226. }
  227. ee_goto(x+2, y+2);
  228. ee_putstr("`V'");
  229. ee_color(EE_WHITE);
  230. ee_goto(x+2, y+1);
  231. ee_putchar('o');
  232. ee_goto(x+4, y+1);
  233. ee_putchar('o');
  234. }