From 8d8c32fdbd61956ccc4792524b621524d83b0467 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Wed, 5 Oct 2011 10:48:13 +0530 Subject: [PATCH] Started work on NPC dialogues Started basic work on NPC dialogues. Created the NPC dialogue screen and successfully displayed text. --- background/dialog_screen.png | Bin 0 -> 9531 bytes butaba.py | 1 - dialogues/bulisa1.dlg | 3 +- maingame.py | 16 +++++- npcs.py | 8 +-- portraits/bulisa.png | Bin 0 -> 6217 bytes utility.py | 91 ++++++++++++++++++++++++++++++++--- 7 files changed, 102 insertions(+), 17 deletions(-) create mode 100644 background/dialog_screen.png create mode 100644 portraits/bulisa.png diff --git a/background/dialog_screen.png b/background/dialog_screen.png new file mode 100644 index 0000000000000000000000000000000000000000..2194d96b9fae50a9ad0ffcf478629281a7145e14 GIT binary patch literal 9531 zcmeHtWmr^S^zK1aq`OBN1f)y4r8}iNBt(V=>4srwh8REzX%LVuMHm{S8~jN(lG6A1 z|9GGK;ok4}%yXXe%-U!6Ui)2Zuf1ozD^^QG5f_UJ3jhFIWhHqX06_Z+-g?g-fs!9Y z=BeNV%|k~~7N{PD?0{dMTB|C`0}uZ`A3I9^HDkV4GV%ZbY~p`68jy{o0EHNy%IdE% z7O|c@#vw{p5LN_5l%B8Oc*?oCy4t<-1mvK0R-SgYbUtrA9qAO6)wK*m@yG#y4p5et z(eqt6$PGw>Oa~qXZ+VV6`!FA1mVe)D~$Tvt(`mxVlXrc<%oz42@gyRm1-iO9MPUF$}_Ec=sif0C0B4c{Dwjy^Y zOY%kV+2Q`-zM7_#M!w|o>75>>vxC2XYrtoz)4Ow#Ks-ieP;KL1!jHj+2nfjfGXO|p z1ORFH|Fs|lf(8Iku!DX=aCRUJ{||!yKj!}t>~(UneeBM&L?2qIpx+4=?SAWXfBx{V zIaKJg#F`)@l9(csmVWE>N9{pJIY%RzQc@_^VA%g*v57b!-IaSNQgxK*<6p;nluuL1 zDlIk^GtrxlwzwKqJ3bo_UaNjjX~PuDpCT{MRP54R-7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6BA)tn)b_jlcRA z^-A(;Kr>HV#C!A1_p({8b7Xu7k*~W$Eeu){jBJ%F9|Ipl z^B-=v@TG2#gvAFz_J0yJaQ!_eWCv*N1KB=;(@Y2=?D@X%KRcQL~BCS7cmN9AxqFE_e_za?22XTP#2-oI(gKy_<{HHg&g0B5JJ7<=4^MPJzevN&H28*CArd0 z6Rb%P3eYS;xHOflbPg};y5XK)d|e&|iwe?Y`A{()sIngg9v7awx!Kf04tI54Ph3WE zUQaqZ&QF$^rGu&3`6=q!9Yb|jZpM@punM5$GULzA8eNW}=SnAEiVhb26OjDpMNwYm zo=jrAbGn&7Gf1|rmo#IGt=$P8+yu${`n-D~6}D{J!OC&W^|S8D0KPja1_m~J$-Od! z(#eJAh0m~qrkOI*XB8aL@v3Mu$cD1EY%F_B6uUTWJ&>r!wykx!sRO znfE51lfs=rW;k2&u)gW-J$Yu4r=1+p7LvD4*o%jJtKHIsyX(Z`i4>{(ztSGR$Tb46 iu;+iT@{z8)#fLdRA9Hp02P>2SK>4+Xe6_4)*#81n0q*_) literal 0 HcmV?d00001 diff --git a/butaba.py b/butaba.py index 7b93980..ca44883 100644 --- a/butaba.py +++ b/butaba.py @@ -20,4 +20,3 @@ class Butaba: self.health = health self.objects = inventory self.gold = gold - diff --git a/dialogues/bulisa1.dlg b/dialogues/bulisa1.dlg index c5db25b..e684042 100644 --- a/dialogues/bulisa1.dlg +++ b/dialogues/bulisa1.dlg @@ -28,8 +28,7 @@ Bye! - Thanks so much! There is an empty bucket somewhere in the garden. - Take that, go to the well behind the house, draw water and bring it back to me. + Thanks so much! There is an empty bucket somewhere in the garden. Take that, go to the well behind the house, draw water and bring it back to me. Right. I'll go at once. \ No newline at end of file diff --git a/maingame.py b/maingame.py index 431d44d..32df4cc 100644 --- a/maingame.py +++ b/maingame.py @@ -28,6 +28,9 @@ class MainGame: self.img_chestbg = pygame.image.load (os.path.join ("background", "chestcontent.png")).convert () + self.img_dialogue = pygame.image.load (os.path.join ("background", "dialog_screen.png")).convert () + self.img_dialogue.set_colorkey (pygame.Color (0, 255, 0)) + # initialize object graphics self.img_redpotion = pygame.image.load (os.path.join ("objects", "red-potion.png")).convert () @@ -61,6 +64,9 @@ class MainGame: self.img_bulisa = pygame.image.load (os.path.join ("sprite", "bulisa.png")).convert () self.img_bulisa.set_colorkey (pygame.Color (0, 255, 0)) + # initialize NPC portraits + self.img_bulisa_portrait = pygame.image.load (os.path.join ("portraits", "bulisa.png")).convert () + # set level data self.setup_levels () # set current level and position of our character @@ -85,7 +91,8 @@ class MainGame: potion2 = gameobjects.HealthPotion (5, 2, self.img_redpotion) potion3 = gameobjects.HealthPotion (5, 2, self.img_redpotion) - npc_bulisa = npcs.Bulisa (4, 3, self.img_bulisa, None) + npc_bulisa = npcs.Bulisa (4, 3, self.img_bulisa, self.img_bulisa_portrait, + [ os.path.join ("dialogues", "bulisa1.dlg") ]) chest1.objects = [ gold50, gold25, potion2, potion3, key2, gold10 ] @@ -247,7 +254,12 @@ class MainGame: # interaction with npcs def interact_npc (self, npc): - pass + # interact with NPC and get the response ID + resp_id = utility.dialogue_play (self.screen, self.img_dialogue, npc, self.butaba, 0, 90) + + # if none + if resp_id is None: + self.status_message = "You cannot initiate a conversation with %s" % npc.charname # interaction with objects def interact_objects (self, container, objs): diff --git a/npcs.py b/npcs.py index ae781da..d368833 100644 --- a/npcs.py +++ b/npcs.py @@ -6,7 +6,7 @@ import os.path class NPC: # initalize the NPC - def __init__ (self, charname, row, col, image=None, portrait=None, dialogue_set=set(), + def __init__ (self, charname, row, col, image=None, portrait=None, dialogues=[], currentdialog=0, is_dead=False): # name of the character self.charname = charname @@ -19,7 +19,7 @@ class NPC: self.portrait = portrait # dialogue set for NPC # each dialogue in the set is a path to an XML file containing the dialogue - self.dialogue_set = dialogue_set + self.dialogues = dialogues # index of the current dialogue which will be initiated with the main # character self.currentdialog = currentdialog @@ -29,6 +29,6 @@ class NPC: # Bulisa is Butaba's friend class Bulisa (NPC): - def __init__ (self, row, col, image, portrait, dialogue_set=set(), currentdialog=0): - NPC.__init__ (self, "Bulisa", row, col, image, portrait, dialogue_set, currentdialog) + def __init__ (self, row, col, image, portrait, dialogues=[], currentdialog=0): + NPC.__init__ (self, "Bulisa", row, col, image, portrait, dialogues, currentdialog) diff --git a/portraits/bulisa.png b/portraits/bulisa.png new file mode 100644 index 0000000000000000000000000000000000000000..f8f7a977c0bf831e699f3284fd0d175f19f4fd79 GIT binary patch literal 6217 zcmV-P7`Eq$P)Px#24YJ`L;w!}3IG6hgsFG{000SaNLh0L00+(h00+(iR2I9d00007bV*G`2ipn+ z4>dX-o|S_D02j$gL_t(|+U;C-bX?V$|L%Qldef+lWLc8c++<@L+t}ESZHfa1Lg>U0 z0)cEu9KeBP;Xq&$0-R)bo!uo6Hk43~A#sX(Os8#t;B3tjejV^n48m0GvG0w)1!w4*(UF zp2vT7!`Fxaz~evv=yxZ}qh_b=B3jb#(ZE0U!VXgc2qm zAq)TrLGu3~2z*Yiv#`LOlkadktj;WpC<^~yK?w$e?GlwfA^K(Wo4WDlu7$ z#k5FFWq@Jqo{ljDRNy(2Nf3EX6nUdTwAzfGf~@M`OUKhMb-2}HT9o= zdZ4-4>+?qfL0Qu&Lnt8+se!oh&5IBNP9>m*GypC2_P&EH?|)EZwMr(VXtNqT1z9UE zI&VgGi6HXl9u%UJzx`#~?wu!nzOc_9m37*O0-8uWg%APM8`641T3c7-_$lx9?X@nK z$(?1bo?W`)qS<-*u5$niW9)->_q_Ag&X)F&PFZTP=g1}^S!Zosk+!bL!J}>Ozq_}f zzoX{Xq0`MhHT&u&7L@0od8fTQ0suN?5tZna83YUfvPNZ%j4T&A zWjbY~?+2nPjjAM$ucFg9YN?-?Mirg*vsvkfKP-P)*A`K<;%vu(#?Bmvd1|3Mbu}C# zZ@j*F0&NNb~`Obe>fJu)YR;2Z0IO1$(s;KIdQz%>yH9}tdsa!B_78# zq7!Bohn{9nYSseEnY<QK*HrZ`)m_(9r z&y-N66Q&XpQ}mFmM^rr|YY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P`tlNDQdN6xI!4aW05+1A6e_b6ZO6-fOO$ zSyAEn$ARMWh2MR5-+@zV*uKE;xHP6>kmE2BLYV-7>?PRje6`N|;54&07zLdybTM$H zPgxKsqq-Z$fH8(K;xQ8i-f1@cXB`*gvZBNVsXsmvPc;=AI97)xrEbHHeEx&0R+XJU zuWVvL2?U}W{b`32;exxV=RfB)gT!}9sue!Lm<1v-<3T0I>eBN6)9}}Mp#(-(q{+X{bcK!Ys<@~ zC5d$buE9D-{OK{lDK%okSK71t77gqR{i0*W3$c!huL5=NxflN)^wdv zLPxKMV2m)rJck4h+f0%q^sO^MxPLz`ExG!NkB@&5ryS8R#xz3=LrK?_@5h#?TVZ=hC#4#3*`fKivAruXb7BtuszzJOCh0_}=|b{jS;Bsh@e! z*~O%XkJ*-d|FNR-ISFn!sKz_|03qOpjhOrY{S+agUJ>sEgIr?3Cq&1foE0^shF`a>E^WF2xF8&B9k6g426EZI*PBkV%iK<)hMNTh2?jyd-_D9{p88^ z(Lvex=Ut`MmtS`M-3W_uBbMVf$J^eiK6+^)8q?xcM1&FJEvk|zfS9aVYwmsWmo3FF zo**(Cqbi}TKJmU|?%eAiyZxWn+q3#2v4FQ-Wyy}S5l>#Fs-=ukIoR!TS!i7$zzWQO3H!hglTfX zY7>K{}rn}zy`_W;&4`Xc07tQxR{^+1jOsy>ba9^zgW?+<2ibl-1RE-cy z;~m*`Yin!D%ROm8*}3!N zf@N305IUo9axv2Of{@J!VVa60!^ohdZE3d8g{%cjp+7Jn90i*|Rl_V#$o zoLTd;b0vdgbi3QpN;z}<&%ccjq{JhD)FU_WeVU=D8qafaD({7IE#K?DHW+B$V) zjGGK3h-0XH0HxGs=~wWjG!<0~qIvqqOS{M<08m#~XsLN80g!tj{+~#+5f*00000NkvXXu0mjfSP2Tr literal 0 HcmV?d00001 diff --git a/utility.py b/utility.py index 05faab5..93dac19 100644 --- a/utility.py +++ b/utility.py @@ -2,6 +2,67 @@ import pygame import sys import os.path +import xml.etree.cElementTree as ET +import textwrap + +# function to run through an interactive dialogue and return the response ID +def dialogue_play (screen, bgscreen, npc, responder, + marginleft=0, margintop=0, marginright=0, marginbottom=0): + + # first check if NPC has a dialogue at all + if len (npc.dialogues) == 0 or npc.currentdialog >= len (npc.dialogues): + return None + + # get the conversation as a dictionary + convtree = xml_to_dict (npc.dialogues[npc.currentdialog]) + + scrwidth = screen.get_width () + scrheight = screen.get_height () + bgwidth = bgscreen.get_width () + bgheight = bgscreen.get_height () + leftedge = scrwidth/2 - bgwidth/2 + topedge = scrheight/2 - bgheight/2 + + # now initiate the conversation + dlg_id = "1" + while 1: + screen.blit (bgscreen, (leftedge, topedge)) + if npc.portrait is not None: + screen.blit (npc.portrait, (leftedge, topedge)) + + # get the lines to display wrapped using textwrap module + lines = [] + textnpc = textwrap.wrap (convtree[dlg_id][0], 40) + for text in textnpc: + lines.append ((10, 0, 0, 0, text)) + + put_lines (screen, lines, + pygame.Rect(leftedge+marginleft, topedge+margintop, + bgwidth-marginleft-marginright, bgheight-margintop-marginbottom)) + pygame.display.update () + + for event in pygame.event.get (): + if event.type == pygame.QUIT: + sys.exit (0) + +# function to parse a conversation XML into a python dictionary +def xml_to_dict (file): + # parse the dialogue XML file + dlgtree = ET.parse (file) + # get the root element + conversation = dlgtree.getroot () + + # build the conversation tree as a dictionary + convtree = dict () + for dlg in conversation.findall ("dialogue"): + id = dlg.get ("id") + convtree[id] = [] + convtree[id].append (dlg.find ("speech").text) + for resp in dlg.findall ("response"): + convtree[id].append ((resp.text, resp.get ("id"), resp.get ("nextdialogue"))) + + return convtree + # function to draw text on surface def put_text (surface, x, y, size, (r,g,b), text): @@ -9,8 +70,9 @@ def put_text (surface, x, y, size, (r,g,b), text): textsurf = pygame.font.Font (harisfont, size).render (text, True, pygame.Color (r,g,b)) surface.blit (textsurf, (x, y)) -# function to draw several lines of text, centered horizontally and vertically on surface -def put_lines (surface, text_lines): +# function to draw several lines of text, centered horizontally and vertically on screen +# or drawn centered on a rectangle +def put_lines (surface, text_lines, rect=None): textsurfs = [] height = 0 harisfont = os.path.join ("font", "harisgamefont.ttf") @@ -21,12 +83,23 @@ def put_lines (surface, text_lines): height = height + s.get_height()*1.5 textsurfs.append (s) - scrwidth = surface.get_width () - scrheight = surface.get_height () i = 0 - for s in textsurfs: - surface.blit (s, (scrwidth/2 - s.get_width()/2, scrheight/2 - height/2+ i* (s.get_height()*1.5))) - i += 1 + # if no rectangle specified, center in screen + if rect is None: + scrwidth = surface.get_width () + scrheight = surface.get_height () + + for s in textsurfs: + surface.blit (s, (scrwidth/2 - s.get_width()/2, scrheight/2 - height/2+ i* (s.get_height()*1.5))) + i += 1 + # center on specified rectangular region + else: + midx = (rect.left + rect.right)/2 + midy = (rect.top + rect.bottom)/2 + num = len (textsurfs) / 2 + for s in textsurfs: + surface.blit (s, (midx - s.get_width()/2, midy - (num-i) * s.get_height() * 3/2)) + i += 1 # function to ask a question and return answer def ask_question (surface, question, answers, bgscreen): @@ -48,7 +121,9 @@ def ask_question (surface, question, answers, bgscreen): surface.blit (bgscreen, (surface.get_width()/2 - bgscreen.get_width()/2, surface.get_height()/2 - bgscreen.get_height()/2)) - put_lines (surface, textarray) + put_lines (surface, textarray, pygame.Rect (surface.get_width()/2 - bgscreen.get_width()/2, + surface.get_height()/2 - bgscreen.get_height()/2, + bgscreen.get_width(), bgscreen.get_height())) pygame.display.update () -- 2.20.1