Beispiel #1
0
    def __init__(self, parent, surface, text, vertical,
                 size=FONT_SIZE, color=FONT_COLOR):
        ## store the parent object
        self.parent = parent

        ## store the surface
        self.surface = surface

        ## store the text
        self.text = text

        ## store the color
        self.color = color

        ## store the vertical offset
        self.vertical = vertical

        ## set the font and size used for the text
        self.font = load_font(
            constants.FILES['fonts']['menu']['share'][3], size)

        # render the text with the appropriate attributes
        self.text = self.font.render(self.text, True, self.color)

        ## set the x coordinate (horizontally in the middle)
        self.x = (self.surface.get_width() - self.text.get_width()) / 2.0
Beispiel #2
0
def init():
    global fonts
    fonts = [ graphics.load_font('fonts/OFLGoudyStMTT.ttf', 16) for i in range(4) ]
    # fonts[2] is for tch tree => scaling it based on screen DPI
    fonts[2] = ui.load_font('fonts/OFLGoudyStMTT.ttf', 16)
    if osutil.is_android:
        init_flags()
Beispiel #3
0
    def __init__(self, parent, surface, text, vertical,
                 size=FONT_SIZE, color=FONT_COLOR):
        ## store the parent object
        self.parent = parent

        ## store the surface
        self.surface = surface

        ## store the text
        self.text = text

        ## store the color
        self.color = color

        ## store the vertical offset
        self.vertical = vertical

        ## set the font and size used for the text
        self.font = load_font(
            constants.FILES['fonts']['menu']['share'][3], size)

        # render the text with the appropriate attributes
        self.text = self.font.render(self.text, True, self.color)

        ## set the x coordinate (horizontally in the middle)
        self.x = (self.surface.get_width() - self.text.get_width()) / 2.0
Beispiel #4
0
def init():
    global fonts
    fonts = [
        graphics.load_font('fonts/OFLGoudyStMTT.ttf', 16) for i in range(4)
    ]
    # fonts[2] is for tch tree => scaling it based on screen DPI
    fonts[2] = ui.load_font('fonts/OFLGoudyStMTT.ttf', 16)
    if osutil.is_android:
        init_flags()
Beispiel #5
0
import pygame, sys
from graphics import Point, Rect, Color, Surface, load_bitmap, load_font, Patch9

box = Patch9(load_bitmap("gui/simple_box.png"))

font = load_font('proggy-tiny')

text = font('hello user.')

background = Color(0x10, 0, 0x50)
front = Color(0xA5, 0x56, 0x94)
red = Color(0xFF, 0x00, 0x00)

redfont = font.recolor(front)

redtext = redfont('hi.')
redbox = box.recolor(front)


def animation_frame(screen):
    background.paint(screen, screen.rect)
    front.paint(screen, front.rect.move(Point(10, 10)))
    box.paint(screen, screen.rect.inset(100, 10, 10, 10))
    text.paint(screen, text.rect.move(Point(200, 200)))
    redtext.paint(screen, redtext.rect.move(Point(200, 216)))
    redbox.paint(screen, redbox.rect.move(Point(200, 230)))


def dispatch(event):
    if event.type == pygame.QUIT:
        sys.exit(0)
Beispiel #6
0
import pygame
import graphics
import sys
from graphics import Color, Surface

font = graphics.load_font('proggy-tiny')

greeting = font("Hello world.")
background = Color(0x10, 0x30, 0x20)

def animation_frame(screen):
    background.paint(screen, screen.rect)
    greeting.paint(screen, greeting.rect.move(
        screen.rect.center - greeting.rect.center
    ))

def dispatch(event):
    if event.type == pygame.QUIT or event.type == pygame.KEYUP:
        sys.exit(0)

pygame.display.init()
screen = Surface(pygame.display.set_mode((320, 240)))
while 1:
    for event in pygame.event.get():
        dispatch(event)
    animation_frame(screen)
    pygame.display.flip()
