from util.loadimages import getImages from entity.sun import Sun from entity.plant.wallnut import Wallnut from entity.plant.sunflower import Sunflower from entity.plant.peashooter import Peashooter from entity.plant.chomper import Chomper from entity.plant.cherryBomb import CherryBomb from entity.plant.repeater import Repeater from entity.plant.cactus import Cactus import sys from util.bus import Bus from musicplayer import MusicPlayer import random sets = Setting() # 当鼠标被点击时调用函数 # 用来绑定卡片监听事件 def cardMouseClickListener(bus): leftButtonDown = pygame.mouse.get_pressed()[0] rightButtonDown = pygame.mouse.get_pressed()[2] if leftButtonDown: mousex, mousey = pygame.mouse.get_pos() CARD_BASIC_X = 80 CARD_BASIC_Y = 10 CARD_HEIGHT = 68 CARD_WIDTH = 55 CARD_OFFSET = 60 # i --> 0-坚果 1-向日葵 2-豌豆射手 3-仙人掌 4-樱桃炸弹 5-豌豆射手double
import pygame from entity.plant.plant import Plant from conf.settings import Setting from entity.bullet import Bullet set = Setting() class Peashooter(Plant): def __init__(self, screen, x, y, images): self.screen = screen self.x = x self.y = y self.images = images self.image = images[0] self.width = 0 self.height = 0 super(Peashooter, self).__init__(screen, self.x, self.y, self.image) # step要用到的index self.index = 0 self.life = 100 self.sunshine = 100 self.attack = 50 self.interval = 150 self.cd = 10 def step(self, bus, screen, sets): self.index += 1 # 执行功能 if self.index == self.interval: