Exemplo n.º 1
0
 def image(self):
     """Draw the 2 images of the lighting"""
     if self._image:
         # memoized image
         return self._image
     phase = self._phase
     if phase==1:
         self._image = utils.load_image('lighting1.png', directory='miscellaneous')
         return self._image
     if phase==2:
         self._image = utils.load_image('lighting2.png', directory='miscellaneous')
         return self._image
Exemplo n.º 2
0
 def _load_images(self, img, weaponInAndOut):
     """Load images for this charas: 12 or 24 if used weaponInAndOut (so we need extra images without weapon)"""
     self.images = {}
     directory = self._imageDirectory
     if not weaponInAndOut:
         # 12 images
         self.images['walk_north_1'], self.images['head_north'], self.images['walk_north_2'], self.images['walk_east_1'], \
             self.images['head_east'], self.images['walk_east_2'], self.images['walk_south_1'], self.images['head_south'], \
             self.images['walk_south_2'], self.images['walk_west_1'], self.images['head_west'], \
             self.images['walk_west_2'] = utils.load_image(img, directory, charasFormatImage=True, weaponInAndOut=weaponInAndOut)
     else:
         # 24 images
         self.images['walk_north_1'], self.images['head_north'], self.images['walk_north_2'], self.images['walk_east_1'], \
             self.images['head_east'], self.images['walk_east_2'], self.images['walk_south_1'], self.images['head_south'], \
             self.images['walk_south_2'], self.images['walk_west_1'], self.images['head_west'], \
             self.images['walk_west_2'], \
             self.images['attack_north_1'], self.images['head_attack_north'], self.images['attack_north_2'], self.images['attack_east_1'], \
             self.images['head_attack_east'], self.images['attack_east_2'], self.images['attack_south_1'], self.images['head_attack_south'], \
             self.images['attack_south_2'], self.images['attack_west_1'], self.images['head_attack_west'], \
             self.images['attack_west_2'] = utils.load_image(img, directory, charasFormatImage=True, weaponInAndOut=weaponInAndOut)
Exemplo n.º 3
0
 def image(self):
     """Draw an image of the wave; image will change with time"""
     if self._image:
         # memoized image
         return self._image
     wave_phase = self._wave_phase
     if wave_phase==0:
         self._image = utils.load_image("water-wave1.png", "miscellaneous")
         self._wave_phase = 1
         return self._image
     if wave_phase==1:
         self._image = utils.load_image("water-wave2.png", "miscellaneous")
         self._wave_phase = 2            
         return self._image
     if wave_phase==2:
         self._image = utils.load_image("water-wave3.png", "miscellaneous")
         self._wave_phase = 3            
         return self._image
     if wave_phase==3:
         self._image = self.generateEmptySprite(self.rect.size, alpha=0)
         self._wave_phase = 0
         return self._image
Exemplo n.º 4
0
 def __init__(self, position, type, orientation, *containers):
     """Init the crate. You need specify the type of the crate, that will change the used image, and also the
     orientation (image can be rotated).
     @type: a integer number to be appended to the createXX.png filename.
     @orientation: an integer from 0 to 3, that rotate the image 90*value degree counterclockwise.
     """
     GameSprite.__init__(self, *containers)
     image = utils.load_image("crate%s.png" % type, directory="miscellaneous")
     if orientation:
         image = pygame.transform.rotate(image, 90*orientation)
     self.image = image
     self.position = position
     self.rect = pygame.Rect(position, image.get_size())
     self.rect.midbottom = position
Exemplo n.º 5
0
 def image(self):
     if self._image:
         # memoized image
         return self._image
     if self._type == LEVEL_TEXT_TYPE_BLACKSCREEN:
         srf = self.generateEmptySprite(self.rect.size, alpha=255 , fillWith=(0,0,0,0))
     else:
         w,h = self.rect.size
         #self.rect.move_ip(0,-V_DIFF)
         srf = self.generateEmptySprite( (w, h), alpha=220, fillWith=(0,0,0,0))
     
     for text, position, color in self._generatePage():
         text_to_display = cblocals.leveltext_font.render(_(text.decode('utf-8')), True, color)
         srf.blit(text_to_display, position)
     
     if self.colophon:
         bx,by = self.rect.bottomright
         srf.blit(utils.load_image('keul-software.png'), (bx-85,by-20) )
     
     self._image = srf
     return srf
