def get_joystick(self): for _ in pygame.event.get(): pass if not self.joysticks: return 0, 0, 0, 0 joystick = self.joysticks[0] return joystick.get_axis(0), joystick.get_axis(1), \ joystick.get_button(0), joystick.get_button(1)
def joystickcontrole(self): try: while self.ps3Connected: for event in pygame.event.get(): if event.type == QUIT: self.quit_game() if event.type == JOYBUTTONDOWN: for i in range(self.knoppen): # Haal de waarde van de knop op. knop = joystick.get_button(i) if knop == 1: print("Knop:", i, "ingedrukt!") if event.type == JOYAXISMOTION: if event.dict['axis'] == 1: for i in range(self.assen): # Haal de waarde van de as op. eenas = joystick.get_axis(i) if eenas != 0: if i == 0: self.asrichting = 'X' if i == 1: self.asrichting = 'Y' if i == 2: self.asrichting = 'X' if i == 3: self.asrichting = 'Y' print("AS", i, "waarde:", self.asrichting, eenas) except KeyboardInterrupt: pygame.quit()
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
def get_keymaps(self): joystick = self.joystick joystick_x = self.joystick.get_axis(0) num_buttons = joystick.get_numbuttons() pressed_buttons = [i for i in range(num_buttons) if joystick.get_button(i)] keymaps = self.mapping.get(joystick_x, pressed_buttons) return keymaps
def checkJoystickButtons(): buttonStates.fire = joystick.get_button(1) xAxis = joystick.get_axis(0) yAxis = joystick.get_axis(1) buttonStates.left = xAxis < -0.01 buttonStates.right = xAxis > 0.01 buttonStates.up = yAxis < -0.01 buttonStates.down = yAxis > 0.01
def doEvents(self, event): """ The mighty all-running loop inherited from gameEnging.Scene. Please have a look in the docstring of gameEnging.Scene. """ if not self.ready_for_playing: # Just in case we actually see this game in reality # if event.type == JOYAXISMOTION: # if self.joystick.both_axis_active(): if event.type == pygame.KEYDOWN: if event.key == STARTBUTTON: self.ready_for_playing = True print "Game started. Now guess!" print "Player1 keys: W, A, S, D" print "Player2 keys: I, J, K, L" pygame.event.post(pygame.event.Event(PLAYSEQUENCE)) if event.type == pygame.KEYDOWN: key = event.key if key in (pygame.K_ESCAPE, pygame.K_q): self.keepGoing = False if key == K_c: # manual override a.k.a. jump to next level with key "c" self.sequence.next_level() if self.ready_for_input: for player in self.players: if key in player.keys: guess = player.keys[key] if player.add_guess(guess, self.sequence.level): self.light(LIGHTS[guess-1], player.name) if self.sequence.completed_by_players(): for player in self.players: print "Player %s guessed: %s Sequence is: %s" % (player.name, player.guess, self.sequence.get_sequence()) if player.guess != self.sequence.get_sequence(): player.die() self.sequence.next_level() self.ready_for_input = True self.ready_for_playing = False pygame.time.delay(500) elif event.type == JOYBUTTONDOWN: # dummy things for the joystick for num in range(num_buttons): button = joystick.get_button(num) if button: print "Button pressed: " + str(num) elif event.type == PLAYSEQUENCE: if self.ready_for_playing: self.play_sequence() self.ready_for_input = True
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}))
def wiimote_handler(): joystick = pygame.joystick.Joystick(wii_joy_index) joystick.init() joy_x = joystick.get_axis(0) joy_y = joystick.get_axis(1) joy_buttons = list() for i in range(0, 8): joy_button = joystick.get_button(i) joy_buttons.append(joy_button) pub_direction((joy_x, joy_y)) pub_arm(joy_buttons[0] - joy_buttons[1]) pub_shovel(joy_buttons[2] - joy_buttons[3]) pitch = joy_buttons[4] - joy_buttons[5] yaw = joy_buttons[6] - joy_buttons[7] pub_camera(pitch, yaw)
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 )
def goon(): global q, q_gui if not dryrun: t = threading.Thread(target=gcodespitter) t.daemon = True t.start() st = 0 b0 = b1 = b2 = b3 = 0 correction = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] def print_(x): print >> sys.stderr, x calibd = skip_calib # False if calibaction == CALIB_LOAD: calibd = True with open(calibfile, "r") as f: correction = map( lambda j: map(float, j), map(lambda x: map(lambda z: z.strip(), x.split(",")), f.readlines()) ) pygame.joystick.init() # initialize joystick module pygame.joystick.get_init() # verify initialization (boolean) joystick_count = pygame.joystick.get_count() # get number of joysticks # it's for some case, important to get the joystick number ... if joystick_count == 1: joystick = pygame.joystick.Joystick(0) joystick.get_name() joystick.init() joystick.get_init() while True: # time.sleep(0.00001) if joystick_count == 1: # verify initialization (maybe cool to do some error trapping with this so game doesn't crash pygame.event.pump() # So Now i can get my joystick Axis events xax_ = joystick.get_axis(0) yax_ = joystick.get_axis(1) zax_ = joystick.get_axis(3) buttons = joystick.get_numbuttons() b0 = joystick.get_button(0) b1 = joystick.get_button(1) b2 = joystick.get_button(2) b3 = joystick.get_button(3) if st == 1: print >> sys.stderr, "put joystick to center and press B0", elif st == 3: print >> sys.stderr, "put joystick to left and press B0", elif st == 5: print >> sys.stderr, "put joystick to right and press B0", elif st == 7: print >> sys.stderr, "put joystick to down and press B0", elif st == 9: print >> sys.stderr, "put joystick to up and press B0", elif st == 11: print >> sys.stderr, "put joystick to bottom and press B0", elif st == 13: print >> sys.stderr, "put joystick to top and press B0", if not calibd: st = calib(st, b0, (xax_, yax_, zax_), correction) print >> sys.stderr, correction if st == 14: print >> sys.stderr, "CALIBRATED.", calibd = True if calibaction == CALIB_SAVE: with open(calibfile, "w+") as f: f.write("\n".join(map(lambda x: ",".join(map(str, x)), correction))) continue (xax, yax, zax) = correct(correction, (xax_, yax_, zax_)) # print >> sys.stderr, correction, # print >> sys.stderr, (xax, yax, zax) if not dryrun: if b1 != b2: if b1: # q.put('G1 Z10', block=False) put_nonblock(q, "G1 Z%f" % (zax)) if b2: # q.put('G1 Z-10', block=False) put_nonblock(q, "G1 Z%f" % (-zax)) # q.put('G1 Z-%f' % (zax), block=False) if b3: put_nonblock(q, "G1 X%f Y%f" % (xax, yax)) # q.put('G1 X%f Y%f' % (xax, yax), block=False) print "q.join" # q.join() if b0: put_nonblock(q_gui, "save")
def input(events): for event in events: if event.type == JOYBUTTONDOWN: button0 = joystick.get_button(0) button1 = joystick.get_button(1) button2 = joystick.get_button(2) button3 = joystick.get_button(3) button4 = joystick.get_button(4) button5 = joystick.get_button(5) button6 = joystick.get_button(6) button7 = joystick.get_button(7) button8 = joystick.get_button(8) button9 = joystick.get_button(9) b = [button0,button1,button2,button3,button4,button5,button6,button7,button8,button9] global base global altura global complemento global garra global STEP global ESTADO_INICIAL global lista_nos_global global lista_nos_local global ser if b[5] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'base_dir', 0, False) if base < grafo.MAX_BASE-STEP: base+=STEP configurar_passos(base,altura,complemento,garra) elif b[4] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'base_esq', 0, False) if base > grafo.MIN_BASE: base-=STEP configurar_passos(base,altura,complemento,garra) elif b[0] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'altura_aum', 0, False) if altura < grafo.MAX_ALT-STEP: altura+=STEP configurar_passos(base,altura,complemento,garra) elif b[2] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'altura_dim', 0, False) if altura > grafo.MIN_ALT: altura-=STEP configurar_passos(base,altura,complemento,garra) elif b[3] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'comp_aum', 0, False) if complemento < grafo.MAX_COMP-STEP: complemento+=STEP configurar_passos(base,altura,complemento,garra) elif b[1] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'comp_dim', 0, False) if complemento > grafo.MIN_COMP: complemento-=STEP configurar_passos(base,altura,complemento,garra) elif b[6] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'garra_fec', 0, False) garra+=1 if garra == 2: garra=0 configurar_passos(base,altura,complemento,garra) elif garra ==1: garra=1 configurar_passos(base,altura,complemento,garra) elif b[7] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'garra_abr', 0, False) '''garra='A' configurar_passos(base,altura,complemento,garra)''' sleep(1) print 'COLETA REALIZADA COM SUCESSO!' sleep(1) criar_lista_global() voltar_pro_inicio() print 'COLETA ATUAL',lista_nos_local sleep(.1) print 'COLETA GERAL',lista_nos_global sleep(1) if len(lista_nos_global) == 1: print 'VOCE POSSUI',len(lista_nos_global),'COLETA! FORNECA OUTRAS!' else: print 'VOCE POSSUI',len(lista_nos_global),'COLETAS! FORNECA OUTRAS!' elif b[8] == 1: #mqttc.publish(AWS_IOT_TOPIC, 'back_index', 0, False) sleep(1) #print 'INCIANDO A FASE DE TREINAMENTO...' #decrementar_pesos(lista_nos_global) caixa_de_dialogo1() elif b[9] == 0: #mqttc.publish(AWS_IOT_TOPIC, 'back_index', 0, False) #selecionar_nos_visitados() print 'BOTAO START QUE NAO FUNCIONA' else: print 'AQUI EH OUTRA COISA' '''
def gather_inputs(player, joystick): player.main_stick = [joystick.get_axis(0), joystick.get_axis(1)] player.c_stick = (joystick.get_axis(5), joystick.get_axis(4)) player.r_trigger = joystick.get_axis(3) player.l_trigger = joystick.get_axis(2) # keys = pygame.key.get_pressed() # buttons = joystick.get_buttons() # create deadzone if abs(player.main_stick[0]) < 0.22: player.main_stick[0] = 0 if abs(player.main_stick[1]) < 0.22: player.main_stick[1] = 0 # if joystick.event == pygame.JOYBUTTONDOWN: if joystick.get_button(0): # A player.akey = True print("controller pressed A") else: player.akey = False if joystick.get_button(1): # B player.specialkey = True else: player.specialkey = False if joystick.get_button(2) or joystick.get_button(3): # X and Y player.jumpkey = True else: player.jumpkey = False player.canJump = True if joystick.get_button(4): # Z player.grabkey = True else: player.grabkey = False if joystick.get_button(5) or joystick.get_button(6): # R and L player.blockkey = True else: player.blockkey = False player.canBlock = True if joystick.get_button(7): # START player.menukey = True else: player.menukey = False if joystick.get_button(8): # UP player.upkey = True else: player.upkey = False if joystick.get_button(9): # DOWN player.downkey = True else: player.downkey = False if joystick.get_button(10): # LEFT player.leftkey = True else: player.leftkey = False if joystick.get_button(11): # RIGHT player.rightkey = True else: player.rightkey = False
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()
if hat[1] == 1: robot.send_vx = x if hat[1] == 0: robot.send_vx = 0 if hat[0] == 0: robot.send_vw = 0 if hat[1] == -1: robot.send_vx = -1 * x if hat[0] == -1: robot.send_vw = w if hat[0] == 1: robot.send_vw = -1 * w robot.set_velocity() elif event.type == pygame.JOYBUTTONDOWN: button_up = joystick.get_button(6) button_down = joystick.get_button(7) button_stop = joystick.get_button(2) print(button_down, button_up, button_stop) if button_stop == 1: robot.stop_control() elif button_up == 1: if x + 0.1 <= max_x: x += 0.1 if w + 0.1 <= max_w: w += 0.1 elif button_down == 1: if x - 0.1 >= 0: x -= 0.1 if w - 0.1 >= 0: w -= 0.1
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) print(axis_0, axis_1, axis_2, axis_3) button_11 = joystick.get_button(11) if button_11 == 1: running = False pygame.quit()