【Python游戏】在这款程序员游戏新作《现代空战—战机游戏》里,你可以体验一把紧张的空战感觉、刺激鸭~打飞机游戏都能有那么多骚操作……

news2024/10/6 16:23:15

导语

不知道大家有没有幻想过遨游在广阔蓝天进行惊险的空战吗?

所有文章完整的素材+源码都在👇👇

粉丝白嫖源码福利,请移步至CSDN社区或文末公众hao即可免费。

虽然这样的画面常常只会出现在电影之中,但小编今天给大家编写的一款Python游戏新作《现

代空战—战机游戏》倒也能让你在游戏中体验一把紧张的空战感觉!

《现代空战—战机游戏》是一款空战射击游戏,游戏画面可谓是空前的“漂亮”~在你一进入游戏

之时,便很难不被眼前科技感十足、简洁有力的页面设计所吸引,背景音乐让即将发生的空中

大战呼之欲出!逼真的场景又会让你产生极强的代入感!蔚蓝的广阔天空一览无余!

一切的精心设计都旨在打造一个壮阔真实的空中视角!

飞机游戏是以飞机为题材的,不同款游戏中飞机起到的效果也是不相同的。当然飞机类游戏拥

有惊艳的画面效果和运行体验,下面跟着小编继续往下看吧~

正文

《现代空战—战机游戏》可以说算是一款界面技术性、以及趣味性都比较ok💯的飞行射击游戏

了。小编自己还是很满意💯的,游戏画面还是游戏效果都编写了的,不信你往下看?!😀

一、环境准备中

 1)运行环境 

 环境安装:Python 3.8: 解释器、pycharm: 代码编辑器,游戏模块Pygame需要安装的模块如 

 下 2)的模块安装方式安装即可。自带的一些模块 直接安装Python就可以使用了。

 相对应的安装包/安装教程/激活码/使用教程/学 习资料/工具插件 可以直接找我厚台获取 。 

 2)模块安装 

 第三方库的安装方式如下:

 一般安装:pip install +模块名 

镜像源安装:pip install -i  https://pypi.douban.com/simple/+模块名 

 (还有很多国内镜像源,这里是豆瓣的用习惯 了,其他镜像源可以去看下之前文章都有的) 

 模块安装问题可以详细的找我给大家讲一下的哈,之前其实也有的文章写了几个点的。 

3)素材(仅部分)

二、代码展示

1)模块导入

import pygame
import sys
import traceback
import my_plane
import enemy_plane
import my_bullet
import supply
import random

2)导入各类图片、字体、音乐等

def main():
	speed = [0,0]
	bg_size = width,height = 500,800
	screen = pygame.display.set_mode(bg_size)
	pygame.display.set_caption('现代空战—战机游戏')
	#载入图片
	background = pygame.image.load('image/sky.png').convert_alpha()
	pause_image1 = pygame.image.load('image/pause_image1.png').convert_alpha()
	pause_image2 = pygame.image.load('image/pause_image2.png').convert_alpha()
	resume_image1 = pygame.image.load('image/resume_image1.png').convert_alpha()
	resume_image2 = pygame.image.load('image/resume_image2.png').convert_alpha()
	bomb_image = pygame.image.load('image/bomb.png').convert_alpha()
	life_image = pygame.image.load('image/life.png').convert_alpha()
	
	#结束画面
	end_image = pygame.image.load('image/end.png').convert_alpha()
	button_end = pygame.image.load('image/button_end.png').convert_alpha()
	button_end2 = pygame.image.load('image/button_end2.png').convert_alpha()
	#给结束人物定位
	end_image_rect = end_image.get_rect()
	end_image_rect.left,end_image_rect.top = 10,10
	font_end = pygame.font.Font('font/font2.ttf',80)
	font_end2 = pygame.font.Font('font/font2.ttf',31)
	font_end3 = pygame.font.Font('font/font2.ttf',40)
	
	#给飞机生命值图标定位
	life_image_rect = life_image.get_rect()
	life_num = 3
	#给暂停图标定位
	pause_image1_rect = pause_image1.get_rect()
	pause_image1_rect.left,pause_image1_rect.top = width -50 ,10
	pause_image = pause_image1
	#给炸弹图标定位
	bomb_rect = bomb_image.get_rect()
	bomb_rect.left, bomb_rect.top = 10,height-50
	#载入音乐
	pygame.mixer.music.load('sound/bg_music1.ogg')
	main_music = pygame.mixer.Sound('sound/main_theme.wav')
	big_music = pygame.mixer.Sound('sound/big_music.wav')
	mine_music = pygame.mixer.Sound('sound/tank_music.wav')
	small_boom_music = pygame.mixer.Sound('sound/small_boom.wav')
	bomb_music = pygame.mixer.Sound('sound/bomb_sound.wav')
	bullet_music = pygame.mixer.Sound('sound/bullet_sound.wav')
	supply_music = pygame.mixer.Sound('sound/supply_sound.wav')
	myplane_music = pygame.mixer.Sound('sound/myplane_boom.wav')
	
	bg_image = pygame.image.load('image/bg_image.png').convert_alpha()
	button_image = pygame.image.load('image/button.png').convert_alpha()
	button2_image = pygame.image.load('image/button2.png').convert_alpha()
	font = pygame.font.Font('font/font.ttf',38)

