本文整理汇总了Python中ship.Ship.shoot方法的典型用法代码示例。如果您正苦于以下问题:Python Ship.shoot方法的具体用法?Python Ship.shoot怎么用?Python Ship.shoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ship.Ship
的用法示例。
在下文中一共展示了Ship.shoot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameController
# 需要导入模块: from ship import Ship [as 别名]
# 或者: from ship.Ship import shoot [as 别名]
class GameController(Tkinter.Frame):
def __init__(self, window, canvas):
Tkinter.Frame.__init__(self, window)
self.window = window
self.canvas = canvas
self.ship = Ship([400, 300], [0, 0], 0, self.canvas)
self.is_started = False
self.lives = 3
self.score = 0
self.rock_group = set([])
self.missile_group = set([])
self.explosion_group = set([])
self.timer = RockSpanTimer(self, 1.5)
def new_game(self):
sound.soundtrack.play()
self.ship = Ship([400, 300], [0, 0], 0, self.canvas)
self.is_started = True
self.lives = 3
self.score = 0
self.rock_group = set([])
self.missile_group = set([])
self.explosion_group = set([])
self.timer = RockSpanTimer(self, 1.5)
self.timer.start()
def game_over(self):
sound.soundtrack.stop()
self.timer.stop()
self.rock_group = set([])
self.missile_group = set([])
self.explosion_group = set([])
self.ship.set_thrust(False)
self.ship.set_game_state(False)
self.is_started = False
def minus_live(self):
self.lives -= 1
def add_score(self):
self.score += 1
def on_key_down(self, event):
self.window.label_key.config(text='key down: ' + str(event.keysym))
if self.is_started == False:
return
if event.keysym == 'Up':
self.ship.set_thrust(True)
if event.keysym == 'Left':
self.ship.decrement_angle_vel()
if event.keysym == 'Right':
self.ship.increment_angle_vel()
if event.keysym == 'space':
self.ship.shoot(self.missile_group)
def on_key_release(self, event):
self.window.label_key.config(text='key up: ' + str(event.keysym))
if self.is_started == False:
return
if event.keysym == 'Up':
self.ship.set_thrust(False)
if event.keysym == 'Left':
self.ship.increment_angle_vel()
if event.keysym == 'Right':
self.ship.decrement_angle_vel()
if event.keysym == 'space':
pass
def mouse_move(self, event):
self.window.label_mouse.config(text='mouse x:{}, y:{}'.format(event.x, event.y))
def mouse_click(self, event):
self.window.label_mouse.config(text='mouse click x:{}, y:{}'.format(event.x, event.y))
inwidth = (400 - 400 / 2) < event.x < (400 + 400 / 2)
inheight = (300 - 300 / 2) < event.y < (300 + 300 / 2)
if (not self.is_started) and inwidth and inheight:
self.new_game()
def rock_spawner(self):
if self.is_started:
if len(self.rock_group) >= Rock.LIMIT:
return
rock_pos = [random.randrange(0, self.canvas.CANVAS_WIDTH), random.randrange(0, self.canvas.CANVAS_HEIGHT)]
rock_vel = [random.random() * .6 - .3, random.random() * .6 - .3]
rock_avel = random.random() * .2 - .1
add_vel = self.score * 0.5 + 1
rock_vel = [rock_vel[0] * add_vel, rock_vel[1] * add_vel]
rock = Rock(rock_pos, rock_vel, 0, rock_avel, self.canvas)
distance = Util.dist(rock.get_position(), self.ship.get_position())
if distance < 200:
return
self.rock_group.add(rock)
#.........这里部分代码省略.........