본문 바로가기
게임/Renpy

Renpy Inventory Item 사용

by MOVE🔥 2020. 11. 9.
728x90
반응형

 

1. Item 및 Inventory 선언

item class 선언

init python :
    class use_itme:
        def __init__ (self, img, value, use):
            self.img = img
            self.value = value
            self.use = False
        def use(self):
            self.use = True

item들을 담을 배열 변수를 선언한다.

init:
	# items 선언 
	$ view_items = []	
	$ use_items = []	

 

2. Inventory에 Item 추가

item을 선언한 item 배열 변수에 담는다.

$ view_items.append("VIXX")
$ view_items.append("RAVI")
$ view_items.append("김원식")

 

3. Inventory button 추가

Inventory button을 선언하고 오버레이에 추가한다

(오버레이에 추가해야 게임 진행과 상관없이 떠있는 버튼이 된다)

def inventory_button():
        if show_inventory:
            ui.vbox(spacing=100, xalign=0.99, yalign=0.01)
            # 인벤토리 이미지 버튼
            # click시 show_item_list label 호출
            ui.imagebutton("Inventory.png", clicked=renpy.curried_call_in_new_context("show_item_list"))
            ui.close()
            
# 오버레이에 추가 
config.overlay_functions.append(inventory_button)

 

4. Inventory Button 클릭시 item list 보여주기

item list 스크린에서 for문을 돌면서 item textbutton을 만들어준다.

label show_item_list:
	# item list screen 호출
    $ renpy.call_screen("sc_item_list")
    return

screen sc_item_list():
    frame:
        xpadding 50
        ypadding 50
        xalign 0.5 yalign 0.5
        vbox:
            spacing 20
            # item list 텍스트 버튼으로 보여줌
            for i in view_items:
                textbutton "[i]" action Return(i)

 

결과

저 가방이 Inventory고 item list들이 출력되는 것을 볼 수 있다 ㅋㅋ.. 

 

728x90
반응형

댓글