Пример #1
0
from plant2 import *
坚果墙 = plant2(name='坚果墙',
             img='坚果墙.png',
             price=50,
             hp=72,
             cooling_time=30,
             hp_img=((2 / 3, 'Wallnut_cracked1.png'),
                     (1 / 3, 'Wallnut_cracked2.png')))
Пример #2
0
                else:
                    hitted_zombies.hit_sound.play()
                if obj.attributes == 1:
                    sputter = obj.attack / len(affect_zombies)
                    for sputter_zombies in affect_zombies[1:]:
                        sputter_zombies.hp -= sputter
                obj.destroy()
                return
            else:
                games.after(obj.bullet_speed, lambda: moving(games, obj, 1))
        else:
            obj.destroy()
            return
    else:
        games.moving_bullets.append(obj)
        return


三线射手 = plant2(name='三线射手',
              img='三线射手.png',
              price=225,
              hp=5,
              cooling_time=7.5,
              attack_interval=1.4,
              bullet_img='pea.png',
              bullet_speed=200,
              bullet_attack=1,
              bullet_sound=('sounds/throw.ogg', ),
              func=peashooter_check,
              bullet_func=moving)
Пример #3
0
    obj.nexted_plants = None
    self.start_time = games.current_time
    random.choice(self.bullet_sound).play()
    goto_another_row(self, obj, games)
    
def goto_another_row(self, obj, games):
    if obj.hp <= 0:
        return
    if games.current_time - self.start_time >= 1.5:
        available_rows = [obj.rows-1, obj.rows+1]
        available_rows = [x for x in available_rows if 0 <= x < games.map_rows]
        obj.stop = False
        obj.rows = random.choice(available_rows)
        obj.button.grid(row=obj.rows, column=obj.columns)
        obj.start_func(obj, games)
        return
    else:
        games.after(10, lambda: goto_another_row(self, obj, games)) 
        return
        
大蒜 = plant2(name='大蒜',
             img='大蒜.png',
             price=50,
             hp=21,
             cooling_time=7.5,
             attack_interval=1.5,
             bullet_attack=0,
             bullet_sound=('sounds/yuck.ogg', 'sounds/yuck2.ogg'),
             sound_volume=(0.5, 0.5),
             effects={'zombies':garlic_check})
大蒜.used = 0
Пример #4
0
                            moving(games, obj)
                        else:
                            return
                    else:
                        return

                else:
                    games.after(obj.bullet_speed,
                                lambda: moving(games, obj, 1))
        else:
            obj.destroy()
            return
    else:
        games.moving_bullets.append(obj)
        return


寒冰射手 = plant2(name='寒冰射手',
              img='寒冰射手.png',
              price=175,
              hp=5,
              cooling_time=7.5,
              attack_interval=1.4,
              bullet_img='snow pea.png',
              bullet_speed=200,
              bullet_attack=1,
              bullet_sound=('sounds/throw.ogg', 'sounds/frozen.ogg'),
              func=snow_pea_check,
              bullet_func=moving,
              other_img=[['pea.png', 3]])
Пример #5
0
                        each.button.destroy()
            else:
                hit_zombies_left = [
                    x for x in hit_zombies if x.columns - j == -1
                ]
                if len(hit_zombies_left) != 0:
                    for each in hit_zombies_left:
                        each.hp -= self.bullet_attack
                        if each.hp <= 0:
                            each.status = 0
                            games.killed_zombies += 1
                            games.current_killed_zombies += 1
                            games.killed_zombies_text.set(
                                f'杀死僵尸数: {games.killed_zombies}')
                            each.button.destroy()
        squash_block = games.blocks[i][j]
        squash_block.configure(image=games.lawn_photo)
        squash_block.plants = None


窝瓜 = plant2(name='窝瓜',
           img='窝瓜.png',
           price=50,
           hp=5,
           cooling_time=30,
           attack_interval=1.5,
           bullet_attack=90,
           bullet_sound=(['sounds/squash_hmm.ogg', 'sounds/squash_hmm2.ogg'],
                         'sounds/gargantuar_thump.ogg'),
           func=squash_check)
Пример #6
0
                                hitted_zombies.remain_time = games.current_time - hitted_zombies.time
                            hitted_zombies.stick_butter += 1
                            hitted_zombies.butter_obj.append(obj)
                        obj.hit_zombies = hitted_zombies
                        obj.time = games.current_time
                        games.after(10, lambda: moving(games, obj))
                else:
                    games.after(obj.bullet_speed,
                                lambda: moving(games, obj, 1))
            else:
                obj.destroy()
                return
    else:
        games.moving_bullets.append(obj)
        return


玉米投手 = plant2(name='玉米投手',
              img='玉米投手.png',
              price=100,
              hp=5,
              cooling_time=7.5,
              attack_interval=3,
              bullet_img='Cornpult_kernal.png',
              bullet_speed=200,
              bullet_attack=1,
              bullet_sound=('sounds/throw.ogg', ),
              func=corn_check,
              other_img=[['Cornpult_butter.png', 3, True]],
              bullet_func=moving)
Пример #7
0
from plant2 import *

