Пример #1
0
    def __init__(self, fname=None, frame_width=0, frame_height=0):
        """Load image file, or create blank image, at frame size"""
        if fname:
            if fname in pre_loaded_images:
                self.bitmap = pre_loaded_images[fname]
            else:
                self.bitmap = pygame.image.load(
                    util.image_dir(fname)).convert()
                self.bitmap.set_colorkey((0, 0, 255), pygame.RLEACCEL)
                pre_loaded_images[fname] = self.bitmap
        else:
            self.bitmap = pygame.Surface((frame_width, frame_height))
            self.bitmap.fill((0, 0, 255))
            self.bitmap.set_colorkey((0, 0, 255), pygame.RLEACCEL)

        if frame_width == 0:
            frame_width = self.bitmap.get_width()
        if frame_height == 0:
            frame_height = self.bitmap.get_height()

        if frame_width > self.bitmap.get_width():
            frame_width = self.bitmap.get_width()
        self.fname = fname
        self.frame_width = frame_width
        self.frame_height = frame_height
Пример #2
0
def init():
    # Don't call init until after the display has been set.
    global INIT_DONE
    if not INIT_DONE:
        INIT_DONE = True
        global MENUFONT
        MENUFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 24 )
Пример #3
0
def main():
    pygame.init()
    pygame.display.set_caption("Dungeon Monkey Eternal","DMEternal")
    pygame.display.set_icon(pygame.image.load(util.image_dir("sys_icon.png")))
    # Set the screen size.
    if util.config.getboolean( "DEFAULT", "fullscreen" ):
        screen = pygame.display.set_mode( (0,0), pygame.FULLSCREEN )
    else:
        screen = pygame.display.set_mode( (800,600) )
    pygwrap.init()
    rpgmenu.init()

    screen_center_x = screen.get_width() // 2
    screen_center_y = screen.get_height() // 2

    rpm = rpgmenu.Menu( screen,screen_center_x-100,screen_center_y + 25,200,200,predraw=TitleScreenRedraw(screen) )

    rpm.add_item( "Create Character", chargen.make_and_save_character )
    rpm.add_item( "Load Campaign", load_campaign )
    rpm.add_item( "Start Endless Campaign", endless_start_campaign )
    #rpm.add_item( "Start Bardic Campaign", bardic_start_campaign )
    #rpm.add_item( "Start Gen1 Campaign", default_start_campaign )
    rpm.add_item( "Browse Characters", campaign.browse_pcs )
    #rpm.add_item( "Test Campaign Generator", test_campaign_generator )
    rpm.add_item( "Quit Game", None )

    cmd = True
    while cmd:
        cmd = rpm.query()
        if cmd:
            cmd( screen )
        if pygwrap.GOT_QUIT:
            break
Пример #4
0
def init():
    # Don't call init until after the display has been set.
    global INIT_DONE
    if not INIT_DONE:
        INIT_DONE = True
        pygwrap.init()
        global MENUFONT
        MENUFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 14 )
Пример #5
0
def init():
    global INIT_DONE
    if not INIT_DONE:
        global INPUT_CURSOR
        INPUT_CURSOR = image.Image( "sys_textcursor.png" , 8 , 16 )

        global SMALLFONT
        SMALLFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 12 )

        global TINYFONT
        TINYFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 9 )

        global ANIMFONT
        ANIMFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 16 )

        global ITALICFONT
        ITALICFONT = pygame.font.Font( util.image_dir( "VeraBI.ttf" ) , 12 )

        global BIGFONT
        BIGFONT = pygame.font.Font( util.image_dir( "Gamaliel.otf" ) , 23 )

        global POSTERS
        POSTERS += glob.glob( util.image_dir("poster_*.png") )

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        # Set key repeat.
        pygame.key.set_repeat( 200 , 75 )

        INIT_DONE = True
Пример #6
0
def init():
    global INIT_DONE
    if not INIT_DONE:
        global INPUT_CURSOR
        INPUT_CURSOR = image.Image("sys_textcursor.png", 8, 16)

        global SMALLFONT
        SMALLFONT = pygame.font.Font(util.image_dir("VeraBd.ttf"), 12)

        global TINYFONT
        TINYFONT = pygame.font.Font(util.image_dir("VeraBd.ttf"), 9)

        global ANIMFONT
        ANIMFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 16)

        global ITALICFONT
        ITALICFONT = pygame.font.Font(util.image_dir("VeraBI.ttf"), 12)

        global BIGFONT
        BIGFONT = pygame.font.Font(util.image_dir("Gamaliel.otf"), 23)

        global POSTERS
        POSTERS += glob.glob(util.image_dir("poster_*.png"))

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        # Set key repeat.
        pygame.key.set_repeat(200, 75)

        INIT_DONE = True
