def create_invader(ai_settings, screen, invaders, invader_num, row_num):
    invader = Invader(ai_settings, screen)
    invader_width = invader.rect.width
    invader.x = invader_width + 2 * invader_width * invader_num
    invader.rect.x = invader.x
    invader.rect.y = invader.rect.height + 2 * invader.rect.height * row_num
    invaders.add(invader)
Exemple #2
0
def game_loop():
    speed = [10, 0]
    invader = Invader(width - 48, height - 48,
                      "graphics/character/boss/boss1/InvaderA_00.png",
                      "graphics/character/boss/boss1/InvaderA_01.png",
                      "graphics/character/boss/boss1/InvaderA_01.png", speed)

    # Idem, on cree notre hero en tant qu'objet MyHero
    my_hero = MyHero(width / 2, height / 2,
                     "graphics/character/hero/heror.png",
                     "graphics/character/hero/herowr.png",
                     "graphics/character/hero/hero.png")

    # Boucle de jeu
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        # Deplacement
        invader.movement(width, height)
        my_hero.movement(width, height)

        # Test de collision
        # On utilise 'collidepoint', qui test si le centre de
        # My_Hero est convenu dans le rectangle de l'Invader
        if invader.get_rect().colliderect(my_hero.get_rect()):
            display_game_over(screen, background_image, background_position)
            sys.exit()
        else:
            # Affichage
            display(screen, background_image, background_position, invader,
                    my_hero)
Exemple #3
0
def game_loop():
	speed = [10, 0]
	invader = Invader(width-48, height-48, "graphics/character/boss/boss1/InvaderA_00.png", "graphics/character/boss/boss1/InvaderA_01.png", "graphics/character/boss/boss1/InvaderA_01.png", speed)

	# Idem, on cree notre hero en tant qu'objet MyHero
	my_hero = MyHero(width/2, height/2, "graphics/character/hero/heror.png", "graphics/character/hero/herowr.png", "graphics/character/hero/hero.png")

	# Boucle de jeu
	while 1:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				sys.exit()

		# Deplacement
		invader.movement(width, height)
		my_hero.movement(width, height)

		# Test de collision
		# On utilise 'collidepoint', qui test si le centre de
		# My_Hero est convenu dans le rectangle de l'Invader
		if invader.get_rect().colliderect(my_hero.get_rect()):
			display_game_over(screen, background_image, background_position)
			sys.exit()
		else:
			# Affichage
			display(screen, background_image, background_position, invader, my_hero)
Exemple #4
0
def create_invader(ai_settings, screen, invaders, invader_number, row_number):
    """Create an invader"""
    invader = Invader(ai_settings=ai_settings, screen=screen)
    invader_width = invader.rect.width
    invader.x = invader_width + 2 * invader_width * invader_number
    invader.rect.x = invader.x
    invader.rect.y = invader.rect.height + 2 * invader.rect.height * row_number
    invaders.add(invader)
Exemple #5
0
def generateInvaders():
    global invLeft, invRight, invBot, direction
    # y of gap between upper and lower pipe
    invaders = []

    # init direction to go to the left
    direction = -1

    row = 4
    column = 7

    initialX = SCREENWIDTH / 2 - ((column * (INVWIDTH + INVGAP)) / 2)
    x = initialX
    y = 30

    invRight = x + (column * (INVWIDTH + INVGAP))  # 5 invaders per row
    invLeft = x
    invBot = y + (row * (INVHEIGHT + INVGAP))  # 3 rows

    for i in range(0, row):
        for i in range(0, column):
            x = initialX + (INVWIDTH + INVGAP) * (i % column)
            invaders.append(Invader(x, y))
        y += INVHEIGHT + INVGAP

    return invaders
def create_fleet(ai_settings, screen, ship, invaders):
    """ Create a set of invaders """
    invader = Invader(ai_settings, screen)
    num_invader_x = get_num_invaders_x(ai_settings, invader.rect.width)
    num_rows = get_num_rows(ai_settings, ship.rect.height, invader.rect.height)
    # Creating the first rorw of invaders
    for row_num in range(num_rows):
        for invader_num in range(num_invader_x):
            create_invader(ai_settings, screen, invaders, invader_num, row_num)
