def load(self):
        pauseImage = sdl.image.load("graphics/states/options.png")
        cursor = sdl.image.load("graphics/sprites/chef_idle_stroke.png")
        blueImage = sdl.image.load("graphics/states/options_indicator.png")

        global optionsTexture
        optionsTexture = driver.renderer.createTextureFromSurface(pauseImage)
        sdl.freeSurface(pauseImage)

        global cursorTexture
        cursorTexture = driver.renderer.createTextureFromSurface(cursor)
        sdl.freeSurface(cursor)

        global indTexture
        indTexture = driver.renderer.createTextureFromSurface(blueImage)
        sdl.free(blueImage)

        global scrollSound, selectSound
        sdl.mixer.allocateChannels(2)
        scrollSound = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile("music//chunks/menu_scroll.wav", 'rw'), 0)
        selectSound = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile("music//chunks/menu_select.wav", 'rw'), 0)

        global boxes
        boxes = []
        boxes.append(MouseBox(225, 190, 260, 115, 'levelZero', 0))
        boxes.append(MouseBox(225, 305, 305, 115, 'pvp', 1))
        boxes.append(MouseBox(225, 420, 305, 115, 'highScore', 2))

        global volumeBoxes
        volumeBoxes = []
        for x in range(10):
            volumeBoxes.append(
                MouseBox(280 + 25 * x, 242, 18, 18, x + 1, x + 1))
    def load(self):
        pauseImage = sdl.image.load("graphics/states/pause_menu.png")
        cursor = sdl.image.load("graphics/sprites/chef_idle_stroke.png")

        global pauseTexture
        pauseTexture = driver.renderer.createTextureFromSurface(pauseImage)
        sdl.freeSurface(pauseImage)

        global cursorTexture
        cursorTexture = driver.renderer.createTextureFromSurface(cursor)
        sdl.freeSurface(cursor)

        global scrollSound, selectSound
        sdl.mixer.allocateChannels(2)
        scrollSound = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile("music//chunks/menu_scroll.wav", 'rw'), 0)
        selectSound = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile("music//chunks/menu_select.wav", 'rw'), 0)

        global boxes
        boxes = []
        boxes.append(MouseBox(245, 220, 260, 60, 'resume', 0))
        boxes.append(MouseBox(245, 280, 320, 60, 'options', 1))
        boxes.append(MouseBox(245, 340, 260, 60, 'controls', 2))
        boxes.append(MouseBox(245, 400, 260, 60, 'quit', 3))
  def load(self):

                background = sdl.image.load("graphics/states/menu.png")
                global textureBG
                textureBG = driver.renderer.createTextureFromSurface(background)
                sdl.freeSurface(background)

                cursor = sdl.image.load("graphics/sprites/chef_idle_stroke.png")
                global cursorTexture
                cursorTexture = driver.renderer.createTextureFromSurface(cursor)
                sdl.freeSurface(cursor)

                global music
                music = sdl.mixer.loadMUS("music/songs/menu_screen.mod")
                global scrollSound, selectSound
                sdl.mixer.allocateChannels(2)
                scrollSound = sdl.mixer.loadWAV_RW(sdl.RWFromFile("music//chunks/menu_scroll.wav", 'rw'), 0)
                selectSound = sdl.mixer.loadWAV_RW(sdl.RWFromFile("music//chunks/menu_select.wav", 'rw'), 0)
                global boxes
                boxes = []
                boxes.append(MouseBox(245,160,260,60, 'levelZero', 0))
                boxes.append(MouseBox(245, 280, 260, 60, 'highScore', 1))
                boxes.append(MouseBox(245, 340, 260, 60, 'options', 2))
                boxes.append(MouseBox(245, 400, 260, 60, 'controls', 3))
                boxes.append(MouseBox(245, 460, 260, 60, 'quit', 4))
