简单实现的植物大战僵尸
我自己网上扣了王校长的图做了个热狗射手hhhhhhhh
最后面给大家分享一下我扣的热狗png图片
求点赞!!!
"""
v1.8
1.完善僵尸类
2.加载僵尸
"""
import pygame
import time
import random
import sys
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 560
# 地图类 v1.2 完善地图类
class Map:
images_list = ['imgs/map1.png','imgs/map2.png']
def __init__(self, x, y, image_index):
self.position = (x,y)
self.image = pygame.image.load(Map.images_list[image_index])
# v1.5 新增是否能种植的属性
self.can_grow = True
# 将当前地图的图片加入到窗口
def display_map(self):
MainGame.window.blit(self.image,self.position)
# 植物类 (父类)
class Plant(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.live = True
# 向日葵类 v1.4 完善向日葵类
class Sunflower(Plant):
def __init__(self,x,y):
super(Sunflower, self).__init__()
self.image = pygame.image.load('imgs/sunflower.png')
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.price = 50
self.hp = 100
# v1.6 时间计数器
self.time_count = 0
# v1.6 新增功能:生成阳光
def produce_money(self):
self.time_count += 1
if self.time_count == 25:
MainGame.money += 5
self.time_count = 0
# 向日葵加入到窗口中
def display_sunflower(self):
MainGame.window.blit(self.image,self.rect)
# 豌豆射手类
# v1.5 完善 豌豆射手类
class PeaShooter(Plant):
def __init__(self,x,y):
super(PeaShooter, self).__init__()
# self.image 为一个 surface
self.image = pygame.image.load('imgs/1-4.png')
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
self.price = 50
self.hp = 200
# v1.7 发射计数器
self.shot_count = 0
# v1.7 增加射击方法
def shot(self):
# v1.9 记录是否应该射击
should_fire = False
for zombie in MainGame.zombie_list:
if zombie.rect.y == self.rect.y and zombie.rect.x < 800 and zombie.rect.x > self.rect
如何用python简单做一个植物大战僵尸 源码
最新推荐文章于 2024-05-16 07:06:58 发布