Exemplo n.º 1
0
 def on_enter(self):
     super(MainMenu, self).on_enter()
     constants.MUSIC = True
     menu_player.set_volume(2)
     if self.game_started:
         Objects.reset_game()
         self.game_started = False
Exemplo n.º 2
0
 def get_user_info(user_extension):
     result = dict()
     result = Objects.get_object_info(user_extension)
     temp = Objects.get_object_info(user_extension.user)
     temp["user_id"] = temp["id"]
     result["userextension_id"] = result["id"]
     result.update(temp)
     return result
Exemplo n.º 3
0
 def update(publish, publish_dict):
     try:
         for (key, value) in publish_dict.items():
             Objects.set_value(publish, key, value)
         publish.save()
         return publish
     except Exception as ex:
         Logs.print_current_function_name_and_line_number(ex)
         return None
Exemplo n.º 4
0
 def static_update(address, address_dict):
     try:
         for (key, value) in address_dict.items():
             Objects.set_value(address, key, value)
         address.save()
         return address
     except Exception as ex:
         Logs.print_current_function_name_and_line_number(ex)
         return Address.get_none()
Exemplo n.º 5
0
 def update_shop(shop, shop_dict):
     try:
         for (key, value) in shop_dict.items():
             Objects.set_value(shop, key, value)
         shop.save()
         return shop
     except Exception as ex:
         Logs.print_current_function_name_and_line_number(ex)
         return Shops.get_none()
Exemplo n.º 6
0
 def on_win(self):
     Objects.reset_game()
     server = Objects.get_server(self.levelName)
     server.curLevel = self.level+1
     utils.play_sound("Enter.wav")
     game = Scene(server.map, server)
     game.add(ImageLayer(os.path.join("images", "backgrounds", "notebook-paper.png")), z=BACKGROUND_Z)
     director.push(game)
     menu_player.stop()
     self.game_started = True
Exemplo n.º 7
0
    def update_user(user, user_extension_dict, user_dict):
        if user_extension_dict:
            try:
                ue = user.userextension
                for (key, value) in user_extension_dict.items():
                    Objects.set_value(ue, key, value)
                ue.save()
            except Exception as ex:
                Logs.print_current_function_name_and_line_number(ex)
                return Users.get_none()
        if user_dict:
            for (key, value) in user_dict.items():
                Objects.set_value(user, key, value)
            user.save()

        return user
Exemplo n.º 8
0
 def server_build_unit(self, pid, tid, vid, uid,buid):        
     # print "building unit", pid, tid, vid, uid
     client = Objects.get_client()
     player = client.players[pid]
     if uid not in player.underConstruction.keys():
         client.build_unit(tid, player, vid=vid, uid=uid)
     return {}
Exemplo n.º 9
0
 def server_on_attack(self,tpid,tuid,val):
     # print "server_on_attack", tpid,tuid,val
     client = Objects.get_client()
     p = client.players[tpid]
     if tuid in p.units.keys():
         p.units[tuid].client_on_attack(val)
     return {}
Exemplo n.º 10
0
 def get_info(red_envelope):
     try:
         result = Objects.get_object_info(red_envelope)
         return result
     except Exception as ex:
         Logs.print_current_function_name_and_line_number(ex)
         return dict()
Exemplo n.º 11
0
    def get_big_categories():
        category_list = list()
        categories = ShopCategory.objects.filter(parent_id=1)
        for c in categories:
            temp = Objects.get_object_info(c)
            category_list.append(temp)

        return category_list
Exemplo n.º 12
0
 def server_start_game(self):
     '''
     The client stub that gets called when the server starts the game
     '''
     client = Objects.get_client()
     client._init_players()
     client.start_game()
     return {}
Exemplo n.º 13
0
 def client_build_unit(self,pid,tid,vid,uid,buid):
     # print "client",pid, "built unit", tid, "on", vid
     server = Objects.get_controller()
     p = server.players[pid]
     if buid != -1:
         server.build_unit(tid,p,vid=vid,builder=p.units[buid])
     else:
         server.build_unit(tid,p,vid=vid)
     return {}
