Created
November 8, 2016 19:38
-
-
Save pathunstrom/547c3ce21410d85baaa6b68d5eb3334c to your computer and use it in GitHub Desktop.
Enemy movement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def enemy_update(enemy, containers): | |
player = containers["player"] | |
enemies = containers["enemies"] | |
attacks = containers["attacks"] | |
if not enemy['awake']: | |
shuffle = random.randint(1, 10) | |
move_object(shuffle, enemy["rect"], enemy["speed"]) | |
enemy["sight"].center = enemy["rect"].center | |
if enemy["sight"].colliderect(player["rect"]): | |
enemy["awake"] = True | |
for other in enemies: | |
if other["awake"] and enemy["rect"].colliderect(other["rect"]): | |
enemy["awake"] = True | |
elif enemy['awake']: | |
up = enemy["rect"].top > player["rect"].centery | |
down = enemy["rect"].bottom < player["rect"].centery | |
left = enemy["rect"].left > player["rect"].centerx | |
right = enemy["rect"].right < player["rect"].centerx | |
move_object(calculate_direction(up, down, left, right), | |
enemy['rect'], | |
enemy['speed']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if e['awake'] == False: | |
shuffle = random.randint(1, 10) | |
if shuffle == 1 and e['rect'].left > 0 and e['rect'].bottom < config.game["height"]: | |
e['rect'].move_ip(-1, 1) | |
elif shuffle == 2 and e['rect'].bottom < config.game["height"]: | |
e['rect'].move_ip(0, 1) | |
elif shuffle == 3 and e['rect'].right < config.game["width"] and e['rect'].bottom < config.game["height"]: | |
e['rect'].move_ip(1, 1) | |
elif shuffle == 4 and e['rect'].left > 0: | |
e['rect'].move_ip(-1, 0) | |
elif shuffle == 6 and e['rect'].right < config.game["width"]: | |
e['rect'].move_ip(1, 0) | |
elif shuffle == 7 and e['rect'].left > 0 and e['rect'].top > 0: | |
e['rect'].move_ip(-1, -1) | |
elif shuffle == 8 and e['rect'].top > 0: | |
e['rect'].move_ip(0, -1) | |
elif shuffle == 9 and e['rect'].right < config.game["width"] and e['rect'].top > 0: | |
e['rect'].move_ip(1, 1) | |
elif e['awake'] == True: | |
if player["rect"].centerx > e['rect'].centerx: | |
if player["rect"].centery > e['rect'].centery: | |
e['rect'].move_ip(e['speed'], e['speed']) | |
elif player["rect"].centery < e['rect'].centery: | |
e['rect'].move_ip(e['speed'], - e['speed']) | |
else: | |
e['rect'].move_ip(e['speed'], 0) | |
elif player["rect"].centerx < e['rect'].centerx: | |
if player["rect"].centery > e['rect'].centery: | |
e['rect'].move_ip(- e['speed'], e['speed']) | |
elif player["rect"].centery < e['rect'].centery: | |
e['rect'].move_ip(- e['speed'], - e['speed']) | |
else: | |
e['rect'].move_ip(- e['speed'], 0) | |
elif player["rect"].centery > e['rect'].centery: | |
e['rect'].move_ip(0, e['speed']) | |
elif player["rect"].centery < e['rect'].centery: | |
e['rect'].move_ip(0, - e['speed']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment