python植物大战僵尸 豆约翰,python植物大战僵尸六之添加僵尸

import pygame

from pygame.locals import *

import sys

from Peashooter import Peashooter

from Sun import Sun

from SunFlower import SunFlower

from WallNut import WallNut

# 初始化pygame

from Zombie import Zombie

pygame.init()

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/SunBack.png').convert_alpha()

myfont = pygame.font.SysFont('arial', 30)

txtImg = myfont.render("1000", True, (0, 0, 0))

peashooter = Peashooter()

sunFlower = SunFlower()

wallNut = WallNut()

zombie = Zombie()

sunList = pygame.sprite.Group()

sunList.add(peashooter)

sunList.add(sunFlower)

sunList.add(wallNut)

sunList.add(zombie)

index = 0

clock = pygame.time.Clock()

while True:

if index > 100:

index = 0

clock.tick(15)

# 启动消息队列,获取消息并处理

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

screen.blit(backgroundImg, (0, 0))

screen.blit(sunbackImg, (250, 30))

screen.blit(txtImg, (300, 33))

if index % 30 == 0:

sun = Sun(sunFlower.rect)

sunList.add(sun)

sunList.update(index)

sunList.draw(screen)

# screen.blit(peashooter.images[index % 13], peashooter.rect)

# screen.blit(sunFlower.images[index % 13], sunFlower.rect)

# screen.blit(wallNut.images[index % 13], wallNut.rect)

index += 1

pygame.display.update()

'''僵尸'''

import pygame

class Zombie(pygame.sprite.Sprite):

def __init__(self):

super(Zombie, self).__init__()

self.image = pygame.image.load('material/images/Zombie_0.png').convert_alpha()

self.images = [pygame.image.load('material/images/Zombie_{}.png'.format(i)).convert_alpha() for i in

range(0, 22)]

self.rect = self.images[0].get_rect()

self.rect.top = 50

self.rect.left = 1000

self.speed = 1

def update(self, *args):

self.image = self.images[args[0] % len(self.images)]

if self.rect.left > 250:

self.rect.left -= self.speed

2a7898d38eb2

image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值