Beispiel #1
0
def init(mapping, **kwargs):
    global axis_mapping, extreme_values, imperfection_offsets, joystick, DO_CALIBRATE
    choice = 0

    if "joystick" in kwargs.iteritems():
        choice = kwargs.iteritems()["joystick"]

    pygame.init()
    pygame.joystick.init()
    if pygame.joystick.get_count() == 0:
        return None

    print "Number of joysticks:" + str(pygame.joystick.get_count())
    #Copy axis mapping
    axis_mapping = mapping

    #init joystick
    joystick = pygame.joystick.Joystick(choice)
    joystick.init()

    #initialise final values
    for i in range(joystick.get_numaxes()):
        extreme_values.append([0, 0])
        imperfection_offsets.append(0.0)

    if "calibration" in kwargs.iteritems() and kwargs.iteritems(
    )["calibration"]:
        extreme_values = kwargs.iteritems()["calibration"]["boundaries"]
        imperfection_offsets = kwargs.iteritems()["calibration"]["offsets"]
        DO_CALIBRATE = False

    print "Axis count:" + str(joystick.get_numaxes())
    print "Joystick name:" + str(joystick.get_name())
    return joystick
Beispiel #2
0
def get_joysticks(joystick_number=None):
    # Get the state of all the joystick
    joystick_count = pygame.joystick.get_count()
    return_joystick_status = {}
    if joystick_number is not None and joystick_count >= joystick_number:
        joystick = pygame.joystick.Joystick(joystick_number)
        joystick.init()
        return_joystick_status[str(joystick_number)] = {}

        joystick_hats = joystick.get_numhats()
        for hat in range(joystick_hats):
            return_joystick_status[str(joystick_number)][
                "hat " + str(hat)] = joystick.get_hat(hat)

        joystick_buttons = joystick.get_numbuttons()
        return_joystick_status[str(
            joystick_number)]["buttons"] = [0] * joystick_buttons
        for button in range(joystick_buttons):
            return_joystick_status[str(joystick_number)]["buttons"][
                button] = joystick.get_button(button)

        joystick_axes = joystick.get_numaxes()
        for axis in range(joystick_axes):
            return_joystick_status[str(joystick_number)][
                "axis " + str(axis)] = round(joystick.get_axis(axis), 3)
    elif joystick_number is None:
        for i in range(joystick_count):
            joystick = pygame.joystick.Joystick(i)
            joystick.init()
            return_joystick_status[str(i)] = {}

            joystick_hats = joystick.get_numhats()
            for hat in range(joystick_hats):
                return_joystick_status[str(i)][
                    "hat " + str(hat)] = joystick.get_hat(hat)

            joystick_buttons = joystick.get_numbuttons()
            return_joystick_status[str(i)]["buttons"] = [0] * joystick_buttons
            for button in range(joystick_buttons):
                return_joystick_status[str(
                    i)]["buttons"][button] = joystick.get_button(button)

            joystick_axes = joystick.get_numaxes()
            for axis in range(joystick_axes):
                return_joystick_status[str(i)]["axis " + str(axis)] = round(
                    joystick.get_axis(axis), 3)
    return return_joystick_status
Beispiel #3
0
    def __init__(self):
        print("")
        print("Joystick initializing...")
        if pygame.joystick.get_count() == 0:
            print("ERROR! Did not found a joystick!")
            time.sleep(2)
            print("")
            print("Keyboard initializing...")
            self.keyboardcontrole()
        else:
            joystick = pygame.joystick.Joystick(0)
            joystick.init()

            print("Joysticks gevonden:", pygame.joystick.get_count(), "(", joystick.get_name(), ")")
            print("Specs: assen:", joystick.get_numaxes(), ", knoppen:", joystick.get_numbuttons())
            self.knoppen = joystick.get_numbuttons()
            self.assen = joystick.get_numaxes()
            self.ps3Connected = True
Beispiel #4
0
def read_joystick():
    global joystick

    axes = joystick.get_numaxes()
    response = [0] * axes

    for i in range(axes):
        response[i] = joystick.get_axis(i)

    return response
