Exemplo n.º 1
0
    def __init__(self, box, sprites, time, delay):
        super(ParallaxBackground, self).__init__()
        self.batch = cocos.batch.BatchNode()
        self.imgA = Sprite(sprites[0])      #Sprite A
        self.imgB = Sprite(sprites[1])      #Sprite B
        self.box = box          #(X, Y, W, H) Window Box (0 = X, 1 = Y, 2 = W, 3 = H)
        self.time = time        #in second

        w = box[2]
        h = box[3]

        self.imgA.position = (w/2, h/2)
        self.imgB.position = (w + (w /2), h/2)

        #point A to point B for image A
        A = MoveBy((-w, 0),time) + Place((w + w/2 ,h/2)) + MoveBy((-w, 0),time)
        B = MoveBy(( -w - w  , 0), time *2) + Place((w + (w /2), h/2))
        #IMAGE ANIMATION
        self.imgA.do(Repeat(A))
        self.imgB.do(Repeat(B))

        self.batch.add(self.imgA)
        self.batch.add(self.imgB)

        self.add(self.batch)
Exemplo n.º 2
0
    def _move_block(self, direction):
        if direction == 'LEFT':
            # Does the movement in conditionals
            if self.current_block.move('LEFT'):
                # Now do the rendering for each square
                for square in self.current_block.squares:
                    texture_cell = self.tetris_maplayer.cells[square.x][
                        square.y]
                    square.sprite.do(
                        Place((texture_cell.x + 9, texture_cell.y + 9)))
        elif direction == 'RIGHT':
            if self.current_block.move('RIGHT'):
                for square in self.current_block.squares:
                    texture_cell = self.tetris_maplayer.cells[square.x][
                        square.y]
                    square.sprite.do(
                        Place((texture_cell.x + 9, texture_cell.y + 9)))
        elif direction == 'DOWN':
            if self.current_block.move('DOWN'):
                for square in self.current_block.squares:
                    texture_cell = self.tetris_maplayer.cells[square.x][
                        square.y]
                    square.sprite.do(
                        Place((texture_cell.x + 9, texture_cell.y + 9)))
        elif direction == 'UP':
            # rotate clockwise only
            if self.current_block.rotate('CLOCKWISE'):
                for square in self.current_block.squares:
                    texture_cell = self.tetris_maplayer.cells[square.x][
                        square.y]
                    square.sprite.do(
                        Place((texture_cell.x + 9, texture_cell.y + 9)))
        elif direction == 'DROP':
            while self.current_block.can_move('DOWN'):
                self._move_block('DOWN')

            # Each clear can produce new lines so iteratively clear.
            while True:
                numlines = self._clear_lines()
                if numlines == 0:
                    break
                # Increment and display score
                self.score += numlines
                self._display_score()

            self.current_block = None
            # debug
            if self.other_start_names:
                self._new_block(self.other_start_names.pop())
            else:
                self._new_block()
