當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。