1 | |
---|

2 | #include <stdlib.h> |
---|

3 | |
---|

4 | #include "common.h" |
---|

5 | |
---|

6 | void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) |
---|

7 | { |
---|

8 | int i; |
---|

9 | |
---|

10 | for( i = 0; i < SHOTS; i++ ) |
---|

11 | { |
---|

12 | if( wp->y[i] >= 0 ) |
---|

13 | { |
---|

14 | if( wp->x[i] <= t->left[wp->y[i]+1] |
---|

15 | || wp->x[i] >= t->right[wp->y[i]+1] ) |
---|

16 | { |
---|

17 | add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 1, 0 ); |
---|

18 | |
---|

19 | if( wp->x[i] <= t->left[wp->y[i]+1] ) |
---|

20 | { |
---|

21 | t->left[wp->y[i]]--; |
---|

22 | t->left[wp->y[i]+1]-=2; |
---|

23 | t->left[wp->y[i]+2]--; |
---|

24 | } |
---|

25 | else |
---|

26 | { |
---|

27 | t->right[wp->y[i]]++; |
---|

28 | t->right[wp->y[i]+1]+=2; |
---|

29 | t->right[wp->y[i]+2]++; |
---|

30 | } |
---|

31 | |
---|

32 | wp->y[i] = -1; |
---|

33 | } |
---|

34 | else if( wp->x[i] <= t->left[wp->y[i]] |
---|

35 | || wp->x[i] >= t->right[wp->y[i]] ) |
---|

36 | { |
---|

37 | add_explosion( g, ex, wp->x[i], wp->y[i], 0, 1, 0 ); |
---|

38 | |
---|

39 | if( wp->x[i] <= t->left[wp->y[i]] ) |
---|

40 | { |
---|

41 | t->left[wp->y[i]-1]--; |
---|

42 | t->left[wp->y[i]]-=2; |
---|

43 | t->left[wp->y[i]+1]--; |
---|

44 | } |
---|

45 | else |
---|

46 | { |
---|

47 | t->right[wp->y[i]-1]++; |
---|

48 | t->right[wp->y[i]]+=2; |
---|

49 | t->right[wp->y[i]+1]++; |
---|

50 | } |
---|

51 | |
---|

52 | wp->y[i] = -1; |
---|

53 | } |
---|

54 | } |
---|

55 | } |
---|

56 | } |
---|

57 | |
---|

58 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) |
---|

59 | { |
---|

60 | int i, j; |
---|

61 | |
---|

62 | for( i = 0; i < SHOTS; i++ ) |
---|

63 | { |
---|

64 | if( wp->y[i] >= 0 ) |
---|

65 | { |
---|

66 | int ok = 0; |
---|

67 | |
---|

68 | for( j = 0; j < ALIENS; j++ ) |
---|

69 | { |
---|

70 | if( wp->x[i] >= al->x[j] |
---|

71 | && wp->x[i] <= al->x[j] + 4 |
---|

72 | && wp->y[i] >= al->y[j] |
---|

73 | && wp->y[i] <= al->y[j] + 2 ) |
---|

74 | { |
---|

75 | al->life[j]--; |
---|

76 | if( al->life[j] == 0 ) |
---|

77 | { |
---|

78 | al->x[j] = -1; |
---|

79 | al->y[j] = -1; |
---|

80 | add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 ); |
---|

81 | } |
---|

82 | ok = 1; |
---|

83 | } |
---|

84 | else if( wp->x[i] >= al->x[j] |
---|

85 | && wp->x[i] <= al->x[j] + 4 |
---|

86 | && wp->y[i]+1 >= al->y[j] |
---|

87 | && wp->y[i]+1 <= al->y[j] + 2 ) |
---|

88 | { |
---|

89 | al->life[j]--; |
---|

90 | if( al->life[j] == 0 ) |
---|

91 | { |
---|

92 | al->x[j] = -1; |
---|

93 | al->y[j] = -1; |
---|

94 | add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 ); |
---|

95 | } |
---|

96 | ok = 1; |
---|

97 | } |
---|

98 | } |
---|

99 | |
---|

100 | if( ok ) |
---|

101 | { |
---|

102 | wp->y[i] = -1; |
---|

103 | } |
---|

104 | } |
---|

105 | } |
---|

106 | } |
---|

107 | |
---|

108 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ) |
---|

109 | { |
---|

110 | if( p->x <= t->left[p->y] ) |
---|

111 | { |
---|

112 | p->x += 3; |
---|

113 | //add_explosion( g, ex, x+1, y-2, 0, 1, 0 ); |
---|

114 | } |
---|

115 | else if( p->x + 5 >= t->right[p->y] ) |
---|

116 | { |
---|

117 | p->x -= 3; |
---|

118 | //add_explosion( g, ex, x+4, y-2, 0, 1, 0 ); |
---|

119 | } |
---|

120 | } |
---|

121 | |
---|