3)生成敌我双方子弹、不同等级飞机类型

me = my_plane.MyPlane(bg_size)

	enemies = pygame.sprite.Group()
	#生成敌方小型飞机
	small_enemies = pygame.sprite.Group()
	add_small_enemies(small_enemies,enemies,15)
	#生成敌方中型飞机
	middle_enemies = pygame.sprite.Group()
	add_middle_enemies(middle_enemies,enemies,4)
	#生成敌方大型飞机
	big_enemies = pygame.sprite.Group()
	add_big_enemies(big_enemies,enemies,1)
	#生成我方子弹
	bullet1 = []
	bullet1_num = 4
	for i in range(bullet1_num):
		bullet1.append(my_bullet.Bullet1(me.rect.midtop))
	#生成我方超级子弹
	bullet2 = []
	bullet2_num = 8
	for i in range(bullet2_num//2):
		bullet2.append(my_bullet.Bullet2((me.rect.centerx-34,me.rect.centery)))
		bullet2.append(my_bullet.Bullet2((me.rect.centerx+30,me.rect.centery)))

4)完整主程序

import pygame
import sys
import traceback
import my_plane
import enemy_plane
import my_bullet
import supply
import random

pygame.init()
pygame.mixer.init()
clock = pygame.time.Clock()



def main():
	speed = [0,0]
	bg_size = width,height = 500,800
	screen = pygame.display.set_mode(bg_size)
	pygame.display.set_caption('现代空战—战机游戏')
	#载入图片
	background = pygame.image.load('image/sky.png').convert_alpha()
	pause_image1 = pygame.image.load('image/pause_image1.png').convert_alpha()
	pause_image2 = pygame.image.load('image/pause_image2.png').convert_alpha()
	resume_image1 = pygame.image.load('image/resume_image1.png').convert_alpha()
	resume_image2 = pygame.image.load('image/resume_image2.png').convert_alpha()
	bomb_image = pygame.image.load('image/bomb.png').convert_alpha()
	life_image = pygame.image.load('image/life.png').convert_alpha()
	
	#结束画面
	end_image = pygame.image.load('image/end.png').convert_alpha()
	button_end = pygame.image.load('image/button_end.png').convert_alpha()
	button_end2 = pygame.image.load('image/button_end2.png').convert_alpha()
	#给结束人物定位
	end_image_rect = end_image.get_rect()
	end_image_rect.left,end_image_rect.top = 10,10
	font_end = pygame.font.Font('font/font2.ttf',80)
	font_end2 = pygame.font.Font('font/font2.ttf',31)
	font_end3 = pygame.font.Font('font/font2.ttf',40)
	
	#给飞机生命值图标定位
	life_image_rect = life_image.get_rect()
	life_num = 3
	#给暂停图标定位
	pause_image1_rect = pause_image1.get_rect()
	pause_image1_rect.left,pause_image1_rect.top = width -50 ,10
	pause_image = pause_image1
	#给炸弹图标定位
	bomb_rect = bomb_image.get_rect()
	bomb_rect.left, bomb_rect.top = 10,height-50
	#载入音乐
	pygame.mixer.music.load('sound/bg_music1.ogg')
	main_music = pygame.mixer.Sound('sound/main_theme.wav')
	big_music = pygame.mixer.Sound('sound/big_music.wav')
	mine_music = pygame.mixer.Sound('sound/tank_music.wav')
	small_boom_music = pygame.mixer.Sound('sound/small_boom.wav')
	bomb_music = pygame.mixer.Sound('sound/bomb_sound.wav')
	bullet_music = pygame.mixer.Sound('sound/bullet_sound.wav')
	supply_music = pygame.mixer.Sound('sound/supply_sound.wav')
	myplane_music = pygame.mixer.Sound('sound/myplane_boom.wav')
	
	bg_image = pygame.image.load('image/bg_image.png').convert_alpha()
	button_image = pygame.image.load('image/button.png').convert_alpha()
	button2_image = pygame.image.load('image/button2.png').convert_alpha()
	font = pygame.font.Font('font/font.ttf',38)
	#获取button的位置和大小
	button_rect = button_image.get_rect()
	button2_rect = button_image.get_rect()
	button_rect.left,button_rect.top = width//2 - button_rect.width/2,height//2-button_rect.height - 10
	button2_rect.left,button2_rect.top = width//2 - button_rect.width/2,height//2+20
	button_images1 = button_image
	button_images2 = button_image
	
	#当游戏重新开始时,调用重置方法
	game_reset = False
	
	def add_small_enemies(group1,group2,num):
		e1 = enemy_plane.SmallEnemy(bg_size)
		for i in range(num):
			e1 = enemy_plane.SmallEnemy(bg_size)
			group1.add(e1)
			group2.add(e1)
	def add_middle_enemies(group1,group2,num):
		e2 = enemy_plane.MiddleEnemy(bg_size)
		for i in range(num):
			group1.add(e2)
			group2.add(e2)
	def add_big_enemies(group1,group2,num):
		e3 = enemy_plane.BigEnemy(bg_size)
		for i in range(num):
			group1.add(e3)
			group2.add(e3)
			
	def improve_speed(group,num):
		for each in group:
			each.speed += num
	def bomb(group):
		for each in group:
			if each.rect.bottom > 0:
				each.active = False
			
	#生成我的飞机
	me = my_plane.MyPlane(bg_size)

	enemies = pygame.sprite.Group()
	#生成敌方小型飞机
	small_enemies = pygame.sprite.Group()
	add_small_enemies(small_enemies,enemies,15)
	#生成敌方中型飞机
	middle_enemies = pygame.sprite.Group()
	add_middle_enemies(middle_enemies,enemies,4)
	#生成敌方大型飞机
	big_enemies = pygame.sprite.Group()
	add_big_enemies(big_enemies,enemies,1)
	#生成我方子弹
	bullet1 = []
	bullet1_num = 4
	for i in range(bullet1_num):
		bullet1.append(my_bullet.Bullet1(me.rect.midtop))
	#生成我方超级子弹
	bullet2 = []
	bullet2_num = 8
	for i in range(bullet2_num//2):
		bullet2.append(my_bullet.Bullet2((me.rect.centerx-34,me.rect.centery)))
		bullet2.append(my_bullet.Bullet2((me.rect.centerx+30,me.rect.centery)))
	
	#每30秒发放一个飞机补给包
	bullet_supply = supply.Bullet_supply(bg_size)
	bomb_supply = supply.Bomb_supply(bg_size)
	supply_time = pygame.USEREVENT
	pygame.time.set_timer(supply_time,15*1000)
	#超级子弹定时器
	double_bullet_time = pygame.USEREVENT + 1
	#无敌状态定时器
	invincible_time = pygame.USEREVENT + 2
	#是否使用超级子弹
	is_double_bullet = False
	#启动游戏
	ready = False
	running = True
	
	#用于阻止反复保存分数
	recorded = False
	
	#用于飞机动态效果切换
	change = True
	#用于延迟
	delay = 100
	#敌方飞机毁灭动态效果切换
	big_enemy_index = 0
	middle_enemy_index = 0
	small_enemy_index = 0
	me_index = 0
	bullet1_index = 0
	bullet2_index = 0
	bullets = []
	score = 0
	black = (0,0,0)
	green = (0,255,0)
	red = (255,0,0)
	pause = False
	level = 1
	bomb_num = 3
	main_music.play(-1)
	while running:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				pygame.quit()
				sys.exit()
			
			#游戏开始界面
			if not ready:
				if event.type == pygame.MOUSEBUTTONDOWN:
					if event.button == 1 and button_rect.collidepoint(event.pos):
						main_music.stop()
						ready = True
						pygame.mixer.music.play(-1)
						bullet_music.play(-1)
						pygame.mixer.music.set_volume(1)
					elif event.button == 1 and button2_rect.collidepoint(event.pos):
						pygame.quit()
						sys.exit()
				if event.type == pygame.MOUSEMOTION:
					if button_rect.collidepoint(event.pos):
						button_images1 = button2_image
					else:
						button_images1 = button_image
						
					if button2_rect.collidepoint(event.pos):
							button_images2 = button2_image
					else:
						button_images2 = button_image
			else:
				#暂停/开始图标的按键检测
				if life_num:
					if event.type == pygame.MOUSEBUTTONDOWN:
						if event.button == 1 and pause_image1_rect.collidepoint(event.pos):
							pause = not pause
							if pause:
								pygame.mixer.music.pause()
								bullet_music.stop()
								pygame.time.set_timer(double_bullet_time,0)
								pygame.time.set_timer(supply_time,0)
							else:
								pygame.mixer.music.unpause()
								bullet_music.play(-1)
								pygame.time.set_timer(double_bullet_time,2*1000)
								pygame.time.set_timer(supply_time,15*1000)
					if event.type == pygame.MOUSEMOTION:
						if pause_image1_rect.collidepoint(event.pos):
							if pause:
								pause_image = pause_image2
							else:
								pause_image = resume_image2
						else:
							if pause:
								pause_image = pause_image1
							else:
								pause_image = resume_image1
					if event.type == pygame.KEYDOWN:
						if event.key == pygame.K_SPACE:
							if not pause:
								if bomb_num>0:
									bomb_music.play()
									bomb(enemies)
									bomb_num -= 1
					#响应补给事件
					if event.type == supply_time:
						if random.choice([True,False]):
							bomb_supply.active = True
						else:
							bullet_supply.active = True
					#当超级子弹的剩余时间为0
					if event.type == double_bullet_time:
						is_double_bullet = False
						pygame.time.set_timer(double_bullet_time,0)
					#当无敌状态剩余时间为0
					if event.type == invincible_time:
						me.invincible = False
						pygame.time.set_timer(invincible_time,0)

		#游戏难度等级
		if level==1 and score > 50000:
			level = 2
			add_small_enemies(small_enemies,enemies,2)
			add_middle_enemies(middle_enemies,enemies,1)
			improve_speed(small_enemies,2)
		elif level == 2 and score > 200000:
			level = 3
			add_small_enemies(small_enemies,enemies,3)
			add_middle_enemies(middle_enemies,enemies,1)
			add_big_enemies(big_enemies,enemies,1)
			improve_speed(small_enemies,2)
			improve_speed(middle_enemies,1)
		elif  level == 3 and score > 500000:
			level = 4
			add_small_enemies(small_enemies,enemies,3)
			add_middle_enemies(middle_enemies,enemies,1)
			add_big_enemies(big_enemies,enemies,1)
			improve_speed(small_enemies,2)
			improve_speed(middle_enemies,1)
			improve_speed(big_enemies,1)
		elif  level == 4 and score > 800000:
			level = 5
			add_small_enemies(small_enemies,enemies,3)
			add_middle_enemies(middle_enemies,enemies,1)
			add_big_enemies(big_enemies,enemies,1)
			improve_speed(small_enemies,2)
			improve_speed(middle_enemies,1)
			improve_speed(big_enemies,1)
			
		if not ready:
			screen.blit(bg_image,(0,0))
			screen.blit(button_images1,button_rect)
			screen.blit(button_images2,button2_rect)
			font1 = font.render('开始游戏',True,(255,0,0))
			font2 = font.render('退出',True,(255,0,0))
			screen.blit(font1,(button_rect[0]+5,button_rect[1]))
			screen.blit(font2,(button2_rect[0]+45,button2_rect[1]))
		else:
			if life_num:
				#绘制背景
				screen.blit(background,(0,0))
				#绘制当前游戏难度等级(字体)
				level_font = pygame.font.Font('font/font.ttf',30)
				level_font_content = level_font.render('level%d' %level,True,(0,0,255))
				screen.blit(level_font_content,(width//2-30,10))
				#绘制炸弹
				bomb_font = pygame.font.Font('font/font.ttf',40)
				bomb_font_content = bomb_font.render('X%d' %bomb_num,True,(255,0,0))
				screen.blit(bomb_font_content,(bomb_rect.left+50,bomb_rect.top))
				screen.blit(bomb_image,bomb_rect)
				if life_num and not pause:		
					key_pressed = pygame.key.get_pressed()
					if key_pressed[pygame.K_w] or key_pressed[pygame.K_UP]:
						me.moveUP()
					if key_pressed[pygame.K_s] or key_pressed[pygame.K_DOWN]:
						me.moveDOWN()
					if key_pressed[pygame.K_a] or key_pressed[pygame.K_LEFT]:
						me.moveLEFT()
					if key_pressed[pygame.K_d] or key_pressed[pygame.K_RIGHT]:
						me.moveRIGHT()

					#检测我方飞机是否被撞
					enemies_hit = pygame.sprite.spritecollide(me,enemies,False,pygame.sprite.collide_mask)
					if enemies_hit and not me.invincible:
						me.active = False
						for each in enemies_hit:
							each.active = False

					#绘制我的飞机
					if me.active:
						if change:
							screen.blit(me.image,me.rect)
						else:
							screen.blit(me.image2,me.rect)
						#我方飞机切换
						if not(delay % 5):
							change = not change
						delay -= 1
						if not delay:
							delay =100
					else:
						#我方飞机毁灭
						myplane_music.play()
						if not(delay%3):
							screen.blit(me.destroy_images[me_index],me.rect)
							me_index = (me_index+1)%3
						if me_index == 0:
							life_num -= 1
							me.reset()
							pygame.time.set_timer(invincible_time,3*1000)
							
					#绘制我方子弹
					if not(delay%10):
						if is_double_bullet:
							bullets = bullet2
							bullets[bullet2_index].reset((me.rect.centerx-36,me.rect.centery))
							bullets[bullet2_index+1].reset((me.rect.centerx+29,me.rect.centery))
							bullet2_index = (bullet2_index+2)%bullet2_num
						else:
							bullets = bullet1
							bullets[bullet1_index].reset((me.rect.left+me.rect.width//2-4,me.rect.top))
							bullet1_index = (bullet1_index+1)%bullet1_num
					#绘制我方子和弹碰撞检测
					for each in bullets:
						if each.active:
							each.move()
							screen.blit(each.image,each.rect)
							enemies_hit2 = pygame.sprite.spritecollide(each,enemies,False,pygame.sprite.collide_mask)
							if enemies_hit2:
								each.active = False
								for each in enemies_hit2:
									if each in middle_enemies or each in big_enemies:
										if each in big_enemies:
											each.hit = True
										each.HP -= 1
										if each.HP == 0:
											each.active = False
									else:
										each.active = False
									if each.active == False:
										small_boom_music.play()
					#绘制敌方大型飞机
					for each in big_enemies:
						if each.active:
							each.move()
							if each.hit:
								screen.blit(each.image_hit,each.rect)
								each.hit = False
							else:
								if change:
									screen.blit(each.image,each.rect)
								else:
									screen.blit(each.image2,each.rect)
							if each.rect.bottom == -100:
								pygame.mixer.music.pause()
								big_music.play()
							#绘制血条
							pygame.draw.line(screen,black,\
							(each.rect.left,each.rect.top-5),\
							(each.rect.right,each.rect.top-5),2)
							#生命值大于20%血条颜色为绿色
							enemy_remain2 = each.HP/enemy_plane.BigEnemy.HP
							if enemy_remain2 < 0.2:
								pygame.draw.line(screen,red,\
								(each.rect.left,each.rect.top-5),\
								(each.rect.left + each.rect.width*enemy_remain2,each.rect.top-5),2)
							else:
								pygame.draw.line(screen,green,\
								(each.rect.left,each.rect.top-5),\
								(each.rect.left + each.rect.width*enemy_remain2,each.rect.top-5),2)
							if each.rect.top > (each.height-10):
								big_music.stop()
								pygame.mixer.music.unpause()
						else:
							#大型飞机毁灭
							if not(delay%3):
								if big_enemy_index == 0:
									big_music.stop()
									pygame.mixer.music.unpause()
								screen.blit(each.destroy_images[big_enemy_index],each.rect)
								big_enemy_index = (big_enemy_index+1)%5
								if big_enemy_index == 0:
									score += 15000
									each.reset()


					#绘制敌方中型飞机
					for each in middle_enemies:
						if each.active:
							each.move()
							screen.blit(each.image,each.rect)
							#绘制血条
							pygame.draw.line(screen,black,\
							(each.rect.left,each.rect.top-5),\
							(each.rect.right,each.rect.top-5),2)
							#生命值大于20%血条颜色为绿色
							enemy_remain1 = each.HP/enemy_plane.MiddleEnemy.HP
							if enemy_remain1 < 0.2:
								pygame.draw.line(screen,red,\
								(each.rect.left,each.rect.top-5),\
								(each.rect.left + each.rect.width*enemy_remain1,each.rect.top-5),2)
							else:
								pygame.draw.line(screen,green,\
								(each.rect.left,each.rect.top-5),\
								(each.rect.left + each.rect.width*enemy_remain1,each.rect.top-5),2)
						else:
							#中型飞机毁灭
							if not(delay%3):
								screen.blit(each.destroy_images[middle_enemy_index],each.rect)
								middle_enemy_index = (middle_enemy_index+1)%3
								if middle_enemy_index == 0:
									score += 5000
									each.reset()
						
					#绘制敌方小型飞机
					for each in small_enemies:
						if each.active:
							each.move()
							screen.blit(each.image,each.rect)
						else:
							#小型飞机毁灭
							if not(delay%5):
								screen.blit(each.destroy_images[small_enemy_index],each.rect)
								small_enemy_index = (small_enemy_index+1)%2
								if small_enemy_index == 0:
									score += 1000
									each.reset()
				
					#绘制炸弹补给并检测是否获得
					if bomb_supply.active:
						bomb_supply.move()
						screen.blit(bomb_supply.image,bomb_supply.rect)
						if pygame.sprite.collide_mask(bomb_supply,me):
							supply_music.play()
							if bomb_num < 3:
								bomb_num += 1
							bomb_supply.reset()
					#绘制超级子弹补给并检测是否获得
					if bullet_supply.active:
						bullet_supply.move()
						screen.blit(bullet_supply.image,bullet_supply.rect)
						if pygame.sprite.collide_mask(bullet_supply,me):
							supply_music.play()
							is_double_bullet = True
							pygame.time.set_timer(double_bullet_time,10*1000)
							bullet_supply.reset()
							#绘制飞机剩余生命
				if life_num:
					for i in range(life_num):
						screen.blit(life_image,(width - life_image_rect.width*(i+1)-10,height-life_image_rect.height -8))
				
				#绘制分数
				font  = pygame.font.Font('font/font.ttf',30)
				score_font = font.render("Score : %s" % str(score),True,(0,255,0))
				screen.blit(score_font,(10,10))
				#绘制暂停按钮
				screen.blit(pause_image,pause_image1_rect)
			#当生命值为0的时候
			elif life_num == 0:
				#停止背景音效
				pygame.mixer.music.stop()
				
				#停止全部音效
				bullet_music.stop()
				if not recorded:
					recorded = True
					#读取存档的历史  分数
					with open('record.txt','r') as f:
						record_score = f.readline()
						best_score = record_score
					if int(record_score) < int(score):
						best_score = score
						with open('record.txt','w') as f:
							f.write(str(score))
							
				screen.fill((67,104,162))
				font_end_srf1 = font_end.render('Your Score',True,(220,111,114))
				font_end_srf2= font_end.render('%s' %score,True,(220,111,114))
				font_end_srf3= font_end2.render('游戏的失败不等于人生的失败,喵~',True,(220,111,114))
				font_end_srf4= font_end3.render('Best Score:%s' %best_score,True,(220,111,114))
				screen.blit(font_end_srf1,(width//2-150,height//2-200))
				screen.blit(font_end_srf2,(width//2-50,height//2-100))
				screen.blit(font_end_srf4,(10,10))
				screen.blit(font_end_srf3,(0,height//2-300))
				screen.blit(button_end,(width/2-164/2,450))
				screen.blit(button_end2,(width/2-164/2,550))
				#检测用户的鼠标操作
				#如果用户按下左键
				if pygame.mouse.get_pressed()[0]:
					#获取鼠标位置
					pos = pygame.mouse.get_pos()
					#如果用户点击重新开始
					if width/2-164/2 < pos[0] < width/2+164/2 and 450<pos[1]<450+46:
						main()
					#如果用户点击退出
					elif width/2-164/2 < pos[0] < width/2+164/2 and 550<pos[1]<550+46:
						print('已退出游戏!')
						pygame.quit()
						sys.exit()
					
		pygame.display.flip()
		clock.tick(60)

if __name__ == "__main__":
	try:
		main()
	except SystemExit:
		pass
	except:
		traceback.print_exc()
		pygame.quit()
		input()

三、效果展示

游戏规则:初始我方飞机生命值为3,每撞击一次消耗一点生命值,我方子弹销毁一辆敌机得分

1000,上下左右键移动我方战机,没一个补给包可增加飞机战斗火力哦~

其他的就交给大家来探索啦!

1)游戏界面

​2)游戏界面

​3)获得补给包

4)生命值为0,游戏结束

总结

游戏画面简直让人泪流满面(写了挺久的),手绘式涂鸦风格,仿佛是童年的彩色蜡笔描画的

一般,如同小学生的作业本一样,满满的都是回忆。不得不说,《现代空战—战机游戏》的画

面是小编见过的挺有趣的一款,足以看出小编的用心之处了吧~(毕竟敲了一天的代码呢)

如果你是一位喜欢怀旧的玩家那么就不要犹豫了,赶紧跟随小编乘坐这款飞机去寻找欢乐

吧!老规矩滴滴我获取完整的资料的哈保证给你~(免费哈)

✨完整的素材源码等:可以滴滴我吖!或者点击文末hao自取免费拿的哈~

 🔨推荐往期文章——

项目1.0 童年游戏合集

【Python童年游戏】满满的回忆杀—那些年玩过的童年游戏你还记得吗?那个才是你的菜?看到第一个我就泪奔了(致我们逝去的青春)

项目1.1  蔡徐坤打篮球

【Python搞笑游戏】因蔡徐坤打篮球动作超火,被某程序员写成了一款游戏,画面美到不敢看,成功学到了精髓~(附源码免费)

项目1.8  Wifi破解免费

Python编程零基础如何逆袭成为爬虫实战高手之《WIFI破解》(甩万能钥匙十条街)爆赞爆赞~

项目1.1   扫雷

 Pygame实战:据说这是史上最难扫雷游戏,没有之一,你们感受下......

项目1.2   魂斗罗

Pygame实战:多年后“魂斗罗”像素风归来 不止是经典与情怀@全体成员

🎄文章汇总——

汇总合集 Python—2022 |已有文章汇总 | 持续更新,直接看这篇就够了

(更多内容+源码都在✨文章汇总哦!!欢迎阅读喜欢的文章🎉~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/461515.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【数据结构】顺序表和链表基本实现(含全代码)

文章目录 一、什么是线性表1. 什么是顺序表动态开辟空间和数组的问题解释LeetCode-exercise 2. 什么是链表2.1链表的分类2.2常用的链表结构及区别2.3无头单向非循环链表的实现2.4带头双向循环链表的实现2.5循序表和链表的区别LeetCode-exercise 3. 快慢指针LeetCode-exercise 一…

【牛客刷题专栏】0x24:JZ23 链表中环的入口结点(C语言编程题)

前言 个人推荐在牛客网刷题(点击可以跳转)&#xff0c;它登陆后会保存刷题记录进度&#xff0c;重新登录时写过的题目代码不会丢失。个人刷题练习系列专栏&#xff1a;个人CSDN牛客刷题专栏。 题目来自&#xff1a;牛客/题库 / 在线编程 / 剑指offer&#xff1a; 目录 前言问…

【GPT】文本生成任务(生成摘要、文本纠错、机器翻译等的模型微调)

note 文章目录 note一、NLG任务二、NLG之文本摘要2.1 基于mT5的文本摘要2.2 基于openai接口测试2.3 基于chatGPT接口 三、根据自己的数据集进行模型微调四、文本纠错任务五、机器翻译任务Reference 一、NLG任务 NLG&#xff1a;自然语言生成任务&#xff0c;很多NLP任务可以被…

Redis入门到入土(day02)

五大数据类型 官方文档 全段翻译&#xff1a; Redis是一个开放源代码&#xff08;BSD许可&#xff09;的内存中数据结构存储&#xff0c;用作数据库&#xff0c;缓存和消息代理。它支持数据结构&#xff0c;例如字符串&#xff0c;哈希&#xff0c;列表&#xff0c;集合&#…

vue项目 解决el-table自适应高度,vue页面不显示多条滚动条,超出的部分让el-table内部出现滚动条(推荐使用第二种解决方案)

一、需求 后台管理系统&#xff1a;最常见的页面都是由—>左侧菜单、头部tabView页签、主体数据渲染页面&#xff08;AppMain&#xff09;&#xff1b;而一般AppMain页面又分为&#xff1a; 搜索区域、table数据&#xff08;分页&#xff09;&#xff0c;可能也会存在底部&a…

Reid训练代码之数据集处理

本篇文章是对yolov5_reid这篇文章训练部分的详解。 该项目目录为&#xff1a; . |-- config # reid输入大小&#xff0c;数据集名称&#xff0c;损失函数等配置 |-- configs # 训练时期超参数定义 |-- data # 存储数据集和数据处理等代码&#xff0c;以及yolov5类别名称等 |--…

【高分论文密码】大尺度空间模拟预测与数字制图技术

大尺度空间模拟预测和数字制图技术和不确定性分析广泛应用于高分SCI论文之中&#xff0c;号称高分论文密码。 大尺度模拟技术可以从不同时空尺度阐明农业生态环境领域的内在机理和时空变化规律&#xff0c;又可以为复杂的机理过程模型大尺度模拟提供技术基础。 在本次&#x…

cocosLua 之 RichText(1)

结构 富文本主要通过RichText来实现, 其继承结构&#xff1a; #mermaid-svg-AHbMrHe3zp3q1wTZ {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-AHbMrHe3zp3q1wTZ .error-icon{fill:#552222;}#mermaid-svg-AHbMrHe3z…

Linux下ds18b20驱动开发获取温度

文章目录 一、修改并且编译设备树&#xff08;1&#xff09;修改设备树&#xff08;2&#xff09;修改开发板设备树进行reboot 二、硬件连接三、驱动开发与测试&#xff08;1&#xff09;编写设备驱动&#xff08;2&#xff09;编写测试代码&#xff08;3&#xff09;Makefile&…

第四章——数学知识1

质数 质数&#xff1a;在大于1的整数中&#xff0c;如果只包含1和本身这俩个约束&#xff0c;就被叫质数或素数。 质数判定试除法 质数的判定——试除法&#xff1a;如果d能整除n&#xff0c;则n/d再除n&#xff0c;结果是一个整数。 d≤n/d。 bool is_prime(int x) {if (x <…

【大数据之Hadoop】二十、Yarn基础框架及工作机制

1、Yarn基础框架 Yarn是一个资源调度平台&#xff0c;负责为运算程序提供服务器运算资源&#xff0c;相当于一个分布式的操作系统平台&#xff0c;而MapReduce等运算程序则相当于运行于操作系统之上的应用程序。 YARN主要由ResourceManager、NodeManager、ApplicationMaster和…

202303-1 田地丈量

代码 #include<iostream> #include<vector> #include<string> #include<cmath> #include<algorithm> #include<stack> using namespace std; int n, a, b;int main() {cin >> n >> a >> b;int x1, y1, x2, y2;int x, y;…

科学计算NumPy之Ndarray数组对象的创建、切片、索引、修改等操作汇总

NumPy的操作汇总 NumPy概述Ndarray对象基本使用Ndarray的属性Ndarray的类型Ndarray的形状 创建数组创建数组创建全1数组创建全1数组从已有数组创建新数组从现有数组生成创建等差数列数组创建等比数列数组创建等间隔数列数组创建随机数数组创建正态分布创建创建均匀分布 数组切片…

【JUC高并发编程】—— 再见JUC

一、读写锁 读写锁概述 1️⃣ 什么是读写锁&#xff1f; 读写锁是一种多线程同步机制&#xff0c;用于在多线程环境中保护共享资源的访问 与互斥锁不同的是&#xff0c;读写锁允许多个线程同时读取共享资源&#xff0c;但在有线程请求写操作时&#xff0c;必须将其他读写锁…

windows10 ubuntu子系统安装perf工具

文章目录 1&#xff0c;ubuntu子系统中perf工具安装不了1.1&#xff0c;查看perf版本如下所示1.2&#xff0c;网上找不到对应的版本的内核源码&#xff0c;下载别的版本后&#xff0c;编译各种报错 2&#xff0c;百度查到说是WSL1不支持perf2.1&#xff0c;查看WSL版本 2.2&…

MySQ基础知识整合

目录 模糊查询 排序 单行函数 多行函数 分组函数 having 单表查询执行顺序总结 distinct 连接查询 子查询 union limit DQL语句执行顺序 DDL语句 日期化 date和date_format区别 update table 的快速创建以及删除&#xff08;及回滚&#xff09; 约束 事务 …

HTTP基础知识汇总

伴随着云原生(Cloud Native)的兴起&#xff0c;面向服务架构(Service-Oriented Architecture&#xff0c;SOA)、微服务(Microservice)、容器(Container)等相关概念与技术正在逐渐影响CAx(CAD/CAE/CAM)软件的架构设计与开发。 在云原生CAx软件中&#xff0c;首先需要把系统按照…

MySQL锁详解及案例分析

MySQL锁详解及案例分析 一、一条update语句二、MySQL锁介绍三、全局锁全局锁演示1.环境准备2.全局锁演示 四、MySQL表级锁&#xff08;都是Server层实现&#xff09;1、表级锁介绍2、表读S、写锁X1&#xff09;表锁相关命令2&#xff09;表锁演示1、表级的共享锁(读锁)2、表级的…

VLAN实验

SW1 [sw1]int g0/0/2 [sw1-GigabitEthernet0/0/2]dis this interface GigabitEthernet0/0/2 port link-type access port default vlan 2 pc1划分到vlan 2 [sw1-GigabitEthernet0/0/3]dis t…

【C++STL】set

前言 前面的CSTL的博客&#xff0c;我们介绍了string&#xff0c;vector&#xff0c;list&#xff0c;deque&#xff0c;priority_queue还有stack和queue。 这些容器统称为序列式容器&#xff0c;因为其底层为线性序列的数据结构&#xff0c;里面存储的是元素本身。 而从本节开…