Beispiel #5
0
def discoverAxis():
    global STOP_DISCOVERY
    #initialise final values
    mapping = [""] * joystick.get_numaxes()

    for i in range(joystick.get_numaxes()):
        axis = raw_input(
            "Type the name of the axis you want to move next?(CAPITALS):")
        print("Move axist to both maximums, you have " + str(CALIBRATE_TIME) +
              " seconds...")
        STOP_DISCOVERY = False
        thread = ThreadWithReturnValue(target=discoverMovedAxis)
        thread.start()
        time.sleep(CALIBRATE_TIME)
        STOP_DISCOVERY = True
        j = thread.join()

        if j >= 0 and j < len(mapping):
            mapping[j] = axis
            print mapping

    return mapping
Beispiel #6
0
def init():
    "init the joystick"
    global joystick
    global lastaxisvalue
    global lasthatvalue
    try:
        num = pygame.joystick.get_count()
        if num > 0:
            joystick = pygame.joystick.Joystick(0)
            joystick.init()
            lastaxisvalue = [None] * joystick.get_numaxes()
            lasthatvalue = [[None, None]] * joystick.get_numhats()

    except pygame.error:
        joystick = None
 def __init__(self):
     pygame.joystick.init()
     pygame.joystick.get_init()
     self.count = pygame.joystick.get_count()
     if self.count > 0:
         self.joystick = pygame.joystick.Joystick(0)
         self.joystick.init()
         print '%d joystick(s) connected: %s' % (self.count, joystick.get_name())
         self.num_axes = joystick.get_numaxes()
         self.num_buttons = joystick.get_numbuttons()
         self.num_hats = joystick.get_numhats()
         print 'Joystick has %d axes, %d buttons and %d hats.' % (num_axes, num_buttons, num_hats)
         pygame.event.pump()
         self.old_axis = []
         for num in range(self.num_axes):
             self.old_axis.append(0.0)
Beispiel #8
0
def run():

    pygame.init()
    if not pygame.joystick.get_count():
        print 'ERROR: joystick count is 0'
        exit()

    # dasboard_app = subprocess.Popen('python app.py d')

    joystick = pygame.joystick.Joystick(0)
    joystick.init()

    joystick_num_buttons = joystick.get_numbuttons()
    joystick_num_axes = joystick.get_numaxes()

    print 'joystick found:', joystick.get_name()
    print 'count buttons:', joystick_num_buttons
    print 'count axes:', joystick_num_axes

    # кнопки
    JOY_STATE.extend([0 for jb in JoyButtons.BUTTONS])
    # ползунки
    JOY_STATE.extend([-1.0 if ja in (JoyButtons.JOY_LT, JoyButtons.JOY_RT) else 0.0 for ja in JoyButtons.JOYS])

    sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
    sender.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sender.bind((settings.SOCKET_CLIENT_HOST, settings.SOCKET_CLIENT_PORT))

    # нам нужны только события джойстика
    pygame.event.set_allowed([JOYAXISMOTION, JOYBUTTONUP, JOYBUTTONDOWN, QUIT])

    get = pygame.event.get
    sleep = time.sleep

    send_to = sender.sendto
    host = settings.SERVER_HOST
    port = settings.SERVER_PORT

    while True:
        # бесконечный сбор событий с геймпада
        if process_events(get(), joystick_num_buttons):
            # print(JOY_STATE)
            send_to(','.join(str(i) for i in JOY_STATE), (host, port))
        else:
            break
        sleep(0.1)
