Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 56 lines (48 sloc) 2.184 kb
a39b9f9 First Commit
Andrew Patrick Dudash authored
1 import pygame
2 from pygame.locals import *
3
4 import mode
5 import config
6 import content
7 import gui
8 import messenger
9
10 class MainMenuMode(mode.Mode):
11 def __init__(self):
12 self.make_background()
13 self.make_buttons()
14 def make_background(self):
15 "Creates a group containing the background."
16 self.background = pygame.sprite.Group()
17 background_sprite = pygame.sprite.Sprite(self.background)
18 background_sprite.image = content.IMAGE["MAINMENU_BACKGROUND_1"]
19 background_sprite.rect = pygame.Rect((0, 0), config.CAMERA_SIZE)
20 def make_buttons(self):
21 "Creates a group for all main menu buttons."
22 self.buttons = pygame.sprite.Group()
23 self.button_refs = [] #Stores a ref to each button
24
25 exit_sprite = gui.Button(self.buttons,
26 content.IMAGE["QUIT_BUTTON_1"],
27 (config.CAMERA_WIDTH / 2 - 128, config.CAMERA_HEIGHT / 4 * 3 - 32),
28 (256, 64))
29 exit_sprite.on_click = lambda : (pygame.quit(), quit())
30 self.button_refs.append(exit_sprite)
31
32 start_sprite = gui.Button(self.buttons,
33 content.IMAGE["START_BUTTON_1"],
34 (config.CAMERA_WIDTH / 2 - 128, config.CAMERA_HEIGHT / 2 - 32),
35 (256, 64))
36 start_sprite.on_click = lambda : messenger.Messenger.switch_mode("GameMode")
37 self.button_refs.append(start_sprite)
38
39 def on_draw(self, display, screen, camera):
40 self.background.draw(screen)
41 self.buttons.draw(screen)
42 display.blit(screen, (0, 0))
43 pygame.display.flip()
44 def on_input(self, a_input):
45 for event in a_input:
46 if event.type == MOUSEBUTTONDOWN:
47 for button in self.buttons:
48 if button.is_hover(event):
49 button.on_hover()
50 if button.is_click(event):
51 button.on_click()
52
53 class MenuMode(mode.Mode): pass
54
55 class SaveMenu(mode.Mode): pass
Something went wrong with that request. Please try again.