Beispiel #7
0
    def __init__(self, game_opts):
        # initialize the state
        State.__init__(self, 'menu')

        ## the game's command line options
        self.game_opts = game_opts

        ## the screen surface
        self.screen = pygame.display.get_surface() 

        ## flag to control the settings menu's loop
        self.menu_settings_running = None

        ## flag to control the main menu's loop
        self.menu_main_running = True

        # enable key repeat for the menu
        pygame.key.set_repeat(MENU_KEY_DEL, MENU_KEY_INT)

        ## set the main menu's background
        self.menu_main_bg = graphics.load_image(
            constants.FILES['graphics']['menu']['main']['bg'][0])[0]

        ## set the settings menu's background
        self.menu_settings_bg = graphics.load_image(
            constants.FILES['graphics']['menu']['share']['bg'][0])[0]

        ## set the settings menu's background box
        self.menu_box_bg = graphics.load_image(
            constants.FILES['graphics']['menu']['settings']['box'][0])[0]

        ## set the window frame
        self.window_frame = graphics.load_image(
            constants.FILES['graphics']['menu']['share']['frame'][0])[0]

        ## set the mouse cursor
        self.mouse_cursor = graphics.load_image(
            constants.FILES['graphics']['menu']['share']['cursor'][0])[0]

        ## set the sound when a menu option is entered
        self.select_option_snd = sound_mixer.load_sound(
            constants.FILES['sounds']['menu']['share']['sel'][0])

        ## create the main menu - string, callback function
        self.menu_main = KezMenu(self.game_opts,
                         ['Play'     , self._play_option],
                         ['Settings' , self._settings_option],
                         ['Credits'  , self._credits_option],
                         ['Quit'     , self._quit_option])

        # set the position of the main menu
        self.menu_main.set_position(MENU_MAIN_POS_X, MENU_MAIN_POS_Y)

        # set the main menu's font
        self.menu_main.set_font(graphics.load_font(
            constants.FILES['fonts']['menu']['share'][0], 30))

        # set the main menu's highlight color
        self.menu_main.set_highlight_color(pygame.Color('brown'))

        ## create the settings menu - string, callback function
        self.menu_settings = KezMenu(self.game_opts,
                             ['Fullscreen' , self._toggle_fullscreen_option],
                             ['Sounds'     , self._toggle_sounds_option],
                             ['Music'      , self._toggle_music_option],
                             ['Back'       , self._back_option])

        # disable the menu graphic for focused options
        self.menu_settings.toggle_image()

        # set the settings menu's font
        self.menu_settings.set_font(graphics.load_font(
            constants.FILES['fonts']['menu']['share'][0], 25))

        # set the position of the settings menu
        self.menu_settings.center_at(constants.SCREEN_WIDTH / 2.0,
                                     constants.SCREEN_HEIGHT / 2.0)
    
        # set the settings menu's highlight color
        self.menu_settings.set_highlight_color(pygame.Color('orange'))

        ## the animated sprite group
        self.anim_sprites = pygame.sprite.RenderUpdates()

        # vertical sprite sample
        self.anim_sprites.add(VertAnimSprite(
                constants.FILES['graphics']['menu']['share']['anim'][0],
                [0, 0], ANIM_SPRITE_SPEED))

        # horizontal sprite sample
        self.anim_sprites.add(HorAnimSprite(
                constants.FILES['graphics']['menu']['share']['anim'][1],
                [0, 0], ANIM_SPRITE_SPEED))

        ## create clock and track time
        self.clock = pygame.time.Clock()
