##### pygame documentation | Pygame Home || Help Contents || Reference Index Most useful stuff: Color | display | draw | event | font | image | key | locals | mixer | mouse | Rect | Surface | time | music | pygame Advanced stuff: cursors | joystick | mask | sprite | transform | BufferProxy | freetype | gfxdraw | midi | Overlay | PixelArray | pixelcopy | sndarray | surfarray | math Other: camera | cdrom | examples | fastevent | scrap | tests | touch | version

??====================================Author:YoungwookKim(Korean)========================================================================Contact:rumia0601@gmail.com========================================================================????? ??T? ??%? ???? ====================================KEYDOWN? ?????????̹,D???ĳ t? ????t? D??? GUI? D?̲ ?????? ??tǔ? t? ǔ? GUI? ??%?@? ??? $??? ??%?(հ???)XՔ? p???̹ ???????0? L?8?t??.GUI?? ?X? ??%?tǀ? ???? ?X??? ?X? ȹ?Ƥ? tǤ???|? ?̬?XՔ? ??t??.HP|? ????¤?p??? ????¤Д? ???? 2?|? ̹ܴ?? ??@? ?Ũ?L??..image::AdvancedInputOutput1.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedInputOutput1.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()..image::AdvancedInputOutput2.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedInputOutput2.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()???? 2?|? ̹ܴ?? ??@? }??.????D? ??t?,T?? ??t?? ????? ȩ???? ??L?D? L? ?? ???.?Ż??? ? ??x???t??X? D?t???Ř??? ? ?X??.????,p? Ȭ???D? ?????.X???,????@? ??? P?خ̹ ?ǔ? ??@? Ȭ???D? ?????.X???̹ t? ?????@? D??? ??%???t??.t? ?????D? ?? tЭ? ??? ???D? ̹䴴?|? ??...image::AdvancedInputOutput3.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedInputOutput3.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()..image::AdvancedInputOutput4.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedInputOutput4.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()..image::AdvancedInputOutput5.gif:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=320,240speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("AdvancedInputOutput5.gif")ballrect=ball.get_rect()while1:foreventinpygame.event.get():ifevent.type==pygame.QUIT:sys.exit()ballrect=ballrect.move(speed)ifballrect.left<0orballrect.right>width:speed[0]=-speed[0]ifballrect.top<0orballrect.bottom>height:speed[1]=-speed[1]screen.fill(black)screen.blit(ball,ballrect)pygame.display.flip()t? ? Event8??? MOUSEBUTTONUPt? ???????.ȹ?Ƥ??UP? ??@? ????ܴ?DOWN? ???? ٳ|?? X???|? ????.̹}? MOUSEBUTTONUPt? ?1?T??t?,event.pos?? x??? y?D? 0?]?t?|? XՔ?p?,t? ??@? tЭ? ???D? ???и??.??????,tЭ?t? ??? Ȭ??? ?????? ? |ǴŬ????? D?̲ ?ɔ? collidepoint|? U?x?X?t? ??.̹}? ??????t?,

> ???Ɛ?? ??? ??? ????|? tЭ???? |? X???XՌ?

??.?? ?L?,???|? ??p?tǸ?XՔ? ??? ?̬?̹t? DՔ?XՌ? ??.??%?D? ?? P? ???? tȬ?X??,(Event8??? ??L?)(270,425,45,45)@? (325,425,45,45).??%?D? ?? P? ???ĳ tȬ?h?D? U?x?X?|?.(drawButtons?? ??L?)(margin,height-r-10,r,r)?? (margin+r+r_margin,height-r-10,r,r).????X? ????,??%? ????? ??%? ???t? ٳ|?t?|? ??.????? J??t?,????X? ?? ???? ??0?? ??!???(??%? ??)?D? l????x? Ĭ??D? ??t? ???(??%? ??)?D? L?DŴ?0? ???t?,t? ????D? ٳ|?? ???? P??? ??t? ??@? ???|? ??t??.P? ???D? X՘?? 6?D? ? ?ǔ? h?? ??<????,t? ?@? m??? ?½? h?|? ??.<8?? T?ܴ>::importpygame,sysfrompygame.localsimport*maxHP=10white=(255,255,255)gray=(127,127,127)black=(0,0,0)red=(255,0,0)green=(0,255,0)blue=(0,0,255)pygame.init()pygame.display.set_caption("ArraybuttonsProject")width=640height=480myScreen=pygame.display.set_mode((width,height))myTextFont=pygame.font.Font("HoonWhitecatR.ttf",32)myText=myTextFont.render((str(maxHP)+"/"+str(maxHP)),True,red,gray)myTextArea=myText.get_rect()myTextArea.center=(width/2,height/2)fpsClock=pygame.time.Clock()defmain():HP=5whileTrue:myText=myTextFont.render((str(HP)+"/"+str(maxHP)),True,red,gray)myScreen.fill(gray)myScreen.blit(myText,myTextArea)drawHP(HP)drawButtons()foreventinpygame.event.get():ifevent.type==QUIT:pygame.quit()sys.exit()elifevent.type==KEYDOWN:ifevent.key==K_UP:ifHP!=10:HP=HP+1elifevent.key==K_DOWN:ifHP!=0:HP=HP-1elifevent.type==MOUSEBUTTONUP:#1x,y=event.posifpygame.Rect(270,425,45,45).collidepoint(x,y):ifHP!=10:HP=HP+1elifpygame.Rect(325,425,45,45).collidepoint(x,y):ifHP!=0:HP=HP-1pygame.display.update()fpsClock.tick(60)defdrawHP(HP):r=int((height-40)/maxHP)pygame.draw.rect(myScreen,black,(20,20,20,20+((maxHP-0.5)*r)))foriinrange(maxHP):ifHP>=(maxHP-i):pygame.draw.rect(myScreen,red,(20,20+(i*r),20,r))pygame.draw.rect(myScreen,white,(20,20+(i*r),20,r),1)returndefdrawButtons():r=45r_margin=10colors=[red,black]num=2margin=int((width-((r*num)+(r_margin*(num-1))))/2)foriinrange(0,num):left=margin+(i*r)+(i*r_margin)up=height-r-10pygame.draw.rect(myScreen,colors[i],(left,up,r,r))pygame.draw.rect(myScreen,gray,(left+2,up+2,r-4,r-4),2)if__name__=='__main__':main()

Edit on GitHub