Beispiel #4
0
def LoadTexture(renderer, file, transparent):
    # Load the sprite image
    rwops = sdl.RWFromFile(file, 'r')
    temp = sdl.loadBMP_RW(rwops, True)
    if temp == ffi.NULL:
        sys.stderr.write("Couldn't load %s: %s\n" % (file, sdl.getError()))
        return None

    # Set transparent pixel as the pixel at (0,0)
    if transparent:
        if temp.format.palette:
            sdl.setColorKey(temp, True, ffi.cast("uint8_t *", temp.pixels)[0])
        else:
            # TODO ffi.cast to correct-width type
            bpp = temp.format.BitsPerPixel
            if bbp == 15:
                sdl.setColorKey(temp, True, temp.pixels[0] & 0x00007FFF)
            elif bpp == 16:
                sdl.setColorKey(temp, sdl.TRUE, temp.pixels[0])
            elif bpp == 24:
                sdl.setColorKey(temp, True, temp.pixels[0] & 0x00FFFFFF)
            elif bpp == 32:
                sdl.setColorKey(temp, True, temp.pixels[0])

    # Create textures from the image
    texture = sdl.createTextureFromSurface(renderer, temp)
    sdl.freeSurface(temp)
    if not texture:
        sys.stderr.write("Couldn't create texture: %s\n" % (sdl.getError()))
        return None

    # We're ready to roll. :)
    return texture
    def load(self):
        time = sdl.getTicks()

        # driver.loading.load()

        global music
        global ratDyingSound, getOut, hitGeneric, woosh
        global hit
        global ladleHit
        global story1, story2
        story1 = Story(1)
        story2 = Story(2)
        story1.load()
        story2.load()
        story1.run()

        # driver.loading.run()

        # assigning music channels

        sdl.mixer.allocateChannels(5)
        music = sdl.mixer.loadMUS('music/songs/level1music.xm')
        ratDyingSound = \
            sdl.mixer.loadWAV_RW(sdl.RWFromFile('music/chunks/rat_death.mp3'
                                 , 'rw'), 0)
        getOut = \
            sdl.mixer.loadWAV_RW(sdl.RWFromFile('music/chunks/get_out_you_dirty_rats.wav'
                                 , 'rw'), 0)

        hit = []
        for i in range(3):
            hit.append(
                sdl.mixer.loadWAV_RW(
                    sdl.RWFromFile('music/chunks/hit' + str(i) + '.wav', 'rw'),
                    0))
        ladleHit = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/ladle_hit.wav', 'rw'), 0)
        hitGeneric = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/hit.wav', 'rw'), 0)
        woosh = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/woosh.wav', 'rw'), 0)

        ratImages = [
            sdl.image.load('graphics/sprites/rat_hurt.png'),  #0
            sdl.image.load('graphics/sprites/rat_up.png'),
            sdl.image.load('graphics/sprites/rat_right.png'),  #2
            sdl.image.load('graphics/sprites/rat_down.png'),
            sdl.image.load('graphics/sprites/rat_left.png'),  #4
            sdl.image.load('graphics/sprites/rat_attack_up.png'),
            sdl.image.load('graphics/sprites/rat_attack_right.png'),  #6
            sdl.image.load('graphics/sprites/rat_attack_down.png'),
            sdl.image.load('graphics/sprites/rat_attack_left.png'),  #8
            sdl.image.load('graphics/items/cheese.png'),
            sdl.image.load('graphics/ui/light.png'),  #10
        ]

        # array of tiles used throughout the map

        mapImages = []
        for x in range(1, 32):
            mapImages.append(sdl.image.load('graphics/map/' + str(x) + '.png'))

        objectImages = []
        objectImages.append(
            sdl.image.load('graphics/items/pizza_animation.png'))
        objectImages.append(
            sdl.image.load('graphics/items/heart_animation.png'))
        objectImages.append(
            sdl.image.load('graphics/items/carrot_animation.png'))
        objectImages.append(sdl.image.load('graphics/items/key_animation.png'))

        weaponImages = []
        weaponImages.append(sdl.image.load('graphics/items/ladles.png'))
        weaponImages.append(sdl.image.load('graphics/items/graters.png'))

        pantryImages = [
            sdl.image.load('graphics/items/open_pantry.png'),
            sdl.image.load('graphics/items/pantry_open.png'),
            sdl.image.load('graphics/messages/press_open.png'),
            sdl.image.load('graphics/items/open_pantry_key.png'),
            sdl.image.load('graphics/messages/found_key.png'),
            sdl.image.load('graphics/messages/basement_locked.png'),
        ]

        pantryTextures = []
        for x in range(len(pantryImages)):
            pantryTextures.append(
                driver.renderer.createTextureFromSurface(pantryImages[x]))
            sdl.freeSurface(pantryImages[x])

    # creates an array of arrays of integrets that represents our map's floor

        global map
        map = []
        with open('data/map.txt') as f:
            for line in f:
                currentLine = []
                split = line.split()
                for value in line.split():
                    currentLine.append(int(value))
                map.append(currentLine)

    # fill up the objects array which contains the objects that can be collided with

        global structures
        structures = []
        count = 0
        for j in range(len(map)):
            for i in range(len(map[j])):
                value = map[j][i]
                if value is 27:
                    if count is 0:
                        struct = Structure(
                            value,
                            i,
                            j,
                            pantryTextures,
                            True,
                            'pantry',
                        )
                        count += 1
                    else:
                        struct = Structure(
                            value,
                            i,
                            j,
                            pantryTextures,
                            False,
                            'pantry',
                        )
                    structures.append(struct)
                elif value is (2 or 3):
                    structures.append(
                        Structure(
                            value,
                            i,
                            j,
                            pantryTextures,
                            False,
                            'stairs',
                        ))
                elif value is not 1:
                    structures.append(
                        Structure(
                            value,
                            i,
                            j,
                            None,
                            False,
                            None,
                        ))

        #a graph of every tile mapped to every one of its neighbors

        self.navGraph = navGraph.navGraph(map, {1}, 1)

        # for now just stuff that's dropped by the rats

        global objects
        objects = []

        global objectTextures
        objectTextures = []
        for x in range(len(objectImages)):
            objectTextures.append(
                driver.renderer.createTextureFromSurface(objectImages[x]))
            sdl.freeSurface(objectImages[x])
        for x in range(len(weaponImages)):
            objectTextures.append(
                driver.renderer.createTextureFromSurface(weaponImages[x]))
            sdl.freeSurface(weaponImages[x])

        global ratTextures
        ratTextures = []
        for x in range(len(ratImages)):
            ratTextures.append(
                driver.renderer.createTextureFromSurface(ratImages[x]))
            sdl.freeSurface(ratImages[x])

        global mapTextures
        mapTextures = []
        for x in range(len(mapImages)):
            mapTextures.append(
                driver.renderer.createTextureFromSurface(mapImages[x]))
            sdl.freeSurface(mapImages[x])

        driver.scoreBoard.clearScore()
        driver.scoreBoard.updateScore(100000)
    def run(self, itemName):
        sdl.mixer.volume(-1, driver.volume)
        sdl.mixer.volumeMusic(driver.volume)

        running = True
        currentTime = 0
        lastTime = 0
        time = 0

        keepOnPlaying = True

        event = sdl.Event()

        sdl.mixer.allocateChannels(2)
        selectSound = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile("music//chunks/menu_select.wav", 'rw'), 0)
        cur = 0
        if itemName is "bsv":
            cur = 0
        elif itemName is "key":
            cur = 1
        elif itemName is "ladles":
            cur = 2
        elif itemName is "graters":
            cur = 3
        elif itemName is "carrot":
            cur = 4
        elif itemName is "pizza":
            cur = 5
        elif itemName is "tomato":
            cur = 6
        elif itemName is "knives":
            cur = 7

        while running:

            #### TIME MANAGEMENT ####
            currentTime = sdl.getTicks()
            dt = currentTime - lastTime
            time += dt
            lastTime = currentTime

            #### TEXTURE MEASUREMENTS ####
            textureW, textureH = game.textureSize(driver.chef.textures[3][cur])
            textureRect = game.centeredRect(game.width, game.height, textureW,
                                            textureH)
            sdl.renderClear(driver.renderer)
            self.camera.display(time, dt, False, None)
            sdl.renderCopy(driver.renderer, driver.chef.textures[3][cur], None,
                           textureRect)
            sdl.renderPresent(driver.renderer)

            #### HANDLE INPUT ####
            while sdl.pollEvent(event):
                if event.type == sdl.QUIT:
                    running = False
                    game.turnOff()
                    keepOnPlaying = False
                elif event.type == sdl.KEYUP:
                    if event.key.keysym.sym in [sdl.K_q, sdl.K_ESCAPE]:
                        running = False
                        game.turnOff()
                        keepOnPlaying = False
                if event.type == sdl.KEYDOWN:
                    if event.key.keysym.sym is sdl.K_SPACE:
                        sdl.mixer.playChannel(0, selectSound, 0)
                        running = False
                        keepOnPlaying = True

