Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize shooting Mini Game based on Python

Shulou Source: shulou.com Published: 2022-06-01 01:18:09 10月03日 Update

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.

Tags: Shooting firing Mini Game stamps articles content knowledge knowledge points mouse mixer propriety code variables ground foundation bullets objects corpses ideas monsters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Redmi Docker NVidia