• 平常心_8888
    了解作者
  • Python
    开发工具
  • 7.2MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 6
    下载次数
  • 2020-08-17 10:12
    上传日期
基于 Python 平台开发的一款坦克大战游戏,画面清晰,操纵灵活,小时候玩过的很经典的射击游戏,希望大家喜欢!
坦克大战.rar
  • BattleCity
  • __pycache__
  • scene.cpython-36.pyc
    5.9KB
  • home.cpython-36.pyc
    887B
  • food.cpython-36.pyc
    1.2KB
  • food.cpython-37.pyc
    1.2KB
  • tank.cpython-36.pyc
    9.8KB
  • bullet.cpython-37.pyc
    1.5KB
  • tank.cpython-37.pyc
    9.2KB
  • bullet.cpython-36.pyc
    1.5KB
  • home.cpython-37.pyc
    859B
  • scene.cpython-37.pyc
    5.4KB
  • .idea
  • workspace.xml
    21.8KB
  • misc.xml
    683B
  • encodings.xml
    159B
  • BattleCity.iml
    398B
  • .name
    10B
  • modules.xml
    272B
  • images
  • others
  • tip.png
    2.6KB
  • boom_dynamic.png
    88KB
  • mask.png
    646B
  • boom_static.png
    22.1KB
  • protect.png
    15.4KB
  • gameover.png
    1.1KB
  • logo.png
    129.6KB
  • background.png
    1.2MB
  • appear.png
    15.4KB
  • bullet
  • bullet_left.png
    15KB
  • bullet_up.png
    15KB
  • bullet_down.png
    15KB
  • bullet_right.png
    15KB
  • myTank
  • tank_T2_1.png
    16KB
  • tank_T1_1.png
    16KB
  • tank_T1_0.png
    15.9KB
  • tank_T2_0.png
    15.9KB
  • tank_T1_2.png
    16.1KB
  • tank_T2_2.png
    16.1KB
  • scene
  • brick.png
    17.1KB
  • river1.png
    2.8KB
  • river2.png
    2.8KB
  • iron.png
    15.3KB
  • ice.png
    1.7KB
  • tree.png
    1012B
  • home
  • home2.png
    22.2KB
  • home1.png
    17.8KB
  • home_destroyed.png
    16.7KB
  • food
  • food_protect.png
    15.8KB
  • food_star.png
    15.9KB
  • food_tank.png
    15.9KB
  • food_iron.png
    15.9KB
  • food_clock.png
    15.8KB
  • food_boom.png
    15.8KB
  • food_gun.png
    15.8KB
  • enemyTank
  • enemy_2_2.png
    15.9KB
  • enemy_2_1.png
    15.9KB
  • enemy_3_3.png
    16KB
  • enemy_3_0.png
    16KB
  • enemy_4_3.png
    16.1KB
  • enemy_1_3.png
    15.9KB
  • enemy_2_0.png
    15.9KB
  • enemy_1_2.png
    16KB
  • enemy_4_1.png
    16.1KB
  • enemy_3_2.png
    16KB
  • enemy_4_2.png
    16.1KB
  • enemy_1_1.png
    16KB
  • enemy_2_3.png
    15.9KB
  • enemy_3_1.png
    16KB
  • enemy_4_0.png
    16.1KB
  • enemy_1_0.png
    16KB
  • audios
  • hit.wav
    790B
  • bang.wav
    9.5KB
  • add.wav
    127.6KB
  • fire.wav
    67.6KB
  • blast.wav
    52.9KB
  • start.wav
    862.6KB
  • Gunfire.wav
    1.9KB
  • font
  • simkai.ttf
    11.2MB
  • home.py
    522B
  • scene.py
    4.7KB
  • food.py
    1.3KB
  • bullet.py
    1.6KB
  • start.py
    17KB
  • tank.py
    13.8KB
