Ejemplo n.º 1
0
    def init_game(self, dictstate):

        self.cardname_list = [
            "card_sunflower",
            'card_peashooter',
            'card_snowpea',
            'card_wallnut',
            'card_cherrybomb',
            'card_threepeater',
            'card_squash',
            'card_jalapeno',
        ]
        if 'select_cards' in dictstate:
            self.card_list = dictstate['select_cards']
        self.money = 30000
        if "money" in dictstate:
            self.money = dictstate['money']
        self.done = False
        self.current_time = dictstate['current_time']

        card_x_length = 53
        card_y_length = 74

        grid_x = 9
        grid_y = 5

        #self.UpperCard_TotalOffSet_X = C.Constant_PlantSelection_LayOut.Upper_Panel_Card_Offset_X + C.Constant_PlantSelection_LayOut.Upper_Panel_Offset_X
        self.UpperCard_TotalOffSet_X = 78
        #self.UpperCard_TotalOffSet_Y=C.Constant_PlantSelection_LayOut.Upper_Panel_Offset_Y+ C.Constant_PlantSelection_LayOut.Upper_Panel_Card_Offset_y
        self.UpperCard_TotalOffSet_Y = 8

        #下面的是用来选牌用的
        self.card_grid = Tool.Grid(1, 8, self.UpperCard_TotalOffSet_X,
                                   self.UpperCard_TotalOffSet_Y, card_x_length,
                                   card_y_length)
        #
        self.map_grid = Tool.Grid(grid_y, grid_x, 30, 80, 80, 100)
        self.plant_position_map = [[True for j in range(grid_x)]
                                   for i in range(grid_y)]
        for i, card_name in enumerate(self.cardname_list):
            single_card_image = Tool.All_Images[card_name]
            single_card_image = Tool.get_surface_from_image_samesize(
                single_card_image)
            card_spirte_info = Tool.get_plant_info_from_card_name(card_name)
            plant_name, plant_freezetime, plant_cost = card_spirte_info
            plant_sprite_images = Tool.All_Images[plant_name]

            single_card = Card(self.card_grid, i, card_name, single_card_image,
                               plant_cost, plant_freezetime, self.current_time)
            self.card_list.append(single_card)
            self.card_to_sprite_image[card_name] = plant_sprite_images
Ejemplo n.º 2
0
import Tool
import PlanSelect
import game_play
import plants
from metainfo import *

background_image_index = 0
background_image_name = 'Background'
BackGroundImage = Tool.All_Images[background_image_name][
    background_image_index]
viewpoint = Tool.Screen.get_rect()
viewpoint.x += C.Constant_MapComponent.BACKGROUND_OFFSET_X
Tool.Screen.blit(BackGroundImage, (0, 0), viewpoint)
grid_x = 9
grid_y = 5
map_grid = Tool.Grid(grid_y, grid_x, 30, 80, 80, 100)
zombie_image = Tool.Zombie_Images
zombie_list = []
plant_list = []
bullet_list = []

for i in range(0, 5, 2):

    # panelSelector=PlanSelect.PanelSelector()
    # panelSelector.Draw(Tool.Screen)
    zombie_x, zombie_y = map_grid.GetCorxCorY(8 + i * grid_x)
    zombie_initial_state = GetZombieInitialState(ZombieName.Zombie)
    zombie_initial_state[ZombieInitialStateKeyEnum.rect] = pg.rect.Rect(
        zombie_x, zombie_y - 50, 80, 100)
    a_zombie = plants.Zombie(zombie_initial_state)
    zombie_list.append(a_zombie)