Ejemplo n.º 1
0
def create_world():
    global _player, _Bg, _Enemy1, timer, GameScore, font, _EBullet, _PBullet, _Life, client_sock, tcp_controller, E_NUM, _Enemy_Data
    global MyNumber, AnotherPlayer, unpacked_all_player_data, game_data, P_NUM, Player_Count, _LifeList, iScore, bgm
    global miScore
    _Bg = BackGround()
    E_NUM = 0
    bgm = load_music('Resource\BGM_B.mp3')
    bgm.set_volume(64)
    bgm.repeat_play()
    _player = Player1(_Bg)
    _LifeList = []
    miScore = CScore()
    iScore = 0
    AnotherPlayer = []
    _Enemy1 = []
    client_sock = GameData.client_socket
    MyNumber = GameData.player_number
    t1 = threading.Thread(target=recv_thread, args=(client_sock, ))
    GameScore = 0
    Player_Count = 0
    font = load_font('Resource\ENCR10B.TTF')

    Player2(0, 0, 0, 0, 0, 0, 0)
    Enemy1(0, 0, 0, 0, 0)
    Enemy2(0, 0, 0, 0, 0)
    EBullet(0, 0)
    PBullet(0, 0)
    t1.start()
Ejemplo n.º 2
0
    def send_in_game_data(client_socket, room_number, player_number):
        global PLAYER_NUM, state, GAME_STATE, E_Data, ready_state, E_NUM
        current_time = time.clock()
        E_NUM = 0
        while 1:  # When Game Over
            P_Data = client_socket.recv(struct.calcsize('=fffff'))

            _Player_Packed = data_struct.unpack_player_data(P_Data)

            frame_time = time.clock() - current_time
            current_time += frame_time
            _Bg.update(_Player_Packed[0], _Player_Packed[1])

            SEND_DATA = b'EMPTY'
            if timer.update(frame_time) == True:
                EnemyDirNum = random.randint(0, 8)
                if EnemyDirNum <= 3:
                    newEnemy = Enemy1(_Player_Packed[2], _Player_Packed[3],
                                      EnemyDirNum, _Bg.window_left,
                                      _Bg.window_bottom)
                    _Enemy.append(newEnemy)
                    SEND_DATA = data_struct.pack_enemy_data(newEnemy)
                    client_socket.send(SEND_DATA)

                if EnemyDirNum >= 4:
                    newEnemy = Enemy2(_Player_Packed[2], _Player_Packed[3],
                                      EnemyDirNum, _Bg.window_left,
                                      _Bg.window_bottom)
                    _Enemy.append(newEnemy)
                    SEND_DATA = data_struct.pack_enemy_data(newEnemy)

                for Enemys in _Enemy:
                    Enemys.A
            client_socket.send(SEND_DATA)
Ejemplo n.º 3
0
    def add(self):
        if self.Whattime >= 0.5:
            self.EnemyDirNum = random.randint(0, 8)
            if self.EnemyDirNum <= 3:
                newEnemy = Enemy1(_player.sx, _player.sy, self.EnemyDirNum,
                                  _Bg.window_left, _Bg.window_bottom)
                _Enemy1.append(newEnemy)

            elif self.EnemyDirNum >= 4:
                newEnemy = Enemy2(_player.sx, _player.sy, self.EnemyDirNum,
                                  _Bg.window_left, _Bg.window_bottom)
                _Enemy1.append(newEnemy)

            self.Whattime = 0