Exemplo n.º 6
0
def menu():
    """Main menu"""
    pygame.display.set_caption("Cheese Boys (alpha release) %s" % cblocals.__version__)
    # Init game menu
    screen = cblocals.screen
    menu = kezmenu.KezMenu(
        [_(u"Start Game"), game],
        [_(u"Check for new version"), lambda: utils.update_version(screen, pygame.Rect( (50,230),(350,300) ))],
        [_(u"Quit"), game_over],
        )
    menu.font = cblocals.leveltext_font
    image = utils.load_image('cheese-boys-logo.png')
    
    menu.center_at(600, 300)
    menu.color = (255,255,255)
    menu.enableEffect('raise-col-padding-on-focus')    
    to_display = u'Cheese Boys'
    to_display_size = cblocals.main_title_font.size(to_display)
    title_text = cblocals.main_title_font.render(to_display, True, (252,252,112))
    text_start_pos_x, text_start_pos_y = (cblocals.SCREEN_SIZE[0]/2-to_display_size[0]/2, 100)
    
    clock = pygame.time.Clock()
    while True:
        time_passed = clock.tick() / 1000.
        events = pygame.event.get()
        menu.update(events, time_passed)

        for e in events:
            if e.type == pygame.QUIT:
                game_over()

        screen.fill((0, 0, 0))
        screen.blit(image, (text_start_pos_x-20-image.get_width(),text_start_pos_y) )
        screen.blit(title_text, (text_start_pos_x,text_start_pos_y) )
        menu.draw(screen)
        pygame.display.flip()
Exemplo n.º 7
0
 def __init__(self, position, size, *containers):
     GameSprite.__init__(self, *containers)
     self.rect = pygame.Rect(position, size)
     self.image = utils.load_image("codigoro-sign.png", "miscellaneous")
Exemplo n.º 8
0
 def __init__(self, position, size, *containers):
     GameSprite.__init__(self, *containers)
     self.x, self.y = position
     self.rect = pygame.Rect(position, size)
     self.image = utils.load_image("dark-large-stain.png", "miscellaneous")
Exemplo n.º 9
0
 def __init__(self, name, size, background=""):
     """Init a level object with a name and a size.
     If a background file name is given, this image is loaded as background.
     If you don't give a background then the level name (converted in a lowecase, less separated png file name)
     is used instead.
     If you really don't have a level image, please use a background parameter to None
     """
     GridMapSupport.__init__(self)
     self.name = name
     self.levelSize = size
     if background == '':
         background = name.lower().replace(" ","-")+".png"
     if background:
         self._background = utils.load_image(background, directory="levels")
     else:
         self._background = None
     self._topleft = (0,0)
     self._centeringSpeed = 50
     self._centeringHeading = None
     self._groups = []
     self._groups_toupdate = []
     self._groups_todraw = []
     self._rain = None
     self.screenReferenceSprite = None
     self.hero = None
     self.timeIn = 0.
     self.shadow = True
     
     # The presentation object running
     self.presentation = None
     self.level_text = None
     
     # This index will act on the ability of characters to hide in shadows in the level
     self.stealthLevel = 1.
     
     # Groups!
     all = GameGroup("all")
     dead = GameGroup("dead", drawable=True, updatable=True)
     physical = GameGroup("physical", drawable=True, updatable=True)
     # visual_obstacles are sprites that block character sight
     visual_obstacles = GameGroup("visual_obstacles")
     charas = GameGroup("charas")
     enemies = GameGroup("enemies")
     animations = GameGroup("animations", drawable=True, updatable=True)
     top_animations = GameGroup("top_animations", drawable=True, updatable=True)
     speech = GameGroup("speech", updatable=True)                                # speechs are handled in a special way
     level_text = GameGroup("level_text")
     exits = GameGroup("exits", drawable=True, updatable=True)
     triggers = GameGroup("triggers", drawable=True, updatable=True)
     tippable = GameGroup("tippable")                                            # Tips are handled in a special way
     self.addGroup(all)
     self.addGroup(dead, zindex=5)
     self.addGroup(physical, zindex=10)
     self.addGroup(visual_obstacles)
     self.addGroup(charas, zindex=10)
     self.addGroup(enemies)
     self.addGroup(animations, zindex=3)
     self.addGroup(top_animations, zindex=20)
     self.addGroup(speech)
     self.addGroup(level_text, zindex=30)
     self.addGroup(exits, zindex=3)
     self.addGroup(triggers, zindex=4)
     self.addGroup(tippable)