Пример #7
0
    def __init__( self, screen, border=pygwrap.default_border, predraw=None, fontSize=14 ):

        x = screen.get_width() // 2 - (ViewDrawer.WIDTH / 2)
        y = screen.get_height() // 2 - ViewDrawer.HEIGHT // 2 + 40 + pygwrap.BIGFONT.get_linesize() * 2
        w= ViewDrawer.WIDTH
        h = ViewDrawer.HEIGHT - pygwrap.BIGFONT.get_linesize() * 2

        super(DevMenu, self).__init__(x,y,w,h)

        self.screen = screen
        self.border = border
        self.MENUFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , fontSize)
        self.predraw = predraw
Пример #8
0
def main():
    pygame.init()
    pygame.display.set_caption("Dungeon Monkey Eternal", "DMEternal")
    pygame.display.set_icon(pygame.image.load(util.image_dir("sys_icon.png")))
    # Set the screen size.
    if util.config.getboolean("DEFAULT", "fullscreen"):
        screen = pygame.display.set_mode((800, 600))
        screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
    else:
        screen = pygame.display.set_mode((800, 600))
    rpgmenu.init()

    screen_center_x = screen.get_width() // 2
    screen_center_y = screen.get_height() // 2

    rpm = rpgmenu.Menu(screen,
                       screen_center_x - 100,
                       screen_center_y + 25,
                       200,
                       200,
                       predraw=TitleScreenRedraw(screen))

    rpm.add_item("Create Character", chargen.make_and_save_character)
    rpm.add_item("Load Campaign", load_campaign)
    rpm.add_item("Start Endless Campaign", endless_start_campaign)
    #rpm.add_item( "Start Bardic Campaign", bardic_start_campaign )
    #rpm.add_item( "Start Gen1 Campaign", default_start_campaign )
    rpm.add_item("Browse Characters", campaign.browse_pcs)
    rpm.add_item("Settings", load_settings)
    #rpm.add_item( "Test Campaign Generator", test_campaign_generator )
    rpm.add_item("Quit Game", None)

    cmd = True
    while cmd:
        cmd = rpm.query()
        if cmd:
            cmd(screen)
        if pygwrap.GOT_QUIT:
            break
Пример #9
0
def init(winname,appname,gamedir,icon="sys_icon.png"):
    global INIT_DONE
    if not INIT_DONE:
        util.init(appname,gamedir)

        pygame.init()
        pygame.display.set_caption(winname,appname)
        pygame.display.set_icon(pygame.image.load(util.image_dir(icon)))
        # Set the screen size.
        if util.config.getboolean( "DEFAULT", "fullscreen" ):
            my_state.screen = pygame.display.set_mode( (0,0), pygame.FULLSCREEN )
        else:
            my_state.screen = pygame.display.set_mode( (800,600), pygame.RESIZABLE )

        rpgmenu.init()

        global INPUT_CURSOR
        INPUT_CURSOR = image.Image( "sys_textcursor.png" , 8 , 16 )

        global SMALLFONT
        SMALLFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 12 )

        global TINYFONT
        TINYFONT = pygame.font.Font( util.image_dir( "VeraBd.ttf" ) , 9 )

        global ANIMFONT
        ANIMFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 16 )

        global ITALICFONT
        ITALICFONT = pygame.font.Font( util.image_dir( "VeraBI.ttf" ) , 12 )

        global POSTERS
        POSTERS += glob.glob( util.image_dir("poster_*.png") )

        global FPS
        FPS = util.config.getint( "DEFAULT", "frames_per_second" )
        pygame.time.set_timer(TIMEREVENT, 1000 / FPS)

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        # Set key repeat.
        pygame.key.set_repeat( 200 , 75 )

        INIT_DONE = True
Пример #10
0
    def __init__(self, fname=None, frame_width=0, frame_height=0):
        """Load image file, or create blank image, at frame size"""
        if fname:
            if fname in pre_loaded_images:
                self.bitmap = pre_loaded_images[fname]
            else:
                self.bitmap = pygame.image.load(util.image_dir(fname)).convert()
                self.bitmap.set_colorkey((0, 0, 255), pygame.RLEACCEL)
                pre_loaded_images[fname] = self.bitmap
        else:
            self.bitmap = pygame.Surface((frame_width, frame_height))
            self.bitmap.fill((0, 0, 255))
            self.bitmap.set_colorkey((0, 0, 255), pygame.RLEACCEL)

        if frame_width == 0:
            frame_width = self.bitmap.get_width()
        if frame_height == 0:
            frame_height = self.bitmap.get_height()

        if frame_width > self.bitmap.get_width():
            frame_width = self.bitmap.get_width()
        self.fname = fname
        self.frame_width = frame_width
        self.frame_height = frame_height
