Пример #1
0
    def __init__(self, hud, scenario):
        super(GameLayer, self).__init__()
        self.hud = hud
        self.scenario = scenario
        self.score = self._score = 0
        self.lives = self._lives = 3

        self.create_player()
        self.create_ghosts()
        self.create_dots()

        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_dots = cm.CollisionManagerGrid(0, w, 0, h, cell_size,
                                                     cell_size)

        pygame.mixer.init()
        self.sounds={'die'   : pygame.mixer.Sound("assets/Sounds/pacman_death.wav"), \
                     'intro' : pygame.mixer.Sound("assets/Sounds/pacman_beginning.wav"), \
                     'waka'  : pygame.mixer.Sound("assets/Sounds/pacman_chomp.wav")}

        self.sounds['intro'].play()
        self.schedule(self.game_loop)
Пример #2
0
    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)
Пример #3
0
    def __init__(self):
        super(GameLayer, self).__init__()
        self.hero = Hero()
        self.add(self.hero,z = 1)
        self.bullet_batch = batch.BatchNode()
        self.enemy_batch = batch.BatchNode()
        self.add(self.bullet_batch,z = 1)
        self.add(self.enemy_batch,z = 1)

        # 保存容器
        self.bullet_resuable = []
        self.enemy_resuable = []
        # 子弹和敌机的碰撞
        # 检测区域
        self.enemy_bullet_collision = collision.CollisionManagerGrid(0,config.WINDOS_WIDTH,0,config.WINDOS_HEIGHT,110,110)
        self.enemy_hero_collosion = collision.CollisionManagerGrid(0,config.WINDOS_WIDTH,0,config.WINDOS_HEIGHT,self.hero.width*1.25,self.hero.height*1.25)
        # 在屏幕上的敌机
        self.active_enemies = []
        self.active_bullets = []

        self.codes = Codes_text()
        self.add(self.codes)

        # 每一帧的事件调度

        self.schedule_interval(self.fire_bullet,0.1)
        self.schedule_interval(self.enemy_update,0.3)
        self.schedule(self.run_schedule)
def test_CollisionManagerGrid_fulfil_obj_can_be_not_known():
    w_width = 200.0
    w_height = 100.0
    cell_side = 20.00
    collman = cm.CollisionManagerGrid(0.0, w_width, 0.0, w_height, cell_side,
                                      cell_side)

    known = create_obj_with_circle('known', eu.Vector2(10, 12), 10)
    collman.add(known)
    not_known = create_obj_with_circle('not-known', eu.Vector2(10, 12), 10)

    for e in collman.objs_colliding(not_known):
        assert e is known

    for e in collman.iter_colliding(not_known):
        assert e is known

    assert known is collman.any_near(not_known, 1.0)

    for e in collman.objs_near(not_known, 1.0):
        assert e is known

    for e in collman.objs_near_wdistance(not_known, 1.0):
        assert e[0] is known

    for e in collman.ranked_objs_near(not_known, 1.0):
        assert e[0] is known
Пример #5
0
    def init(self):
        self.bird = Bird()
        self.bird.set_initial_speed()

        self.collision_manager = cm.CollisionManagerGrid(
            0, self.width, 0, self.height, self.bird.image.width,
            self.bird.image.width)
Пример #6
0
    def __init__(self, hud):
        super(GameLayer, self).__init__()
        self.hud = hud

        # grab window width and height for frequent use
        w, h = cd.director.get_window_size()
        self.width = w
        self.height = h

        # initialize lives and score
        self.lives = 3
        self.score = 0

        # create a collision manager
        cell = 1.25 * 50
        self.collman = cm.CollisionManagerGrid(0, w, 0, h, cell, cell)

        # call methods to create cannon and update both HUD labels
        self.update_score()

        # create the player cannon
        self.create_player()
        self.create_swarm(100, 300)

        # start game loop
        self.schedule(self.game_loop)
