コード例 #1
0
    def setFutureTile(self):

        # princess move inside of the box, just east and west
        # set the new tile target, where she is going to
        if self.direction == 'e':

            future_tile_number = self.get_number() + Tile.H

            if future_tile_number in range(1, Tile.total_tiles + 1):
            
                future_tile = Tile.get_tile(future_tile_number)
                if future_tile.walkable: # if player can move for that direction(future tile), we set the target with that tile
                                         # and the method will take cara of how to move the player smothly - on object-classes.py
                    self.set_target(future_tile)
                    self.rotate('e')

                else:
                    self.direction = 'w'
                    #print('w')

        elif self.direction == 'w':

            future_tile_number = self.get_number() - Tile.H
            #print('Position ',self.get_number())

            if future_tile_number in range(1, Tile.total_tiles + 1):
                
                future_tile = Tile.get_tile(future_tile_number)
                if future_tile.walkable: 
                    self.set_target(future_tile)
                    self.rotate('w')

                    #print(future_tile_number)
                elif future_tile_number <= 32*15:
                    self.direction = 'e'
コード例 #2
0
    def spawn():
        for tile_num in Zombie.zombies:
            if tile_num not in Tile.invalidsSideWalls and tile_num not in Tile.invalidsCenterWalls:

                spawn_node = Tile.get_tile(
                    tile_num)  # get the tile that represents that tile
                Zombie(spawn_node.x, spawn_node.y)
コード例 #3
0
    def spawn(total_frames, FPS):

        if total_frames % (FPS * FruitsBonus.bonusTimeGeneration) == 0 and total_frames >0: 

            # have to put the music

            randTile = randint(1,601) # get a randow number tile, we have 600 tiles in the screen

            while(not Tile.isTileFree(randTile)):  # check if actually, that tile is free, or other words, it's an empty path
                randTile = randint(1,601) # get a randow number tile, we have 600 tiles in the screen

            tile = Tile.get_tile(randTile) # get the tile, randTile is just the tile number
            FruitsBonus(tile.x, tile.y)  # have to get the x and y from the tile number now
コード例 #4
0
    def spawn(total_frames, FPS):

        if total_frames % (FPS * LifeBonus.bonusTimeGeneration) == 0 and total_frames >0: 

            luckBonus = randint(1,4) # in other words, player has 33.33% of gain a heart life, each 30 seconds

            if luckBonus == 1:  # new heart will show up if the rand luck bonus is 1
                # have to put the music

                randTile = randint(1,601) # get a randow number tile, we have 600 tiles in the screen

                while(not Tile.isTileFree(randTile)):  # check if actually, that tile is free, or other words, it's an empty path
                    randTile = randint(1,601) # get a randow number tile, we have 600 tiles in the screen

                tile = Tile.get_tile(randTile) # get the tile, randTile is just the tile number
                LifeBonus(tile.x, tile.y)  # have to get the x and y from the tile number now
コード例 #5
0
	def get_surrounding_tiles(base_node):

		# makes an array that save all the combinations of tiles surround the zombie( base_node == zombieTile)
		# so if zombie moves to N, W, or etc, we have all these combinations numbers (position + 1 or - 1 or + 18, etc)
		# so then we can use them to our math to predict the better path
		array =(
			(base_node.number + N),
			(base_node.number + NE),
			(base_node.number + E),
			(base_node.number + SE),
			(base_node.number + S),
			(base_node.number + SW),
			(base_node.number + W),
			(base_node.number + NW),
			)

		tiles = []

		# *****
		# make this change to make the zombie to be able to walk just N,S,E,W - not NE,SW, etc
		# original node number
		onn = base_node.number 
		diagonals = [onn + NE, onn + NW, onn + SE, onn + SW]
        # *****


        # this for get all the new position(number of the tiles) from the array, that represet the tiles sorround from the Zombie
        # and get the tile, from Tile list in Tile class. Then we check if zombie can really go in the direction(tile)
        # if it does, we add that tile for the tile list
		for tile_number in array:

			surrounding_tile = Tile.get_tile(tile_number)

			# to avoid a zombie to get possible new path in tiles that doen's exist, for example if the zombie is in the
			# border, it cannot go up, for that we have to avoid with this if below
			if tile_number not in range(1, Tile.total_tiles + 1):
			    continue # if there'e not that tile, we jump the for for the next loop, so then, it doen's run the lines below
			    			# and consequently, it doen't calculate the path for that tile

			if surrounding_tile.walkable and surrounding_tile not in closed_list:
			    #tiles.append(surrounding_tile) # Diagonal movement - just add this and coment next line

				tiles = blocky(tiles, diagonals, surrounding_tile) # make sure to add the tile just if it is n,s,w,e

		return tiles
