本文整理汇总了Python中Ball.Ball.fire方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.fire方法的具体用法?Python Ball.fire怎么用?Python Ball.fire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ball.Ball
的用法示例。
在下文中一共展示了Ball.fire方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ship
# 需要导入模块: from Ball import Ball [as 别名]
# 或者: from Ball.Ball import fire [as 别名]
class Ship(Screen):
def __init__(self, name_image="ship-1.png"):
Screen.__init__(self)
self.keys = {
"up" : [K_UP],
"down" : [K_DOWN],
"left" : [K_LEFT],
"right" : [K_RIGHT],
"rotate_left" : [K_a, K_q],
"rotate_right": [K_d],
"fire" : [K_SPACE],
# test
"lose_life": [K_l] # c'est un L
}
self.image = pygame.image.load('img/' + name_image).convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = self.srect.center
self.ball = Ball(default_center=self.rect.center)
self.vitesse = 2
self.vitesse_rotate = 2
self.orginal = self.image.copy()
self.current_angle = 0
self.cheated = 0
self.max_life = 50
self.life = self.max_life
self.score = Score()
def _test_index(self, liste, index):
"""
Cette fonction test si UN des element selectionne par les index sont vrai
ex:
liste = [0, 1, 0, 0, 0, 1]
index = [1, 5] # test l index 1 et 5
"""
ok = 0
for i in index:
if liste[i]:
ok = self.cheated if 0 else 1
return ok
def _move(self, x, y):
self.rect.move_ip((x, y))
self.ball.follow(self.rect.center)
def _spin(self, angle):
prev_rect_center = self.rect.center
image = pygame.transform.rotate(self.orginal, self.current_angle + angle)
self.rect = image.get_rect(center=prev_rect_center)
self.current_angle += angle
self.image = image
def checker(self):
self.is_rotate = False
keystate = pygame.key.get_pressed()
# bouger
if self._test_index(keystate, self.keys["left"]):
if self.rect.left > self.srect.left:
self._move(-self.vitesse, 0)
if self._test_index(keystate, self.keys["right"]):
if self.rect.right < self.srect.right:
self._move(self.vitesse, 0)
if self._test_index(keystate, self.keys["up"]):
if self.rect.top > self.srect.top:
self._move(0, -self.vitesse)
if self._test_index(keystate, self.keys["down"]):
if self.rect.bottom < self.srect.bottom:
self._move(0, self.vitesse)
# tourner
if self._test_index(keystate, self.keys["rotate_left"]):
self._spin(self.vitesse_rotate)
self.is_rotate = True
if self._test_index(keystate, self.keys["rotate_right"]):
self._spin(-self.vitesse_rotate)
self.is_rotate = True
# tirer
if self._test_index(keystate, self.keys["fire"]):
self.ball.fire(self.current_angle)
# test
if self._test_index(keystate, self.keys["lose_life"]):
self.life -= 1
def render(self):
# on se sert de cette fonction pour faire bouger la balle
# car elle est appele a chaque fois
self.ball.move(self.srect, self.rect.center)
#.........这里部分代码省略.........