本文整理汇总了Python中terrain.Terrain.explosion方法的典型用法代码示例。如果您正苦于以下问题:Python Terrain.explosion方法的具体用法?Python Terrain.explosion怎么用?Python Terrain.explosion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terrain.Terrain
的用法示例。
在下文中一共展示了Terrain.explosion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from terrain import Terrain [as 别名]
# 或者: from terrain.Terrain import explosion [as 别名]
class Game(pyglet.event.EventDispatcher):
def __init__(self):
self.window = pyglet.window.Window(fullscreen=True)
self.terrain = Terrain(self.window.width, self.window.height-100)
self.players = [
Player(name, self, i)
for i, name in enumerate(sys.argv[1:])]
self.moving = []
# Setup events
self.window.event(self.on_draw)
Game.register_event_type('next_player')
Game.register_event_type('start_moving')
Game.register_event_type('stop_moving')
Game.register_event_type('explosion')
# Start the game.
self.reset()
# Run the fucker
pyglet.app.run()
def reset(self):
self.terrain.reset()
for p in self.players:
p.reset()
random.shuffle(self.players)
for p in self.players:
new_x = None
while not new_x:
new_x = int(random.uniform(20, self.window.width - 20))
for other in self.players:
if other != p and abs(other.pos[0] - new_x) < 50:
new_x = None
break
p.pos = new_x, self.terrain.flatten(new_x)
self.next_player()
def next_round(self):
for p in self.players:
p.next_round()
self.next_player()
def next_player(self):
live_players = list(filter(lambda p: p.alive, self.players))
if len(live_players) < 2:
for p in live_players:
p.score += 10000
self.reset()
return
for p in live_players:
if not p.ready:
p.take_turn()
return
self.moving = [
Shot(p.pos, p.angle, p.power, p)
for p in self.players
if p.alive]
pyglet.clock.schedule(self.move, 1/60)
def move(self, *args, **kwargs):
for s in self.moving:
s.move(self)
def explosion(self, x, y, r, player=None):
self.terrain.explosion(x, y, r)
for p in self.players:
p.explosion(x, y, r, player)
def stop_moving(self, thing):
self.moving.remove(thing)
if not self.moving:
pyglet.clock.unschedule(self.move)
self.next_round()
def start_moving(self, thing):
self.moving.append(thing)
def on_draw(self):
self.window.clear()
self.terrain.draw(self.window.width, self.window.height-100, 100)
for p in self.players:
p.draw()
for m in self.moving:
m.draw(self.window.height-100)