??====================================Author:YoungwookKim(Korean)========================================================================Contact:rumia0601@gmail.com========================================================================Prolog?WhyPygame?====================================Asweknow,everykindofgamehas3sections(Becausegameisasubgroupofprogram):**input**,**process**and**output**.IfyouwanttomakeagameinC**consoleenvironment**(WriteCsourcecodethenexecutethatontheconsole)simply,allyouhavetodoisjustusinglotsofscanf(orunnormalizedgetchfunction)functionsandproceduralcomplexalgorithmfollowedbyprintf(withblinkingclearfunction)functionswithASCIIarts!However,whenyougetboredofmakingoutdated,graphic-lessCUI,discontinuousgame,nowit stimetolearnGUIbasedgamemakingtool.YoucandirectlyenterintoUnity**gameengine**orUnrealgameengine.However,therearetoomuchbarriertoovercome.Quaternionfor3Dcollision,Mechanim/Legacyanimationcompatibility,Largermemory/FasterCPUforsimulateinhigh-graphicmod,andetc!So,thereisadilemmabetweenconsoleenvironmentandgameengine.Canthisdilemmatobesolved?..image::introduction-PuyoPuyo.png:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=220,140speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("introduction-PuyoPuyo.png")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()(ExmapleofCconsolegame-PuyoPuyo)..image::introduction-TPS.png:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=220,140speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("introduction-TPS.png")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()(ExmapleofUnityEnginegame-TPS)Yes.Pygamecansolvethat.Pygameisanexternallibraryof**Python**whichenablesyoutomakea**game**.Pygamehasadvantagesofconsoleenvironment.Forexample,singlepygameprojectnearlyequalssinglesourcecode,sowehavetofocusonwritingsourcecodeonly.(withsomesoundfileorsomeimagefileinthesamedirectory).BecausePygameisnotatoolbutalibrary,singlecommand
- importpygame
makescurrentsourcecodetousepygame severything.Thatis,Pygameissimpletoaccess.Pygamehasadvantagesofgameengine,too.Forexample,Pygameprovideinputfunctions(whichcheckeverypossiblestateofkeyboard,mouseandevenfiles)andoutputfunctions(drawinggeometry,fillcertaincolorsorsetdisplay)touser.Thatis,usercanruntheprogramontheGUIenvironmentifitbasedonPygame.BecausePygameisbasedonPython,functionsinPygameprojectcanbeexecutedselectively,evenalmostsimultaneously.Thatis,Pygameisevent-driven.
..image::introduction-Battleship.png:class:inlined-right..code-block::python:linenos:importsys,pygamepygame.init()size=width,height=220,140speed=[2,2]black=0,0,0screen=pygame.display.set_mode(size)ball=pygame.image.load("introduction-Battleship.png")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()(ExampleofPygame-Battleship)So,Pygamehasbothgoodpointofconsoleenvironment(exampleoflow-levelgamemaker)andgameengine(exampleofhigh-levelgamemaker).Pygameisgood**intersection**betweenconsoleenvironmenttogameengine.That senoughtousePygame.Noneedtomasterit(ifyourdreamisone-mangamedeveloperinadvancedgameengine,starttolearnaboutthatgameenginerightnow!),butatleast,tryPygame.(ifyouareinterestedinanykindofuniqueprogramincludinggamemakerorifyouwanttocodeanygameonadvancedenvironmentasidefromconsoleenvironment)
Edit on GitHub