Changeset 479:fb9258d66137


Ignore:
Timestamp:
04/09/11 19:59:59 (12 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Message:

New Main Menu

Location:
skaapsteker
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/cutscene.py

    r452 r479  
    9191
    9292    def done(self, selected=None, data=None):
    93         ChangeScene.post(LevelScene(self.game_state, self._soundsystem,
    94                                     'temple.starting'))
     93        fox = self.game_state.world.fox
     94        ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
    9595
    9696
  • skaapsteker/engine.py

    r454 r479  
    4343                if ev.type is QUIT:
    4444                    return
    45                 if NewGameEvent.matches(ev):
    46                     self.game_state.new_game()
    47                     fox = self.game_state.world.fox
    48                     ChangeScene.post((ev.scene_type, '.'.join([fox.level, fox.doorway])))
    4945                if ChangeScene.matches(ev):
    5046                    next_scene = ev.next_scene
     
    106102        return ev.type is USEREVENT and ev.utype == cls.utype
    107103
    108 class NewGameEvent(UserEvent):
    109 
    110     utype = "NEW_GAME_EVENT"
    111 
    112     @classmethod
    113     def post(cls, scene_type):
    114         super(NewGameEvent, cls).post(scene_type=scene_type)
    115104
    116105class ChangeScene(UserEvent):
  • skaapsteker/gamestate.py

    r454 r479  
    5555
    5656    def save_game(self):
     57        if self.world is None:
     58            return
    5759        save_dir, _ = os.path.split(self._game_file)
    5860        if not os.path.exists(save_dir):
  • skaapsteker/menuscene.py

    r454 r479  
    11import pygame
    2 from pygame.locals import K_ESCAPE, K_q, KEYDOWN, QUIT
     2from pygame.locals import K_ESCAPE, K_q, K_UP, K_DOWN, K_RETURN, KEYDOWN, QUIT
    33
     4from .data import load_image
    45from .cutscene import OpeningCutScene, UsageCutScene, CreditsCutScene
    5 from .engine import ChangeScene, Scene, NewGameEvent
     6from .engine import ChangeScene, Scene
    67from .levelscene import LevelScene
    78from .widgets.text import Text, TextChoice
     
    1112    def __init__(self, game_state, soundsystem):
    1213        super(MenuScene, self).__init__(game_state, soundsystem)
    13         self.widgets.append(Text("MENU:", (50, 50), color='white', size=48))
    14         menu_options = [
    15             ('Start new game', 'restart'),
    16             ('Starting Cutscene', 'cutscene'),
    17             ('Temple', 'temple.starting'),
    18             ("Temple grounds", "temple_grounds.starting"),
    19             ("Road", "road.starting"),
    20             ("Town", "town.starting"),
    21             ("Tea house", "tea_house.starting"),
    22             ("Kumiko's rooms", "geisha_room.starting"),
    23             ("Market", "market.starting"),
    24             ("Fishmonger's house", "fishmonger_house.starting"),
    25             ("Theatre", "theatre.starting"),
    26             ("Celestial plane", "celestial_plane.starting"),
    27             ('Usage', 'usage'),
    28             ('Credits', 'credits'),
    29             ('Quit', 'quit'),
    30         ]
    31         if self.game_state.world is not None:
    32             menu_options.insert(0, ('Resume Game', 'resume'))
    33         self.choice = TextChoice(menu_options, (50, 100), color='white')
    34         self.choice.callbacks.append(self.selected)
    35         self.widgets.append(self.choice)
    36 
    37     def resume_game(self):
    38         fox = self.game_state.world.fox
    39         ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
     14        self._background = load_image('backgrounds/main-menu.png')
     15        self._cursor = load_image('sprites/main-menu-cursor.png')
     16        self._selected = 0
     17        self._options = ['restart', 'usage', 'credits', 'quit']
     18        self._can_resume = self.game_state.world is not None
     19        if self._can_resume:
     20            resume = load_image('sprites/main-menu-resume.png')
     21            self._background.blit(resume, (73, 180))
     22            self._options.insert(0, 'resume')
    4023
    4124    def selected(self, option, data):
    42         "Callback from menu TextChoice"
    4325        if data == 'resume':
    44             self.resume_game()
     26            fox = self.game_state.world.fox
     27            ChangeScene.post((LevelScene, '.'.join([fox.level, fox.doorway])))
    4528        elif data == 'restart':
    46             NewGameEvent.post(LevelScene)
    47         elif data == 'cutscene':
     29            self.game_state.new_game()
    4830            ChangeScene.post(OpeningCutScene(self.game_state, self._soundsystem))
    4931        elif data == 'usage':
     
    5335        elif data == 'quit':
    5436            pygame.event.post(pygame.event.Event(QUIT))
    55         else:
    56             ChangeScene.post(LevelScene(self.game_state, self._soundsystem, data))
    5737
    5838    def draw(self, surface, engine):
    59         surface.fill(pygame.Color('black'))
    60         super(MenuScene, self).draw(surface, engine)
     39        cursor_x = 35
     40        cursor_y = 232
     41        if self._can_resume:
     42            cursor_y -= 43
     43        cursor_y += 43 * self._selected
     44        surface.blit(self._background, (0, 0))
     45        surface.blit(self._cursor, (cursor_x, cursor_y))
    6146
    6247    def dispatch(self, ev):
    6348        if ev.type is KEYDOWN:
    64             if ev.key in(K_q, K_ESCAPE):
     49            if ev.key in (K_q, K_ESCAPE):
    6550                pygame.event.post(pygame.event.Event(QUIT))
    66         super(MenuScene, self).dispatch(ev)
     51            elif ev.key == K_DOWN:
     52                self._selected += 1
     53            elif ev.key == K_UP:
     54                self._selected -= 1
     55            elif ev.key == K_RETURN:
     56                self.selected(self._selected, self._options[self._selected])
     57
     58        self._selected %= 4 + int(self._can_resume)
Note: See TracChangeset for help on using the changeset viewer.