本文整理汇总了Python中course.Course.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Course.draw方法的具体用法?Python Course.draw怎么用?Python Course.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course.Course
的用法示例。
在下文中一共展示了Course.draw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Editor
# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import draw [as 别名]
class Editor(GameState):
"""Allows the user to edit a course."""
def __init__(self):
super(Editor, self).__init__()
self.next_state = "MAIN_MENU"
def startup(self, persistent):
"""Creates a Course object from the previously selected JSON file."""
self.persist = persistent
name = self.persist["course_name"]
filepath = os.path.join("resources", "courses", "{}.json".format(name))
with open(filepath, "r") as f:
course_info = json.load(f)
self.course = Course(course_info)
self.scroll_speed = .25
self.view_center = list(self.course.view_rect.center)
def save_to_json(self):
"""Saves location of all course objects to be loaded for future use."""
course_info = {
"map_name": self.course.map_name,
"map_size": self.course.map_size,
"obstacles": [[x.name, x.rect.midbottom] for x in self.course.obstacles]
}
filepath = os.path.join("resources", "courses", "{}.json".format(self.course.map_name))
with open(filepath, "w") as f:
json.dump(course_info, f)
def get_event(self, event):
if event.type == pg.QUIT:
self.save_to_json()
self.done = True
elif event.type == pg.KEYUP:
if event.key == pg.K_ESCAPE:
self.save_to_json()
self.done = True
def scroll(self, dt, mouse_pos):
"""Move the view rect when the mouse is at the edge of the screen."""
speed = self.scroll_speed * dt
x, y = mouse_pos
w, h = prepare.SCREEN_SIZE
if x < 20:
self.view_center[0] -= speed
elif x > w - 20:
self.view_center[0] += speed
if y < 20:
self.view_center[1] -= speed
elif y > h - 20:
self.view_center[1] += speed
self.course.view_rect.center = self.view_center
def update(self, dt):
mouse_pos = pg.mouse.get_pos()
self.scroll(dt, mouse_pos)
def draw(self, surface):
surface.fill(pg.Color(242, 255, 255))
self.course.draw(surface)
示例2: Boarding
# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import draw [as 别名]
class Boarding(GameState):
def __init__(self):
super(Boarding, self).__init__()
def startup(self, persistent):
self.persist = persistent
name = self.persist["course_name"]
filepath = os.path.join("resources", "courses", "{}.json".format(name))
with open(filepath, "r") as f:
course_info = json.load(f)
self.course = Course(course_info)
x, y = self.course.map_rect.centerx, 50
self.player = Snowboarder((x, y))
pg.mouse.set_visible(False)
pg.mixer.music.load(prepare.MUSIC["wind"])
pg.mixer.music.set_volume(.7)
pg.mixer.music.play(-1)
def get_event(self, event):
if event.type == pg.KEYUP:
if event.key == pg.K_ESCAPE:
self.done = True
self.next_state = "MAIN_MENU"
pg.mouse.set_visible(True)
pg.mixer.music.fadeout(3000)
def update(self, dt):
keys = pg.key.get_pressed()
self.player.update(dt, keys, self.course.map_rect)
self.course.update(dt, self.player)
def draw(self, surface):
surface.fill(pg.Color(242, 255, 255))
self.course.draw(surface, self.player)