Пример #7
0
    def __init__(self):
        super(World, self).__init__()
        world = consts['game_area']
        self.width = world['width']
        self.height = world['height']
        self.rPlayer = world['r']
        self.wall_scale_min = world['wall_scale_min']
        self.wall_scale_max = world['wall_scale_max']
        self.top_speed = world['top_speed']
        self.ang_velocity = world['ang_velocity']
        self.acceleration = world['acceleration']

        pics = {}
        pics["player"] = pyglet.resource.image('assets/player.png')
        pics["wall"] = pyglet.resource.image('assets/wall.png')
        pics["enemy"] = pyglet.resource.image('assets/enemy.png')
        pics["health"] = pyglet.resource.image('assets/health.png')
        self.pics = pics

        cell_size = self.rPlayer * self.wall_scale_max * 2.0 * 1.25
        self.collisions = colmod.CollisionManagerGrid(0.0, self.width, 0.0,
                                                      self.height, cell_size,
                                                      cell_size)
        self.bindings = world['bindings']
        buttons = {}
        for i in self.bindings:
            buttons[self.bindings[i]] = 0
        self.buttons = buttons

        self.toRemove = set()
        self.schedule(self.update)
        self.empty_level()
        self.level_launch()
Пример #8
0
    def on_game_start(self, type):
        width = director._window_virtual_width
        height = director._window_virtual_height

        self.pingpong = PingPong(width / 2, height / 2, self.model)
        self.lpaddle = Paddle(0, height / 2, 255, 0, 0)

        if (type == 'computer'):
            self.rpaddle = ComputerPaddle(width, \
                                          height/2, \
                                          0, 255, 255)
        elif (type == 'player'):
            self.rpaddle = Paddle(width, \
                                  height/2, \
                                  0, 255, 255)
        cellsize = self.pingpong.width * 1.25
        self.collman = cm.CollisionManagerGrid(0, width, 0, height, cellsize,
                                               cellsize)
        self.lpaddle.position = 0, height / 2
        self.rpaddle.position = width, height / 2
        self.pingpong.init()

        self.add(self.rpaddle)
        self.add(self.lpaddle)
        self.add(self.score_text_left)
        self.add(self.score_text_right)
        self.add(self.pingpong)

        self.lpaddle.do(RotateBy(360, 2))
        self.rpaddle.do(RotateBy(360, 2))
        self.pingpong.do(RotateBy(360, 2))
        self.callupdate = self.do(Delay(2) + Repeat(CallFunc(self.update)))
        self.resume()
Пример #9
0
    def _init_map_and_cm(self, mapName):
        if mapName == "srandom" or mapName == "sRandom" or mapName == "sr" or mapName == "sR":
            # Single player random -> adds AI
            self.mapName = str(random.randint(100, 10000))
            m = Map("random",
                    numPlayers=2,
                    AIPlayers=["1"],
                    seed=int(self.mapName))
        elif mapName == "random" or mapName == "Random" or mapName == "r" or mapName == "R":
            # Multi player random -> doesn't add AI
            self.mapName = str(random.randint(100, 10000))
            m = Map("random", numPlayers=2, seed=int(self.mapName))
        elif mapName.isdigit():
            m = Map("random", numPlayers=2, seed=int(mapName))
            self.mapName = mapName
        else:
            m = Map(os.path.join("maps", mapName + ".map"))
            self.mapName = mapName
        # self.map = Map(os.path.join("maps", "random", "random487.map"))
        self.cm = collision_model.CollisionManagerGrid(
            -BLEED, m.w * CELL_SIZE + BLEED, -BLEED, m.h * CELL_SIZE + BLEED,
            CELL_SIZE / 2, CELL_SIZE / 2)
        m.cm = self.cm
        self.scroller = ScrollingManager(viewport=director.window)
        self.scroller.add(m)

        self.h = CELL_SIZE * m.h
        if self.h < WINDOW_HEIGHT:
            self.h = WINDOW_HEIGHT

        self.w = CELL_SIZE * m.w
        if self.w < WINDOW_WIDTH:
            self.w = WINDOW_WIDTH

        return m