Exemplo n.º 10
0
def cheeseBoysInit():
    """Init of the engine"""    
    LOGLEVEL_CHOICES = ('ERROR','WARN','INFO', 'DEBUG')
    DARKNESS_CHOICES = ('on', 'off')
    usage = "usage: %prog [options] [arg]"
    p = optparse.OptionParser(usage=usage, description="Run the Cheese Boys game engine, or execute some other usefull utility instead if you give some of the options below.")
    p.add_option('--version', '-v', action='store_true', help='print software version then exit')
    p.add_option('--debug', '-d', action="store_true", help="Enable game debug mode (for develop and test purpose)")
    p.add_option('--logverbosity', '-l', default="WARN", action="store", choices=LOGLEVEL_CHOICES, help='set the game log verbosity, one of %s (default is ERROR)' % ",".join(LOGLEVEL_CHOICES), metavar="VERBOSITY")
    p.add_option('--tests', '-t', action='store_true', help='run all game unittests') 
    p.add_option('--fullscreen', '-f', action='store_true', help='load the game in fullscreen mode')
    p.add_option("--parse", "-p" , action='store_true', help=("parse a data file for dinamically change the content. See also -cbp options"
                                                              "You can also use the --timestamp option to begin begin operation only after found a specific timestamp"))
    p.add_option("--cbp", "-c" , dest="cbp_filename", help="Must be used in combination of -p option. Parse a .cbp file to change absolute timestamps with dinamical ones. ", metavar="FILE")
    p.add_option("--timestamp", dest="timestamp", help="Use this for other options that can require timestamp values", metavar="TIMESTAMP")

    options, arguments = p.parse_args()
    
    if options.version:
        print "Cheese Boys version %s" % cblocals.__version__
        exit()

    if options.logverbosity=="ERROR":
        logging.getLogger().setLevel(logging.ERROR)
    elif options.logverbosity=="WARN":
        logging.getLogger().setLevel(logging.WARN)
    elif options.logverbosity=="INFO":
        logging.getLogger().setLevel(logging.INFO)
    elif options.logverbosity=="DEBUG":
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        print "error: %s is an invalid option for --logverbosity option, use one of %s" % (options.logverbosity, ",".join(LOGLEVEL_CHOICES))  
        sys.exit(1)

    if options.tests:
        tests()
        exit()

    if options.fullscreen:
        cblocals.FULLSCREEN = True

    if options.parse:
        if not options.cbp_filename:
            print "error: The --parse parameter need also the use of --cbp option."
            sys.exit(1)
        else:
            from cheeseboys.presentation.presentation_parser import PresentationParser
            outFile = None
            if arguments:
                outFile = arguments[0]
            PresentationParser.replaceCbpFileAbsoluteTimestamps(options.cbp_filename, options.timestamp, outFile)
            sys.exit(0)

    cblocals.object_registry = UniqueObjectRegistry()

    # init of some pygame graphics stuff
    pygame.init()
    screen = handleFullScreen()
    pygame.display.set_icon(utils.load_image("cheese_icon.gif",simpleLoad=True))
    gettext.install('cheeseboys', 'data/i18n', unicode=1)

    if cblocals.SHADOW:
        cblocals.shadow_image = utils.load_image("lightray_1.png", "shadows", simpleLoad=True)
        cblocals.shadow_image.set_alpha(0, RLEACCEL)
        cblocals.total_shadow_image_09 = utils.load_image("total_dark_09.png", "shadows", simpleLoad=True)
        #cblocals.total_shadow_image_09.set_alpha(0, RLEACCEL)
        cblocals.total_shadow_image_05 = utils.load_image("total_dark_05.png", "shadows", simpleLoad=True)
        #cblocals.total_shadow_image_05.set_alpha(0, RLEACCEL)

    cblocals.default_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 12)
    cblocals.font_mini = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 10)
    cblocals.default_font_big = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 16)
    cblocals.speech_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 14)
    cblocals.leveltext_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_LEVELTEXT_FONT), 24)
    cblocals.main_title_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.MAIN_TITLE_FONT), 72)