1. Game screen
1.1 Beginning
1.2 Shooting monsters
2. Knowledge points covered
mixer
3. Stamps
basic grammar
3.Code
3.1 Emission of sound
from sprites import * try: import pygame () fire_sound = ("audio/emission sound.wav") cricket_sound = ('audio/') except: import sys input("This program requires pygame mixer support for dubbing, please install this module with pip install pygame under cmd first.")
3.2 Background
width,height = 480,360 screen = Screen() ('res/') (width,height) batimages = ['res/','res/'] batindex = 0 bat = Sprite(visible=False,pos=(-50-width//2,100)) = 3 = 0 = True ()
3.3 Shooting effects
def bat_alt_costume(): global batindex batindex = 1 - batindex (batimages[batindex]) (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 button clock = Clock() # Clock objects start_stamp = False while True: (,) # Stamp it when it hits the ground and leave the body behind # if () < (-200,-100): = 0 = 0 ((1,360)) () (-500-width//2,100,3,0,delay=2) = True (0) # The bat touched the mouse pointer and pressed the left mouse button # if bat.collide_mouse() and () and : = -10 # Starting to fall = False try: cricket_sound.play() except:pass # When you get to the far right, go to the far left and start over # if () > width//2 : (-500-width//2,100,3,0,delay=2) = True (0) (mouse_position()) # Bullets fired, holes left with stamps, start_stamp variable used to prevent continuous firing if () and not start_stamp: () start_stamp = True try: fire_sound.play() except: pass # After releasing the key if not ():start_stamp = False (60)
4. Summary of experience
Any mini-game can be made using the various python game libraries
This article on the production of shooting games based on Python implementation of the article is introduced to this, more related Python shooting game content, please search for my previous articles or continue to browse the following related articles I hope that you will support me in the future!