In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to achieve simple shooting Mini Game by Python+Pygame" with detailed contents, clear steps and proper handling of details. I hope that this article "how to achieve simple shooting Mini Game by Python+Pygame" can help you solve your doubts.
I. operating environment
1) Environmental installation
Python3, Pycharm, Pygame module part of the built-in module is not displayed.
Installation of third-party libraries: pip install pygame or
Pip install-I https://pypi.douban.com/simple/ + module name with mirror source
2) material (pictures, music, etc.)
Second, code display
Main program
Import pygame,os,randomfrom pygame.locals import * from pygame.sprite import * def load_image (name): fullname=os.path.join (os.path.join (os.path.split (os.path.abspath (_ file__)) [0], "filedata"), name) image=pygame.image.load (fullname) return imagedef load_sound (name): fullname=os.path.join (os.path.join (os.path.split (os.path.abspath (_ file__)) [0], "filedata") Name) sound=pygame.mixer.Sound (fullname) return soundWIDTH=700HEIGHT=600class Explosion (Sprite): def _ _ init__ (self,screen,posrect): super (Explosion) Self). _ init__ () self.screen=screen self.posrect=posrect self.image=load_image ("explosion.png") self.rect=self.image.get_rect () self.rect=self.posrect self.rates=0 def update (self): self.rates+=1 if self.rates > = 40: self.kill () class Enemy (Sprite): def _ init__ (self,screen): super (Enemy) Self). _ init__ () self.screen=screen self.screenrect=self.screen.get_rect () self.image=load_image ("eatingfood.png") self.rect=self.image.get_rect () self.rect.center= (random.uniform (50) WIDTHMur50), random.uniform (50) HEIGHT-50)) self.xspeed=random.uniform (1, 2) self.yspeed=random.uniform (1, 2) if random.choice ([True,False]): self.xspeed=-self.xspeed if random.choice ([True]) False]): self.yspeed=-self.yspeed def update (self): self.rect.centerx+=self.xspeed self.rect.centery+=self.yspeed if self.rect.top > self.screenrect.height or self.rect.bottomself.screenrect.width or self.rect.right
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.