def __init__(self, hud, scenario):
        super(GameLayer, self).__init__()
        self.hud = hud
        self.scenario = scenario
        # use setters (defined below) to initialize text labels
        self.score = self._score = 0
        self.points = self._points = 40
        self.turrets = []

        w, h = director.get_window_size()
        cell_size = 32

        # use two collision managers for better performance,
        # as the turret slots never collide with the other
        # Actors

        # collision manager for tanks and bunker
        self.coll_man = cm.CollisionManagerGrid(0, w, 0, h,
                                                cell_size,
                                                cell_size)
        # collision manager for static turret slots
        self.coll_man_slots = cm.CollisionManagerGrid(0, w, 0, h,
                                                      cell_size,
                                                      cell_size)
        for slot in scenario.turret_slots:
            self.coll_man_slots.add(actors.TurretSlot(slot,
                                                      cell_size))

        # unpack tuple into x and y by using *
        self.bunker = actors.Bunker(*scenario.bunker_position)
        self.add(self.bunker)
        self.schedule(self.game_loop)
Beispiel #2
0
    def __init__(self, hud, scenario):
        super(GameLayer, self).__init__()
        self.hud = hud
        self.scenario = scenario
        self.score = self._score = 0
        self.points = self._points = 60
        self.turrets = []

        w, h = director.get_window_size()
        cell_size = 32
        self.coll_man = cm.CollisionManagerGrid(0, w, 0, h, cell_size,
                                                cell_size)
        self.coll_man_slots = cm.CollisionManagerGrid(0, w, 0, h, cell_size,
                                                      cell_size)
        for slot in scenario.turret_slots:
            self.coll_man_slots.add(actors.TurretSlot(slot, cell_size))

        self.bunker = actors.Bunker(*scenario.bunker_position)
        self.add(self.bunker)
        self.schedule(self.game_loop)
    def __init__(self, hud, scenario):
        super(GameLayer, self).__init__()
        self.hud = hud
        self.scenario = scenario
        self.score = self._score = 0
        self.points = self._points = 60
        self.turrets = []

        w, h = director.get_window_size()
        
        #使用兩個碰撞管理器,因為slots只是要放砲塔而已所以可以獨立開來,並不需要發生碰撞,雖然全放在一起也可以,但在判斷是否是敵人或是on_mouse_press()時就要多判斷一堆,因此獨立開來可以改善效能
        cell_size = 32
        self.coll_man = cm.CollisionManagerGrid(0, w, 0, h, cell_size, cell_size)
        self.coll_man_slots = cm.CollisionManagerGrid(0, w, 0, h, cell_size, cell_size)
        for slot in scenario.turret_slots: #在腳本設定的位子全部放入砲塔槽演員,其全部加入coll_man_slots碰撞管理器
            self.coll_man_slots.add(actors.TurretSlot(slot, cell_size))

        self.bunker = actors.Bunker(*scenario.bunker_position) #碉堡
        self.add(self.bunker)
        self.schedule(self.game_loop) #註冊排程game_loop 開始每幀循環
Beispiel #4
0
    def __init__(self, hud, scenario):
        super(GameLayer, self).__init__()
        self.hud = hud
        self.scenario = scenario
        self.score = self._score = 0
        self.points = self._points = 60
        self.turrets = []
        self.bunker = actors.Bunker(*scenario.bunker_position)
        self.add(self.bunker)

        width, height = director.get_window_size()
        cell_size = 32

        self.coll_man_turret_slots = cm.CollisionManagerGrid(
            0, width, 0, height, cell_size, cell_size)
        for slot in scenario.turret_slots:
            self.coll_man_turret_slots.add(actors.TurretSlot(slot, cell_size))

        # We have 2 collision managers to avoid unnecessary additions and removals
        # from the turret slot shapes
        self.coll_man = cm.CollisionManagerGrid(0, width, 0, height, cell_size,
                                                cell_size)

        self.schedule(self.game_loop)