In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to achieve shooting Mini Game based on Python" with detailed content, clear steps and proper handling of details. I hope that this article "how to achieve shooting Mini Game based on Python" can help you solve your doubts.
1. Game screen 1.1 begins
1.2 shooting monsters
two。 Knowledge points involved
1.sprites
2.pygame mixer
3. Stamp
Basic syntax of 4.python
3. Code 3.1 from sprites import * try: import pygame pygame.mixer.init () fire_sound = pygame.mixer.Sound ("audio/ emission sound .wav") cricket_sound = pygame.mixer.Sound ('audio/cricket.wav') except: import sys input ("this program requires pygame mixer support for dubbing, please first install this module with pip install pygame under cmd"). 3.2 background width,height = 480360screen = Screen () screen.bgpic ('res/ghosthouse.jpg') screen.setup (width,height) batimages = [' res/bat1.png','res/bat2.png'] batindex = 0bat = Sprite (visible=False Pos= (- 50-width//2100) bat.dx = 3bat.dy = 0bat.alive = Truebat.show () 3.3.The shooting effect def bat_alt_costume (): global batindex batindex = 1-batindex bat.shape (batimaxes [batindex]) screen.ontimer (bat_alt_costume,90) bat_alt_costume () hole = Sprite (shape='res/Bullet_Hole.png') Visible=False) M1 = Mouse (1) # left mouse button m3 = Mouse (3) # right mouse clock = Clock () # clock object start_stamp = Falsewhile True: bat.move (bat.dx,bat.dy) # stamped when it falls to the ground Leave the body if bat.ycor ()
< random.randint(-200,-100): bat.dx = 0 bat.dy = 0 bat.setheading(random.randint(1,360)) bat.stamp() bat.reborn(-500-width//2,100,3,0,delay=2) bat.alive = True bat.setheading(0) # 蝙蝠碰到鼠标指针并且按下了鼠标左键 if bat.collide_mouse() and m1.down() and bat.alive: bat.dy = -10 # 开始往下掉 bat.alive = False try: cricket_sound.play() except:pass # 到了最右边就到最左边去重新开始 if bat.xcor() >Width//2: bat.reborn (- 500waywidthUniverse 2) bat.alive = True bat.setheading (0) hole.goto (mouse_position ()) # fire a bullet and leave a bullet hole with a stamp The start_stamp variable if m1.down () and not start_stamp: hole.stamp () start_stamp = True try: fire_sound.play () except: pass # is used to prevent continuous launches. If not m1.down (): start_stamp = False clock.tick (60) after releasing the button, the article "how to shoot Mini Game based on Python" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the articles, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.