Пример #10
0
    def __init__(self, hud):
        super(GameLayer, self).__init__()
        self.hud = hud

        # grab window width and height for frequent use
        w, h = cd.director.get_window_size()
        self.width = w
        self.height = h

        # initialize lives and score
        self.lives = 3
        self.score = 0
        # Increase the difficulty by halving the period at which the swarm moves
        # every time the player earns an additional 150 points.
        self.difficulty = 150
        self.speed_factor = 1

        # create a collision manager
        cell = 1.25 * 50
        self.collman = cm.CollisionManagerGrid(0, w, 0, h, cell, cell)

        # call methods to create cannon and update both HUD labels
        self.update_score()

        # create the player cannon
        self.create_player()
        self.create_swarm(100, 300)

        # start game loop
        self.schedule(self.game_loop)
Пример #11
0
    def __init__(self):
        super(MainLayer, self).__init__()
        """ Initializes the world, places background and all actors in the specified positions.
        Builds the collision manager and sets up the starting parameters of the game.

        """
        self.animation = pyglet.image.load_animation('assets/corgi1.gif')
        bin_ = pyglet.image.atlas.TextureBin()
        self.animation.add_to_texture_bin(bin_)
        self.place_sprites()

        # Initializes the collision manager and all starting parameters, sets up the scheduler.
        cell = self.player.width * 1.25
        self.collman = cm.CollisionManagerGrid(0, cfg.WINDOW_WIDTH, 0,
                                               cfg.WINDOW_HEIGHT, cell, cell)

        self.player_speed = PlayerSpeed()
        self.lives = 6000  # cfg.STARTING_LIVES
        self.score = cfg.STARTING_SCORE
        self.may_jump = True
        self.may_walk = True
        self.facing_right = False
        self.jump_range = cfg.JUMP
        self.pressed = defaultdict(int)

        # Starts the main loop of the game
        self.schedule(self.update)
def test_ops_near_boundaries():
    # applies only to CollisionManagerGrid, boundaries are the grid boundaries
    w_width = 200.0
    w_height = 100.0
    cell_side = 20.00
    collman = cm.CollisionManagerGrid(0.0, w_width, 0.0, w_height, cell_side,
                                      cell_side)

    # adding object near boundaries should not fail
    radius = 5.0
    
    lo_lo = create_obj_with_circle('lo-lo',
                        eu.Vector2(radius+fe, radius+fe), radius)

    collman.add(lo_lo) #must not fail
    assert collman.knows(lo_lo)

    lo_hi = create_obj_with_circle('lo-hi',
                        eu.Vector2(radius+fe, w_height - (radius+fe)), radius)
    collman.add(lo_hi) #must not fail
    assert collman.knows(lo_hi)
    
    hi_lo = create_obj_with_circle('hi-lo',
                        eu.Vector2(w_width - (radius+fe), radius+fe), radius)
    collman.add(hi_lo) #must not fail
    assert collman.knows(hi_lo)
    
    hi_hi = create_obj_with_circle('hi-hi',
                        eu.Vector2(w_width - (radius+fe), w_height - (radius+fe)),
                        radius)
    collman.add(hi_hi) #must not fail
    assert collman.knows(hi_hi)


    # asking for others near obj should not fail if the near capsule goes out
    # of world boundaries
    
    near_distance = w_width
    nears = collman.objs_near(lo_lo, near_distance) #must not fail
    li = collman.objs_near_wdistance(lo_lo, near_distance) #must not fail
    ranked = collman.ranked_objs_near(lo_lo, near_distance) #must not fail
    
    nears = collman.objs_near(lo_hi, near_distance) #must not fail
    li = collman.objs_near_wdistance(lo_hi, near_distance) #must not fail
    ranked = collman.ranked_objs_near(lo_hi, near_distance) #must not fail
    
    nears = collman.objs_near(hi_lo, near_distance) #must not fail
    li = collman.objs_near_wdistance(hi_lo, near_distance) #must not fail
    ranked = collman.ranked_objs_near(hi_lo, near_distance) #must not fail

    nears = collman.objs_near(hi_hi, near_distance) #must not fail
    li = collman.objs_near_wdistance(hi_hi, near_distance) #must not fail
    ranked = collman.ranked_objs_near(hi_hi, near_distance) #must not fail

    nears = collman.objs_near(lo_lo, w_width + w_height)
    assert set(nears) == set([lo_hi, hi_lo, hi_hi])
