Mercurial > sypikslang
annotate gamelib/mainmenu.py @ 87:d93e1ea2bd0d
Fix method name assumption bug
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 09 May 2012 20:06:44 +0200 |
parents | 8d1cf0cbe5e1 |
children | 74ce25ec2073 |
rev | line source |
---|---|
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
3 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
4 """The main menu""" |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
5 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
6 import pygame |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
7 from pygame import image |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
8 |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
9 from gamelib import data |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
10 from gamelib.gui_base import Window |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
11 from gamelib.gui import BigButton |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
12 from gamelib.engine import AddWindow |
63
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
13 from gamelib.gamegui import LabWindow |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
14 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
15 from gamelib.constants import WIDTH, HEIGHT |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
16 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
17 |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
18 class MainMenuButton(BigButton): |
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
19 WIDTH = 276 |
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
20 HEIGHT = 75 |
76 | 21 BG_IMAGE_NORMAL = image.load(data.filepath('images/main_normal.png')) |
22 BG_IMAGE_DOWN = image.load(data.filepath('images/main_down.png')) | |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
23 |
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
24 |
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
25 class NewGameButton(MainMenuButton): |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
26 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
27 def __init__(self, parent): |
79 | 28 super(NewGameButton, self).__init__(((WIDTH - self.WIDTH) / 2, |
29 (HEIGHT - self.HEIGHT) / 2 - self.HEIGHT), | |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
30 'Start New Game') |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
31 self.parent = parent |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
32 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
33 def on_click(self): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
34 self.parent.start_new_game() |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
35 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
36 |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
37 class ResumeGameButton(MainMenuButton): |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
38 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
39 def __init__(self, parent): |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
40 super(ResumeGameButton, self).__init__(((WIDTH - self.WIDTH) / 2, |
79 | 41 (HEIGHT - self.HEIGHT) / 2), 'Resume Game') |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
42 self.parent = parent |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
43 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
44 def on_click(self): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
45 self.parent.resume_game() |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
46 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
47 |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
48 class QuitButton(MainMenuButton): |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
49 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
50 def __init__(self): |
74
22b65c943712
prettified main menu - temp background
Rizmari Versfeld <rizziepit@gmail.com>
parents:
63
diff
changeset
|
51 super(QuitButton, self).__init__(((WIDTH - self.WIDTH) / 2, |
79 | 52 (HEIGHT - self.HEIGHT) / 2 + self.HEIGHT), 'Quit') |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
53 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
54 def on_click(self): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
55 pygame.event.post(pygame.event.Event(pygame.QUIT)) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
56 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
57 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
58 class MainMenu(Window): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
59 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
60 def __init__(self, screen): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
61 super(MainMenu, self).__init__(screen) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
62 self.game_window = None |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
63 self.resume = None |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
64 self.screen = screen |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
65 self.background_colour = (0, 0, 0) |
75 | 66 self.background_image = image.load(data.filepath('images/temp.jpg')) |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
67 button1 = NewGameButton(self) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
68 self.add_child(button1) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
69 button2 = QuitButton() |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
70 self.add_child(button2) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
71 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
72 def start_new_game(self): |
63
364ff3479ef2
Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents:
53
diff
changeset
|
73 self.game_window = LabWindow(self.screen) |
53
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
74 if not self.resume: |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
75 # Add the resume button |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
76 self.resume = ResumeGameButton(self) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
77 self.add_child(self.resume) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
78 AddWindow.post(self.game_window) |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
79 |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
80 def resume_game(self): |
655a6912e0ae
Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff
changeset
|
81 AddWindow.post(self.game_window) |