def make_buttons(self):
        button_info = (("Hit the Slopes", self.hit_the_slopes),
                       ("Create Course",
                        self.create_course), ("Edit Course", self.edit_course))

        self.buttons = ButtonGroup()
        style = {
            "button_size": (350, 120),
            "font_size": 64,
            "fill_color": pg.Color(48, 75, 50),
            "hover_fill_color": pg.Color(72, 96, 74),
            "text_color": pg.Color("gray80"),
            "hover_text_color": pg.Color("gray90")
        }
        w, h = style["button_size"]
        left = self.screen_rect.centerx - (w // 2)
        top = 100
        vert_space = 180
        for text, callback in button_info:
            Button((left, top),
                   self.buttons,
                   text=text,
                   hover_text=text,
                   call=callback,
                   **style)
            top += vert_space
Exemple #2
0
 def make_buttons(self):
     self.buttons = ButtonGroup()
     style = {"fill_color": pg.Color("gray10"),
                 "hover_fill_color": pg.Color("gray20"),
                 "text_color": pg.Color("gray80"),
                 "hover_text_color": pg.Color("gray90")}
     continents = sorted(prepare.CONTINENTS)
     w, h = 250, 80
     left = self.screen_rect.centerx - (w // 2)
     top = 10
     vert_space = 100 
     for continent in continents:
         Button((left, top, w, h), self.buttons, text=continent, 
                   hover_text=continent, call=self.choose_map,
                   args=continent, **style)
         top += vert_space
class MainMenu(GameState):
    def __init__(self):
        super(MainMenu, self).__init__()
        self.make_buttons()
    
    def startup(self, persistent):
        self.persist = persistent
        
    def make_buttons(self):
        button_info = (
                ("Hit the Slopes", self.hit_the_slopes),
                ("Create Course", self.create_course),
                ("Edit Course", self.edit_course))
                               
        self.buttons = ButtonGroup()
        style = {"button_size": (350, 120),
                     "font_size": 64,
                    "fill_color": pg.Color(48, 75, 50),
                    "hover_fill_color": pg.Color(72, 96, 74),
                    "text_color": pg.Color("gray80"),
                    "hover_text_color": pg.Color("gray90")}
        w, h = style["button_size"]
        left = self.screen_rect.centerx - (w // 2)
        top = 100
        vert_space = 180 
        for text, callback in button_info:
            Button((left, top), self.buttons, text=text, 
                      hover_text=text, call=callback, **style)
            top += vert_space
    
    def create_course(self, *args):
        self.next_state = "NEW_COURSE"
        self.done = True
        
    def edit_course(self, *args):
        self.next_state = "COURSE_SELECT_EDIT"    
        self.done = True
        
    def hit_the_slopes(self, *args):
        self.next_state = "COURSE_SELECT_PLAY"
        self.done  = True
        
    def get_event(self, event):
        self.buttons.get_event(event)
        if event.type == pg.QUIT:
            self.quit = True
        elif event.type == pg.KEYUP:
            if event.key == pg.K_ESCAPE:
                self.quit = True
        
    def update(self, dt):
        self.buttons.update(pg.mouse.get_pos())
        
    def draw(self, surface):
        surface.fill(pg.Color(242, 255, 255))
        self.buttons.draw(surface)        
 def make_buttons(self):
     self.buttons = ButtonGroup()
     style = {"button_size": (250, 80),
                 "fill_color": pg.Color(48, 75, 50),
                 "hover_fill_color": pg.Color(72, 96, 74),
                 "text_color": pg.Color("gray80"),
                 "hover_text_color": pg.Color("gray90")}
     course_dict = tools.load_all_courses(os.path.join("resources", "courses"))
     w, h = style["button_size"]
     left = self.screen_rect.centerx - (w // 2)
     top = 10
     vert_space = 100 
     for name in course_dict:
         Button((left, top), self.buttons, text=name.replace("-", " "), 
                   hover_text=name.replace("-", " "), call=self.load_course,
                   args=name, **style)
         top += vert_space
 def __init__(self):
     super(MenuScreen, self).__init__()
     self.next_state = "SIM"
     self.screen_rect = prepare.SCREEN.get_rect()
     style = {"text_color": pg.Color("gray80"),
                 "fill_color": pg.Color("gray10"),
                 "hover_fill_color": pg.Color("gray20"),
                 "hover_text_color": pg.Color("gray90")}
     self.buttons = ButtonGroup()
     w, h = 200, 80
     space = 50
     left = self.screen_rect.centerx - (w//2)
     top = self.screen_rect.centery - (h + space)
     Button((left, top, w, h), self.buttons, text="New Sim",
               hover_text="New Sim", call=self.new_game, **style)
     top += h + space + space
     Button((left, top, w, h), self.buttons, text="Load Sim", 
               hover_text="Load Sim", call=self.load_game, **style)
class CourseSelectEdit(GameState):
    def __init__(self):
        super(CourseSelectEdit, self).__init__()            
    
    def startup(self, persistent):
        self.persist = persistent
        self.make_buttons()
        
    def make_buttons(self):
        self.buttons = ButtonGroup()
        style = {"button_size": (250, 80),
                     "font_size": 48,
                    "fill_color": pg.Color(48, 75, 50),
                    "hover_fill_color": pg.Color(72, 96, 74),
                    "text_color": pg.Color("gray80"),
                    "hover_text_color": pg.Color("gray90")}
        course_dict = tools.load_all_courses(os.path.join("resources", "courses"))
        w, h = style["button_size"]
        left = self.screen_rect.centerx - (w // 2)
        top = 10
        vert_space = 100
        for name in course_dict:
            Button((left, top), self.buttons, text=name.replace("-", " "), 
                      hover_text=name.replace("-", " "), call=self.load_course,
                      args=name, **style)
            top += vert_space
        
    def load_course(self, course_name):
        self.persist["course_name"] = course_name
        self.next_state = "EDITOR"
        self.done = True
        
    def leave_state(self, next_state):
        self.next_state = next_state
        self.done = True

    def get_event(self, event):
        self.buttons.get_event(event)
        if event.type == pg.QUIT:
            self.leave_state("MAIN_MENU")
        elif event.type == pg.KEYUP:
            if event.key == pg.K_ESCAPE:
                self.leave_state("MAIN_MENU")
                
    def update(self, dt):
        self.buttons.update(pg.mouse.get_pos())
        
    def draw(self, surface):
        surface.fill(pg.Color(242, 255, 255))
        self.buttons.draw(surface)
class MenuScreen(GameState):
    def __init__(self):
        super(MenuScreen, self).__init__()
        self.make_buttons()

    def make_buttons(self):
        self.buttons = ButtonGroup()
        style = {
            "fill_color": pg.Color("gray10"),
            "hover_fill_color": pg.Color("gray20"),
            "text_color": pg.Color("gray80"),
            "hover_text_color": pg.Color("gray90"),
        }
        continents = sorted(prepare.SCALES.keys())
        w, h = 250, 80
        left = self.screen_rect.centerx - (w // 2)
        top = 50
        vert_space = 100
        for continent in continents:
            Button(
                (left, top, w, h),
                self.buttons,
                text=continent,
                hover_text=continent,
                call=self.choose_map,
                args=continent,
                **style
            )
            top += vert_space

    def choose_map(self, continent):
        self.persist["map name"] = continent
        self.next_state = "MAPVIEWER"
        self.done = True

    def get_event(self, event):
        if event.type == pg.QUIT:
            self.quit = True
        self.buttons.get_event(event)

    def update(self, dt):
        mouse_pos = pg.mouse.get_pos()
        self.buttons.update(mouse_pos)

    def draw(self, surface):
        surface.fill(pg.Color("black"))
        self.buttons.draw(surface)
class MenuScreen(GameState):
    def __init__(self):
        super(MenuScreen, self).__init__()
        self.make_buttons()

    def make_buttons(self):
        self.buttons = ButtonGroup()
        style = {
            "fill_color": pg.Color("gray10"),
            "hover_fill_color": pg.Color("gray20"),
            "text_color": pg.Color("gray80"),
            "hover_text_color": pg.Color("gray90")
        }
        continents = sorted(prepare.SCALES.keys())
        w, h = 250, 80
        left = self.screen_rect.centerx - (w // 2)
        top = 50
        vert_space = 100
        for continent in continents:
            Button((left, top, w, h),
                   self.buttons,
                   text=continent,
                   hover_text=continent,
                   call=self.choose_map,
                   args=continent,
                   **style)
            top += vert_space

    def choose_map(self, continent):
        self.persist["map name"] = continent
        self.next_state = "MAPVIEWER"
        self.done = True

    def get_event(self, event):
        if event.type == pg.QUIT:
            self.quit = True
        self.buttons.get_event(event)

    def update(self, dt):
        mouse_pos = pg.mouse.get_pos()
        self.buttons.update(mouse_pos)

    def draw(self, surface):
        surface.fill(pg.Color("black"))
        self.buttons.draw(surface)
Exemple #9
0
class Menu(GameState):
    def __init__(self):
        super(Menu, self).__init__()
        self.screen_rect = prepare.SCREEN_RECT
        self.make_buttons()
        
    def make_buttons(self):
        self.buttons = ButtonGroup()
        style = {"fill_color": pg.Color("gray10"),
                    "hover_fill_color": pg.Color("gray20"),
                    "text_color": pg.Color("gray80"),
                    "hover_text_color": pg.Color("gray90")}
        continents = sorted(prepare.CONTINENTS)
        w, h = 250, 80
        left = self.screen_rect.centerx - (w // 2)
        top = 10
        vert_space = 100 
        for continent in continents:
            Button((left, top, w, h), self.buttons, text=continent, 
                      hover_text=continent, call=self.choose_map,
                      args=continent, **style)
            top += vert_space
            
    def choose_map(self, continent):
        name = continent.replace(" ", "-")
        img = pg.transform.smoothscale(prepare.GFX[name], (640, 480))
        self.persist["puzzle"] = Puzzle(img)
        self.next_state = "IDLE"
        self.done = True
            
    def startup(self, persistent):
        self.persist = persistent
        
    def get_event(self, event):
        self.buttons.get_event(event)
        if event.type == pg.QUIT:
            self.quit = True
        
    def update(self, dt):
        mouse_pos = pg.mouse.get_pos()
        self.buttons.update(mouse_pos)
        
    def draw(self, surface):
        surface.fill(pg.Color("black"))
        self.buttons.draw(surface)
class MenuScreen(GameState):
    """
    First state of the game. It allows the user to start a new simulation
    or load a previously saved simulation.
    """    
    def __init__(self):
        super(MenuScreen, self).__init__()
        self.next_state = "SIM"
        self.screen_rect = prepare.SCREEN.get_rect()
        style = {"text_color": pg.Color("gray80"),
                    "fill_color": pg.Color("gray10"),
                    "hover_fill_color": pg.Color("gray20"),
                    "hover_text_color": pg.Color("gray90")}
        self.buttons = ButtonGroup()
        w, h = 200, 80
        space = 50
        left = self.screen_rect.centerx - (w//2)
        top = self.screen_rect.centery - (h + space)
        Button((left, top, w, h), self.buttons, text="New Sim",
                  hover_text="New Sim", call=self.new_game, **style)
        top += h + space + space
        Button((left, top, w, h), self.buttons, text="Load Sim", 
                  hover_text="Load Sim", call=self.load_game, **style)
            
    def new_game(self, *args):
        """
        Set up the populations for a new sim to be passed to the Sim state.
        """
        rect = self.screen_rect.inflate(-64, -64)
        num_grass = 50
        num_rabbits = 20
        num_wolves = 1
        grasses = pg.sprite.Group()
        rabbits = pg.sprite.Group()
        wolves = pg.sprite.Group()
        for g in range(num_grass):
            Grass(random_pos(rect), 1000, grasses)
        for r in range(num_rabbits):
            direction = choice(("left", "right", "up", "down"))
            Rabbit(random_pos(rect), direction, 1000, 0, rabbits)
        for f in range(num_wolves):
            direction = choice(("left", "right", "up", "down"))
            Wolf(random_pos(rect), direction, 1000, 0, wolves)
        self.persist["grasses"] = grasses
        self.persist["rabbits"] = rabbits
        self.persist["wolves"] = wolves
        self.done  = True
            

    def load_game(self, *args):
        """
        Load the previously saved populations from JSON and 
        pass them to the Sim state by adding them to self.persist. 
        """
        pass
        
    def get_event(self, event):
        self.buttons.get_event(event)
        
    def update(self, dt):
        mouse_pos = pg.mouse.get_pos()
        self.buttons.update(mouse_pos)
        
    def draw(self, surface):
        #Treat the whole screen as dirty
        dirty = [surface.get_rect()]
        self.buttons.draw(surface)
        return dirty