Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

143 linhas
3.4 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. struct ee_sprite *medium_sprite;
  26. struct ee_sprite *small_sprite;
  27. void init_explosions(game *g, explosions *ex)
  28. {
  29. int i;
  30. for(i = 0; i < EXPLOSIONS; i++)
  31. {
  32. ex->type[i] = EXPLOSION_NONE;
  33. }
  34. medium_sprite = ee_load_sprite("data/xplmed.txt");
  35. small_sprite = ee_load_sprite("data/xplsmall.txt");
  36. }
  37. void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
  38. {
  39. int i;
  40. for(i = 0; i < EXPLOSIONS; i++)
  41. {
  42. if(ex->type[i] == EXPLOSION_NONE)
  43. {
  44. ex->type[i] = type;
  45. ex->x[i] = x;
  46. ex->y[i] = y;
  47. ex->vx[i] = vx;
  48. ex->vy[i] = vy;
  49. switch(type)
  50. {
  51. case EXPLOSION_MEDIUM:
  52. ex->n[i] = 11;
  53. break;
  54. case EXPLOSION_SMALL:
  55. ex->n[i] = 7;
  56. break;
  57. }
  58. break;
  59. }
  60. }
  61. }
  62. void draw_explosions(game *g, explosions *ex)
  63. {
  64. int i;
  65. for(i = 0; i < EXPLOSIONS; i++)
  66. {
  67. #if 0
  68. ee_set_color(GREEN);
  69. ee_goto(ex->x[i] + 3, ex->y[i]);
  70. switch(ee_rand(0,2))
  71. {
  72. case 0:
  73. ee_putchar('p');
  74. ee_putchar('i');
  75. ee_putchar('f');
  76. break;
  77. case 1:
  78. ee_putchar('p');
  79. ee_putchar('a');
  80. ee_putchar('f');
  81. break;
  82. case 2:
  83. ee_putchar('p');
  84. ee_putchar('o');
  85. ee_putchar('u');
  86. ee_putchar('f');
  87. break;
  88. }
  89. ee_putchar('!');
  90. #endif
  91. switch(ex->type[i])
  92. {
  93. case EXPLOSION_MEDIUM:
  94. ee_draw_sprite(ex->x[i], ex->y[i], medium_sprite,
  95. 10 - ex->n[i]);
  96. break;
  97. case EXPLOSION_SMALL:
  98. ee_draw_sprite(ex->x[i], ex->y[i], small_sprite,
  99. 6 - ex->n[i]);
  100. break;
  101. case EXPLOSION_NONE:
  102. break;
  103. }
  104. }
  105. }
  106. void update_explosions(game *g, explosions *ex)
  107. {
  108. int i;
  109. for(i = 0; i < EXPLOSIONS; i++)
  110. {
  111. switch(ex->type[i])
  112. {
  113. case EXPLOSION_MEDIUM:
  114. case EXPLOSION_SMALL:
  115. ex->x[i] += ex->vx[i];
  116. ex->y[i] += ex->vy[i];
  117. ex->n[i]--;
  118. if(ex->n[i] < 0)
  119. {
  120. ex->type[i] = EXPLOSION_NONE;
  121. }
  122. break;
  123. case EXPLOSION_NONE:
  124. break;
  125. }
  126. }
  127. }