Search
Duplicate

캐릭터 선택창

캐릭터 선택창은 마우스 입력을 활용하여 제작한다.
제작한 선택창 맵(pygame활용)
def select(self): pygame.init() SCREEN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) set_count = 0 player = [] player.append(pygame.image.load("state/bunnyFace_Mute.png")) player.append(pygame.image.load("state/catFace_Mute.png")) player.append(pygame.image.load("state/cowFace_Mute.png")) player.append(pygame.image.load("state/mouseFace_Mute.png")) player[0] = pygame.transform.scale(player[0], (100, 100)) player[1] = pygame.transform.scale(player[1],(100,100)) player[2] = pygame.transform.scale(player[2],(100,100)) player[3] = pygame.transform.scale(player[3],(100,100)) player_Rect = player[0].get_rect() cat_Rect = player[1].get_rect() cow_Rect = player[2].get_rect() mouse_Rect = player[3].get_rect() player_Rect.centerx = 200 player_Rect.centery = 200 cat_Rect.centerx = 400 cat_Rect.centery = 200 cow_Rect.centerx = 600 cow_Rect.centery = 200 mouse_Rect.centerx = 800 mouse_Rect.centery = 200 MOVE = False playing = TRUE while playing: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.MOUSEBUTTONDOWN: pygame.mouse.get_rel() mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] > player_Rect.left and mouse_pos[0] < player_Rect.right and mouse_pos[1] > player_Rect.top and mouse_pos[1] < player_Rect.bottom: MOVE = True set_count = 1 pygame.mouse.set_cursor(*pygame.cursors.broken_x) if mouse_pos[0] > cat_Rect.left and mouse_pos[0] < cat_Rect.right and mouse_pos[1] > cat_Rect.top and mouse_pos[1] < cat_Rect.bottom: MOVE = True set_count = 2 pygame.mouse.set_cursor(*pygame.cursors.broken_x) if mouse_pos[0] > cow_Rect.left and mouse_pos[0] < cow_Rect.right and mouse_pos[1] > cow_Rect.top and mouse_pos[1] < cow_Rect.bottom: MOVE = True set_count = 3 pygame.mouse.set_cursor(*pygame.cursors.broken_x) if mouse_pos[0] > mouse_Rect.left and mouse_pos[0] < mouse_Rect.right and mouse_pos[1] > mouse_Rect.top and mouse_pos[1] < mouse_Rect.bottom: MOVE = True set_count = 4 pygame.mouse.set_cursor(*pygame.cursors.broken_x) if event.type == pygame.MOUSEBUTTONUP: MOVE = False pygame.mouse.set_cursor(*pygame.cursors.arrow) if MOVE: playing = False return set_count SCREEN.fill((255,255,255)) SCREEN.blit(player[0], player_Rect) SCREEN.blit(player[1],cat_Rect) SCREEN.blit(player[2],cow_Rect) SCREEN.blit(player[3],mouse_Rect) self.draw_text("Charater Seletion Page", 22,(0,0,0), 500, 400) pygame.display.flip() clock.tick(60)
Python
복사
추신 : 2D밖에 안되니 복잡한 것이면 Unity나 UE 쓰는게 정신건강엔 이롭다
글자 넣어주는 코드
def draw_text(self, text, size, color, x, y): font = pygame.font.Font(self.font_name, size) text_surface = font.render(text, True, color) text_rect = text_surface.get_rect() text_rect.midtop = (x, y) SCREEN.blit(text_surface, text_rect)
Python
복사