Exemplo n.º 14
0
def main():
    while 1:
        try:
            queue_id, decoded_json = get_data()
        except:
            time.sleep(0.5)
            continue
        try:
            print "AAAA"
            objects = Objects(queue_id, decoded_json)
            results = objects.calculate()
        except:
            errorMessage = sys.exc_info()
            print('Error Type: %s' % errorMessage[0])
            print('Error Message: %s' % errorMessage[1])
            write_error(queue_id, errorMessage)
            continue
        put_data(queue_id, results)
Exemplo n.º 15
0
 def join_game(self):
     constants.MULTIPLAYER = True
     utils.play_sound("Enter.wav")
     c = Objects.get_client()
     c.start_server()  # start client server
     connection = c.server_connect()  # connect to game server
     if not connection:
         c.stop_server()
     menu_player.stop()
     self.game_started = True
Exemplo n.º 16
0
    def get_category_info(category):
        result = Objects.get_object_info(category)
        owners = list()
        for owner in category.owners.all():
            user_extension = Users.get_user_extension(owner.username)
            if user_extension:
                owners.append(Users.get_user_info(user_extension))

        result["owners"] = owners
        return result
Exemplo n.º 17
0
 def client_attack_unit(self,pid,uid,tpid,tuid,path):
     # print "client_attack_unit",pid,uid,tpid,tuid
     #if tuid=-1, it's a vertex,tpid is actually tvid
     server = Objects.get_controller()
     attacker = server.players[pid].units[uid]
     if tuid == -1:
         target = server.map.vertices[str(tpid)]
     else:
         target = server.players[tpid].units[tuid]
     server.attack_unit(target,attacker)
     return {}
Exemplo n.º 18
0
 def server_update_health(self, pid, uid, h, tid,vid):
     # print "update_health", pid, uid, h
     client = Objects.get_client()
     player = client.players[pid]
     if uid not in player.underConstruction.keys():
         unit = client.build_unit(tid,player,vid=vid,uid=uid)
     else:
         unit = player.underConstruction[uid]
     unit.health = h
     client._complete_build(unit, player, uid)
     return {}
Exemplo n.º 19
0
    def start_game(self):
        constants.MULTIPLAYER = True
        server = Objects.get_controller()
        server.client_start_game()
        if server.serverStarted:
            utils.play_sound("Enter.wav")
            game = Scene(server.map, server)
            menu_player.stop()
            game.add(ImageLayer(
                     os.path.join("images", "backgrounds", "notebook-paper.png")), z=BACKGROUND_Z)
            director.push(game)
            self.game_started = True

        else:
            print "start server first"
Exemplo n.º 20
0
    def server_animate_attack(self,pid,uid,tpid,tuid,path):
        #if no path, stop attacking
        # print "server_animate_attack",pid,uid, tpid,tuid,path
        client = Objects.get_client()

        if (uid in client.players[pid].units.keys()):
            attacker = client.players[pid].units[uid]
            if tpid == -1 or tuid == -1:
                attacker.end_attack(True)
            elif path:
                target = client.players[tpid].units[tuid]
                attacker.attackingPath = path
                if not attacker.is_attacking:
                    attacker.client_attack(target,client.map)
        return {}
Exemplo n.º 21
0
    def __init__(self, window, data):
        self.window = window
        self.data = data

        Mob.data = data
        Human.data = data

        self.interface = Interface()
        self.ground = Ground()
        self.objects = Objects()

        self.player = Player()

        self.timer = sf.Clock()

        self.load_map("data/amd/elvine")
Exemplo n.º 22
0
 def client_connect(self, ip):
     server = Objects.get_controller()
     cur = server.playerList + [server.pid]
     print "connected client of ip: " + ip
     if ip in server.connectedClientsIP.keys():
         # print "client already exist"
         return {"id": server.connectedClientsIP[ip], "cur": cur,"map":server.mapName}
     if len(server.map.players) != 0 and (not server.gameStarted):
         pid = server.map.players.pop()
         server.client_add_player(pid)
         server.connectedClients[pid] = ip
         server.connectedClientsIP[ip] = pid
         server.playerList.append(pid)
         # print "added player",pid
         return {"id": pid, "cur": cur, "map":server.mapName}
     # print "can't add player"
     return {"id": -1, "cur": [],"map":""}