Exemplo n.º 3
0
    def __init__(self):
        super( TestLayer, self ).__init__()

        x,y = director.get_window_size()

        self.sprite = Sprite( 'grossini.png', (x,y//2)  )
        self.add( self.sprite )
        self.sprite.do( Place( (0, y//2) ) + MoveBy( (x//2, 0) ) )
Exemplo n.º 4
0
 def getHit(self):
     if self.is_dead_scene_Playing == False and self.is_shield == False:
         self.total_lives -= 1
         self.revive_Pattern = Place(self.startLocation) + CallFunc(
             self.revive) + Blink(4, 2) + CallFunc(self.shieldoff)
         self.deadtemplate = Delay(0.5) + CallFunc(self.destroy)
         self.die()
         if self.total_lives <= 0:
             director.replace(FadeTransition(FinishScene(self.gScene)))
Exemplo n.º 5
0
    def __init__(self):
        super( TestLayer, self ).__init__()
        
        x,y = director.get_window_size()

        self.sprite = Sprite( 'grossini.png', (x/2, y/2) )
        self.add( self.sprite )
        move = MoveBy((100,0), 1)
        rot = Rotate(360, 1)
        seq = Place((x/4,y/2)) + rot+move+rot+move
        self.sprite.do( Repeat ( seq ) )
Exemplo n.º 6
0
    def __init__(self):
        super(PlaceTest, self).__init__()

        sprite = cocos.sprite.Sprite('icon.jpg')

        sprite.position = 320, 240
        sprite.scale = 0.5
        self.add(sprite)

        place = Place((50, 100))

        sprite.do(place)
Exemplo n.º 7
0
 def __init__(self, R):
     super(_PlayerAnimation, self).__init__()
     self.R = R
     self.SamplePlayer = Sprite(self.R.PLAYERANIME[0])
     self.SamplePlayer.scale = 0.5
     self.size = director.get_window_size()
     #SIMPLE ANIMATION
     _WH = self.SamplePlayer.get_AABB()
     _place = (-_WH.width, self.size[1] - 120)
     _move = MoveBy((self.size[0] + (_WH.width * 2), 0), 3)
     self.SamplePlayer.do(Repeat(Place(_place) + _move))
     self.add(self.SamplePlayer)
Exemplo n.º 8
0
    def do_animate(self):
        boat_location = 'L'
        current_state = '0000'
        states = solver.path[1:]

        farmer_action = Place(settings.pos_of_farmer['L']) + Delay(2)
        cabbage_action = Place(settings.pos_of_cabbage['L']) + Delay(2)
        sheep_action = Place(settings.pos_of_sheep['L']) + Delay(2)
        wolf_action = Place(settings.pos_of_wolf['L']) + Delay(2)
        boat_action = Place(settings.pos_of_boat['L']) + Delay(2)

        for state in states:
            move = self.who_move(''.join([
                str(int(x) ^ int(y)) for (x, y) in zip(current_state, state)
            ]))
            current_state = state

            (x, y) = settings.pos_of_boat[boat_location]

            if boat_location == 'R':
                boat_location = 'L'
                t = 350
            else:
                boat_location = 'R'
                t = -350

            if 'w' in move:  # wolf
                wolf_action += Place((x, y + 10)) + MoveBy((t, 0), 2) \
                    + Place(settings.pos_of_wolf[boat_location])
                sheep_action += Delay(2)
                cabbage_action += Delay(2)
            elif 's' in move:  # sheep
                sheep_action += Place((x, y + 10)) + MoveBy((t, 0), 2) \
                    + Place(settings.pos_of_sheep[boat_location])
                cabbage_action += Delay(2)
                wolf_action += Delay(2)
            elif 'c' in move:  # cabbage
                cabbage_action += Place((x, y + 10)) + MoveBy((t, 0), 2) \
                    + Place(settings.pos_of_cabbage[boat_location])
                sheep_action += Delay(2)
                wolf_action += Delay(2)
            else:
                sheep_action += Delay(2)
                wolf_action += Delay(2)
                cabbage_action += Delay(2)

            farmer_action += Place((x + 20, y + 50)) + MoveBy((t, 0), 2) \
                + Place(settings.pos_of_farmer[boat_location])
            boat_action += MoveBy((t, 0), 2)

        self.farmer.do(farmer_action)
        self.wolf.do(wolf_action)
        self.cabbage.do(cabbage_action)
        self.boat.do(boat_action)
        self.sheep.do(sheep_action)
Exemplo n.º 9
0
 def playerBack(self):
     if(self.player.velocity[0]>0):
         x = self.player.position[0]-10
         y= self.player.position[1]
         self.player.do( Place( (x, y) ))
Exemplo n.º 10
0
    def _collapse(self, rows_to_clear):
        """ Sticky method: identify all clumps above each cleared row and drop 
        them independently. More specifically, round robin drop them one square
        at a time. The round robin order starts with clumps above first complete
        line, then above second line and so on.
        """

        #-----------------------------------------------------------------------
        #                          NESTED FUNCTIONS
        #-----------------------------------------------------------------------
        def find_clumps(square):
            """ Iterative flood search to identify clump from given square """
            visited_squares = set()
            travel_stack = [square]
            while travel_stack:
                sq = travel_stack.pop()
                if sq in visited_squares:
                    continue

                visited_squares.add(sq)
                if sq.y - 1 >= 0 and self.squares_matrix[sq.x][sq.y -
                                                               1] is not None:
                    travel_stack.append(self.squares_matrix[sq.x][sq.y - 1])
                if sq.y + 1 < self.height and self.squares_matrix[sq.x][
                        sq.y + 1] is not None:
                    travel_stack.append(self.squares_matrix[sq.x][sq.y + 1])
                if sq.x - 1 >= 0 and self.squares_matrix[sq.x -
                                                         1][sq.y] is not None:
                    travel_stack.append(self.squares_matrix[sq.x - 1][sq.y])
                if sq.x + 1 < self.width and self.squares_matrix[sq.x + 1][
                        sq.y] is not None:
                    travel_stack.append(self.squares_matrix[sq.x + 1][sq.y])
            return list(visited_squares)

        def is_moveable(clump):
            for square in clump:
                # Not moveable if square is at bottom of grid or the square below
                # it is not part of clump
                if square.y == 0:
                    return False
                the_square_below = self.squares_matrix[square.x][square.y - 1]
                if the_square_below is not None and the_square_below not in clump:
                    return False
            return True

        def move(clump):
            # Erase
            for square in clump:
                self.squares_matrix[square.x][square.y] = None

            # Update square.y's
            # TODO refactor if I want to try to cascade method as well from this
            # code. I will need to update existing block locations.
            for square in clump:
                square.y = square.y - 1

            # add back to matrix in new locations
            for square in clump:
                self.squares_matrix[square.x][square.y] = square

        #-----------------------------------------------------------------------
        #                          _collapse() method begin
        #-----------------------------------------------------------------------
        # identify clumps and add to clump list: start with a square and
        # recursively find non-diagonally adjacent neighbor squares: recursive
        # implementation can do a flood scan until no more unvisited cells left
        # to go to.
        clumps = []  # list of lists of squares
        for y in rows_to_clear:
            for x in range(self.width):
                # start square for recursive clump indentification procedure
                if y + 1 > self.height:
                    break
                square = self.squares_matrix[x][y + 1]
                if square is None:
                    continue

                exists_in_clump = False
                for clump in clumps:
                    if square in clump:
                        exists_in_clump = True
                        break
                if exists_in_clump:
                    continue

                new_clump = find_clumps(square)
                clumps.append(new_clump)

        # Assertion that clumps must be disjoint ie not intersect
        unionset = set()
        for clump in clumps:
            for sq in clump:
                if sq in unionset:
                    print("size of unionset={}".format(len(unionset)))
                    raise ShouldntHappenError('clumps share squares')
                else:
                    unionset.add(sq)

        #
        # Keep a counter of consecutive unmoveable clumps visited. Once counter == total
        # number of clumps, end. Moveable is defined as ALL "bottom squares" of
        # a clump having currently empty space below them. if clump is moveable, increment counter
        #
        consecutive_unmoveable_clumps = 0
        i = 0  # for modulus round robin indexing
        while consecutive_unmoveable_clumps < len(clumps):
            clump = clumps[i % len(clumps)]
            if is_moveable(clump):
                move(clump)
                consecutive_unmoveable_clumps = 0
            else:
                consecutive_unmoveable_clumps += 1
            i += 1

        # render
        for clump in clumps:
            for square in clump:
                texture_cell = self.tetris_maplayer.cells[square.x][square.y]
                square.sprite.do(
                    Place((texture_cell.x + 9, texture_cell.y + 9)))