Beispiel #9
0
def postactive():
    keystate = pygame.key.get_pressed()
    for key in range (len(keystate)):
        if keystate[key]:
            #I don't know how to get unicode
            pygame.event.post(pygame.event.Event(KEYDOWN, {'key': key, 'mod': pygame.key.get_mods()}))
    if joystick:
        for button in range(joystick.get_numbuttons()):
            if joystick.get_button(button):
                pygame.event.post(pygame.event.Event(JOYBUTTONDOWN, {'joy': joystick.get_id(), 'button': button}))
        for hat in range(joystick.get_numhats()):
            value = joystick.get_hat(hat)
            if 0 != value[0] or 0 != value[1]:
                pygame.event.post(pygame.event.Event(JOYHATMOTION, {'joy': joystick.get_id(), 'hat': hat, 'value': value}))
        for axis in range(joystick.get_numaxes()):
            lastaxisvalue[axis] = None
            value =  joystick.get_axis(axis)
            pygame.event.post(pygame.event.Event(JOYAXISMOTION, {'joy': joystick.get_id(), 'axis': axis, 'value': value}))
Beispiel #10
0
name = sys.argv[1]
registry = rotorc.RemoteRegistry( name )
options  = registry.options()


registry.registerMessageType( "JOYSTICK", joystickDefinition )
frequency = options.getDouble( name, "frequency", 10 )



joystickInfo = rotorc.Structure( "Joystick", None, registry )

pygame.init()
pygame.joystick.init()
joystick = pygame.joystick.Joystick( 0 )
joystick.init()
time = rotorc.seconds()

while True:
  delta   = rotorc.seconds()
  time = delta
  pygame.event.pump()
  joystickInfo.axesCount = joystick.get_numaxes()
  for i in xrange( joystickInfo.axesCount ):
    joystickInfo.axes[i] = joystick.get_axis( i )
  joystickInfo.buttonCount = joystick.get_numbuttons()
  for i in xrange( joystickInfo.buttonCount ):
    joystickInfo.buttons[i] = joystick.get_button( i )
  registry.sendStructure( "JOYSTICK", joystickInfo )
  rotorc.Thread.sleep( 0.1 )
Beispiel #11
0
    def run(self):
        while True:
            self.window.blit(
                pygame.transform.flip(self.cam.get_image(), self.inversed.h,
                                      self.inversed.v), (0, 0))
            self.window.blit(self.intizalize, (10, 10))
            self.window.blit(self.inv_sys, (10, 40))
            self.window.blit(self.position_X, (10, 70))
            self.window.blit(self.position_Y, (10, 100))
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()

#evenement du clavier:
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        if self.online:
                            self.intizalize = self.commande.initialize(
                                'Offline')
                            self.online = False
                        else:
                            self.intizalize = self.commande.initialize(
                                'Online')
                            self.online = True

                    if self.online:
                        if event.key == pygame.K_F4 or event.key == pygame.K_q:
                            sys.exit()

                        if event.key == pygame.K_i:
                            if self.inversed.boolean:
                                self.inversed.set_bool(False)
                                self.inversed.h = 1
                            else:
                                self.inversed.set_bool(True)
                                self.inversed.h = 0
                            self.inv_sys = self.commande.initialize(
                                'Inversed : ' + str(self.inversed.boolean))

                        if event.key == pygame.K_UP:
                            self.commande.forward()
                            self.position_Y = self.commande.get_position_Y()

                        if event.key == pygame.K_DOWN:
                            self.commande.backward()
                            self.position_Y = self.commande.get_position_Y()

                        if event.key == pygame.K_RIGHT:
                            self.commande.right()
                            self.position_X = self.commande.get_position_X()

                        if event.key == pygame.K_LEFT:
                            self.commande.left()
                            self.position_X = self.commande.get_position_X()

                        if event.key == pygame.K_a:
                            self.commande.grab(self.window, 'drop')

                        if event.key == pygame.K_l:
                            self.commande.drop(self.window, 'grab')

                        if event.key == pygame.K_s:
                            self.commande.screensaver(self.window)

#evenement du joystick bouton:
                if event.type == pygame.JOYBUTTONDOWN:
                    if event.button == 5:  #fermeture de la pince
                        self.commande.grab(self.window, 'grab')
                    if event.button == 4:  #Ouverture de la pince
                        self.commande.drop(self.window, 'drop')
                    else:
                        print(event.button)

