You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

122 lines
3.2 KiB

  1. #include <stdlib.h>
  2. #include "common.h"
  3. void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex )
  4. {
  5. int i;
  6. for( i = 0; i < SHOTS; i++ )
  7. {
  8. if( wp->y[i] >= 0 )
  9. {
  10. if( wp->x[i] <= t->left[wp->y[i]+1]
  11. || wp->x[i] >= t->right[wp->y[i]+1] )
  12. {
  13. add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 1, 0 );
  14. if( wp->x[i] <= t->left[wp->y[i]+1] )
  15. {
  16. t->left[wp->y[i]]--;
  17. t->left[wp->y[i]+1]-=2;
  18. t->left[wp->y[i]+2]--;
  19. }
  20. else
  21. {
  22. t->right[wp->y[i]]++;
  23. t->right[wp->y[i]+1]+=2;
  24. t->right[wp->y[i]+2]++;
  25. }
  26. wp->y[i] = -1;
  27. }
  28. else if( wp->x[i] <= t->left[wp->y[i]]
  29. || wp->x[i] >= t->right[wp->y[i]] )
  30. {
  31. add_explosion( g, ex, wp->x[i], wp->y[i], 0, 1, 0 );
  32. if( wp->x[i] <= t->left[wp->y[i]] )
  33. {
  34. t->left[wp->y[i]-1]--;
  35. t->left[wp->y[i]]-=2;
  36. t->left[wp->y[i]+1]--;
  37. }
  38. else
  39. {
  40. t->right[wp->y[i]-1]++;
  41. t->right[wp->y[i]]+=2;
  42. t->right[wp->y[i]+1]++;
  43. }
  44. wp->y[i] = -1;
  45. }
  46. }
  47. }
  48. }
  49. void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
  50. {
  51. int i, j;
  52. for( i = 0; i < SHOTS; i++ )
  53. {
  54. if( wp->y[i] >= 0 )
  55. {
  56. int ok = 0;
  57. for( j = 0; j < ALIENS; j++ )
  58. {
  59. if( wp->x[i] >= al->x[j]
  60. && wp->x[i] <= al->x[j] + 4
  61. && wp->y[i] >= al->y[j]
  62. && wp->y[i] <= al->y[j] + 2 )
  63. {
  64. al->life[j]--;
  65. if( al->life[j] == 0 )
  66. {
  67. al->x[j] = -1;
  68. al->y[j] = -1;
  69. add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 );
  70. }
  71. ok = 1;
  72. }
  73. else if( wp->x[i] >= al->x[j]
  74. && wp->x[i] <= al->x[j] + 4
  75. && wp->y[i]+1 >= al->y[j]
  76. && wp->y[i]+1 <= al->y[j] + 2 )
  77. {
  78. al->life[j]--;
  79. if( al->life[j] == 0 )
  80. {
  81. al->x[j] = -1;
  82. al->y[j] = -1;
  83. add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 );
  84. }
  85. ok = 1;
  86. }
  87. }
  88. if( ok )
  89. {
  90. wp->y[i] = -1;
  91. }
  92. }
  93. }
  94. }
  95. void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex )
  96. {
  97. if( p->x <= t->left[p->y] )
  98. {
  99. p->x += 3;
  100. //add_explosion( g, ex, x+1, y-2, 0, 1, 0 );
  101. }
  102. else if( p->x + 5 >= t->right[p->y] )
  103. {
  104. p->x -= 3;
  105. //add_explosion( g, ex, x+4, y-2, 0, 1, 0 );
  106. }
  107. }