Beispiel #8
0
    def __init__(self, game_opts):
        # initialize the state
        State.__init__(self, constants.SCENES['menu'])

        ## the game's command line options
        self.game_opts = game_opts

        ## the screen surface
        self.screen = pygame.display.get_surface()

        ## flag to control the settings menu's loop
        self.menu_settings_running = None

        ## flag to control the main menu's loop
        self.menu_main_running = True

        # enable key repeat for the menu
        pygame.key.set_repeat(MENU_KEY_DEL, MENU_KEY_INT)

        ## set the main menu's background
        self.menu_main_bg = graphics.load_image(
            constants.FILES['graphics']['menu']['main']['bg'][0])[0]

        ## set the settings menu's background
        self.menu_settings_bg = graphics.load_image(
            constants.FILES['graphics']['menu']['share']['bg'][0])[0]

        ## set the settings menu's background box
        self.menu_box_bg = graphics.load_image(
            constants.FILES['graphics']['menu']['settings']['box'][0])[0]

        ## set the window frame
        self.window_frame = graphics.load_image(
            constants.FILES['graphics']['menu']['share']['frame'][0])[0]

        ## set the mouse cursor
        self.mouse_cursor = graphics.load_image(
            constants.FILES['graphics']['menu']['share']['cursor'][0])[0]

        ## set the sound when a menu option is entered
        self.select_option_snd = sound_mixer.load_sound(
            constants.FILES['sounds']['menu']['share']['sel'][0])

        ## create the main menu - string, callback function
        self.menu_main = KezMenu(self.game_opts, ['Play', self._play_option],
                                 ['Settings', self._settings_option],
                                 ['Credits', self._credits_option],
                                 ['Quit', self._quit_option])

        # set the position of the main menu
        self.menu_main.set_position(MENU_MAIN_POS_X, MENU_MAIN_POS_Y)

        # set the main menu's font
        self.menu_main.set_font(
            graphics.load_font(constants.FILES['fonts']['menu']['share'][0],
                               MAIN_FONT_SIZE))

        # set the main menu's highlight color
        self.menu_main.set_highlight_color(MAIN_FOCUS_COLOR)

        ## create the settings menu - string, callback function
        self.menu_settings = KezMenu(
            self.game_opts, ['Fullscreen', self._toggle_fullscreen_option],
            ['Sounds', self._toggle_sounds_option],
            ['Music', self._toggle_music_option], ['Back', self._back_option])

        # disable the menu graphic for focused options
        self.menu_settings.toggle_image()

        # set the settings menu's font
        self.menu_settings.set_font(
            graphics.load_font(constants.FILES['fonts']['menu']['share'][0],
                               MENU_FONT_SIZE))

        # set the position of the settings menu
        self.menu_settings.center_at(constants.SCREEN_WIDTH / 2.0,
                                     constants.SCREEN_HEIGHT / 2.0)

        # set the settings menu's highlight color
        self.menu_settings.set_highlight_color(SETTINGS_FOCUS_COLOR)

        ## the animated sprite group
        self.anim_sprites = pygame.sprite.RenderUpdates()

        # create the animated sprites
        sprite_num = len(constants.FILES['graphics']['menu']['share']['anim'])
        sprite_fact = SpriteFactory()
        for i in range(sprite_num):
            # create the "right" type of animated sprite using the factory
            r_sprite = sprite_fact.create_anim_sprite(
                i, constants.FILES['graphics']['menu']['share']['anim'][i],
                ANIM_SPRITE_SPEED)
            self.anim_sprites.add(r_sprite)

        ## create clock and track time
        self.clock = pygame.time.Clock()
Beispiel #9
0
def init():
    global fonts
    fonts = [ graphics.load_font('fonts/OFLGoudyStMTT.ttf', 15) for i in range(4) ]
    init_flags()
Beispiel #10
0
import pygame, sys
from graphics import Point, Rect, Color, Surface, load_bitmap, load_font, Patch9

box = Patch9(load_bitmap("gui/simple_box.png"))

font = load_font('proggy-tiny')

text = font('hello user.')

background = Color(0x10, 0, 0x50)
front = Color(0xA5, 0x56, 0x94)
red = Color(0xFF, 0x00, 0x00)

redfont = font.recolor(front)

redtext = redfont('hi.')
redbox = box.recolor(front)

def animation_frame(screen):
    background.paint( screen, screen.rect )
    front.paint( screen, front.rect.move(Point(10, 10)) ) 
    box.paint( screen, screen.rect.inset(100, 10, 10, 10) )
    text.paint( screen, text.rect.move(Point(200, 200)) )
    redtext.paint( screen, redtext.rect.move(Point(200, 216)) )
    redbox.paint( screen, redbox.rect.move(Point(200, 230)) )