#evenement du joystick axis:
                if event.type == pygame.JOYAXISMOTION:

                    if (joystick.get_axis(0) > -32768
                            and joystick.get_axis(0) < 32768):
                        if (joystick.get_axis(0) > -32768
                                and joystick.get_axis(0) < 0):
                            self.commande.arm_rotation_left()

                    if (joystick.get_axis(0) > 0
                            and joystick.get_axis(0) <= 32768):
                        self.commande.arm_rotation_right()

                    if (joystick.get_axis(1) > -32768
                            and joystick.get_axis(1) < 32768):
                        if (joystick.get_axis(1) > -32768
                                and joystick.get_axis(1) < 0):
                            self.commande.arm_rotation_forward()

                    if (joystick.get_axis(1) > 0
                            and joystick.get_axis(1) <= 32768):
                        self.commande.arm_rotation_backward()
#evenement du joystick hat:
                if event.type == pygame.JOYHATMOTION:

                    if (joystick.get_hat(0) == (0, 1)):  #up
                        self.commande.arm_rotation_forward()
                    if (joystick.get_hat(0) == (0, -1)):  #down
                        self.commande.arm_rotation_backward()
                    if (joystick.get_hat(0) == (1, 0)):  #droite
                        self.commande.arm_rotation_right()
                    if (joystick.get_hat(0) == (-1, 0)):  #gauche
                        self.commande.arm_rotation_left()


#initialisation du joystick et des bouton et axis:
            joystick_count = pygame.joystick.get_count()

            for i in range(joystick_count):
                joystick = pygame.joystick.Joystick(i)
                joystick.init()

                buttons = joystick.get_numbuttons()
                axes = joystick.get_numaxes()
