Esempio n. 1
0
def mouseClick(x, y):
    global activeIcon
    global pauseActive
    global buildingMenuOpen
    for i in icons:
        if (x > i[2][0] and x < i[2][0] + UI_ICON_SIZE):
            if (y > i[2][1] and y < i[2][1] + UI_ICON_SIZE):
                if (i[1] == 90):
                    if (buildingMenuOpen == False):
                        continue

                SoundUtil.play_sound("click")

                if (i[4] == True):
                    i[5] = not i[5]

                if (i[1] == 0):
                    pauseActive = not pauseActive
                    setBuildMode(0, None)

                if (i[3] == openMenu or i[3] == buyTruck
                        or i[3] == Notification.addNotification):
                    i[3](i[6])
                    return True
                if (i[3] == setBuildMode):
                    if (pauseActive == False):
                        i[3](i[6], i)
                    return True

                i[3]()

                return True
    return False
Esempio n. 2
0
 def __init__(self):
     print('Initialize Dictionary Manager...')
     self.init_dir()
     self.translator = GCPutil.GTranslator()
     self.tts = GCPutil.GTextToSpeech()
     self.sound_player = SoundUtil.PlaySound()
     self.dic_db = DictionaryUtil.DictionaryDB()
     self.cur_word = DictionaryUtil.DictionaryWord()
     self.new_word = DictionaryUtil.DictionaryWord()
     self.dic_db.connect_db()
     print('Initialize Done!')
Esempio n. 3
0
    def static_init():
        BaseInvader.invader_explosion = SoundUtil.load_sound(Globals.INVADER_SHOT)

        InvList = [ InvaderC, InvaderB, InvaderA ]

        for InvType in InvList:
            if 0 == len(InvType.file_list):
                raise SystemExit, "BaseInvader method loadImages failed - no image files lists!"
            InvType.image_list = load_images(InvType.file_list, BaseInvader.scale)
            InvType.num_images = len(InvType.image_list)
            if 0 == InvType.num_images:
                raise SystemExit, "BaseInvader method loadImages failed - no images were loaded!"
Esempio n. 4
0
 def static_init(container_list):
     Player.explosion_sound = SoundUtil.load_sound(Globals.PLAYER_EXPLOSION)
     Player.loadImages([ Globals.LASER_BASE_FILE ], Player)
     Player.containers = container_list
     Player.shoot_sound = SoundUtil.load_sound(Globals.PLAYER_SHOT)
Esempio n. 5
0
ImageUtil.create_image("road", "res/tile/tile-road.png")
ImageUtil.create_image("water", "res/tile/tile-water-2.png")
ImageUtil.create_image("temp", "res/tile/tile-template.png")
ImageUtil.create_image("landfill", "res/tile/tile-landfill.png")
ImageUtil.create_image("truck1-TL", "res/trucks/truck1/truck1TL.png")
ImageUtil.create_image("truck1-TR", "res/trucks/truck1/truck1TR.png")
ImageUtil.create_image("truck1-BL", "res/trucks/truck1/truck1BL.png")
ImageUtil.create_image("truck1-BR", "res/trucks/truck1/truck1BR.png")
ImageUtil.create_image("menu-name-white", "res/mainmenu/name-white.png")
ImageUtil.create_image("menu-name-black", "res/mainmenu/name-black.png")
ImageUtil.create_image("menu-back", "res/mainmenu/menu-back.png")
ImageUtil.create_image("incinerator", "res/tile/tile-incinerator.png")
ImageUtil.create_image("recycler", "res/tile/tile-recycler.png")
ImageUtil.create_image("blackhole", "res/tile/tile-blackholefacility.png")

SoundUtil.create_sound("click", "res/sound/Click.ogg")

Build.init()

GameState = GAME_STATE_MENU


def startGame():
    global GameState
    GameState = GAME_STATE_GAME


aMainMenu.init(screen, startGame)

