本文整理汇总了Python中ball.Ball.update_forces方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.update_forces方法的具体用法?Python Ball.update_forces怎么用?Python Ball.update_forces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ball.Ball
的用法示例。
在下文中一共展示了Ball.update_forces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ButtonSoccer
# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import update_forces [as 别名]
#.........这里部分代码省略.........
def create_goal(self):
self.goal_red = Goal("LEFT")
self.goal_red.team_owner = self.team_red
self.goal_red.team_enemy = self.team_blue
self.goal_blue = Goal("RIGHT")
self.goal_blue.team_owner = self.team_blue
self.goal_blue.team_enemy = self.team_red
self.goals = (self.goal_red, self.goal_blue)
for goal in self.goals:
for dash in goal.elements():
self.add(dash)
def create_scores(self):
self.score_red = Score('left', 'red')
self.score_blue = Score('right', 'blue')
self.team_red.score = self.score_red
self.team_blue.score = self.score_blue
self.add(self.score_red)
self.add(self.score_blue)
def check_turn(self):
print('Turn -> ' + str(self.current_team))
if self.moves + 1 >= MOVES:
self.change_turn()
self.current_team = self.team_red if self.team_red.turn else self.team_blue
self.moves = 0
else:
self.moves += 1
def change_turn(self):
self.team_red.change_turn()
self.team_blue.change_turn()
@listen('mouse-long-press', 'left')
def update_poiter(self, pos):
self.clear_pointer()
button = None
for team in self.teams:
if team.turn:
button = team.get_clicked_button()
if button != None:
try:
size = button.pos - Vec2(pos)
p = Pointer(button.pos.as_tuple(), size.as_tuple())
self.add(p)
except ZeroDivisionError:
pass
def clear_pointer(self):
for element in self.get_render_tree().walk():
if isinstance(element, Pointer):
self.remove(element)
def movement_started(self):
self.clear_pointer()
self.movement_check = CHECK_ACTIVE
def check_goal(self, goal):
if goal.is_goal(self.ball.pos):
goal.team_enemy.points += 1
goal.team_enemy.score.submit()
self.moves = 0
self.ball.reset()
if goal.team_enemy.points >= MAX_SCORE:
self.reset()
return
if self.current_team != goal.team_owner:
self.change_turn()
def reset(self):
time.sleep(2)
self.score_red.reset()
self.score_blue.reset()
self.ball.reset()
self.team_red.reset()
self.team_blue.reset()
@listen('frame-enter')
def process(self):
# bolinha
self.ball.update_forces()
# botões
for team in self.teams:
team.update_forces()
# verificar se houve gol
self.check_goal(self.goal_red)
self.check_goal(self.goal_blue)
if self.movement_check == CHECK_ACTIVE:
if self.team_red.is_stopped() and self.team_blue.is_stopped():
self.movement_check = CHECK_IDLE
self.check_turn()