Пример #13
0
    def __init__(self, level_info, hud):
        self.hud = hud
        self.level_info = level_info

        # mache das lager
#        self.storage = Storage(self.level_info)

        super().__init__()
        w, h = cocos.director.director.get_window_size()
        self.width = w
        self.height = h
        self.money = self._money = 99999   # fuer tests viel geld
        self.score = self._score = 0
        self.add(hud)
        self.material_cost = self.level_info.material_cost
        self.machine_menu = None

        # wie oft ein material los geschickt wird
        self.material_sendoff = self.level_info.material_sendoff

        self.machines = []
        self.conveyor_spots = []
        self.machine_options = None

        w, h = director.get_window_size()
        # tile map ist 64 x 64 pixels pro tile
        self.cell_size = self.level_info.cell_size
        self.coll_man = cm.CollisionManagerGrid(0, w, 0, h,
                                                self.cell_size, self.cell_size)

        start = level_info.start
        segments = level_info.segments

        for segment in segments:
            x = segment[0]
            y = segment[1]
            steps = [(i, 0) for i in range(0, x, self.sign(x))] if y == 0 else \
                    [(0, j) for j in range(0, y, self.sign(y))]
            direction = ('right' if x > 0 else 'left') if y == 0 else ('up' if y > 0 else 'down')

            for index, step in enumerate(steps):
                # index = 0: Ecke
                # index = 1: erste nach der Ecke
                # index = len(steps) - 1: letzte vor der Ecke
                # definiere "an der Ecke" als neuen Typ und denke dann logic
                # aus um den Ueberlapp zu verhindern
                self.create_conveyor_belt((start[0] + step[0] + 0.5) * self.cell_size,
                                          (start[1] + step[1] + 0.5) * self.cell_size, direction,
                                          corner=(index == 0 or index == len(steps) - 1))
            start = (start[0] + segment[0], start[1] + segment[1])

        self.elapsedTime = 0
#        self.timeStamp = 0

        self.schedule(self.game_loop)
Пример #14
0
 def __init__(self):
     super(MainLayer, self).__init__()
     self.player = Actor(320, 240, (0, 0, 255))
     self.add(self.player)
     for pos in [(100, 100), (540, 380), (540, 100), (100, 380)]:
         self.add(Actor(pos[0], pos[1], (255, 0, 0)))
     cell = self.player.width * 1.25
     self.collman = cm.CollisionManagerGrid(0, 640, 0, 480, cell, cell)
     self.speed = 100.0
     self.pressed = defaultdict(int)
     self.schedule(self.update)
Пример #15
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)
Пример #16
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()
        
        #使用兩個碰撞管理器,因為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 開始每幀循環
Пример #17
0
    def __make_collision_manager(self, cell_size):
        """Crea un manejador de colisiones.

        Args:
            cell_size: Tamaño de las celdas en las que se divide el escenario para capturar una colisión.
        """
        return cm.CollisionManagerGrid(xmin=self.left_limit,
                                       xmax=self.right_limit,
                                       ymin=self.bottom_limit,
                                       ymax=self.top_limit,
                                       cell_width=cell_size,
                                       cell_height=cell_size)