Map.loadMap()
Map.loadPathFindingMap()
Esempio n. 6
0
def main(winstyle=0):
    # Initialize pygame
    pygame.init()
    if pygame.mixer and not pygame.mixer.get_init():
        print "Warning, no sound"
        pygame.mixer = None

    # Set the display mode
    winstyle = 0  # |FULLSCREEN
    bestdepth = pygame.display.mode_ok(Globals.SCREENRECT.size, winstyle, Globals.BIT_DEPTH)
    screen = pygame.display.set_mode(Globals.SCREENRECT.size, winstyle, bestdepth)

    # Load images, assign to sprite classes
    # (do this before the classes are used, after screen setup)
    Globals.GameData.setupContainers()
    Globals.GameData.loadSounds()
    Globals.GameData.doStaticInits()
    Globals.GameData.loadImages()
    Globals.GameData.setBaseShelters()

    # decorate the game window
    icon = pygame.transform.scale(SpriteLib.InvaderA.image_list[0], (Globals.ICON_WIDTH, Globals.ICON_HEIGHT))
    pygame.display.set_icon(icon)
    pygame.display.set_caption(Globals.GAME_NAME)
    pygame.mouse.set_visible(0)

    # create the background, tile the bgd image
    bgdtile = SpriteLib.load_image(Globals.BACKGROUND_IMAGE)
    background = pygame.Surface(Globals.SCREENRECT.size)
    for x in range(0, Globals.SCREENRECT.width, bgdtile.get_width()):
        background.blit(bgdtile, (x, 0))
    screen.blit(background, (0, 0))
    pygame.display.flip()

    # move the below to the formation object
    invader_thump = SoundUtil.load_sound(Globals.INVADER_THUMP[0])

    if pygame.mixer and Globals.MUSIC_TOGGLE:
        music = os.path.join(Globals.ART_DIR, Globals.INVADER_THUMP[0])
        pygame.mixer.music.load(music)
        pygame.mixer.music.play(-1)

    # Create Some Starting Values
    alienreload = 0
    clock = pygame.time.Clock()

    # initialize our starting sprites
    player = SpriteLib.Player()

    if pygame.font:
        Score = SpriteLib.Score()
        Globals.GameData.all.add(Score)

    # pygame.time.set_timer(pygame.USEREVENT, 13)
    invader_thump.play(Globals.SOUND_LOOP_FOREVER)
    ufo = 0

    while player.alive():

        # get input
        for event in pygame.event.get():
            if event.type == pygame.locals.QUIT or (
                event.type == pygame.locals.KEYDOWN and event.key == pygame.locals.K_ESCAPE
            ):
                return
            # elif event.type == pygame.USEREVENT:
            #        pygame.time.set_timer(pygame.USEREVENT, 750)
            #        invader_thump.play()

        keystate = pygame.key.get_pressed()

        # clear/erase the last drawn sprites
        Globals.GameData.all.clear(screen, background)

        # update all the sprites
        Globals.GameData.all.update()

        # handle player input
        direction = keystate[pygame.locals.K_RIGHT] - keystate[pygame.locals.K_LEFT]
        player.move(direction)
        firing = keystate[pygame.locals.K_SPACE]

        if not player.reloading and firing and len(Globals.GameData.shots) < Globals.MAX_SHOTS:
            player.fire()

        player.reloading = firing

        # Create new alien
        if alienreload:
            alienreload = alienreload - 1
        elif not int(random.random() * Globals.ALIEN_ODDS):
            inv_type = int(random.random() * 3)
            if inv_type == 0:
                SpriteLib.InvaderA()
            elif inv_type == 1:
                SpriteLib.InvaderB()
            elif inv_type == 2:
                SpriteLib.InvaderC()
            else:
                print "error inv_type %d" % inv_type
            alienreload = Globals.ALIEN_RELOAD

        SpriteLib.Ufo.reload_time = SpriteLib.Ufo.reload_time - 1

        if not SpriteLib.Ufo.ufo_overhead and SpriteLib.Ufo.reload_time <= 0:
            SpriteLib.Ufo.ufo_overhead = True
            ufo = SpriteLib.Ufo()
            SpriteLib.Ufo.reload_time = Globals.UFO_RELOAD_TIME

        # Detect collisions
        for alien in pygame.sprite.spritecollide(player, Globals.GameData.aliens, 1):
            Score.addToScore(alien.score)
            player.handleDeath()

        for bomb in pygame.sprite.groupcollide(Globals.GameData.bombs, Globals.GameData.shots, 1, 1).keys():
            SpriteLib.BombHitsLaserExplosion(bomb)
            Score.addToScore(1)

        if SpriteLib.Ufo.ufo_overhead:
            for laser_shot in pygame.sprite.spritecollide(ufo, Globals.GameData.shots, 1):
                ufo.takeHit()
                Score.addToScore(ufo.score)

        if len(Globals.GameData.bombs):
            for bomb in Globals.GameData.bombs:
                for shelter in pygame.sprite.groupcollide(Globals.GameData.base_shelters, [bomb], 0, 0).keys():
                    shelter.bombHit(bomb, False)

        if len(Globals.GameData.shots):
            for shot in Globals.GameData.shots:
                for shelter in pygame.sprite.groupcollide(Globals.GameData.base_shelters, [shot], 0, 0).keys():
                    shelter.bombHit(shot, True)

        for alien in pygame.sprite.groupcollide(Globals.GameData.aliens, Globals.GameData.shots, 1, 1).keys():
            Score.addToScore(alien.score)

        for bomb in pygame.sprite.spritecollide(player, Globals.GameData.bombs, 1):
            SpriteLib.PlayerExplosion(player)
            player.kill()

        # draw the scene
        dirty = Globals.GameData.all.draw(screen)
        pygame.display.update(dirty)

        # cap the framerate
        clock.tick(Globals.FRAMES_PER_SEC)

    if pygame.mixer:
        pygame.mixer.music.fadeout(Globals.ONE_SECOND)
    pygame.time.wait(Globals.ONE_SECOND)
Esempio n. 7
0
 def loadSounds():
     # load some sounds
     SpriteLib.Ufo.alert_sound = SoundUtil.load_sound(UFO_ALERT)