-
Notifications
You must be signed in to change notification settings - Fork 0
/
gun.py
208 lines (170 loc) · 8.4 KB
/
gun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
# coding:utf-8
from bullet import *
from beam import *
from define import R_time
import pygame
import math
import random
from timer import Timer
class Gun:
def __init__(self, machines,principal, max):
"""引数は、発射する弾の当たり判定対象となる機体グループ。発射できる弾の上限値max(初期値は無限を意味する-1)"""
self.max = self.num = max # インスタンス変数max, numに引数の値をセットする
self.machines = machines
self.principal = principal #弾を打つ本人の位置情報
self.count = 0
self.gun_start = R_time.get_ticks()
self.dx,self.dy = -10,0
def isBulletZero(self):
"""銃弾数が0ならTrue
そうでないならFalseを返す"""
return self.num == 0
def shoot(self, x, y):
"""引数は弾の発射位置(x, y)"""
if self.principal.cop_flag:
Bullet(x, y, self.dx*-1, self.dy, self.machines) # 弾を生成する(BulletクラスはMainクラスでグループ化されているため、返却する必要はない)
else:
Bullet(x+self.principal.rect.width, y, self.dx*-1, self.dy, self.machines)
self.num -= 1
def reload(self):
self.num = self.max #bulletの玉数を上限に戻す
def BulletZero(self):
self.num = 0
class Tracking_Gun(Gun):
def shoot(self, x, y):
play_list = self.machines.sprites() #相手の設定情報を入手
for play in play_list:
distance = math.sqrt((play.rect.centerx-x)**2+(play.rect.centery-y)**2) #自身と相手の距離を計測
angle = distance / 10
Bullet(x, y, (play.rect.centerx-x)/angle,(play.rect.centery-y)/angle, self.machines) #相手の現在の場所に弾を飛ばす
break
self.num -= 1 #弾の残弾数を減らす
class Opposite_Gun(Gun): #右から左に弾を飛ばす
def shoot(self, x, y):
if self.principal.cop_flag:
Bullet(x-self.principal.rect.width, y, self.dx, self.dy, self.machines)
else:
Bullet(x, y, self.dx, self.dy, self.machines)
self.num -= 1
class Reflection_Gun(Gun): #左から右に弾を飛ばす
def __init__(self, machines,principal, max):
super().__init__(machines,principal, max)
if principal.cop_flag:
self.dx = self.dx*-1
def shoot(self, x, y):
Reflection_Bullet(x, y, self.dx, self.dy, self.machines)
self.num -= 1
class Circle_Gun(Gun):
def shoot(self, x, y):
Bullet_list1 = [[-4.0,0],[-3.5,-3.5],[0,-4.0],[3.5,-3.5],[4.0,0],[3.5,3.5],[0,4.0],[-3.5,3.5]] #弾の飛ばす方向を格納
Bullet_list2 = [[1.9,-4.6],[4.6,-1.9],[4.6,1.9],[1.9,4.6],[-1.9,4.6],[-4.6,1.9],[-4.6,-1.9],[-1.9,-4.6]] #弾の飛ばす方向を格納
if self.count == 0: #弾をそれぞれ交互にとばすためのself.count
for bullet_list in Bullet_list1:
Bullet(x, y, bullet_list[0],bullet_list[1], self.machines)
#self.gun_start = R_time.get_ticks()
self.count = 1
self.num -= 1
elif self.count == 1:
for bullet_list in Bullet_list2:
Bullet(x, y, bullet_list[0], bullet_list[1], self.machines)
#self.gun_start = R_time.get_ticks()
self.count = 0
self.num -= 1
class Twist_Gun(Gun):
def __init__(self, machines, principal, max):
super().__init__(machines, principal, max) #superクラス(Gun)を呼び出す
self.standard_parameter = -10.0 #飛ばす弾の速度と角度を格納
self.standard_angle = 0 #飛ばす弾の角度を格納(例15)
self.shot_flag = True
self.angle_count = 0
self.shot_count = 0
if self.principal.cop_flag:
self.standard_parameter *= -1
def shoot(self, x, y):
#self.count_angle()
dx = self.standard_parameter*math.cos(math.radians(self.standard_angle)) #飛ばす角度を指定してdxの値を変化させる
dy = self.standard_parameter*math.sin(math.radians(self.standard_angle)) #飛ばす角度を指定してdyの値を変化させる
Bullet(x, y, dx, dy, self.machines)
#self.shot_count += 1
if self.standard_angle >= 45: #角度が45度以上になると角度の変化が反時計回りになる
self.count = 1
if self.standard_angle <= -45: #角度が-45度以下になると角度の変化が時計回りになる
self.count = 0
if self.count == 0:
self.standard_angle += 10 #変化角度を+10度する
if self.count == 1:
self.standard_angle -= 10 #変化角度を-10度する
"""if self.angle_count == 3:
self.change_flag()
#Timer(2000,self.change_flag)
self.angle_count = 0
self.shot_count = 0
print(self.angle_count)"""
self.num -= 1
def change_flag(self):
self.shot_flag ^= True
def count_angle(self):
if self.standard_angle == 0:
self.angle_count += 1
class Beam_Gun(Gun):
def __init__(self, machines, principal, max, angle=180):
super().__init__(machines, principal, max)
self.principal.beam_flag = 0
self.gun_start = pygame.time.get_ticks()
self.beam_count = 0
self.angle = angle
def shoot(self, x, y):
if self.principal.beam_flag == 0 and self.beam_count == 0:
Beam_principal(x, y, self.machines, self.principal,"img/bullet/beam/beam3.png",self.angle)
self.principal.beam_flag = 1
self.num -= 1
self.beam_count += 1
elif self.principal.beam_flag == 0 and self.beam_count == 1 and pygame.time.get_ticks() - self.gun_start >= 600:
Beam_principal(x, y, self.machines, self.principal,"img/bullet/beam/beam3.png", self.angle)
self.principal.beam_flag = 1
self.num -= 1
if self.principal.beam_flag == 1:
self.gun_start = pygame.time.get_ticks()
class Missile_Gun(Gun):
def __init__(self, machines, principal, max):
super().__init__(machines, principal, max)
self.gun_flag = 0
def shoot(self, x, y):
if self.principal.cop_flag == 1 and R_time.get_ticks() - self.gun_start >= 1000 or self.gun_flag == 0:
Missile_Bullet(x, y, self.dx*-1, self.dy, self.machines, self.principal, 1)
self.gun_start = R_time.get_ticks()
self.gun_flag = 1
self.num -= 1
elif self.principal.cop_flag == 0:
Missile_Bullet(x, y, self.dx, self.dy, self.machines, 0)
self.num -= 1
class Fluffy_Gun(Gun):
def __init__(self, machines, principal, max):
super().__init__(machines, principal, max)
def shoot(self, x, y):
Fluffy_Bullet(x, y, self.dx*-1, self.dy, self.machines)
self.num -= 1
class Thunder_Gun(Gun):
def __init__(self, machines, principal, max):
super().__init__(machines, principal, max)
def shoot(self, x, y):
Thunder_Bullet(x, y, self.dx*-2, self.dy, self.machines)
self.num -= 1
class Fire_Gun(Gun):
def __init__(self, machines, principal, max):
super().__init__(machines, principal, max)
def shoot(self, x, y):
fire_Bullet(x, y, self.dx*-2, self.dy, self.machines)
self.num -= 1
class Laser_Gun(Gun):
def __init__(self, machines, principal, max):
super().__init__(machines, principal, max)
self.bit = Bit_Manage(machines, principal)
def shoot(self, x, y):
Laser_Bullet(self.principal.rect.right, self.principal.rect.centery, 10, 0, self.machines, self.principal)
if self.bit.bitA.break_flag == 0:
Laser_Bullet(self.bit.bitA.rect.right, self.bit.bitA.rect.centery, 10, 0, self.machines, self.principal)
if self.bit.bitB.break_flag == 0:
Laser_Bullet(self.bit.bitB.rect.right, self.bit.bitB.rect.centery, 10, 0, self.machines, self.principal)
self.num -= 1