Пример #18
0
    def __init__(self):
        super().__init__()

        self.player = Player()
        self.enemy = Enemy()

        self.add(self.player, 1)
        self.add(self.enemy, 0)

        # self.coll_manager = cm.CollisionManagerBruteForce()
        self.coll_manager = cm.CollisionManagerGrid(0, 1280, 0, 720, 70, 70)
        self.coll_manager.add(self.player)
Пример #19
0
 def __init__(self, tile_map, scroller, scenario):
     super(MainLayer, self).__init__()
     self.tile_map = tile_map
     self.place_sprites()
     self.scroller = scroller
     self.scenario = scenario
     cell = self.player.width * 1.25
     self.collman = cm.CollisionManagerGrid(0, self.scenario.background.px_width, 0,
                                            self.scenario.background.px_height, cell, cell)
     self.keys = key.KeyStateHandler()
     director.window.push_handlers(self.keys)
     self.schedule(self.update)
Пример #20
0
    def __init__(self):
        win_width, win_height = config.WIN_WIDTH, config.WIN_HEIGHT
        super(GameLayer, self).__init__()

        self.bg1 = sprite.Sprite('imgs/bg.png')
        self.bg1.image_anchor = 0, 0
        self.bg1.position = 0, 0

        self.bg2 = sprite.Sprite('imgs/bg.png')
        self.bg2.image_anchor = 0, 0
        self.bg2.position = 0, win_height

        # 添加背景
        self.add(self.bg1)
        self.add(self.bg2)

        # 添加自己的飞机
        self.hero = Hero()
        self.add(self.hero, z=1000)

        # 敌机
        self.enemy_batch = batch.BatchNode()
        self.add(self.enemy_batch)
        self.resuable_small_enemy_set = set()
        self.active_small_enemy_set = set()
        self.all_small_enemy_set = set()

        # 积分榜
        self.score_board = ScoreBoard()
        self.add(self.score_board)

        # 碰撞检测
        self.enemy_collision = collision_model.CollisionManagerGrid(
            0, config.WIN_WIDTH, 0, config.WIN_HEIGHT, 110, 110)
        self.enemy_bullet_collisoin = collision_model.CollisionManagerGrid(
            0, config.WIN_WIDTH, 0, config.WIN_HEIGHT - 50, 10, 10)

        # 消息调度
        self.schedule(self.run)
        self.schedule_interval(self.update_enemy, 0.2)
Пример #21
0
 def __init__(self):
     super(GameLayer, self).__init__()
     w, h = cocos.director.director.get_window_size()
     self.width = w
     self.height = h
     self.lives = 3
     self.score = 0
     self.update_score()
     self.create_player()
     self.create_alien_group(100, 300)
     cell = 1.25 * 50
     self.collman = cm.CollisionManagerGrid(0, w, 0, h, cell, cell)
     self.schedule(self.update)
def initialize(width, height, size):
    for manager_name in col_managers:
        if globals().get(manager_name):
            globals()[manager_name].clear()
        print(globals()[manager_name])
        globals()[manager_name] = cm.CollisionManagerGrid(
            0,
            width * size * 1.5,
            0,
            height * size * 1.5,
            size * 1.5,
            size * 1.5
        )
        print(globals()[manager_name])
Пример #23
0
    def __init__(self):
        super(WorldItems, self).__init__()

        player = config.settings['player']
        world = config.settings['world']

        self.pics = config.pics
        self.to_remove = []

        # TODO: Only create if needed by game `mode`
        cell_size = player['radius'] * 0.25
        self.collman = cm.CollisionManagerGrid(0.0, world['width'], 0.0,
                                               world['height'], cell_size,
                                               cell_size)
Пример #24
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)
Пример #25
0
    def __init__(self):
        super(Game, self).__init__(0, 80, 125, 255)

        self.heart_pic = "assets/heart.png"
        for pos in [(100, 100), (540, 380), (540, 100), (100, 380)]:
            self.add(Actor(pos[0], pos[1], self.heart_pic))
        self.player = Actor(320, 240, "assets/horngirl.png")
        self.add(self.player)

        cell = self.player.width * 1.25
        self.collman = cm.CollisionManagerGrid(0, 640, 0, 480, cell, cell)

        self.speed = 100.0
        self.pressed = defaultdict(int)
        self.schedule(self.update)
