python植物大战僵尸九之绘制顶部卡片

简介: 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")
score = '1000'
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()
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, 2000)
GENERATOR_ZOMBIE_EVENT = pygame.USEREVENT + 2
pygame.time.set_timer(GENERATOR_ZOMBIE_EVENT, 5000)
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:
            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]:
                pos = pygame.mouse.get_pos()
                for sun in sunList:
                    if sun.rect.collidepoint(pos):
                        # 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))
    if index % 10 == 0:
        bullet = Bullet(peashooter.rect, size)
        spriteList.add(bullet)
    spriteList.update(index)
    spriteList.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()



image.png


目录
相关文章
|
5月前
|
存储 JSON 搜索推荐
Python植物大战僵尸源码分享
Python植物大战僵尸源码分享
184 0
|
10月前
|
存储 网络协议 小程序
我的小工具,用C和python实现远程读卡器,远程读写消费卡片
我的小工具,用C和python实现远程读卡器,远程读写消费卡片
我的小工具,用C和python实现远程读卡器,远程读写消费卡片
|
11月前
|
Python
python&pygame植物大战僵尸后续课程及项目资源
python&pygame植物大战僵尸后续课程及项目资源
124 0
|
11月前
|
开发框架 Python
手把手教你使用python开发植物大战僵尸游戏
手把手教你使用python开发植物大战僵尸游戏
211 0
|
11月前
|
Python
python植物大战僵尸二十六之打包游戏为exe可执行文件
python植物大战僵尸二十六之打包游戏为exe可执行文件
159 0
|
11月前
|
Python
python植物大战僵尸二十五之只碰撞当前行僵尸
python植物大战僵尸二十五之只碰撞当前行僵尸
56 0
|
11月前
|
Python
python植物大战僵尸二十四之调整植物放置位置
python植物大战僵尸二十四之调整植物放置位置
69 0
|
11月前
|
Python
python植物大战僵尸二十三之添加音乐
python植物大战僵尸二十三之添加音乐
63 0
|
11月前
|
Python
python植物大战僵尸二十二之僵尸攻击状态改变
python植物大战僵尸二十二之僵尸攻击状态改变
65 0
|
11月前
|
Python
python植物大战僵尸二十一之僵尸吃太阳花
python植物大战僵尸二十一之僵尸吃太阳花
84 0