Пример #11
0
    for t in range(100):
        nart = narrator.Narrative(
            camp, narrator.plots.PlotState(rank=t % 5 + 1), adv_type="SHORTIE", start_rank=t % 5 + 1, end_rank=5
        )
        # nart.build()
        print t

    for p in narrator.UNSORTED_PLOT_LIST:
        if p._used > 0:
            print "{} [{}]".format(p, p._used)


if __name__ == "__main__":
    pygame.init()
    pygame.display.set_caption("Dungeon Monkey Eternal", "DMEternal")
    pygame.display.set_icon(pygame.image.load(util.image_dir("sys_icon.png")))
    # Set the screen size.
    if util.config.getboolean("DEFAULT", "fullscreen"):
        screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
    else:
        screen = pygame.display.set_mode((800, 600))
    pygwrap.init()
    rpgmenu.init()

    screen_center_x = screen.get_width() // 2
    screen_center_y = screen.get_height() // 2

    rpm = rpgmenu.Menu(screen, screen_center_x - 100, screen_center_y + 25, 200, 200, predraw=TitleScreenRedraw(screen))

    rpm.add_item("Create Character", chargen.make_and_save_character)
    rpm.add_item("Load Campaign", load_campaign)
Пример #12
0
def test_campaign_generator( screen ):
    camp = campaign.Campaign()
    for t in range( 100 ):
        nart = narrator.Narrative( camp, narrator.plots.PlotState(rank=t%5+1), adv_type="SHORTIE",start_rank=t%5+1, end_rank=5 )
        #nart.build()
        print t

    for p in narrator.UNSORTED_PLOT_LIST:
        if p._used > 0:
            print "{} [{}]".format( p, p._used )

if __name__=='__main__':
    pygame.init()
    pygame.display.set_caption("Dungeon Monkey Eternal","DMEternal")
    pygame.display.set_icon(pygame.image.load(util.image_dir("sys_icon.png")))
    # Set the screen size.
    if util.config.getboolean( "DEFAULT", "fullscreen" ):
        screen = pygame.display.set_mode( (0,0), pygame.FULLSCREEN )
    else:
        screen = pygame.display.set_mode( (800,600) )
    pygwrap.init()
    rpgmenu.init()

    screen_center_x = screen.get_width() // 2
    screen_center_y = screen.get_height() // 2

    rpm = rpgmenu.Menu( screen,screen_center_x-100,screen_center_y + 25,200,200,predraw=TitleScreenRedraw(screen) )

    rpm.add_item( "Create Character", chargen.make_and_save_character )
    rpm.add_item( "Load Campaign", load_campaign )
Пример #13
0
import pygame
import random
import util
import collections

if __name__=='__main__':
    import random

    # Set the screen size.
    screen = pygame.display.set_mode( (432,432) )

    # Analyze the sample.
    sample = pygame.image.load( util.image_dir( "sample.png" ) ).convert()

    # There are two ways to try and copy a terrain texture- the first is just
    # to apply random colors with the same frequency as the sample. The second
    # is to use a left to right markov chain generator to decide on pixel colors.
    spots = []
    mc_spots = collections.defaultdict( list )

    last_a,last_b,last_c = (0,0,0,255),(0,0,0,255),(0,0,0,255)

    for y in range( sample.get_height() ):
        for x in range( sample.get_width() ):
            c = tuple( sample.get_at( (x,y) ) )
            if c != (0,0,0,255):
                spots.append( c )
                mc_spots[(last_a,last_b,last_c)].append(c)
                last_a,last_b,last_c = last_b,last_c,c

    spots = spots * 100