コード例 #6
0
    def update(self, screen, clock_elapsed):

        self.img = Survivor.survivor_img[self.current]
        rotateDirection = self.direction
        self.direction = ''
        self.rotate(rotateDirection)

        # check if next tile/target is a portal, if it's, we change the player position to one of the other portal tile
        if self.tx != None and self.ty != None: 
            self.movement(clock_elapsed)
            # have to change here, instead get where we are, get where we are going to
            targetTileNumber = ((self.x // self.width) + Tile.H) + ((self.y // self.height) * Tile.V)

            # check if the next tile number is actually inside of the portals list, in the tile class
            # it holds the tile numbers that has a portal
            if self.future_tile_number in Tile.portals:
                sortNewPortalTile = randint(0, 3)
                # make sure if actually move from the portal to another one
                while Tile.portals[sortNewPortalTile]==targetTileNumber:
                    sortNewPortalTile = randint(0, 3)

                # then change the position of player to the new portal x and y position
                futureSortPortal = Tile.get_tile(Tile.portals[sortNewPortalTile])
                
                """for i in range(10000):
                    for i in range(10000):
                        a=i
                """
                self.x = futureSortPortal.x
                self.y = futureSortPortal.y

                self.tx = None
                self.ty = None
                # after move to the new portal, we move the player, just to make the action of walking throught the portal
                """self.tx = self.x + 32  
                self.ty = self.y + 32 
                self.movement()
                """
            

        screen.blit(self.img, (self.x, self.y))
コード例 #7
0
    def spawn(total_frames, FPS):
        if total_frames % (FPS * Zombie.zombieTimeGeneration) == 0: # how much new zombies will show up per frame

            # select one of the musics for when the zombie is create
            # however, we create a new zombie around each 3 second, but we don't want to make a zombie sound every 3 second
            # so then we put * 6, to the zombie make sound, roundly choose for the list, in each 6 seconds(around)
            if total_frames % (FPS * 6) == 0 and total_frames >0:

                r = randint(0, 4)
                sounds = [pygame.mixer.Sound('../Sound_Effects/I_will_kill_you.wav'), 
                        pygame.mixer.Sound('../Sound_Effects/zombie_attack.wav'),
                        pygame.mixer.Sound('../Sound_Effects/zombie_scream1.wav'),
                        pygame.mixer.Sound('../Sound_Effects/zombie_scream2.wav'),
                        pygame.mixer.Sound('../Sound_Effects/zombie_come_here.wav')]
                sound = sounds[ r ]
                sound.play()
            


            r = randint(0, len(Tile.dangeounZombies) - 1) # get a random position from spawn_tiles, to put the zombie on screen
            tile_num = Tile.dangeounZombies[r] # get the number in that random position of the list
            spawn_node = Tile.get_tile(tile_num) # get the tile that represents that tile
            Zombie(spawn_node.x, spawn_node.y) # create a new zombie with that tile x and y position, and add to the static 
コード例 #8
0
ファイル: character.py プロジェクト: thiagosantos1/Maze_Game
  def get_tile_n(self, number):

    return Tile.get_tile(number)
コード例 #9
0
ファイル: character.py プロジェクト: thiagosantos1/Maze_Game
  def get_tile(self):

    return Tile.get_tile(self.get_number())
コード例 #10
0
def interaction(screen, survivor):

    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

        # you can change the gun when you press the key/letter 'e'
        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_e:

                survivor.current += 1
                survivor.current %= 3 # to make sure it goes to 0,1,2 - because when you get 3, mode 3 by 3 =0
                

    # Movemnt of the player is gonna be not just when you press a key, but when you press or you are holding
    # that's why it goes outside of the loop events
    keys = pygame.key.get_pressed()

    if keys[pygame.K_w]:# North

    	# first, before move we have to ckeck if that position is walkable
    	# so them, you first get the "new" position for that character
    	# in this case we get the number of the character, that represents
    	# his position on screen, minus how many we can move, Remember that is is to
    	# left or right, is gonna move always 1 block, if it's up or down, 18 block
        future_tile_number = survivor.get_number() - Tile.V

        # then we check if that number of tile is walkable, for the we move
        # the character
        # first if check if the new tile actually exist, if the tile number is in the Tile list, it can move
        if future_tile_number in range(1, Tile.total_tiles + 1):
            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable: # if player can move for that direction(future tile), we set the target with that tile
                                     # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile) # it make the movemnt
                survivor.rotate('n') # since we are moving north, we change the rotation of the picture to north
                survivor.future_tile_number = future_tile_number
             
    if keys[pygame.K_s]: # South
    
        future_tile_number = survivor.get_number() + Tile.V
        if future_tile_number in range(1, Tile.total_tiles + 1):

            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable: # if player can move for that direction(future tile), we set the target with that tile
                                     # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)
                survivor.rotate('s') 
                survivor.future_tile_number = future_tile_number 

    if keys[pygame.K_a]: # West
        future_tile_number = survivor.get_number() - Tile.H

        if future_tile_number in range(1, Tile.total_tiles + 1):
            
            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable: # if player can move for that direction(future tile), we set the target with that tile
                                     # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)
                survivor.rotate('w')
                survivor.future_tile_number = future_tile_number

    if keys[pygame.K_d]: # East
        future_tile_number = survivor.get_number() + Tile.H
       # print("Future left ",future_tile_number)

        if future_tile_number in range(1, Tile.total_tiles + 1):
            
            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable: # if player can move for that direction(future tile), we set the target with that tile
                                     # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)
                survivor.rotate('e')
                survivor.future_tile_number = future_tile_number

    # you use the arrow to rotate the character, to point for with direction you want to shot. so you can walk left
    # pressind 'A', but zombies are coming from right, so you can turn your face to right and shot in that direction
    # but keep walking for left

    if keys[pygame.K_LEFT]:
        survivor.rotate('w')
        
        Bullet(survivor.centerx, survivor.centery +5, -20, 0, 'w', survivor.get_bullet_type() )

    elif keys[pygame.K_RIGHT]:
        survivor.rotate('e')
        Bullet(survivor.centerx, survivor.centery +5, 20, 0, 'e', survivor.get_bullet_type() )

    elif keys[pygame.K_UP]:
        survivor.rotate('n')
        Bullet(survivor.centerx, survivor.centery +5, 0, -20, 'n', survivor.get_bullet_type() )

    elif keys[pygame.K_DOWN]:
        survivor.rotate('s')
        Bullet(survivor.centerx, survivor.centery +5, 0, 20, 's', survivor.get_bullet_type() )
コード例 #11
0
def interaction(screen, survivor):

    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Movemnt of the player is gonna be not just when you press a key, but when you press or you are holding
    # that's why it goes outside of the loop events
    keys = pygame.key.get_pressed()

    if keys[pygame.K_w]:  # North

        # first, before move we have to ckeck if that position is walkable
        # so them, you first get the "new" position for that character
        # in this case we get the number of the character, that represents
        # his position on screen, minus how many we can move, Remember that is is to
        # left or right, is gonna move always 1 block, if it's up or down, 18 block
        future_tile_number = survivor.get_number() - Tile.V

        # then we check if that number of tile is walkable, for the we move
        # the character
        # first if check if the new tile actually exist, if the tile number is in the Tile list, it can move
        if future_tile_number in range(1, Tile.total_tiles + 1):
            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable:  # if player can move for that direction(future tile), we set the target with that tile
                # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)  # it make the movemnt
                survivor.rotate(
                    'n'
                )  # since we are moving north, we change the rotation of the picture to north
                survivor.future_tile_number = future_tile_number

    if keys[pygame.K_s]:  # South

        future_tile_number = survivor.get_number() + Tile.V
        if future_tile_number in range(1, Tile.total_tiles + 1):

            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable:  # if player can move for that direction(future tile), we set the target with that tile
                # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)
                survivor.rotate('s')
                survivor.future_tile_number = future_tile_number

    if keys[pygame.K_a]:  # West
        future_tile_number = survivor.get_number() - Tile.H

        if future_tile_number in range(1, Tile.total_tiles + 1):

            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable:  # if player can move for that direction(future tile), we set the target with that tile
                # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)
                survivor.rotate('w')
                survivor.future_tile_number = future_tile_number

    if keys[pygame.K_d]:  # East
        future_tile_number = survivor.get_number() + Tile.H
        # print("Future left ",future_tile_number)

        if future_tile_number in range(1, Tile.total_tiles + 1):

            future_tile = Tile.get_tile(future_tile_number)
            if future_tile.walkable:  # if player can move for that direction(future tile), we set the target with that tile
                # and the method will take cara of how to move the player smothly - on object-classes.py
                survivor.set_target(future_tile)
                survivor.rotate('e')
                survivor.future_tile_number = future_tile_number

    # you use the arrow to rotate the character, to point for with direction you want to shot. so you can walk left
    # pressind 'A', but zombies are coming from right, so you can turn your face to right and shot in that direction
    # but keep walking for left

    if keys[pygame.K_LEFT]:
        survivor.rotate('w')

        Bullet(survivor.centerx, survivor.centery + 5, -20, 0, 'w')

    elif keys[pygame.K_RIGHT]:
        survivor.rotate('e')
        Bullet(survivor.centerx, survivor.centery + 5, 20, 0, 'e')

    elif keys[pygame.K_UP]:
        survivor.rotate('n')
        Bullet(survivor.centerx, survivor.centery + 5, 0, -20, 'n')

    elif keys[pygame.K_DOWN]:
        survivor.rotate('s')
        Bullet(survivor.centerx, survivor.centery + 5, 0, 20, 's')
コード例 #12
0
    def get_tile(self):

        return Tile.get_tile(self.get_number())