当前位置: 首页>>代码示例>>Python>>正文


Python Course.draw方法代码示例

本文整理汇总了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)
开发者ID:reddit-pygame,项目名称:snowboard-challenge,代码行数:62,代码来源:editor.py

示例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)    
开发者ID:reddit-pygame,项目名称:snowboard-challenge,代码行数:36,代码来源:boarding.py


注:本文中的course.Course.draw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。