Dec-06-2019, 12:58 AM
This is code for selecting a star from a map and asking if you want to travel there. Move a selector sprite over the star sprite, hit enter, and it asked the right question with the "destination" name correct. It works up to the bottom While loop. It loops but doesn't accept the key input.
def get_keys(self): self.vx, self.vy = 0, 0 keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] or keys[pygame.K_a]: self.vx = -selector_speed if keys[pygame.K_RIGHT] or keys[pygame.K_d]: self.vx = selector_speed if keys[pygame.K_UP] or keys[pygame.K_w]: self.vy = -selector_speed if keys[pygame.K_DOWN] or keys[pygame.K_s]: self.vy = selector_speed if self.vx != 0 and self.vy != 0: self.vx *= 0.7071 self.vy *= 0.7071 if keys[pygame.K_RETURN]: self.destination() def destination(self): hits = pygame.sprite.groupcollide(stars, selectors, False, False) for hit in hits: destination = hit.name print("Travel to " + destination + "?") asking = True while asking: keys = pygame.key.get_pressed() if keys[pygame.K_y]: print("yes") #going = Go_destination(destination) if keys[pygame.K_n]: print("no")I've gone cross-eyes staring at it.