Exemple #7
0
 def gen_enemies(self):
     if sum(self.current_wave) <= 0 and len(self.enemies) == 0:
         self.wave += 1
         self.current_wave = waves[self.wave]
         self.pause = True
         self.playPauseButton.change_img()
     else:
         wave_enemies = [Scorpion(), Wizard(), Invader(), Sword()]
         for x in range(len(self.current_wave)):
             if self.current_wave[x] != 0:
                 self.enemies.append(wave_enemies[x])
                 self.current_wave[x] -= 1
                 break
Exemple #8
0
def create_fleet(ai_settings, screen, ship, invaders):
    """Create a fleet of invaders"""
    invader = Invader(ai_settings, screen)
    number_invaders_x = get_number_invaders_x(ai_settings, invader.rect.width)
    number_rows = get_number_rows(ai_settings=ai_settings,
                                  ship_height=ship.rect.height,
                                  invader_height=invader.rect.height)

    for row_number in range(number_rows):
        for invader_number in range(number_invaders_x):
            create_invader(ai_settings=ai_settings,
                           screen=screen,
                           invaders=invaders,
                           invader_number=invader_number,
                           row_number=row_number)
Exemple #9
0
def load(filename, game):
	invaders = []
	asteroids = []
	data = open(filename).read()
	r = 0
	for line in data.split("\n"):
		c = 0
		for letter in line:
			if letter == '7':
				asteroids.append(Asteroid(game, c * 32 + 16, r * 32 + 16))

			elif letter != '0':
				invaders.append(Invader(game, c * 32 + 16, r * 32 + 16, letter))

			c += 1

		r += 1

	return (invaders, asteroids)
def create_fleet(settings, screen, invaders):
    """Create a full fleet of invaders."""
    # Create the fleet of aliens.

    for row in range(settings.fleet_rows):
        for column in range(settings.fleet_columns):
            # Create an alien and place it in the fleet.
            if row == 0:
                offset, gap, length = 6, 24, 24
            elif row == 1 or row == 2:
                offset, gap, length = 0, 15, 33
            else:
                offset, gap, length = 0, 12, 36

            new_invader = Invader(settings, screen, row, column)
            new_invader.rect.x = settings.invader_start_x + offset + (
                column * (gap + length))
            new_invader.rect.y = settings.invader_start_y + (
                row * (settings.invader_height * 2))
            invaders.add(new_invader)
 def __init__(self,x, y,vel):
     self.lista_invaders = [Invader(x,y,vel),Invader(x+60,y,vel),Invader(x+120,y,vel),Invader(x+180,y,vel)]
Exemple #12
0
 def __init__(self, **kwargs):
     super(Dock, self).__init__(**kwargs)
     self.invader = Invader()
     self.add_widget(self.invader)
     self.bind_invader()
Exemple #13
0
from invader import Invader

url = 'https://duckduckgo.com/?q=python&t=hb&ia=web'
invader = Invader(url, js=True)

res = invader.take_list('#links .result', {
    'title': ['.result__a', 'text'],
    'src': ['.result__a', 'href']
})

print(res)
score_pen.hideturtle()

# Create the player
player = Player()

# Choose a number of invaders
number_of_invaders = 5

# Create an empty list of ememies
invaders = []

# Add invaders to list
for i in range(number_of_invaders):
    x = random.randint(-200, 200)
    y = random.randint(100, 250)
    invaders.append(Invader(x,y))

# Create the invader 
#invader = Invader()

item_zone_x_y = 280

def isCollision(t1, t2):
    distance = math.sqrt(math.pow(t1.xcor() - t2.xcor(), 2) + math.pow(t1.ycor() - t2.ycor(), 2))
    if distance < 15:
        return True
    else:
        return False

def step_down(invader):
    y = invader.ycor()
Exemple #15
0
from invader import Invader

url = 'https://habrahabr.ru/post/321292/'
invader = Invader(url)
 
text = invader.take(['.content.html_format', 'text'])
img = invader.take(['.content.html_format img', 'src'])

print(text)
print(img)