Пример #14
0
def init(winname,appname,gamedir,icon="sys_icon.png",poster_pattern="poster_*.png"):
    global INIT_DONE
    if not INIT_DONE:
        util.init(appname,gamedir)
        # Init image.py
        image.init_image(util.image_dir(""))

        pygame.init()
        pygame.mixer.init()
        pygame.display.set_caption(winname,appname)
        pygame.display.set_icon(pygame.image.load(util.image_dir(icon)))
        # Set the screen size.
        if util.config.getboolean( "GENERAL", "fullscreen" ):
            my_state.screen = pygame.display.set_mode( (0,0), pygame.FULLSCREEN )
        else:
            my_state.screen = pygame.display.set_mode( (800,600), pygame.RESIZABLE )

        global INPUT_CURSOR
        INPUT_CURSOR = image.Image( "sys_textcursor.png" , 8 , 16 )

        global SMALLFONT
        SMALLFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 12 )
        my_state.small_font = SMALLFONT

        global TINYFONT
        TINYFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 9 )
        my_state.tiny_font = TINYFONT

        global ANIMFONT
        ANIMFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 16 )
        my_state.anim_font = ANIMFONT

        global MEDIUMFONT
        MEDIUMFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-Bold.ttf" ) , 14 )
        my_state.medium_font = MEDIUMFONT


        global ITALICFONT
        ITALICFONT = pygame.font.Font( util.image_dir( "DejaVuSansCondensed-BoldOblique.ttf" ) , 12 )

        global BIGFONT
        BIGFONT = pygame.font.Font( util.image_dir( "Anita semi square.ttf" ) , 16 )
        my_state.big_font = BIGFONT

        my_state.huge_font = pygame.font.Font( util.image_dir( "Anita semi square.ttf" ) , 24 )

        global POSTERS
        POSTERS += glob.glob( util.image_dir(poster_pattern) )

        global FPS
        FPS = util.config.getint( "GENERAL", "frames_per_second" )
        pygame.time.set_timer(TIMEREVENT, 1000 / FPS)

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        # Set key repeat.
        pygame.key.set_repeat( 200 , 75 )

        INIT_DONE = True
Пример #15
0
import os, re, random
import weakref

import pygame
import pygame.surfarray as surfarray # FIXME: fall back gracefully
surfarray.use_arraytype('numpy')
import numpy as np

import lru
import util
import yaml

# Cache of recolored images: keep them around as long as they're in use
_images = weakref.WeakValueDictionary()
_image_dir = util.image_dir()
# Use LRU to make sure the weakref deletion isn't too aggressive
@lru.cache()
def get(name, recoloring = None, rect = None):
    if (name, recoloring, rect) not in _images:
        print "Looking up image for", (name, recoloring, rect)
        if rect is not None:
            i = get(name,recoloring).subsurface(rect)
        elif recoloring is not None:
            i = recolor(get(name),recoloring)
        else:
            i = pygame.image.load(os.path.join(_image_dir,name))
            # Colorkey has no effect if the image already has alpha
            i.set_colorkey((0,0,255))
            i = i.convert_alpha(pygame.Surface((1,1), pygame.SRCALPHA, 32))
        _images[(name,recoloring,rect)] = i
Пример #16
0
def init(winname,
         appname,
         gamedir,
         icon="sys_icon.png",
         poster_pattern="poster_*.png"):
    global INIT_DONE
    if not INIT_DONE:
        util.init(appname, gamedir)

        pygame.init()
        pygame.mixer.init()
        pygame.display.set_caption(winname, appname)
        pygame.display.set_icon(pygame.image.load(util.image_dir(icon)))
        # Set the screen size.
        if util.config.getboolean("DEFAULT", "fullscreen"):
            my_state.screen = pygame.display.set_mode((0, 0),
                                                      pygame.FULLSCREEN)
        else:
            my_state.screen = pygame.display.set_mode((800, 600),
                                                      pygame.RESIZABLE)

        global INPUT_CURSOR
        INPUT_CURSOR = image.Image("sys_textcursor.png", 8, 16)

        global SMALLFONT
        SMALLFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 12)
        my_state.small_font = SMALLFONT

        global TINYFONT
        TINYFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 9)
        my_state.tiny_font = TINYFONT

        global ANIMFONT
        ANIMFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 16)
        my_state.anim_font = ANIMFONT

        MEDIUMFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Bold.ttf"), 14)
        my_state.medium_font = MEDIUMFONT

        global ITALICFONT
        ITALICFONT = pygame.font.Font(
            util.image_dir("DejaVuSansCondensed-Oblique.ttf"), 12)

        global BIGFONT
        BIGFONT = pygame.font.Font(util.image_dir("Anita semi square.ttf"), 16)
        my_state.big_font = BIGFONT

        my_state.huge_font = pygame.font.Font(
            util.image_dir("Anita semi square.ttf"), 24)

        global POSTERS
        POSTERS += glob.glob(util.image_dir(poster_pattern))

        global FPS
        FPS = util.config.getint("DEFAULT", "frames_per_second")
        pygame.time.set_timer(TIMEREVENT, 1000 / FPS)

        if android:
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

        # Set key repeat.
        pygame.key.set_repeat(200, 75)

        INIT_DONE = True