##### 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? ?̬? -h??T? ====================================?? ?,MѤ¸?? D?̲,ĳ?D? ???T? Xՠ??.HP??? ?Ť???̹}? HPX? ???t? ????? ??? $??? ֬? HP?̹t? ????t?,t? P? p?t?0?|? ??%?XՔ? ??? l´? )???@? 4???x???..image::AdvancedOutputProcess1.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("AdvancedOutputProcess1.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::AdvancedOutputProcess2.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("AdvancedOutputProcess2.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::AdvancedOutputProcess3.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("AdvancedOutputProcess3.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()???X? ?t? ??`? L?ȹ? MѤ¸?|? ??? ?T??? X?0?̹ X?t? ??.???X? ?@? ?Ż??? ???????????@? Event8??? ? t?踴????.(????ܴ ? ??? DŘ?|? ?? HP|? p??XՌ? X???.)t???? ٳ|?? )???t??.X???̹,tǃ??@? ??Ȉ? MѤ¸?t??.D??? ?̈́??? ???T? ??? JŔ??.t? p?t?0??D? ?Ż??? T? ??8?XՌ? ???T? `?L??? ??=??? ? D?t????|? 0?,? ? ???.HP?? ?? ?t??,???ō?? ?D? ??????,DŘ?@? ?t? ??%? ? ? ???...image::AdvancedOutputProcess4.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("AdvancedOutputProcess4.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::AdvancedOutputProcess5.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("AdvancedOutputProcess5.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::AdvancedOutputProcess6.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("AdvancedOutputProcess6.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()??,? ??D?L??.?????? ???@? #6D? U?x?X?t? ??.???@? ? ?X??.<??,p? ??@? ?? ?ɬ???D? ?????.?? ?L?,֬? HPD? 0?8? ? ??@? h?? ?? ?ɬ????D? 0? ??? ?? ??̹|? ?????.ȹ??ɹ<??,??@? ?ɬ?????? XՀ? L?P???|? ?????.pygame.draw.recth???? ? ?X? ???? 4?X? ? ? ???? ???? ? ??D? U?x?`? ? ?ǔ?p? (?̈??? ??? ?΄??? ???t??,P????? ??? ???? ???,$????? ??? P?خ ???t??.)t? 4?X? ? ? ???X? ??ĳ? 4???x??ɔ? ??? $???XՔ? ?????,??? ?D? ????X?t? ? U?x?XՔ? ??t? ??? }? t?t?`? ? ???.3?X? ?t? 20|? L? X՘?X? ? ̹D? 10??? 30<?? ?ԯ ??D?|?!?????,t? Ȕ? ?????<?? h??T?|? t?|? ??.Always8??? Event8?D? mainh???? ??XŔ?p?,t? ???? mainh??|? ??????t? >?D? ? ??ĳ]? #7?? ? ????x? ?̬?|? t?|? ??.?? ?L? drawHP|??? ????? h??|? ̹????.?????? ?X? h??T? D?t???Ŕ? GUI??????D? ̹? L?X? h??T? D?t????@? lЌ? ?t??? J??.?|? ?t?,X՘?X? ???|? ??%?XՔ? X՘?X? ??%? h??|? ?? ̹䴴? P??? ??t? ??D? ??t??.<?`?,??X? ???? ??%? ? ???|? ?XՔ? ??@? T?t? ȴ?|? ???x?`? L? ??????|? `? ??t??.<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("HPbarProject")width=640#1height=480#2myScreen=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)#3fpsClock=pygame.time.Clock()defmain():#4HP=5whileTrue:myText=myTextFont.render((str(HP)+"/"+str(maxHP)),True,red,gray)myScreen.fill(gray)myScreen.blit(myText,myTextArea)drawHP(HP)#5foreventinpygame.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-1pygame.display.update()fpsClock.tick(60)defdrawHP(HP):#6r=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)returnif__name__=='__main__':#7main()

Edit on GitHub