Ejemplo n.º 4
0
    def game_thread(client_socket, room_number):
        global main_time
        room_player = game_sys_main.waitting_room_data[room_number -
                                                       1]['player_number']
        room_player_data = game_sys_main.all_player_data[room_number]
        while 1:
            for i in range(3):
                if (room_player[i] == -1):
                    break
                to_all_event[room_player[i]].wait()
                to_all_event[room_player[i]].clear()
            frame_time = time.clock() - main_time
            main_time += frame_time
            if timer.update(frame_time) == True:  # 적 만드는 부분
                EnemyDirNum = random.randint(0, 8)
                if EnemyDirNum <= 3:
                    newEnemy = Enemy1(EnemyDirNum)
                    dis = []
                    for i in range(3):
                        if (room_player[i] == -1):
                            break
                        dis.append(
                            newEnemy.get_distance(
                                room_player_data['player_x'][i],
                                room_player_data['player_y'][i]))
                    near = dis.index(min(dis))
                    newEnemy.set_dir(room_player_data['player_x'][near],
                                     room_player_data['player_y'][near])
                    _EnemyList.append(newEnemy)

                if EnemyDirNum >= 4:
                    newEnemy = Enemy2(EnemyDirNum)
                    dis = []
                    for i in range(3):
                        if (room_player[i] == -1):
                            break
                        dis.append(
                            newEnemy.get_distance(
                                room_player_data['player_x'][i],
                                room_player_data['player_y'][i]))
                    near = dis.index(min(dis))
                    newEnemy.set_dir(room_player_data['player_x'][near],
                                     room_player_data['player_y'][near])
                    _EnemyList.append(newEnemy)
            for i in range(3):
                if (room_player[i] == -1):
                    break
                if room_player_data['player_isShoot'][i] == True:
                    newBullet = PBullet(room_player_data['player_x'][i],
                                        room_player_data['player_y'][i],
                                        room_player_data['player_dir'][i])
                    _Bullet.append(newBullet)

            for enemy in _EnemyList:
                if enemy.ADD_Bullet() == True:
                    newBullet = EBullet(enemy.x, enemy.y)
                    dis = []
                    for i in range(3):
                        if (room_player[i] == -1):
                            break
                        dis.append(
                            newBullet.get_distance(
                                room_player_data['player_x'][i],
                                room_player_data['player_y'][i]))
                    near = dis.index(min(dis))
                    newBullet.set_dir(room_player_data['player_x'][near],
                                      room_player_data['player_y'][near])
                    _Bullet.append(newBullet)

            for enemy in _EnemyList:
                enemy.update(frame_time)
                for i in range(3):
                    if (room_player[i] == -1):
                        break
                    if collide2(room_player_data['player_x'][i],
                                room_player_data['player_y'][i], enemy.x,
                                enemy.y):
                        enemy.alive = 0
                        room_player_data['player_life'][i] -= 1

            player = 0
            for bullets in _Bullet:
                bullets.update(frame_time)
                if bullets.shooter == player:
                    for enemys in _EnemyList:
                        if collide(bullets, enemys):
                            bullets.alive = 0
                            enemys.alive = 0
                            room_player_data['Score'] += 300

                else:
                    for i in range(3):
                        if (room_player[i] == -1):
                            break
                        if collide2(room_player_data['player_x'][i],
                                    room_player_data['player_y'][i], bullets.x,
                                    bullets.y):
                            bullets.alive = 0
                            room_player_data['player_life'][i] -= 1

            for enemy in _EnemyList:
                if enemy.alive == 0:
                    _EnemyList.remove(enemy)
            for pbullets in _Bullet:
                if pbullets.alive == 0:
                    _Bullet.remove(pbullets)
            for ebullets in _Bullet:
                if ebullets.alive == 0:
                    _Bullet.remove(ebullets)

            for i in range(3):
                if (room_player[i] == -1):
                    break
                to_one_event[room_player[i]].set()
            gc.collect()
