File: gamewin.py

package info (click to toggle)
solarwolf 1.5%2Bdfsg1-3
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 3,592 kB
  • sloc: python: 5,349; ansic: 159; makefile: 100; pascal: 50; sh: 27
file content (105 lines) | stat: -rw-r--r-- 2,594 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"gamemenu handler. main menu"

import math, os
import pygame
from pygame.locals import *
import game, gfx, snd, txt
import gameplay, gamemenu, players



cheer = (
    'Congratulations!',
    'You Beat The Game!',
    ' ',
    'The known galaxy is once again safe',
    'from the unsightly Power Cubes blocking',
    'everyone\'s clear view of space. The',
    'deadly Guardian\'s plan of a littered skyline',
    'has been foiled by your cunning and skill.',
    '',
    'We can only hope that one day this threat',
    'never returns, or the power of the SolarWolf',
    'will once again be put to the test.',
)


fonts = []

def load_game_resources():
    global fonts
    fontname = None
    fonts.append(txt.Font(fontname, 28))
    snd.preload('select_choose')


class GameWin:
    def __init__(self, prevhandler):
        self.prevhandler = prevhandler
        self.done = 0
        self.top = 20
        self.center = gfx.rect.centerx
        self.text = []
        self.time = 0.0
        font = fonts[0]
        for line in cheer:
            img, r = font.text((250, 250, 250), line, (self.center, self.top))
            self.top += 30
            self.text.append((img, r))
        self.g = gamemenu.boximages
        self.y = gamemenu.yboximages
        self.r = gamemenu.rboximages



    def quit(self):
        if not game.player:
            game.player = players.Player("NONAME")
        players.make_winner(game.player)

        game.handler = self.prevhandler
        self.done = 1
        snd.play('select_choose')

        r = self.r[0].get_rect()
        gfx.dirty(self.background(r.move(50, 400)))
        gfx.dirty(self.background(r.move(300, 400)))
        gfx.dirty(self.background(r.move(550, 400)))


    def input(self, i):
        if self.time > 30.0:
            self.quit()

    def event(self, e):
        pass


    def run(self):
        for cred in self.text:
            r = cred[1]
            self.background(r)
            gfx.dirty(r)

        ratio = game.clockticks / 25
        speedadjust = max(ratio, 1.0)
        self.time += speedadjust

        gfx.updatestars(self.background, gfx)

        if not self.done:
            frame = int(self.time * .5) % len(self.r)
            surf = gfx.surface
            gfx.dirty(surf.blit(self.g[frame], (50, 400)))
            gfx.dirty(surf.blit(self.y[frame], (300, 400)))
            gfx.dirty(surf.blit(self.r[frame], (550, 400)))

            for cred, pos in self.text:
                gfx.surface.blit(cred, pos)


    def background(self, area):
        return gfx.surface.fill((0, 0, 0), area)