Exemplo n.º 23
0
class ViewBase(object):
    columns = COLUMNS

    def __init__(self, host):
        self.host = host

        self.objects = Objects(host)

    @property
    def sp(self):
        return self.host.sp

    @property
    def client(self):
        return self.host.client

    @staticmethod
    def use_placeholders():
        return Client.Product in [
            'Plex Home Theater'
        ]

    @classmethod
    def append_header(cls, oc, title='', key=''):
        oc.add(DirectoryObject(key=key, title=title))

    def append_items(self, oc, items, count=COLUMNS, plain=False, placeholders=None):
        """Append spotify metadata `items` to an ObjectContainer"""

        if placeholders is None:
            placeholders = self.use_placeholders()

        for x in range(count):
            if x < len(items):
                # Build object for metadata item
                oc.add(self.objects.get(items[x]))
            elif not plain and placeholders:
                # Add a placeholder to fix alignment on PHT
                self.append_header(oc)
Exemplo n.º 24
0
    def get_info(detector):

        result = Objects.get_object_info(detector)
        result_weather = None
        try:
            relation = DetectorRelation.objects.exclude(state=False).get(mac_address=detector.mac_address)
            result["shop_address"] = relation.address
            # Logs.print_log("shop_address", relation.address)
            # if relation.shop:
            #     if relation.shop.dianping_business_id:
            #         result["shop_address"] = relation.shop.dianping_city + relation.shop.dianping_address
            #     else:
            #         if relation.shop.address:
            #             result["shop_address"] = relation.shop.address.detail_address
            #         else:
            #             result["shop_address"] = None
            # Logs.print_log("relation.city", relation.city)
            if relation.city:
                weather = Weathers.get_weather_from_db(relation.city)
                result["address"] = relation.address

                if not weather or Weathers.is_weather_in_db_timeout(weather):
                    weather = Weathers.get_weather_from_heweather(relation.city)
                    # Logs.print_log("weather", weather)
                    Weathers.create_weather(weather)
                    result_weather = weather
                else:
                    result_weather = Weathers.get_weather_info(weather)
        except Exception as ex:
            Logs.print_current_function_name_and_line_number(ex)
            result_weather = None
        if result_weather:
            for (key, value) in result_weather.items():
                result["weather_" + key] = value

        return result
Exemplo n.º 25
0
    ('Spell Sounds Starter Pack - p0ss',
     'https://creativecommons.org/licenses/by-sa/3.0/legalcode',
     'http://www.gnu.org/licenses/gpl-3.0.html',
     'http://www.gnu.org/licenses/old-licenses/gpl-2.0.html',
     'https://opengameart.org/content/spell-sounds-starter-pack',
     'Foram feitas modificações neste trabalho para o uso neste projeto', '',
     'Another Egyptian Theme - Spring',
     'https://creativecommons.org/licenses/by/4.0/legalcode',
     'https://creativecommons.org/licenses/by/3.0/legalcode',
     'https://creativecommons.org/licenses/by-sa/4.0/legalcode',
     'https://creativecommons.org/licenses/by-sa/3.0/legalcode',
     'https://static.opengameart.org/OGA-BY-3.0.txt',
     'https://opengameart.org/content/another-egyptian-theme')
]

pilar = Objects(4000, 1450, pilar_img.get_width(), pilar_img.get_height(),
                pilar_img)
gate = Objects(3263, 1300, gate_img.get_width(), gate_img.get_height(),
               gate_img)
gate_down = Objects(3648, 2500, gate_down_img.get_width(),
                    gate_down_img.get_height(), gate_down_img)
gate_side = Objects(2750, 1728, gate_side_img.get_width(),
                    gate_side_img.get_height(), gate_side_img)

armasAfricanas = Objects(4200, 1720, armasAfricanas_img.get_width(),
                         armasAfricanas_img.get_height(), armasAfricanas_img)
mascaraAfricana = Objects(4250, 2100, mascaraAfricana_img.get_width(),
                          mascaraAfricana_img.get_height(),
                          mascaraAfricana_img)
elmoRomano = Objects(3800, 1770, elmoRomano_img.get_width(),
                     elmoRomano_img.get_height(), elmoRomano_img)