Ejemplo n.º 5
0
def update(frame_time):
    global E_NUM ,_Enemy_Data
    #for enemy in _Enemy1:
    #    enemy.update(frame_time, _player.x, _player.y, _Bg.window_left, _Bg.window_bottom,State)
    '''
    for enemy in _Enemy1 :
        if collide(enemy, _player):
            _player.life -=1
            _Enemy1.remove(enemy)
    for ebullets in _EBullet:
        ebullets.update(frame_time, _player.x, _player.y, _Bg.window_left, _Bg.window_bottom )
        PACK_DATA_PBULLET(ebullets)

    for ebullets in _EBullet :
        if collide(ebullets, _player):
            _player.life -= 1
            _EBullet.remove(ebullets)
    for pbullets in _PBullet:
        PACK_DATA_PBULLET(pbullets)
        pbullets.update(frame_time,)
    for pbullets in _PBullet :
        for enemys in _Enemy1 :
            if collide(pbullets, enemys):
                _PBullet.remove(pbullets)
                _Enemy1.remove(enemys)
    for enemy in _Enemy1 :
        if enemy.alive == 0 :
            _Enemy1.remove(enemy)
    for pbullets in _PBullet :
        if pbullets.alive == 0 :
            _PBullet.remove(pbullets)
    for ebullets in _EBullet :
        if ebullets.alive == 0 :
            _EBullet.remove(ebullets)

#SEND_ENEMY_DATA is ENEMY _X,_Y, TYPE
    E_NUM = struct.unpack('=i', recved_E_NUM)[0]
    for enemy in range(0, E_NUM) :
        _Enemy_packed = client_sock.recv(struct.calcsize('=fffi'))
        _Enemy_Data = DataStruct.unpack_enemy_data(_Enemy_packed)
        if _Enemy_Data[2] ==1 :
            newEnemy = Enemy1(_Enemy_Data[0],_Enemy_Data[1], _Bg.window_left, _Bg.window_bottom)
        if _Enemy_Data[2] ==2 :
            newEnemy = Enemy2(_Enemy_Data[0],_Enemy_Data[1],_Bg.window_left, _Bg.window_bottom)
        _Enemy1.insert(_Enemy_Data[3], newEnemy)

        print('_Enemy1 : ', _Enemy1)

    for enemy in _Enemy1 :
        enemy.update()
'''
    _player.update(frame_time)
    Player_packed = DataStruct.pack_player_data(_player)
    client_sock.send(Player_packed)



    recved_NUM = client_sock.recv(struct.calcsize('=ii'))
    Recved_Number_Data = struct.unpack('=ii',recved_NUM )
    #SEND_ENEMY_DATA is ENEMY _X,_Y, TYPE
    E_NUM = Recved_Number_Data[0]
    EB_NUM = Recved_Number_Data[1]
    #?
    print('E_NUM ,EB_NUM : ', E_NUM,EB_NUM)
    for i in range(0, E_NUM) :
        _Enemy_packed = client_sock.recv(struct.calcsize('=ffffi'))
        _Enemy_Data = DataStruct.unpack_enemy_data(_Enemy_packed)
        if _Enemy_Data[2] ==1 :
            newEnemy = Enemy1(_Enemy_Data[0],_Enemy_Data[1],_Enemy_Data[3], _Bg.window_left, _Bg.window_bottom)
            newEnemy.update(frame_time,_player.x, _player.y, _Bg.window_left, _Bg.window_bottom,State)
        if _Enemy_Data[2] ==2 :
            newEnemy = Enemy2(_Enemy_Data[0],_Enemy_Data[1],_Enemy_Data[3],_Bg.window_left, _Bg.window_bottom)
            newEnemy.update(frame_time,_player.x, _player.y, _Bg.window_left, _Bg.window_bottom,State)
        _Enemy1.append(newEnemy)

    for i in range(0,EB_NUM) :
        _Bullet_packed = client_sock.recv(struct.calcsize('=fff'))
        _Bullet_Data = DataStruct.unpack_bullet_data(_Bullet_packed)
        if _Bullet_Data[0] == 1:     #EnemyBullet
            newEBullet = EBullet(_Bullet_Data[1],_Bullet_Data[2] )
        newEBullet.update()
        _EBullet.append(newEBullet)
        if _Bullet_Data[0] == 0:     # playerBullet
            pass
