本文整理汇总了Python中snake.Snake.gen_dot方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.gen_dot方法的具体用法?Python Snake.gen_dot怎么用?Python Snake.gen_dot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.gen_dot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import gen_dot [as 别名]
#.........这里部分代码省略.........
"background",
pos=Point2(0, 0),
scale=39.5,
depth=100,
transparency=False
)
gen_label_text("ESC : Quit", 0)
gen_label_text("SPACE: Pause", 1)
gen_label_text("R : Restart", 2)
self._score = gen_label_text(
"", 0, left=False
)
self._bricks = deque()
self._dot = load_object(
"brick", pos=Point2(0, 0)
)
self._restart()
self.accept("escape", sys.exit)
self.accept("enter", self.restart)
self.accept("arrow_up", self._turn, [settings.POS_Y])
self.accept("arrow_down", self._turn, [settings.NEG_Y])
self.accept("arrow_left", self._turn, [settings.NEG_X])
self.accept("arrow_right", self._turn, [settings.POS_X])
self.accept("space", self._tooggle_pause)
self.accept("r", self._restart)
self.period = settings.PERIOD
self.pause = True
def _game_loop(self, task):
dt = task.time - task.last
if not self._snake.alive:
return task.done
if self.pause:
return task.cont
elif dt >= self.period:
task.last = task.time
self._snake.move_forward()
self._snake.check_state()
self._update_snake()
self._update_dot()
self._update_score()
return task.cont
def _draw_snake(self):
for point in self._snake.body:
brick = load_object("brick", pos=Point2(point.real, point.imag))
self._bricks.append(brick)
def _update_snake(self):
if len(self._snake.body) > len(self._bricks):
new_head = self._dot
self._make_dot()
self._bricks.appendleft(new_head)
for i in range(len(self._snake.body)):
point = self._snake.body[i]
brick = self._bricks[i]
brick.setPos(point.real, settings.SPRITE_POS, point.imag)
def _make_dot(self):
self._dot = load_object(
"brick", pos=Point2(self._snake.dot.real, self._snake.dot.imag)
)
def _update_dot(self):
x, y = self._dot.getX(), self._dot.getZ()
if (x, y) != self._snake.dot:
self._dot.setPos(
self._snake.dot.real, settings.SPRITE_POS, self._snake.dot.imag)
def _update_score(self):
self._score.setText(
"Score: %s" % self._snake.get_score()
)
def _tooggle_pause(self):
self.pause = not self.pause
def _restart(self):
self.pause = True
for b in self._bricks:
b.remove_node()
self._snake = Snake(
body=_make_default_body(),
vector=settings.POS_X,
dot=complex()
)
self._snake.gen_dot()
self._bricks = deque()
self._update_dot()
self._draw_snake()
taskMgr.remove("GameLoop")
self._game_task = taskMgr.add(self._game_loop, "GameLoop")
self._game_task.last = 0
def _turn(self, direction: complex):
if not self.pause:
self._snake.turn(direction)