Пример #26
0
 def __init__(self, hud):
     super(GameLayer, self).__init__()
     #初始化各項數值
     w, h = cocos.director.director.get_window_size()
     self.hud = hud
     self.width = w
     self.height = h
     self.lives = 3
     self.score = 0
     self.update_score()
     self.create_player()
     self.create_alien_group(100, 300)
     #碰撞管理器的一種,將整個空間分成指定寬度與高度的矩形方格,計算物件之間的關係時只考慮物件與已知實體重疊的相同方格,例如某兩物件分別有2格長度,當他們的第一格互相碰撞,就只會計算第一格,效能較好。
     cell = 1.25 * 50
     self.collman = cm.CollisionManagerGrid(0, w, 0, h, cell, cell)
     self.schedule(self.update)  #呼叫身為layer內建的schedule方法,排程每禎呼叫它
Пример #27
0
Файл: llama.py Проект: mre/llama
    def __init__(self):
        super(Game, self).__init__(0, 80, 125, 0)

        self.block_pic = "assets/img/heart.png"
        for pos in [(100, 100), (540, 380), (540, 100), (100, 380)]:
            self.add(Block(pos[0], pos[1], self.block_pic))
        self.lama = Lama(WIDTH / 2, 100)
        self.add(self.lama)

        cell = self.lama.width * 1.25
        self.collman = cm.CollisionManagerGrid(0, 640, 0, 480, cell, cell)

        self.pressed = defaultdict(int)
        self.schedule(self.update)

        self.kiss_sound = Sound("assets/sound/kiss.ogg")
        self.jump_sound = Sound("assets/sound/jump.ogg")
Пример #28
0
 def __init__(self):
     super(GameLayer, self).__init__()
     x, y = cocos.director.director.get_window_size()
     cell_size = 32
     self.coll_man = cm.CollisionManagerGrid(0, x, 0, y, cell_size, cell_size)
     self.planet_area = 400
     planet1 = self.add_planet(450, 280)
     planet2 = self.add_planet(180, 200)
     planet3 = self.add_planet(270, 440)
     planet4 = self.add_planet(650, 480)
     planet5 = self.add_planet(700, 150)
     self.add_pickup(250, 250, planet2)
     self.add_pickup(740, 480, planet4)
     self.add_pickup(700, 60, planet5)
     self.player = Player(300, 350, planet3)
     self.add(self.player)
     self.add(Enemy(600, 100, self.player))
     self.schedule(self.game_loop)
    def __init__(self):
        super(MainLayer, self).__init__()

        self.player = Actor(320, 240, (0, 0, 255))
        self.add(self.player)

        self.points = 0
        self.elapsed_game_time = 0

        for pos in [(100, 100), (540, 380), (540, 100), (100, 300)]:
            self.add(Actor(pos[0], pos[1], (255, 0, 0)))

        self.schedule(self.update)

        w, h = cd.director.get_window_size()

        cell = self.player.width * 1.25
        self.collman = cm.CollisionManagerGrid(0, w, 0, h, cell, cell)
    def __init__(self, hud):
        super(GameLayer, self).__init__()
        width, height = cocos.director.director.get_window_size()
        self.hud = hud
        self.width = width
        self.height = height
        self.lives = 3
        self.score = 0
        self.update_score()
        self.create_player()
        self.create_alien_group(100, 300)
        self.create_bunker_groups()

        # recommended cell size is the maximum object width *1.25
        cell = self.player.width * 1.25
        self.collman = cm.CollisionManagerGrid(0, width, 0, height, cell, cell)

        # Defined in cocos.cocosnode.CocosNode
        self.schedule(self.update)