Beispiel #12
0
    def run_game():
        global ch, dobollet, db, wea, t
        pygame.init()
        pygame.mixer.init()
        shoot = mixer.Sound("C:\windows\media\Ring02.wav")
        music = mixer.Sound("sounds/Windows Critical Stop.wav")
        image = pygame.image.load('bg.gif')

        turn = 0

        ch = 10

        fg = 1
        pfg = 1
        joysticks = [
            pygame.joystick.Joystick(x)
            for x in range(pygame.joystick.get_count())
        ]
        print(joysticks.pop(1))
        for joystick in joysticks:
            joystick.init()
        i = 0

        j = False
        sit = False
        sco = 0

        ai_settings = Settings()
        screen = pygame.display.set_mode(
            (ai_settings.screen_width, ai_settings.screen_height))
        pygame.display.set_caption('Alien Invasion')
        ship = Ship(ai_settings, screen)
        bullets = Group()

        ships = Group()
        blocks = Group()
        aliens = Group()
        l = 0
        r = 0
        godown = 0
        sb = Scoreboard(ai_settings, screen, 0, sco)
        alies = Group()
        buttons = Group()
        yu = False
        #rint(ship.y)iii
        alienbullets = Group()
        ert = 0
        tr = [
            1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 0, 0, 0, 0, 1, 1, 1, 1, 0,
            0, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
            1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
            1, 2
        ]
        sty = Group()
        uii = 0
        do_liberint(pygame, Block, blocks, ai_settings, screen, 'liberint.txt',
                    Alien, aliens)
        upup = 0
        ship2 = Ship(ai_settings, screen)
        for alien in aliens.sprites():
            alien.image = pygame.image.load('bomb.gif')
        poweraps = Group()
        aiens = Group()
        ant = Ant_men(ai_settings, screen, ship)
        ships.add(ship)
        ships.add(ship2)
        shoot.play(-1)
        time = 0
        un = 0
        while True:

            if r == 0:
                #ship.imageship.image = pygame.image.load('SCrightup.gif')
                ship.blitme()
                #pygame.display.flip()

                for alien in blocks.sprites():

                    alien.x -= 1
                    alien.rect.x = alien.x
                #pygame.display.flip()
                #pygame.display.flip()
                #pygame.display.flip()
                #ship.image = pygame.image.load('SCright.gif')
                ship.blitme()
                # if pygame.sprite.spritecollideany(ship,blocks):
                #     for alien in poweraps.sprites():
                #         alien.x += 1
                #         alien.rect.x = alien.x
                #     for alien in blocks.sprites():
                #         alien.x += 1
                #         alien.rect.x = alien.x

            if l == 0:

                #                ship.image = pygame.image.load('SCleftup.gif')

                #pygame.display.flip()

                for alien in blocks.sprites():

                    alien.x += 1
                    alien.rect.x = alien.x
                #pygame.display.flip()
                #pygame.display.flip()
                #pygame.display.flip()

                #ship.blitme()
                # if pygame.sprite.spritecollideany(ship,blocks):
                #     for alien in poweraps.sprites():
                #         alien.x += 1
                #         alien.rect.x = alien.x
                #     for alien in blocks.sprites():
                #         alien.x += 1
                #         alien.rect.x = alien.x

            if r == 0:

                ant.x -= 1
                ant.rect.x = ant.x
                # if pygame.sprite.spritecollideany(ship,blocks):
                #     for alien in poweraps.sprites():
                #         alien.x += 1
                #         alien.rect.x = alien.x
                #     for alien in blocks.sprites():
                #         alien.x += 1
                #         alien.rect.x = alien.x

            if l == 0:

                ant.x += 1
                ant.rect.x = ant.x  # if pygame.sprite.spritecollideany(ship,blocks):
                #     for alien in poweraps.sprites():
                #         alien.x -= 1
                #         alien.rect.x = alien.x
                #     for alien in blocks.sprites():
                #         alien.x -= 1
                #         alien.rect.x = alien.x

            for event in pygame.event.get():

                #for event in pygame.event.get():

                # #                if event.type == pygame.KEYDOWN:
                #                     if event.key == pygame.K_1:
                #                         first = randint(0,220)
                #                         second = randint(0,220)
                #                         three = randint(0,220)
                #                         ai_settings.bg_color = (first,second,three)
                #                     if event.key == pygame.K_b:
                #                         sys.exit()
                #                     if event.key == pygame.K_RIGHT:

                #                         #ship.movin_right = True
                #                         cr = 0
                #                         t = 2
                #                     if event.key == pygame.K_LEFT:
                #                         #ship.movin_left = True
                #                         cl = 0
                #                         t = 3
                # if event.key == pygame.K_r:
                #     #ship.movin_left = True
                #     if len(bullets) <= bulets:
                #         new_bullet = Bullet(ai_settings,screen,ship,aliens,bullets,0)
                #         bullets.add(new_bullet)
                # if event.key == pygame.K_UP:

                #     cu = 0
                #     t = 0
                if event.type == pygame.MOUSEBUTTONDOWN:
                    xy, yx = pygame.mouse.get_pos()
                    blok = Block(ai_settings, screen, 'fkdf')
                    blok.rect.x, blok.rect.y = xy, yx
                    blok.x, blok.y = xy, yx
                    blocks.add(blok)
                if event.type == pygame.JOYAXISMOTION:
                    buttons = joystick.get_numaxes()
                    for i in range(buttons):
                        but = joystick.get_axis(0)

                        if but < -.5:

                            ship.x -= 1
                            ship.rect.x = ship.x
                            t = 3
                        but = joystick.get_axis(0)
                        if but > .5:

                            ship.x += 1
                            ship.rect.x = ship.x

                            t = 2
                        but = joystick.get_axis(1)
                        if but < -.5:
                            ship.y -= 1
                            ship.rect.y = ship.y
                        if but > .5:
                            ship.y += 1
                            ship.rect.y = ship.y

                        # but = joystick.get_axis(1)
                        # if but <  -.5:

                        #     ship.y -= 1
                        #     ship.rect.y = ship.y
                        #     if pygame.sprite.spritecollideany(ship,blocks):
                        #         ship.y += fuster
                        #         ship.rect.y = ship.y

                        #     t = 0
                        # but = joystick.get_axis(1)
                        # if but > .5:

                        #     ship.y += 1
                        #     ship.rect.y = ship.y
                        #     if pygame.sprite.spritecollideany(ship,blocks):
                        #         ship.y -= fuster
                        #         ship.rect.y = ship.y
                        #     t = 1

                buttons = joystick.get_numhats()
                for i in range(buttons):
                    but = joystick.get_hat(i)
                    if but == (-1, 0):

                        ship.rect.x -= 1
                    but = joystick.get_hat(i)
                    if but == (1, 0):
                        ship.rect.x += 1
                    but = joystick.get_hat(i)

                    if but == (0, -1):

                        ship.rect.y -= 1
                    but = joystick.get_hat(i)
                    if but == (0, 1):

                        ship.rect.y += 1
                    but = joystick.get_hat(i)
                    print(but)
                    #if but == (0,1):

                    #     j = False
                    #     pfg *=-1
                    #     j = True
                    # but = joystick.get_hat(i)

                if event.type == pygame.JOYBUTTONDOWN:
                    buttons = joystick.get_numbuttons()
                    for button in range(buttons):
                        # # print(button)
                        # #pass
                        # # if button == (0,0):
                        # #     music.play()

                        # #     new_bullet = Bullet(ai_settings,screen,ship,aliens,bullets,alien,t)
                        # #     bullets.add(new_bullet)
                        but = joystick.get_button(0)
                        if but:
                            j = False
                            pfg *= -1
                            j = True
                        but = joystick.get_button(2)
                        if but:

                            if upup == 0:

                                upup = 1
                                break
                            if upup == 1:

                                upup = 0
                                break

                        #print(but)

                        # if but == 2:

                        #     j = False
                        #     pfg *=-1
                        #     j = True
                        # but = joystick.get_button(button)
                        # if but == 1:
                        #     upup = 1

                elif event.type == pygame.JOYBUTTONUP:
                    #buttons = joystick.get_numbuttons()
                    buttons = joystick.get_numbuttons()
                    for button in range(buttons):
                        # # print(button)
                        # #pass
                        # # if button == (0,0):
                        # #     music.play()

                        # #     new_bullet = Bullet(ai_settings,screen,ship,aliens,bullets,alien,t)
                        # #     bullets.add(new_bullet)

                        but = joystick.get_button(2)
                        if but:
                            upup = 0

                if event.type == pygame.KEYDOWN:

                    if event.key == pygame.K_LEFT:

                        cl2 = 0
                        cr2 = 1
                        cu2 = 1
                        cd2 = 1
                        t2 = 3

                    if event.key == pygame.K_RIGHT:

                        cl2 = 1
                        cr2 = 0
                        cu2 = 1
                        cd2 = 1
                        t2 = 2
                        #but = joystick.get_hat(i)
                    if event.key == pygame.K_DOWN:

                        cl2 = 1
                        cr2 = 1
                        cu2 = 1
                        cd2 = 0
                        t2 = 1
                    #but = joystick.get_hat(i)
                    if event.key == pygame.K_UP:

                        cl2 = 1
                        cr2 = 1
                        cu2 = 0
                        cd2 = 1
                        t2 = 0
                    if event.key == pygame.K_v:
                        new_bullet = Bullet(ai_settings, screen, ship2, aliens,
                                            bullets, alien, t2)
                        bullets.add(new_bullet)