#### RENDER ####

                if not running:
                    return keepOnPlaying
        sdl.renderClear(driver.renderer)
        if selectSound is not None:
            sdl.mixer.freeChunk(selectSound)
Beispiel #7
0
    def load(self):
        time = sdl.getTicks()

        # driver.loading.load()

        global music
        global hit
        global ladleHit, graterHit, hitGeneric
        global explosionSound
        global ratDyingSound, woosh
        global haveCarrot, needCarrot

        # driver.loading.run()

        story = Story(3)
        story.load()
        story.run()

        sdl.mixer.allocateChannels(4)
        music = sdl.mixer.loadMUS('music/songs/2.mod')
        hit = []
        for i in range(3):
            hit.append(
                sdl.mixer.loadWAV_RW(
                    sdl.RWFromFile('music/chunks/hit' + str(i) + '.wav', 'rw'),
                    0))
        explosionSound = \
            sdl.mixer.loadWAV_RW(sdl.RWFromFile('music/chunks/explosion.wav'
                                 , 'rw'), 0)
        ratDyingSound = \
            sdl.mixer.loadWAV_RW(sdl.RWFromFile('music/chunks/rat_death.mp3'
                                 , 'rw'), 0)
        haveCarrot = \
            sdl.mixer.loadWAV_RW(sdl.RWFromFile('music/chunks/carrot_lets_me_see.wav'
                                 , 'rw'), 0)
        needCarrot = \
            sdl.mixer.loadWAV_RW(sdl.RWFromFile('music/chunks/need_a_carrot.wav'
                                 , 'rw'), 0)
        ladleHit = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/ladle_hit.wav', 'rw'), 0)
        graterHit = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/grater_hit.wav', 'rw'), 0)
        hitGeneric = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/hit.wav', 'rw'), 0)
        woosh = sdl.mixer.loadWAV_RW(
            sdl.RWFromFile('music/chunks/woosh.wav', 'rw'), 0)

        ratImages = [
            sdl.image.load('graphics/sprites/rat_hurt.png'),
            sdl.image.load('graphics/sprites/rat_up.png'),
            sdl.image.load('graphics/sprites/rat_right.png'),
            sdl.image.load('graphics/sprites/rat_down.png'),
            sdl.image.load('graphics/sprites/rat_left.png'),
            sdl.image.load('graphics/sprites/rat_attack_up.png'),
            sdl.image.load('graphics/sprites/rat_attack_right.png'),
            sdl.image.load('graphics/sprites/rat_attack_down.png'),
            sdl.image.load('graphics/sprites/rat_attack_left.png'),
            sdl.image.load('graphics/items/cheese.png'),
        ]

        # array of tiles used throughout the map

        mapImages = []
        for x in range(1, 32):
            mapImages.append(
                sdl.image.load('graphics/map/level_2/' + str(x) + '.png'))

        objectImages = []
        objectImages.append(
            sdl.image.load('graphics/items/pizza_animation.png'))
        objectImages.append(
            sdl.image.load('graphics/items/heart_animation.png'))
        objectImages.append(
            sdl.image.load('graphics/items/carrot_animation.png'))
        objectImages.append(sdl.image.load('graphics/items/key_animation.png'))
        objectImages.append(
            sdl.image.load('graphics/items/bomb_animation.png'))

        pantryImages = [
            sdl.image.load('graphics/items/lvl2_open_pantry.png'),
            sdl.image.load('graphics/items/lvl2_pantry_open.png'),
            sdl.image.load('graphics/messages/press_open.png'),
            sdl.image.load('graphics/items/open_pantry_key.png'),
            sdl.image.load('graphics/messages/found_key.png'),
            sdl.image.load('graphics/messages/basement_locked.png'),
            sdl.image.load('graphics/messages/found_graters.png'),
        ]

        weaponImages = []
        weaponImages.append(sdl.image.load('graphics/items/ladles.png'))
        weaponImages.append(sdl.image.load('graphics/items/graters.png'))

        pantryTextures = []
        for x in range(len(pantryImages)):
            pantryTextures.append(
                driver.renderer.createTextureFromSurface(pantryImages[x]))
            sdl.freeSurface(pantryImages[x])

    # creates an array of arrays of integrets that represents our map's floor

        global map
        map = []
        with open('data/level2.txt') as f:
            for line in f:
                currentLine = []
                split = line.split()
                for value in line.split():
                    currentLine.append(int(value))
                map.append(currentLine)

    # fill up the objects array which contains the objects that can be collided with

        global structures
        structures = []
        global exit
        for j in range(len(map)):
            for i in range(len(map[j])):
                value = map[j][i]
                if value is 31:
                    struct = Structure(
                        value,
                        i,
                        j,
                        pantryTextures,
                        False,
                        'pantry',
                    )
                    structures.append(struct)
                if value is 1:
                    exit = Structure(
                        value,
                        i,
                        j,
                        None,
                        False,
                        'exit',
                    )

        self.navGraph = navGraph.navGraph(map, {3}, 2)

        # for now just stuff that's dropped by the rats + the carrot

        global objects
        objects = []

        global objectTextures
        objectTextures = []
        for x in range(len(objectImages)):
            objectTextures.append(
                driver.renderer.createTextureFromSurface(objectImages[x]))
            sdl.freeSurface(objectImages[x])
        for x in range(len(weaponImages)):
            objectTextures.append(
                driver.renderer.createTextureFromSurface(weaponImages[x]))
            sdl.freeSurface(weaponImages[x])

        global ratTextures
        ratTextures = []
        for x in range(len(ratImages)):
            ratTextures.append(
                driver.renderer.createTextureFromSurface(ratImages[x]))
            sdl.freeSurface(ratImages[x])

        global mapTextures
        limitedVisionTexture1 = \
            driver.renderer.createTextureFromSurface(sdl.image.load('graphics/ui/limited_vision1.png'
                ))
        limitedVisionTexture2 = \
            driver.renderer.createTextureFromSurface(sdl.image.load('graphics/ui/limited_vision2.png'
                ))
        mapTextures = []
        for x in range(len(mapImages)):
            mapTextures.append(
                driver.renderer.createTextureFromSurface(mapImages[x]))
            sdl.freeSurface(mapImages[x])
        mapTextures.append(limitedVisionTexture1)
        mapTextures.append(limitedVisionTexture2)

        # set the current score to waht it was plus 100000

        driver.scoreBoard.setScore(driver.chef.score + 100000)
        story.cleanup()
Beispiel #8
0
def Mix_LoadWAV(file):
    return Mix_LoadWAV_RW(sdl.RWFromFile(file, b"rb"), 1)