コード例 #1
0
    def __init__(self):
        self.config = assets.getData("config.json")
        self.scale = self.config["scale"]
        self.width = metrics.SCREEN_WIDTH * self.scale
        self.height = metrics.SCREEN_HEIGHT * self.scale

        fullscreen = 0
        if self.config["fullscreen"]:
            fullscreen = pygame.FULLSCREEN

        # Changing some of the mixer settings reduces the delay before playing sound effects
        pygame.mixer.pre_init(44100, -16, 2, 2048)
        pygame.init()
        pygame.display.set_caption("Cat Astro Fee")  # TODO: Come up with better name
        pygame.display.set_icon(pygame.image.load(assets.path("graphics/icon.png")))
        pygame.mouse.set_visible(False)
        self.display = pygame.display.set_mode((self.width, self.height), pygame.HWSURFACE | pygame.DOUBLEBUF | fullscreen)
        self.surface = pygame.Surface((metrics.SCREEN_WIDTH, metrics.SCREEN_HEIGHT), pygame.HWSURFACE)

        self.clock = pygame.time.Clock()

        inputs.init(self.config)

        statemgr.init()
        statemgr.switch("title")

        self.playing = True

        self.debug_mode = False
コード例 #2
0
ファイル: run.py プロジェクト: tobice/intellectual-snake
def loadDictionary():
    path = assets.path("dictionary")
    if not os.path.isfile(path):
        print("Unable to find the dictionary file in the assets folder!")
        sys.exit(1)

    dictionary = open(path, "r")
    words = dictionary.read().splitlines()
    dictionary.close()

    return words
コード例 #3
0
def play(filename):
    global current_music, previous_music, is_playing
    try:
        pygame.mixer.music.set_volume(assets._volume)
    except:
        print 'No mixer found'
    if filename != current_music:
        previous_music = current_music
        current_music = filename
        try:
            pygame.mixer.music.load(assets.path(filename))
            pygame.mixer.music.play(-1)
        except:
            print 'No music found for level.'
        is_playing = True
    else:
        if not is_playing:
            pygame.mixer.music.unpause()
コード例 #4
0
    def run(self):
        while self.playing:
            for event in pygame.event.get():
                self.playing = statemgr.event(event)

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_F12:
                        # Debug Mode
                        self.debug_mode = not self.debug_mode

                    if event.key == pygame.K_F2:
                        # Save a screenshot.  Simply uses the time stamp with some time removed for file name.
                        timestamp = str(int(time.time()) - 1382496589)
                        pygame.image.save(self.surface, assets.path("screenshots/screenshot" + timestamp + ".png"))

                    #if event.key == pygame.K_ESCAPE:
                        # Escape quits the game
                    #    self.playing = False

                if event.type == pygame.QUIT:
                    # X button
                    self.playing = False

            td = self.clock.tick(metrics.FPS)

            # Don't let frames take longer than 50 milliseconds to prevent objects
            # from falling through floors when dragging window.
            if td > 50:
                td = 50

            inputs.update()
            statemgr.update(td)
            statemgr.draw(self.surface)

            if self.debug_mode:
                statemgr.debug_draw(self.surface)

            # Scale up the screen for nice blocky pixels
            pygame.transform.scale(self.surface, (self.width, self.height), self.display)

            pygame.display.flip()

        pygame.quit()
コード例 #5
0
    def __init__(self, state, filename):
        self.state = state
        # Create Object Manager
        self.object_mgr = objectmgr.ObjectManager(self)

        # Load TMX file
        tmx = tmxlib.Map.open(assets.path(filename))

        # Initialize variables using TMX map properties
        # Properties used in maps are:
        #   name          - The name of the map
        #   script        - File name of custom script that should be used with map
        #   music         - The file name of the music that should play during the level
        #   camera_x      - Camera's starting x coordinate
        #   camera_y      - Camera's starting y coordinate
        #   camera_state  - State camera should start in
        #   camera_params - Parameters to initialize camera's state in dict format

        self.width, self.height = tmx.pixel_size

        self.properties = tmx.properties
        self.name = tmx.properties.get("name", "")
        self.script = tmx.properties.get("script")
        self.music = tmx.properties.get("music", "music.ogg")

        # Camera initialization properties
        self.camera = Camera(self, "camera", int(tmx.properties.get("camera_x", 0)), int(tmx.properties.get("camera_y", 0)))

        # TODO: Camera state (normal, follow, move to, etc.)
        # TODO: Camera state parameters

        # Generate tile map using TMX tile map data
        self.tilemap = tilemap.TileMap(tmx)

        # Pass TMX object data to Object Manager to generate objects
        self.object_mgr.createFromTMX(tmx)
コード例 #6
0
#!/usr/bin/env python

"""
This is just a scratchpad for testing little things.  Don't expect it to be in a runnable state.
"""

import tmxlib
import assets
import pygame
import tilemap

d = pygame.display.set_mode((480,270))

m = tmxlib.Map.open(assets.path("maps/test.tmx"))
t = tilemap.TileMap(m)

y=0
x=0

p = True
while p:
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            p = False

        if e.type == pygame.KEYDOWN:
            if e.key == pygame.K_DOWN:
                y -= 16
            if e.key == pygame.K_UP:
                y += 16
            if e.key == pygame.K_LEFT:
コード例 #7
0
 def gainFocus(self, previous, previous_name, *args, **kwargs):
     """What should be done when the state gets focus.  Previous is the state that had focus before this one."""
     music.play(assets.path("music/state_title.mp3"))
     pass