#                 elif event.type == pygame.KEYUP:
#                     if event.key == pygame.K_RIGHT:

#                         ship.movin_right = False
#                         cr = 1

#                     if event.key == pygame.K_LEFT:
#                         ship.movin_left = False
#                         cl = 1
#                     if event.key == pygame.K_UP:

#                         cu = 1

#                     if event.key == pygame.K_DOWN:
#                         cd = 1
#                     if event.key == pygame.K_2:
#                         ship.image = pygame.image.load(random.choice(images))
#                     if event.key == pygame.K_DOWN:
#                         ship.movin_down = False
# #276
#276
            ship.update(blocks, ship)

            bullets.update(bullets, aliens)
            collisions = pygame.sprite.groupcollide(ships, aliens, False, True)

            #print('you lose')
            #break
            ship.blitme()

            # if pygame.sprite.spritecollideany(ship,blocks):

            #     for alien in blocks.sprites():
            #         alien.y += 1
            #         alien.rect.y = alien.y
            #     ant.y += 1
            #     ant.rect.y = ant.y

            #    godown = 0
            #           pygame.display.flip()
            for bullet in bullets.copy():
                if bullet.rect.bottom <= 0 or bullet.rect.bottom >= 900 or bullet.rect.centerx <= 0 or bullet.rect.centerx >= 1000:
                    bullets.remove(bullet)

            screen.fill(ai_settings.bg_color)
            # for bullet in alienbullets.copy():
            #     if bullet.rect.bottom >= 900:
            #         bullets.remove(bul
            # screen.fill(ai_settings.bg_color)

            # for bullet in alienbullets.sprites():

            #     bullet.draw_bullet()

            #     first = randint(0,200)
            #     second = randint(0,200)
            #     three = randint(0,200)
            #     ai_settings.bullet_color = (first,second,three)
            #     collisins = pygame.sprite.groupcollide(blocks,bullets,True,True)
            collisions = pygame.sprite.groupcollide(ships, poweraps, False,
                                                    True)
            if len(aliens) <= 0:
                print('you win')
                break

            # for alien in aliens.sprites():

            #     if pygame.sprite.spritecollideany(alien,blocks):
            #         alien.duraction *= -1
            for bullet in bullets.sprites():

                bullet.draw_bullet()
                collisions = pygame.sprite.groupcollide(
                    bullets, aliens, True, True)
                if collisions:
                    moneys += 1

                collisions = pygame.sprite.groupcollide(
                    bullets, blocks, True, False)

                first = randint(0, 200)
                second = randint(0, 200)
                three = randint(0, 200)
                ai_settings.bullet_color = (first, second, three)

            bullets.update(bullets, aliens)
            ship.blitme()
            #chekupdown_fleet_edges(ai_settings,aliens)
            #alien.blitme()
            bullets.draw(screen)
            sb.show_score()
            alienbullets.update(bullets, aliens)
            collisions = pygame.sprite.groupcollide(ships, aliens, False, True)
            aliens.draw(screen)

            #if un == 0:

            blocks.draw(screen)
            blocks.update()
            if pygame.sprite.spritecollideany(ant, ships):
                if pfg == -1:
                    g = 1

                    bullets.empty()
                    ch -= 1
                    if ch <= 0:
                        ant.image = pygame.image.load('bowserflat.gif')
                        un = 1
                    #    print('you win')
                    #    break

                    j = False
                    pfg *= -1

                    j = True
                else:
                    if un == 0:
                        print('you lose')
                        sys.exit()

            if pygame.sprite.spritecollideany(ant, bullets):
                ch -= 1
                bullets.empty()
                if ch <= 0:

                    print('you win')
                    break
            bullets.update(0, 0)
            bullets.draw(screen)
            ship2.blitme()
            #if bezero == 34:
            #bezero = 0

            #sb.show_score()
            #poweraps.draw(screen)
            #pygame.display.update()
            #screen.blit(image,(0,0))
            pygame.display.flip()
Beispiel #13
0
import pygame.joystick

pygame.init()
pygame.joystick.init()

joystick_count = pygame.joystick.get_count()
print("Number of joysticks: ", joystick_count)

joystick = pygame.joystick.Joystick(0)
joystick.init()

name = joystick.get_name()
print(name)

axes = joystick.get_numaxes()
print("Nombre d'axes : ", axes)

buttons = joystick.get_numbuttons()
print("Nombre de boutons : ", buttons)

hats = joystick.get_numhats()
print("Nombres de HAT : ", hats)

running = True
while running:
    pygame.event.get()
    axis_0 = joystick.get_axis(0)
    axis_1 = joystick.get_axis(1)
    axis_2 = joystick.get_axis(2)
    axis_3 = joystick.get_axis(3)