向日葵 = plant2(name='向日葵',
             img='向日葵.png',
             price=50,
             hp=4,
             cooling_time=7.5,
             attack_interval=10,
             bullet_img='sun.png',
             bullet_attack=25,
             no_cooling_start=True,
             is_bullet=False)
Пример #8
0
from plant2 import *
火炬树桩 = plant2(name='火炬树桩',
              img='火炬树桩.png',
              price=175,
              hp=5,
              cooling_time=7.5,
              bullet_img='FirePea.png')


def fire_update(self, obj):
    if obj.attributes == 0:
        obj.attack *= 2
        obj.configure(image=self.bullet_img)
        obj.attributes = 1


def normal_fire_update(self, obj):
    if hasattr(obj, 'name') and obj.name == 'snow pea':
        obj.configure(image=obj.change_img)
        obj.melt = 1
    else:
        if obj.attributes == 0:
            obj.attack *= 2
            obj.configure(image=self.bullet_img)
            obj.attributes = 1


火炬树桩.effects = {'bullet': fire_update}
Пример #9
0
    if len(attack_zombies) != 0:
        self.bullet_sound[1].play()
        for each in attack_zombies:
            each.hp -= self.bullet_attack
            if each.hp <= 0:
                each.status = 0
                games.killed_zombies += 1
                games.current_killed_zombies += 1
                games.killed_zombies_text.set(f'杀死僵尸数: {games.killed_zombies}')
                each.button.configure(image=games.zombie_explode_img)
                games.after(3000, lambda t=each: t.button.destroy())
        potato_block = games.blocks[i][j]
        potato_block.configure(image=games.lawn_photo)
        potato_block.plants = None
        return
    games.after(50, lambda: potato_detect(self, games))


土豆雷 = plant2(name='土豆雷',
             img='土豆雷.png',
             price=25,
             hp=5,
             cooling_time=30,
             attack_interval=2,
             bullet_img='UnarmedPotatoMine.png',
             bullet_attack=90,
             bullet_sound=('sounds/dirt_rise.ogg', 'sounds/potato_mine.ogg'),
             func=potato_checking,
             is_bullet=False,
             use_bullet_img_first=True)
Пример #10
0
    each.stop = False
    each.time = games.current_time
    each.runs(games)
    if each.button.winfo_exists():
        each.button.grid(row=i, column=each.columns)


def attract(self, games):
    i, j = self.rows, self.columns
    adjacent_rows = [i - 1, i + 1]
    adjacent_rows = [k for k in adjacent_rows if 0 <= k < games.map_rows]
    adjacent_zombies = [
        x for x in games.whole_zombies if x.status == 1 and x.columns - 1 -
        x.adjust_col == j + 1 and x.rows in adjacent_rows
    ]
    for each in adjacent_zombies:
        if not (hasattr(each, 'stick_butter') and each.stick_butter > 0):
            each.stop = True
            each.rows = i
            games.after(2000, lambda each=each: move_here(each, i, games))


番薯 = plant2(name='番薯',
            img='番薯.png',
            price=150,
            hp=40,
            cooling_time=20,
            img_transparent=True,
            func=attract,
            information=text)
Пример #11
0

def random_choose(self, games):
    if games.current_time - self.time >= self.attack_interval:
        choosed_plant = random.randint(0, games.plants_num - 1)
        j, k = self.rows, self.columns
        current = games.blocks[j][k]
        current.plants = None
        current_time = games.current_time
        choose_plant = games.whole_plants[choosed_plant]
        current.plants = games.get_plant(choose_plant, j, k)
        games.make_img(current.plants)
        if current.plants.use_bullet_img_first:
            current.configure(image=current.plants.bullet_img)
        else:
            current.configure(image=current.plants.img)

        current.plants.time = current_time
        current_plant_name = current.plants.name
        games.action_text.set(f'你成功放置了{current_plant_name}在第{j+1}行,第{k+1}列')


神奇花芽 = plant2(name='神奇花芽',
              img='神奇花芽.png',
              price=100,
              hp=5,
              cooling_time=7.5,
              attack_interval=2,
              func=random_choose,
              information=text)
Пример #12
0
        around_zombies = [
            q for q in games.whole_zombies
            if q.status == 1 and [q.rows, q.columns] in around
        ]
        for each in around_zombies:
            each.hp -= self.bullet_attack
            if each.hp <= 0:
                each.status = 0
                games.killed_zombies += 1
                games.current_killed_zombies += 1
                games.killed_zombies_text.set(f'杀死僵尸数: {games.killed_zombies}')
                each.button.configure(image=games.zombie_explode_img)
                games.after(3000, lambda t=each: t.button.destroy())
        wallnut_block = games.blocks[i][j]
        wallnut_block.configure(image=games.lawn_photo)
        wallnut_block.plants = None


爆炸坚果 = plant2(name='爆炸坚果',
              img='爆炸坚果.png',
              price=100,
              hp=72,
              bullet_attack=90,
              cooling_time=30,
              bullet_sound=('sounds/cherrybomb.ogg', ),
              func=wallnut_explode,
              dead_normal=False,
              information=text,
              hp_img=((2 / 3, 'Explode-o-nut2.png'), (1 / 3,
                                                      'Explode-o-nut3.png')))