内容介绍
import sys import pygame # 开始界面显示 import scene, tank, home, food def show_start_interface(screen, width, height): tfont = pygame.font.Font('font/simkai.ttf', width//5) cfont = pygame.font.Font('font/simkai.ttf', width//20) title = tfont.render(u'TANK', True, (255, 0, 0)) content1 = cfont.render(u'1 PLAYER(按1)', True, (0, 0, 255)) content2 = cfont.render(u'2 PLAYER(按2)', True, (0, 0, 255)) trect = title.get_rect() trect.midtop = (width/2, height/5) crect1 = content1.get_rect() crect1.midtop = (width/2, height/1.8) crect2 = content2.get_rect() crect2.midtop = (width/2, height/1.6) screen.blit(title, trect) screen.blit(content1, crect1) screen.blit(content2, crect2) pygame.display.update() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_1: return 1 if event.key == pygame.K_2: return 2 # 结束界面显示 def show_end_interface(screen, width, height, is_win): bg_img = pygame.image.load("images/others/background.png") screen.blit(bg_img, (0, 0)) if is_win: font = pygame.font.Font('font/simkai.ttf', width//10) content = font.render(u'恭喜通关!', True, (255, 0, 0)) rect = content.get_rect() rect.midtop = (width/2, height/2) screen.blit(content, rect) else: fail_img = pygame.image.load("images/others/gameover.png") rect = fail_img.get_rect() rect.midtop = (width/2, height/2) screen.blit(fail_img, rect) pygame.display.update() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # 关卡切换 def show_switch_stage(screen, width, height, stage): bg_img = pygame.image.load("images/others/background.png") screen.blit(bg_img, (0, 0)) font = pygame.font.Font('font/simkai.ttf', width//10) content = font.render(u'第%d关' % stage, True, (0, 255, 0)) rect = content.get_rect() rect.midtop = (width/2, height/2) screen.blit(content, rect) pygame.display.update() delay_event = pygame.constants.USEREVENT pygame.time.set_timer(delay_event, 1000) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == delay_event: return # 主函数 def main(): # 初始化 pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((630, 630)) pygame.display.set_caption("TANK") # 加载图片 bg_img = pygame.image.load("images/others/background.png") # 加载音效 add_sound = pygame.mixer.Sound("audios/add.wav") add_sound.set_volume(1) bang_sound = pygame.mixer.Sound("audios/bang.wav") bang_sound.set_volume(1) blast_sound = pygame.mixer.Sound("audios/blast.wav") blast_sound.set_volume(1) fire_sound = pygame.mixer.Sound("audios/fire.wav") fire_sound.set_volume(1) Gunfire_sound = pygame.mixer.Sound("audios/Gunfire.wav") Gunfire_sound.set_volume(1) hit_sound = pygame.mixer.Sound("audios/hit.wav") hit_sound.set_volume(1) start_sound = pygame.mixer.Sound("audios/start.wav") start_sound.set_volume(1) # 开始界面 num_player = show_start_interface(screen, 630, 630) # 播放游戏开始的音乐 start_sound.play() # 关卡 stage = 0 num_stage = 2 # 游戏是否结束 is_gameover = False # 时钟 clock = pygame.time.Clock() # 主循环 while not is_gameover: # 关卡 stage += 1 if stage > num_stage: break show_switch_stage(screen, 630, 630, stage) # 该关卡坦克总数量 enemytanks_total = min(stage * 12, 60) # 场上存在的敌方坦克总数量 enemytanks_now = 0 # 场上可以存在的敌方坦克总数量 enemytanks_now_max = min(max(stage * 2, 4), 8) # 精灵组 tanksGroup = pygame.sprite.Group() mytanksGroup = pygame.sprite.Group() enemytanksGroup = pygame.sprite.Group() bulletsGroup = pygame.sprite.Group() mybulletsGroup = pygame.sprite.Group() enemybulletsGroup = pygame.sprite.Group() myfoodsGroup = pygame.sprite.Group() # 自定义事件 # -生成敌方坦克事件 genEnemyEvent = pygame.constants.USEREVENT + 0 pygame.time.set_timer(genEnemyEvent, 100) # -敌方坦克静止恢复事件 recoverEnemyEvent = pygame.constants.USEREVENT + 1 pygame.time.set_timer(recoverEnemyEvent, 8000) # -我方坦克无敌恢复事件 noprotectMytankEvent = pygame.constants.USEREVENT + 2 pygame.time.set_timer(noprotectMytankEvent, 8000) # 关卡地图 map_stage = scene.Map(stage) # 我方坦克 tank_player1 = tank.myTank(1) tanksGroup.add(tank_player1) mytanksGroup.add(tank_player1) if num_player > 1: tank_player2 = tank.myTank(2) tanksGroup.add(tank_player2) mytanksGroup.add(tank_player2) is_switch_tank = True player1_moving = False player2_moving = False # 为了轮胎的动画效果 time = 0 # 敌方坦克 for i in range(0, 3): if enemytanks_total > 0: enemytank = tank.enemyTank(i) tanksGroup.add(enemytank) enemytanksGroup.add(enemytank) enemytanks_now += 1 enemytanks_total -= 1 # 大本营 myhome = home.Home() # 出场特效 appearance_img = pygame.image.load("images/others/appear.png").convert_alpha() appearances = [] appearances.append(appearance_img.subsurface((0, 0), (48, 48))) appearances.append(appearance_img.subsurface((48, 0), (48, 48))) appearances.append(appearance_img.subsurface((96, 0), (48, 48))) # 关卡主循环 while True: if is_gameover is True: break if enemytanks_total < 1 and enemytanks_now < 1: is_gameover = False break for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == genEnemyEvent: if enemytanks_total > 0: if enemytanks_now < enemytanks_now_max: enemytank = tank.enemyTank() if not pygame.sprite.spritecollide(enemytank, tanksGroup, False, None): tanksGroup.add(enemytank) enemytanksGroup.add(enemytank) enemytanks_now += 1 enemytanks_total -= 1 if event.type == recoverEnemyEvent: for each in enemytanksGroup: each.can_move = True if event.type == noprotectMytankEvent: for each in mytanksGroup: mytanksGroup.protected = False # 检查用户键盘操作 key_pressed = pygame.key.get_pressed() # 玩家一 if key_pressed[pygame.K_w]: tanksGroup.remove(tank_player1) tank_player1.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player1) player1_moving = True elif key_pressed[pygame.K_s]: tanksGroup.remove(tank_player1) tank_player1.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player1) player1_moving = True elif key_pressed[pygame.K_a]: tanksGroup.remove(tank_player1) tank_player1.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player1) player1_moving = True elif key_pressed[pygame.K_d]: tanksGroup.remove(tank_player1) tank_player1.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player1) player1_moving = True elif key_pressed[pygame.K_j]: if not tank_player1.bullet.being: fire_sound.play() tank_player1.shoot() # 玩家二 if num_player > 1: if key_pressed[pygame.K_UP]: tanksGroup.remove(tank_player2) tank_player2.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player2) player2_moving = True elif key_pressed[pygame.K_DOWN]: tanksGroup.remove(tank_player2) tank_player2.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player2) player2_moving = True elif key_pressed[pygame.K_LEFT]: tanksGroup.remove(tank_player2) tank_player2.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome) tanksGroup.add(tank_player2) player2_moving = True elif key_pressed[pygam
评论
    相关推荐
    • 坦克大战.zip
      游戏,坦克大战python进行开发,实现基本的游戏界面和操作
    • 坦克大战.zip
      通过编写简单的python语句,实现了简单的坦克游戏,能够完成一定的功能
    • Python坦克大战代码.rar
      Python坦克大战的源代码,初学Python的小白练习和模仿,结构简单,明了,易懂。工程文件分开建造,测试阶段合理
    • 坦克大战python编写)
      python编写的坦克大战,主要用到的模块是pygame。代码有足够详细的注释,非常容易理解,喜欢的朋友支持支持~
    • java版坦克大战源码-battle-city-ai:战斗城市-ai
      每个玩家都是一个单独的客户端(坦克)连接到游戏服务器。 客户端通过向服务器发送动作来控制他们的坦克。 当两个连接都建立并且问候消息发送到两个客户端时,游戏就开始了。 客户端的动作被定义一次,并且在游戏...
    • 坦克大战游戏
      这是我们用python语言开发的一个名为坦克大战的小游戏,可以作为源码直接跑,也可以继续开发
    • python.pygame.坦克大战源代码
      这是我分享的著名的坦克大战python版,python游戏的进阶版。很好的游戏参考资源。 有兴趣的同学可以加群634295212 一起讨论学习。参考分享或改进代码请注明原作者信息。 及新作者信息
    • pygame 坦克游戏
      利用90坦克大战的图像声音资源重新组合的一款用python语言写的Pygame引擎小游戏·
    • Game5-坦克大战.rar
      游戏坦克大战,画面还很粗糙,后期期待改进
    • snowglobe-src-viewer-2.0.0-r0.tar.gz
      国外的开源游戏引擎,能够承载上千人,属于社交类的游戏