def dispatch(event):
    if event.type == pygame.QUIT:
        sys.exit(0)

pygame.display.init()
Beispiel #11
0
def load_font(name, size):
    return graphics.load_font('fonts/ProcionoTT.ttf', size)
Beispiel #12
0
def load_font(name, size):
    return graphics.load_font('fonts/ProcionoTT.ttf', size)
Beispiel #13
0
import pygame
import graphics
import sys
from graphics import Color, Surface

font = graphics.load_font('proggy-tiny')

greeting = font("Hello world.")
background = Color(0x10, 0x30, 0x20)


def animation_frame(screen):
    background.paint(screen, screen.rect)
    greeting.paint(
        screen, greeting.rect.move(screen.rect.center - greeting.rect.center))


def dispatch(event):
    if event.type == pygame.QUIT or event.type == pygame.KEYUP:
        sys.exit(0)


pygame.display.init()
screen = Surface(pygame.display.set_mode((320, 240)))
while 1:
    for event in pygame.event.get():
        dispatch(event)
    animation_frame(screen)
    pygame.display.flip()
Beispiel #14
0
def load_font(name, size):
    if name is None:
        name = 'fonts/ProcionoTT.ttf'
    return graphics.load_font(name, scale_for_device(size))
    def __init__(self, game_opts):
        State.__init__(self, constants.SCENES['menu'])

        self.game_opts = game_opts
        self.screen = pygame.display.get_surface() 

        self.menu_settings_running = None
        self.menu_main_running = True

        pygame.key.set_repeat(MENU_KEY_DEL, MENU_KEY_INT)

        self.menu_main_bg = ResourceManager().getImage(
            constants.FILES['graphics']['menu']['main']['bg'][0])
        self.menu_settings_bg = ResourceManager().getImage(
            constants.FILES['graphics']['menu']['share']['bg'][0])
        self.menu_box_bg = ResourceManager().getImage(
            constants.FILES['graphics']['menu']['settings']['box'][0])
        self.window_frame = ResourceManager().getImage(
            constants.FILES['graphics']['menu']['share']['frame'][0])
        self.mouse_cursor = ResourceManager().getImage(
            constants.FILES['graphics']['menu']['share']['cursor'][0])

        self.select_option_snd = sound_mixer.load_sound(
            constants.FILES['sounds']['menu']['share']['sel'][0])

        # create the main menu - string, callback function
        self.menu_main = KezMenu(self.game_opts,
                         ['Play'     , self._play_option],
                         ['Settings' , self._settings_option],
                         ['Credits'  , self._credits_option],
                         ['Quit'     , self._quit_option])

        self.menu_main.set_position(MENU_MAIN_POS_X, MENU_MAIN_POS_Y)
        self.menu_main.set_font(graphics.load_font(
            constants.FILES['fonts']['menu']['share'][0], MAIN_FONT_SIZE))
        self.menu_main.set_highlight_color(MAIN_FOCUS_COLOR)

        # create the settings menu - string, callback function
        self.menu_settings = KezMenu(self.game_opts,
                             ['Fullscreen' , self._toggle_fullscreen_option],
                             ['Sounds'     , self._toggle_sounds_option],
                             ['Music'      , self._toggle_music_option],
                             ['Back'       , self._back_option])

        # disable the menu graphic for focused options
        self.menu_settings.toggle_image()

        self.menu_settings.set_font(graphics.load_font(
            constants.FILES['fonts']['menu']['share'][0], MENU_FONT_SIZE))
        self.menu_settings.center_at(constants.SCREEN_WIDTH / 2.0,
                                     constants.SCREEN_HEIGHT / 2.0)
        self.menu_settings.set_highlight_color(SETTINGS_FOCUS_COLOR)

        self.sprites = pygame.sprite.LayeredUpdates()

        sprites_number = len(constants.FILES['graphics']['menu']['share']['anim'])
        sprite_area = self.screen.get_rect()
        sprite_limiter = LimiterFactory().getInstance('Default')
        for i in range(sprites_number):
            sprite = MenuSprite(constants.FILES['graphics']['menu']['share']['anim'][i],
                                (sprite_area.center), i, MAX_ALPHA, False, SPRITE_SPEED,
                                sprite_area, 'Random')
            sprite.limiter = sprite_limiter
            self.sprites.add(sprite)

        self.clock = pygame.time.Clock()
