In this article, we share the example of python to achieve the specific code of WeChat airplane game for your reference, the specific content is as follows
import pygame import random import sys # Initialization () .set_caption('Airplane firefight')#Set the window title screen= .set_mode((320, 570), 0, 32) .set_visible(False)#Hide the cursor #Load the picture boom1=('../Game/fly/src/') boom2=("../Game/fly/src/") bullet=('../Game/fly/src/') plane=("../Game/fly/src/").convert_alpha() enemy=('../Game/fly/src/') #Set the window icon .set_icon(plane) background=("../Game/fly/src/bg_01.png") start=('../Game/fly/src/') pause=("../Game/fly/src/") #() #Xexplosion=("explosion.mp3") #Xbullet=("../Game/fly/sound/bullet.mp3") #XgameOver=("../Game/fly/sound/game_over.mp3") #Xexplosion.set_volume(1) #("../Game/fly/sound/game_music.mp3") #(-1, 0.0) #.set_volume(0.25) i=0 # Score score=0 font=('Microsoft Black', 36) # Bullets bullets=[] # Enemy planes enemies=[] # Record the location of enemy aircraft explosions boomplace=[] # Game over gameover=False .set_pos(200, 200) while True: i += 1 if i > 200: i =0 (background, (0, 0)) #Control the airplane with the mouse x, y=.get_pos() #print(x, y) x -= plane.get_width()/2 y -= plane.get_height()/2 (plane, (x, y)) # Every 25 frames # if i%25 == 0: #Back Press the left button Center button Right button l,m,r=.get_pressed() if l ==True: #Generate bullet position additions ([x+plane.get_width()/2, y]) #() for place in bullets: # Bullet position out of bounds if place[1]<=0: (place) #Move the bullet position for place in bullets: place[1] -= 55 # Drawing bullets for place in bullets: (bullet,(place[0],place[1])) # Enemy planes generate, move, disappear if i%199 == 0: ([(0,320-enemy.get_width()),-enemy.get_width()/2]) for place in enemies: if place[1] >= 600: (place) for place in enemies: place[1] += 35 for place in enemies: (enemy,(place[0],place[1])) # Enemy planes exploding for place in boomplace: if place[2]>0: (boom1,(place[0],place[1])) place[2] -=1 # Bullet collision detection for bulletplace in bullets: for enemyplace in enemies: if (bulletplace[0] > enemyplace[0] and bulletplace[0] < enemyplace[0] + enemy.get_width()) and \ (bulletplace[1] > enemyplace[1] and bulletplace[1] < enemyplace[1] + enemy.get_height()): boomflag = 75 (boomflag) (enemyplace) (enemyplace) (bulletplace) #() score += 1 #Aircraft collision detection for enemyplace in enemies: if (x + 0.7*plane.get_width() > enemyplace[0]) and (x + 0.3*plane.get_width()<enemyplace[0]+ enemy.get_width())\ and (y + 0.7*plane.get_height() > enemyplace[1]) and (y + 0.3*plane.get_height()<enemyplace[1]+ enemy.get_height()): (enemyplace) (pause,(0,0)) (boom2, (x, y)) #for place in bullets: #(bullet, (place[0], place[1])) #for place in enemies: #(enemy, (place[0], place[1])) text=('Score%d'%score,True,(0,0,0)) (text,(200,270)) text=("Right ReStart",True,(0, 0,0)) (text,(30,310)) ()# Redraw the window gameover=True while gameover == True and r == False : l, m, r = .get_pressed() for event in (): if == : () exit() #Reset the game i=0 score=0 bullets=[] enemies=[] boomplace=[] x, y=185-plane.get_width()/2,550 - plane.get_height()/2 # Detect Pause Continue l,m,r=.get_pressed() if r == True: (background,(0,0)) (start,(0,0)) (plane,(x,y)) for place in bullets: (bullet,(place[0],place[1])) for place in enemies: (enemy,(place[0],place[1])) for place in boomplace: if place[2] >0: (boom1,(place[0],place[1])) place[2] -=1 text=(u'Score %d'%score,1,(0,0,0)) (text,(50,0)) if gameover == True: x,y =185,550 gameover =False text =(' left to start',True,(0,0,0)) (text,(35,300)) else: x,y=.get_pos() text=(' left to continue ',True,(0,0,0)) (text,(10,300)) () while True : for event in (): if == : () exit() l, m, r = .get_pressed() if l == True: .set_pos(x,y) break text=(u"%d"%score, True, (0, 0, 0)) (text,(50, 0)) for event in (): if == : () exit()
Rendering:
For more great articles on python games check out the following topics:
Collection of python tetris games
Summary of classic python mini-games
python wechat jump game collection
This is the whole content of this article.