estatuaAfricana = Objects(3800, 2100, estatuaAfricana_img.get_width(),
Exemplo n.º 26
0
def main():
    """ Main function """

    game_activated = True

    while game_activated:
        """ Main loop containing 'Welcome loop', ' Instruction loop' and 'Game loop'.
        Initialization of all the game elements """

        pygame.time.Clock().tick(30)

        # SCREEN LOADING
        level = Level()
        pygame.init()
        screen = pygame.display.set_mode(
            (SPRITES * SPRITE_SIZE, SPRITES * SPRITE_SIZE + 50))
        icon = pygame.image.load(IMAGE_MCGYVER).convert()
        pygame.display.set_icon(icon)
        pygame.display.set_caption(TITLE_WELCOME)

        # MUSIC LOADING
        sound_mac_theme = pygame.mixer.Sound(MAC_THEME)
        music_win = pygame.mixer.Sound(MAC_WIN)

        # MAP IS CREATED
        background = pygame.image.load(IMAGE_BACKGROUND).convert()
        level.map_generator()

        # CHARACTERS ARE CREATED
        mcgyver = Character(0, 1, IMAGE_MCGYVER, level)
        guardian = Character(14, 13, IMAGE_GUARDIAN, level)

        # OBJECTS ARE CREATED
        needle = Objects('N', IMAGE_NEEDLE, level)
        ether = Objects('E', IMAGE_ETHER, level)
        tube = Objects('T', IMAGE_TUBE, level)

        # WELCOME PAGE LOADING AND SHOWING
        welcome = pygame.image.load(WELCOME_MAC).convert()

        # INSTRUCTION PAGE LOADING
        instructions = pygame.image.load(IMAGE_INSTRUCTIONS).convert()

        # INVENTORY AT THE BOTTOM OF THE SCREEN LOADING
        inventory = pygame.image.load(IMAGE_INVENTORY).convert()

        pygame.display.flip()

        continue_game = True
        continue_title = True
        continue_instructions = True

        # WELCOME LOOP
        while continue_title:
            sound_mac_theme.play()
            screen.blit(welcome, (0, 0))

            if level.player_decision():
                continue_title = False

            pygame.display.flip()

        # INSTRUCTIONS LOOP
        while continue_instructions:
            sound_mac_theme.stop()
            screen.blit(instructions, (0, 0))
            screen.blit(inventory, (0, 600))

            if level.player_decision():
                continue_instructions = False

            pygame.display.flip()

        # GAME LOOP
        while continue_game:

            # Displaying map and refreshing screen
            screen.blit(background, (0, 0))
            level.map_draw(screen)
            screen.blit(
                mcgyver.visual,
                (mcgyver.pos_x * SPRITE_SIZE, mcgyver.pos_y * SPRITE_SIZE))
            screen.blit(
                guardian.visual,
                (guardian.pos_x * SPRITE_SIZE, guardian.pos_y * SPRITE_SIZE))

            # Displaying objects images for each objects position
            ether.displaying_objects(level, screen)
            tube.displaying_objects(level, screen)
            needle.displaying_objects(level, screen)

            # Games actions
            mcgyver.is_moving()
            if mcgyver.is_moving() is False:
                continue_game = False

            # Inventory displaying
            ether.display_in_inventory(mcgyver, screen)
            tube.display_in_inventory(mcgyver, screen)
            needle.display_in_inventory(mcgyver, screen)

            # MacGyver wins or loses
            mcgyver.wins_or_not(screen, music_win, level)
            if mcgyver.wins_or_not(screen, music_win, level) is False:
                continue_game = False

            pygame.display.flip()
Exemplo n.º 27
0
 def server_move_troop(self, pid, uid, vid, path):
     # print "server move unit", pid, vid, uid, path
     client = Objects.get_client()
     path = client.move_unit(client.players[pid].units[uid], path)
     return {}
Exemplo n.º 28
0
 def on_init(self):
     self.game_objects = Objects(self.width, self.height)
Exemplo n.º 29
0
 def server_add_player(self, pid):
     # print "server add player"
     client = Objects.get_client()
     client.playerList.append(pid)
     return {}
Exemplo n.º 30
0
 def server_update_location(self, pid, uid, vid):
     client = Objects.get_client()
     p = client.players[pid]
     curVertex = client.map.vertices[str(vid)]
     client.update_location(p.units[uid], curVertex.position, curVertex)
     return {}
Exemplo n.º 31
0
    def _sql(self, file):
        ''' Get the database path based on the file objects/obj_map.json
            Compatible check, in the event multiple db version are supported with the same Kodi version.
            Load video, music, texture databases from the log file. Will only run once per service thread.
            Running database version lines
        '''
        from objects import Objects

        databases = Objects().objects

        if file not in ('video', 'music', 'texture') or databases.get(
                'database_set%s' % file):
            return self._get_database(databases[file], True)

        folder = xbmc.translatePath("special://database/").decode('utf-8')
        dirs, files = xbmcvfs.listdir(folder)
        dbs = {'Textures': "texture", 'MyMusic': "music", 'MyVideos': "video"}
        for db in dbs:

            count = 0
            filename = None

            for name in files:

                if (name.startswith(db) and not name.endswith('-wal')
                        and not name.endswith('-shm')
                        and not name.endswith('db-journal')):

                    count += 1
                    filename = name

            if count == 1:

                key = dbs[db]
                databases[key] = os.path.join(
                    folder, filename.decode('utf-8')).decode('utf-8')
                databases['database_set%s' % key] = True

                continue

            break
        else:
            return databases[file]

        with open(
                xbmc.translatePath('special://logpath/kodi.log').decode(
                    'utf-8'), 'r') as log:
            found_lines = len(dbs)

            for line in log:
                if 'Running database version' in line:

                    filename = line.rsplit('version ', 1)[1].strip()
                    filename = "%s.db" % filename

                    for database in dbs:
                        if database in line:

                            key = dbs[database]
                            databases[key] = os.path.join(
                                folder,
                                filename.decode('utf-8')).decode('utf-8')
                            databases['database_set%s' % key] = True
                            found_lines -= 1

                            break

                elif not found_lines:
                    break

        return databases[file]
Exemplo n.º 32
0
class Game:
    def __init__(self, window):
        self.is_playing = False
        self.window = window
        # self.pressed = {}

    def initialization(self, window):
        """
        Initialise new objects when call
        """
        self.labyrinth = Labyrinth()
        self.mac_gyver = Player(
            MAC_GYVER_IMAGE, FLOOR_IMAGE, self.labyrinth, self.window
        )
        self.mac_gyver.position = [0, 0]
        self.objects = Objects(
            SYRINGE_IMAGE, ETHER_IMAGE, NEEDLE_IMAGE, self.labyrinth, self.window
        )

        # Labyrinth
        self.labyrinth.labyrinth_construction()
        self.labyrinth.display_level(window)

        # Player
        self.mac_gyver.blit(self.mac_gyver.position)

        # Objects
        self.objects.generate_random_position()
        self.objects.display_objects()
        self.objects.objects_collected = 0

        self.run = True
        self.response = None

    def menu(self, menu_image, window):
        """
        Display menu
        """
        self.menu_i = pygame.image.load(menu_image).convert_alpha()
        self.window.blit(self.menu_i, (0, 0))

        play_button = pygame.image.load("assets/playbutton.png")
        play_button = pygame.transform.scale(play_button, (200, 70))
        play_button_rect = play_button.get_rect()
        play_button_rect.x = math.ceil(window.get_width() / 3.333)
        play_button_rect.y = math.ceil(window.get_height() / 1.4)
        window.blit(play_button, play_button_rect)

        continu = True
        while continu:
            pygame.display.update()
            for event in pygame.event.get():
                # Waiting for events
                if event.type == pygame.QUIT:
                    continu = False
                    return False
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if play_button_rect.collidepoint(event.pos):
                        continu = False
                        return True

    def play(self):
        """Manage all input player's input"""
        continu = True
        while continu:
            pygame.display.update()
            for event in pygame.event.get():
                # Waiting for events
                if event.type == pygame.QUIT:
                    continu = False
                    self.run = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_RIGHT:
                        self.mac_gyver.move("right")
                    elif event.key == pygame.K_LEFT:
                        self.mac_gyver.move("left")
                    elif event.key == pygame.K_UP:
                        self.mac_gyver.move("up")
                    elif event.key == pygame.K_DOWN:
                        self.mac_gyver.move("down")
                    self.objects.collect_objects(self.mac_gyver)
                    continu = self.labyrinth.end_game(self.mac_gyver)
                    self.response = self.labyrinth.response(
                        self.mac_gyver, self.objects
                    )

            pygame.display.flip()
        return self.response

    def player_win(self, win_image):
        """Display Win Screen at the end of the game"""
        self.win_image = pygame.image.load(win_image).convert_alpha()
        self.window.blit(self.win_image, ((0, 0)))

        continu = True
        while continu:
            pygame.display.update()
            for event in pygame.event.get():
                # Waiting for events
                if event.type == pygame.QUIT:
                    continu = False
                    self.run = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        continu = False
                        return True

    def player_loose(self, loose_image):
        """Display Loose Screen at the end of the game"""
        self.loose_image = pygame.image.load(loose_image).convert_alpha()
        self.window.blit(self.loose_image, ((0, 0)))

        continu = True
        while continu:
            pygame.display.update()
            for event in pygame.event.get():
                # Waiting for events
                if event.type == pygame.QUIT:
                    continu = False
                    self.run = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        continu = False
                        return True
Exemplo n.º 33
0
 def get_none():
     return Objects.get_none(Company)
Exemplo n.º 34
0
 def client_remove_unit(self,pid,uid):
     # print "remove unit", pid, uid
     client = Objects.get_client()
     unit = client.players[pid].units[uid]
     unit.destroy_action()
     return {}
Exemplo n.º 35
0
 def new_game(self):
     constants.MULTIPLAYER = True
     utils.play_sound("Enter.wav")
     Objects.get_server(self.levelName).start_server()
Exemplo n.º 36
0
 def get_info(label):
     return Objects.get_object_info(label)
Exemplo n.º 37
0
def backup():
    ''' Jellyfin backup.
    '''
    from helper.utils import delete_folder, copytree

    path = settings('backupPath')
    folder_name = "Kodi%s.%s" % (xbmc.getInfoLabel('System.BuildVersion')[:2],
                                 xbmc.getInfoLabel('System.Date(dd-mm-yy)'))
    folder_name = dialog("input",
                         heading=translate(33089),
                         defaultt=folder_name)

    if not folder_name:
        return

    backup = os.path.join(path, folder_name)

    if xbmcvfs.exists(backup + '/'):
        if not dialog("yesno", "{jellyfin}", translate(33090)):

            return backup()

        delete_folder(backup)

    addon_data = xbmc.translatePath(
        "special://profile/addon_data/plugin.video.jellyfin")
    destination_data = os.path.join(backup, "addon_data",
                                    "plugin.video.jellyfin")
    destination_databases = os.path.join(backup, "Database")

    if not xbmcvfs.mkdirs(path) or not xbmcvfs.mkdirs(destination_databases):

        LOG.info("Unable to create all directories")
        dialog("notification",
               heading="{jellyfin}",
               icon="{jellyfin}",
               message=translate(33165),
               sound=False)

        return

    copytree(addon_data, destination_data)

    databases = Objects().objects

    db = xbmc.translatePath(databases['jellyfin'])
    xbmcvfs.copy(db, os.path.join(destination_databases,
                                  db.rsplit('\\', 1)[1]))
    LOG.info("copied jellyfin.db")

    db = xbmc.translatePath(databases['video'])
    filename = db.rsplit('\\', 1)[1]
    xbmcvfs.copy(db, os.path.join(destination_databases, filename))
    LOG.info("copied %s", filename)

    if settings('enableMusic.bool'):

        db = xbmc.translatePath(databases['music'])
        filename = db.rsplit('\\', 1)[1]
        xbmcvfs.copy(db, os.path.join(destination_databases, filename))
        LOG.info("copied %s", filename)

    LOG.info("backup completed")
    dialog("ok", "{jellyfin}", "%s %s" % (translate(33091), backup))
Exemplo n.º 38
0
 def server_move_troop(self, pid, uid, vid, path):
     # print "server move unit", pid, vid, uid, path
     client = Objects.get_client()
     path = client.move_unit(client.players[pid].units[uid], path)
     return {}
Exemplo n.º 39
0
 def client_move_troop(self, pid, uid, vid, path):
     # print "client",pid, "move unit", uid, "on", vid
     server = Objects.get_controller()
     server.move_unit(server.map.vertices[str(vid)],
                      server.players[pid].units[uid], pid)
     return {}
Exemplo n.º 40
0
 def on_enter(self):
     super(MultiplayerMenu, self).on_enter()
     if self.game_started:
         Objects.reset_game()
         self.game_started = False
Exemplo n.º 41
0
 def client_remove_unit(self, pid, uid):
     # print "client",pid, "remove unit", uid
     server = Objects.get_controller()
     unit = server.players[pid].units[uid]
     server.remove_unit(unit)
     return {}
Exemplo n.º 42
0
def dispose_objects(screen, group, score):
    obj = Objects(screen)
    elements_in_x = space_available_x(screen, obj)
    for v_number in range(score.level):
        for h_number in range(elements_in_x + 1):
            create_object(group, h_number, v_number, screen)
Exemplo n.º 43
0
 def client_remove_unit(self, pid, uid):
     # print "remove unit", pid, uid
     client = Objects.get_client()
     unit = client.players[pid].units[uid]
     unit.destroy_action()
     return {}
Exemplo n.º 44
0
def run_game():
    pygame.init()
    set = Settings()
    screen = pygame.display.set_mode((set.width, set.height))

    images = ["rsc/objekt01.png", "rsc/objekt02.png", "rsc/objekt03.png", "rsc/objekt04.png", "rsc/objekt05.png"]
    objects = []
    for i in range(0, 5):
        object = Objects(set, screen, images[i])
        objects.append(object)

    hintergrund = pygame.image.load("rsc/hintergrund.png")
    rect_hintergrund = hintergrund.get_rect()
    rect_hintergrund.x = 0
    rect_hintergrund.y = 0

    teppich = pygame.image.load("rsc/teppich.png")
    rect_teppich = teppich.get_rect()
    rect_teppich.x = 100
    rect_teppich.y = 60

    rucksack = pygame.image.load("rsc/rucksack.png")
    rect_rucksack = rucksack.get_rect()
    rect_rucksack.x = rect_teppich.width + 200
    rect_rucksack.y = 60

    button01 = pygame.image.load("rsc/button01.png")
    rect_button01 = button01.get_rect()
    rect_button01.x = set.width - rect_button01.width - 100
    rect_button01.y = set.height - rect_button01.height - 60

    button02 = pygame.image.load("rsc/button02.png")
    rect_button02 = button02.get_rect()
    rect_button02.x = set.width - rect_button02.width - 100
    rect_button02.y = set.height - rect_button02.height - 60

    def update_screen(screen):
        if not set.game_over:
            screen.blit(hintergrund, rect_hintergrund)
            screen.blit(button01, rect_button01)
            screen.blit(teppich, rect_teppich)
            screen.blit(rucksack, rect_rucksack)
            for object in objects:
                object.blit()
        else:
            screen.blit(hintergrund, rect_hintergrund)
            screen.blit(button02, rect_button02)

    def check_mouse_down(mouse):
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                set.mouse_down = True
                for object in objects:
                    if object.rect_image.collidepoint(mouse):
                        return objects.index(object)

    def check_mouse_up():
        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONUP:
                set.mouse_down = False

    def check_collide_object(mouse, current_object):
        for object in objects:
            if object.rect_image.collidepoint(mouse):
                if set.mouse_down:
                    current = objects[current_object]
                    current.rect_image.x = round(mouse[0] - object.rect_image.width / 2)
                    current.rect_image.y = round(mouse[1] - object.rect_image.height / 2)
        if rect_button02.collidepoint(mouse) and set.game_over == True:
            sys.exit()

    def check_object_in_backpack():
        if set.mouse_down == False:
            for object in objects:
                if object.rect_image.colliderect(rect_rucksack):
                    set.items += 1
                    object.rect_image.x = -100
                    object.rect_image.y = -100

    def check_game_over():
        if set.items >= 5:
            set.game_over = True

    while True:
        if set.mouse_down == False:
            current_object = check_mouse_down(pygame.mouse.get_pos())
        else:
            check_collide_object(pygame.mouse.get_pos(), current_object)
        check_mouse_up()
        check_object_in_backpack()
        check_game_over()
        update_screen(screen)
        pygame.display.flip()
Exemplo n.º 45
0
class MainConstructor():

    def __init__ (self, mainMenuSound, soundMouse, soundSpace, soundGun, soundClick, takeSomething, soundCoin, soundSpaceShip):
        self.spaceShip = SpaceShip(width/2, height/2+150, 150, 150, 5, soundGun, takeSomething, soundCoin)
        self.enemy = Enemy(random(0+75/2, width-75/2), -300, 75, 75, 3)
        self.spaceShip.setEnemy(self.enemy)
        self.objects = Objects(soundGun)
        self.spaceShip.setSecondWeapon(self.objects.secondWeapon)
        self.spaceShip.setSecondWeaponTimer(self.objects.secondWeaponTimer)
        self.dropedObjects = DropedObjects(random(0+25, width-25), -2400, 50, 50, 2, random(0+25, width-25))
        self.spaceShip.setDropedSecondWeapon(self.dropedObjects.dropedSecondWeapon)
        self.stars = Stars()
        self.gameState = False
        self.buttonToStartGame = StartGame(width/2, height/2, 100, 50)

        self.mainMenuSound = mainMenuSound
        self.mainMenuSound.loop()

        self.soundMouse = soundMouse

        self.soundSpace = soundSpace

        self.soundClick = soundClick

        self.soundSpaceShip = soundSpaceShip

    def game(self, mouseState):
        if self.gameState == False:
            self.soundClick.rewind()
            self.soundSpace.rewind()
            self.buttonToStartGame.run()
            newGameState = self.buttonToStartGame.pressed(mouseState)
            self.soundSpaceShip.pause()
            if newGameState:
                self.mainMenuSound.pause()
                self.soundSpaceShip.loop()
                self.gameState = newGameState
            self.spaceShip.score.timer.workTimer(self.spaceShip.score.bestScore, self.buttonToStartGame.x, self.buttonToStartGame.y)
            self.enemy.spawn()

            aiming = self.buttonToStartGame.aiming()
            if aiming:
                self.soundMouse.play()
            else:
                self.soundMouse.rewind()
                self.soundMouse.pause()

        else:
            self.soundClick.play()
            self.soundSpace.play()
            self.spaceShip.score.timer.restartOptions()
            self.run()


    def run(self):
        self.stars.run()
        self.spaceShip.run() 
        self.enemy.run(self.spaceShip.firstWeapon.listOfBullets, self.objects.secondWeapon.listOfBullets)
        self.objects.run()
        self.dropedObjects.run()
        newGameState = self.spaceShip.setGameState(self.gameState)
        if newGameState == False:
            self.mainMenuSound.rewind()
            self.mainMenuSound.loop()

        self.gameState = newGameState

    def shootWithFirstWeapon(self):
        if self.gameState:
            if self.spaceShip.state == 'ShootWithFirstGun':
                self.spaceShip.firstWeapon.runToShoot(self.spaceShip.x)

    def shootWithSecondWeapon(self):
        if self.gameState:
            if self.spaceShip.state == 'ShootWithSecondGun':
                self.objects.secondWeapon.shoot(self.spaceShip.x)
Exemplo n.º 46
0
 def get_info(comment):
     return Objects.get_object_info(comment)
Exemplo n.º 47
0
    def __init__(self, host):
        self.host = host

        self.objects = Objects(host)
Exemplo n.º 48
0
 def get_none():
     return Objects.get_none(ForumLabel)
Exemplo n.º 49
0
#game screen generation
pygame.display.set_caption('Surrender')
size = width, height = 1280, 720
screen = pygame.display.set_mode((size))
icon = pygame.image.load('assets/icon.png')
pygame.display.set_icon(icon)

#mouse
pygame.mouse.set_cursor(*pygame.cursors.diamond)

#Player creation
player = Player()

#Map creation
maps = Map()
objects_light = Objects(0)
objects_dark = Objects(1)

hud = HudText()
hud.render_text("Press [SPACE].", "", "")

#Sound
ost = pygame.mixer.Sound('assets/ost.ogg')
ost.set_volume(0.2)
ost.play(loops=-1, maxtime=0, fade_ms=0)

running = True


def collide(character, obj):
    if obj.contains(character) == 1: