python植物大战僵尸十一之太阳花摆放
import pygame from pygame.locals import * import sys from Bullet import Bullet from Peashooter import Peashooter from Sun import Sun from SunFlower import SunFlower from WallNut import WallNut # 初始化pygame from Zombie import Zombie pygame.init() for font in pygame.font.get_fonts(): print(font) size = (1200, 600) # 设置屏幕宽高 screen = pygame.display.set_mode(size) # 设置屏幕标题 pygame.display.set_caption("植物大战僵尸") backgroundImg = pygame.image.load('material/images/background1.jpg').convert_alpha() sunbackImg = pygame.image.load('material/images/SeedBank.png').convert_alpha() flower_seed = pygame.image.load("material/images/TwinSunflower.gif") wallNut_seed = pygame.image.load("material/images/WallNut.gif") peashooter_seed = pygame.image.load("material/images/Peashooter.gif") sunFlowerImg = pygame.image.load('material/images/SunFlower_00.png').convert_alpha() score = '500' myfont = pygame.font.SysFont('arial', 20) txtImg = myfont.render(score, True, (0, 0, 0)) peashooter = Peashooter() # sunFlower = SunFlower() wallNut = WallNut() # zombie = Zombie() spriteList = pygame.sprite.Group() sunFlowerList = pygame.sprite.Group() spriteList.add(peashooter) # spriteList.add(sunFlower) spriteList.add(wallNut) # spriteList.add(zombie) sunList = pygame.sprite.Group() zombieList = pygame.sprite.Group() index = 0 clock = pygame.time.Clock() GENERATOR_SUN_EVENT = pygame.USEREVENT + 1 pygame.time.set_timer(GENERATOR_SUN_EVENT, 5000) GENERATOR_ZOMBIE_EVENT = pygame.USEREVENT + 2 pygame.time.set_timer(GENERATOR_ZOMBIE_EVENT, 5000) choose = 0 while True: clock.tick(15) # 启动消息队列,获取消息并处理 for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == GENERATOR_SUN_EVENT: # 当前是否有太阳花对象,有几个太阳花对象,就生成几个太阳 if len(sunFlowerList) > 0: for sunFlower in sunFlowerList: sun = Sun(sunFlower.rect) sunList.add(sun) if event.type == GENERATOR_ZOMBIE_EVENT: zombie = Zombie() zombieList.add(zombie) if event.type == MOUSEBUTTONDOWN: mouse_pressed = pygame.mouse.get_pressed() # 判断是否按下的事鼠标左键 if mouse_pressed[0]: (x, y) = pygame.mouse.get_pos() # 判断鼠标是否点中了某个卡片 if 330 <= x <= 380 and 10 <= y <= 80 and int(score) >= 50: choose = 1 elif 380 < x <= 430 and 10 <= y <= 80 and int(score) >= 50: choose = 2 elif 430 < x <= 480 and 10 <= y <= 80 and int(score) >= 100: choose = 3 elif 250 < x < 1200 and 70 < y < 600: if choose == 1: sunFlower = SunFlower() sunFlower.rect.top = y sunFlower.rect.left = x sunFlowerList.add(sunFlower) choose = 0 # 扣去太阳花相应的分数 score = int(score) score -= 50 myfont = pygame.font.SysFont('arial', 20) txtImg = myfont.render(str(score), True, (0, 0, 0)) for sun in sunList: if sun.rect.collidepoint((x, y)): # sunList.remove(sun) sun.is_click = True score = int(score) + 50 myfont = pygame.font.SysFont('arial', 20) txtImg = myfont.render(str(score), True, (0, 0, 0)) screen.blit(backgroundImg, (0, 0)) screen.blit(sunbackImg, (250, 0)) screen.blit(txtImg, (270, 60)) screen.blit(flower_seed, (330, 10)) screen.blit(wallNut_seed, (380, 10)) screen.blit(peashooter_seed, (430, 10)) # 根据选中的卡片,将对应的植物图片,显示在当前鼠标的右下角,跟随鼠标移动 (x, y) = pygame.mouse.get_pos() if choose == 1: screen.blit(sunFlowerImg, (x, y)) if choose == 2: screen.blit(wallNut.images[0], (x, y)) if choose == 3: screen.blit(peashooter.images[0], (x, y)) if index % 10 == 0: bullet = Bullet(peashooter.rect, size) spriteList.add(bullet) sunFlowerList.update(index) sunFlowerList.draw(screen) sunList.update(index) sunList.draw(screen) zombieList.update(index) zombieList.draw(screen) for zombie in zombieList: headStr = '刘无敌' yourfont = pygame.font.SysFont('simsunnsimsun', 30) headpic = yourfont.render(headStr, True, (0, 0, 0)) screen.blit(headpic, (zombie.rect.left + 60, zombie.rect.top - 20)) index += 1 pygame.display.update()
相关知识
Python制作植物大战僵尸(附源码)
植物大战僵尸
植物大战僵尸大王花
向日葵的花语,植物大战僵尸中的太阳之力
《植物大战僵尸
植物大战僵尸,植物大战僵尸中文版,植物大战僵尸小游戏 www.4399.com
魔幻植物大战僵尸
植物大战僵尸之花园战争,植物大战僵尸,花园战争游戏介绍
植物大战僵尸网游版
植物大战僵尸mc版下载=植物大战僵尸mc版手机下载
网址: python植物大战僵尸十一之太阳花摆放 https://www.huajiangbk.com/newsview1786890.html
上一篇: python赋值语句的返回值是什 |
下一篇: 对接第三方聚合支付平台支付宝先用 |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039