Beispiel #16
0
    def __init__(self, game_opts):
        # initialize the state
        State.__init__(self, constants.SCENES["menu"])

        ## the game's command line options
        self.game_opts = game_opts

        ## the screen surface
        self.screen = pygame.display.get_surface()

        ## flag to control the settings menu's loop
        self.menu_settings_running = None

        ## flag to control the main menu's loop
        self.menu_main_running = True

        # enable key repeat for the menu
        pygame.key.set_repeat(MENU_KEY_DEL, MENU_KEY_INT)

        ## set the main menu's background
        self.menu_main_bg = graphics.load_image(constants.FILES["graphics"]["menu"]["main"]["bg"][0])[0]

        ## set the settings menu's background
        self.menu_settings_bg = graphics.load_image(constants.FILES["graphics"]["menu"]["share"]["bg"][0])[0]

        ## set the settings menu's background box
        self.menu_box_bg = graphics.load_image(constants.FILES["graphics"]["menu"]["settings"]["box"][0])[0]

        ## set the window frame
        self.window_frame = graphics.load_image(constants.FILES["graphics"]["menu"]["share"]["frame"][0])[0]

        ## set the mouse cursor
        self.mouse_cursor = graphics.load_image(constants.FILES["graphics"]["menu"]["share"]["cursor"][0])[0]

        ## set the sound when a menu option is entered
        self.select_option_snd = sound_mixer.load_sound(constants.FILES["sounds"]["menu"]["share"]["sel"][0])

        ## create the main menu - string, callback function
        self.menu_main = KezMenu(
            self.game_opts,
            ["Play", self._play_option],
            ["Settings", self._settings_option],
            ["Credits", self._credits_option],
            ["Quit", self._quit_option],
        )

        # set the position of the main menu
        self.menu_main.set_position(MENU_MAIN_POS_X, MENU_MAIN_POS_Y)

        # set the main menu's font
        self.menu_main.set_font(graphics.load_font(constants.FILES["fonts"]["menu"]["share"][0], MAIN_FONT_SIZE))

        # set the main menu's highlight color
        self.menu_main.set_highlight_color(MAIN_FOCUS_COLOR)

        ## create the settings menu - string, callback function
        self.menu_settings = KezMenu(
            self.game_opts,
            ["Fullscreen", self._toggle_fullscreen_option],
            ["Sounds", self._toggle_sounds_option],
            ["Music", self._toggle_music_option],
            ["Back", self._back_option],
        )

        # disable the menu graphic for focused options
        self.menu_settings.toggle_image()

        # set the settings menu's font
        self.menu_settings.set_font(graphics.load_font(constants.FILES["fonts"]["menu"]["share"][0], MENU_FONT_SIZE))

        # set the position of the settings menu
        self.menu_settings.center_at(constants.SCREEN_WIDTH / 2.0, constants.SCREEN_HEIGHT / 2.0)

        # set the settings menu's highlight color
        self.menu_settings.set_highlight_color(SETTINGS_FOCUS_COLOR)

        ## the animated sprite group
        self.anim_sprites = pygame.sprite.RenderUpdates()

        # create the animated sprites
        sprite_num = len(constants.FILES["graphics"]["menu"]["share"]["anim"])
        sprite_fact = SpriteFactory()
        for i in range(sprite_num):
            # create the "right" type of animated sprite using the factory
            r_sprite = sprite_fact.create_anim_sprite(
                i, constants.FILES["graphics"]["menu"]["share"]["anim"][i], ANIM_SPRITE_SPEED
            )
            self.anim_sprites.add(r_sprite)

        ## create clock and track time
        self.clock = pygame.time.Clock()