luxkun / unabomber

Bomberman clone

This URL has Read+Write access

luxkun (author)
Wed Dec 17 15:01:22 -0800 2008
commit  ce98d371adf7ec3cd58f5309c83873c92c785db2
tree    a9822cb3ae2d8ae3760f867a342c5b94a2f47704
parent  3d15959ef62701f948941de6aaf1962161021f32
unabomber / main.py
100644 108 lines (94 sloc) 4.172 kb
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
106
107
108
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2008 Ferraro Luciano (aka lux) <luciano.ferraro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pygame
 
import menu
import playground
 
class Core:
    running = True
    pause = False
    menu_mode = True
    def_res = (1280,1024)
    FPS = 90
    def __init__ (self, res):
        self.res = res
        if not self.res:
            self.res = self.def_res
        self.xscale = float(self.res[0])/self.def_res[0]
        self.yscale = float(self.res[1])/self.def_res[1]
        self.scale = min(self.xscale, self.yscale)
        
        pygame.init()
 
        self.screen = pygame.display.set_mode(self.res)
        pygame.display.set_caption("UnaBomber v1")
        
        self.menu = menu.Core(self, self.res, self.scale)
 
        self.clock = pygame.time.Clock()
        pygame.time.set_timer(pygame.USEREVENT, 1000)
    
    def redraw (self):
        self.screen.blit(self.background, self.background.get_rect())
    def clear (self, rects):
        for rect in rects:
            if not isinstance(rect, pygame.rect.Rect):
                rect = pygame.rect.Rect(rect[1], rect[1])
            self.screen.blit(self.background, rect, rect)
            
    def OnMenu (self, diff_level, level=0):
        self.diff_level = (diff_level, ("hard", "medium", "easy")[diff_level])
        self.menu_mode = False
        self.StartLevel(level)
        
    def StartLevel (self, level):
        self.playground = playground.Core(self, self.res, self.xscale,self.yscale,self.scale)
        
    def run (self):
        update_text = True
        self.background = pygame.transform.scale(pygame.image.load("sprites/background.png").convert_alpha(), self.res)
        self.redraw()
        pygame.display.flip()
        while self.running == True:
            #self.fps = int(self.clock.get_fps())
            if self.menu_mode:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        self.running = False
                    elif event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_ESCAPE:
                            self.running = False
                            continue
                        self.menu.OnKeyDown(event)
                self.menu.update()
                self.clear(self.menu.rects)
                self.menu.draw(self.screen)
            
            else:
                if not self.pause:
                    self.clear(self.playground.GetRects())
                
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        self.running = False
                    elif event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_ESCAPE:
                            self.running = False
                            continue
                        self.playground.OnKeyDown(event)
                    elif event.type == pygame.KEYUP:
                        self.playground.OnKeyUp(event)
                    elif (event.type == pygame.USEREVENT) and (not self.pause):
                        self.playground.OnDelayEvent(event)
                if not self.pause:
                    self.playground.Updates()
                    if update_text:
                        #update_text
                        pass
                        
                    self.playground.Draws()
                    pass
                
            pygame.display.flip()
            self.clock.tick(self.FPS)