2017-05-29 84 views
2

我試圖找到一種方法讓我學習如何使用renpy在python/pygame中製作視覺小說。我有幾個我用pygame編寫的遊戲,我希望在整個更大的單一遊戲中使用這個視覺小說部分作爲遊戲的轉換。在我來到這裏之前,我已經搜尋了很多東西,爲什麼沒有辦法在pygame中製作一款沒有renpy的視覺小說類遊戲。創建一個Pygame視覺小說,不與renpy

我有一段代碼寫下來,但如果我要顯示一行和下一行,我將不得不重複相同的代碼大約四十次。我怎樣才能壓縮代碼並讓玩家實際點擊以獲得下一個文本集(而不是像樣本中那樣等待三秒鐘)?

相關示例代碼:

def two(): 
    screen.blit(bg,bg_rect) 
    draw_text(screen, "C:", 26, width/3, 426) 
    draw_text(screen, "R, it's this.", 22, width/2, 466) 
    pg.display.flip() 
    time.sleep(3) 
    for event in pg.event.get(): 
     if event.type == pg.QUIT: 
      pg.QUIT() 

def one(): 
    screen.blit(bg, bg_rect) 
    draw_text(screen, "R:", 26, width/3, 426) 
    draw_text(screen, "C, don't think.", 22, width/2, 466) 
    pg.display.flip() 
    time.sleep(3) 
    for event in pg.event.get(): 
     if event.type == pg.QUIT: 
      pg.QUIT() 
     else: 
      two() 

running = True 
game_over = True 
while running: 
    if game_over: 
     show_menu() 
     one() 
     two() 

感謝您與我堅持; - ;

回答

0
screenOne = { 
    "text": "Do you want to hangout?", 
    "options": ["Yes", "No", "Are you sure?"] 
    } 

screenTwo = { 
    "text": "Are you ok?", 
    "options": ["I feel ok...", "No", "Feed me senpai..."] 
    } 

def draw_stuff(currentScreen): 
    renderText(currentScreen["text"]) 
    for option in currentScreen["options"]: 
     renderText(option) 


currentScreen = screenOne 
while (gameRunning): 
    draw_stuff(currentScreen) 

不使用pygame術語,但我想你明白了。

編輯一個

mousePos = getMousePos() 
optionButtons = [1, 2, 3] 

for b in optionButtons: 
    if mousePos.x == optionButtons.x and mousePos.y == optionButtons.y: 
     getEvent(b) 

再次這基本上是僞代碼,但它應該幫助。

+0

我明白你在做什麼,但它會不會要求我根據該代碼的「currentScreen = screenone」編碼40次? –

+0

您將不得不爲每個屏幕創建多個字典並在完成屏幕後重置屏幕 –

+1

我想我現在已經註冊了thx。 030我正在與其他兩個合作伙伴進行合作,而且我對編碼幾乎毫無頭緒,所以我想我一直等到我對編碼更加熟悉。 thx tho 0v0 –