Ejemplo n.º 6
0
def recv_thread(client_sock):
    global AnotherPlayer, _Enemy1, _EBullet, _Bg, Player_Count, _LifeList, iScore

    _ETEMP = []
    _BTEMP = []
    _PTEMP = []
    _LTEMP = []

    while 1:
        Player_packed = DataStruct.pack_player_data(_player)
        client_sock.send(Player_packed)
        _player.isshoot = False

        #AllPlayerRECVED START
        all_player_packed = client_sock.recv(
            struct.calcsize('=iffffffffffffiiiBBBfffi'))

        unpacked_all_player_data = DataStruct.unpack_all_player_data(
            all_player_packed)
        Player_Count = unpacked_all_player_data['player_count']
        iScore = unpacked_all_player_data['Score']
        for i in range(unpacked_all_player_data['player_count']):
            newLIFE = unpacked_all_player_data['player_life'][i]
            _LTEMP.append(newLIFE)
            if i != MyNumber:
                newPlayer = Player2(
                    unpacked_all_player_data['player_x'][i],
                    unpacked_all_player_data['player_y'][i],
                    unpacked_all_player_data['player_dir'][i],
                    unpacked_all_player_data['player_life'][i],
                    _Bg.window_left, _Bg.window_bottom,
                    GameData.waitting_room_data['player_witch_select'][i])
                _PTEMP.append(newPlayer)
            if i == MyNumber:
                _player.life = unpacked_all_player_data['player_life'][i]
        AnotherPlayer = _PTEMP
        _LifeList = _LTEMP
        if len(_PTEMP) > 0:
            _PTEMP = []
        if len(_LTEMP) > 0:
            _LTEMP = []
        #ALLPlayerRECVED END

        #GAMEOVER RECVED START
        packed_is_game_over = client_sock.recv(struct.calcsize('?'))
        GameData.is_game_over = (struct.unpack('?', packed_is_game_over))[0]
        if (GameData.is_game_over):
            print('game_over')
            return
        #GAMEOVER RECVED END

        recved_NUM = client_sock.recv(struct.calcsize('=ii'))
        Recved_Number_Data = struct.unpack('=ii', recved_NUM)

        recved_IN_Window_NUM = client_sock.recv(struct.calcsize('=ii'))
        Recved_IN_Window_Number_Data = struct.unpack('=ii',
                                                     recved_IN_Window_NUM)
        # SEND_ENEMY_DATA is ENEMY _X,_Y, TYPEUM = 0
        E_NUM = Recved_IN_Window_Number_Data[0]
        EB_NUM = Recved_IN_Window_Number_Data[1]
        # ?

        for i in range(0, E_NUM):
            _Enemy_packed = client_sock.recv(struct.calcsize('=fffi'))
            _Enemy_Data = DataStruct.unpack_enemy_data(_Enemy_packed)
            if _Enemy_Data[2] == 1:
                newEnemy = Enemy1(_Enemy_Data[0], _Enemy_Data[1],
                                  _Enemy_Data[3], _Bg.window_left,
                                  _Bg.window_bottom)
                #newEnemy.update(_player.x, _player.y, _Bg.window_left, _Bg.window_bottom, State)
            if _Enemy_Data[2] == 2:
                newEnemy = Enemy2(_Enemy_Data[0], _Enemy_Data[1],
                                  _Enemy_Data[3], _Bg.window_left,
                                  _Bg.window_bottom)
                #newEnemy.update(_player.x, _player.y, _Bg.window_left, _Bg.window_bottom, State)
            _ETEMP.append(newEnemy)
        _Enemy1 = _ETEMP
        if len(_ETEMP) > 0:
            _ETEMP = []

        for i in range(0, EB_NUM):
            _Bullet_packed = client_sock.recv(struct.calcsize('=fff'))
            _Bullet_Data = DataStruct.unpack_bullet_data(_Bullet_packed)
            if _Bullet_Data[0] == 1:  # EnemyBullet
                newBullet = EBullet(_Bullet_Data[1], _Bullet_Data[2])

            elif _Bullet_Data[0] == 0:  # playerBullet
                newBullet = PBullet(_Bullet_Data[1], _Bullet_Data[2])
            #newBullet.update()
            _BTEMP.append(newBullet)
        _EBullet = _BTEMP
        if len(_BTEMP) > 0:
            _BTEMP = []