Skip to content
Snippets Groups Projects
Commit c5a49e19 authored by Nicholas Danh's avatar Nicholas Danh
Browse files

latest agent

parent fe201cf3
No related branches found
No related tags found
No related merge requests found
...@@ -191,7 +191,7 @@ class Level(Singleton): ...@@ -191,7 +191,7 @@ class Level(Singleton):
self.__base_monster = Monster( self.__base_monster = Monster(
config.HALF_XWIN - self.platform_size[0] // 2, # X POS config.HALF_XWIN - self.platform_size[0] // 2, # X POS
config.HALF_YWIN, # Y POS config.YWIN / 8, # Y POS
*self.monster_size) # SIZE *self.monster_size) # SIZE
...@@ -245,7 +245,7 @@ class Level(Singleton): ...@@ -245,7 +245,7 @@ class Level(Singleton):
randint(0, config.XWIN - self.monster_size[0]), randint(0, config.XWIN - self.monster_size[0]),
self.__monsters[-1].rect.y - offset, self.__monsters[-1].rect.y - offset,
*self.monster_size, *self.monster_size,
speed=randint(1, 3), speed=randint(1, 2),
direction=randint(0, 1) * 2 - 1) direction=randint(0, 1) * 2 - 1)
else: else:
new_monster = Monster( new_monster = Monster(
......
...@@ -154,16 +154,40 @@ class Player(Sprite, Singleton): ...@@ -154,16 +154,40 @@ class Player(Sprite, Singleton):
player_x = self.rect.centerx player_x = self.rect.centerx
player_y = self.rect.centery player_y = self.rect.centery
game_window_width = config.XWIN-self.rect.width
dist = [] dist = []
for platform in lvl.platforms: for platform in lvl.platforms:
weight = 20 if platform.rect.centery > player_y else 40 y_weight = 40 if platform.rect.top < player_y else 20
if not collide_rect(self, platform): if not collide_rect(self, platform):
dist.append((sqrt((min(abs(platform.rect.left - player_x), abs(platform.rect.right - player_x)))**2 + (weight * (platform.rect.bottom - player_y))**2), platform)) platform_x = platform.rect.centerx
if (abs(player_x - platform_x) <= game_window_width / 2):
dist.append((sqrt((platform_x - player_x)**2 + (y_weight * (platform.rect.top - player_y + random.random()))**2), platform))
else:
if player_x < platform_x:
dist.append((sqrt((game_window_width - platform_x + player_x)**2 + (y_weight * (platform.rect.top - player_y + random.random()))**2), platform))
else:
dist.append((sqrt((game_window_width + platform_x - player_x)**2 + (y_weight * (platform.rect.top - player_y + random.random()))**2), platform))
danger_zone_x = self.rect.width * 2
danger_zone_y = self.rect.height * 2
for monster in lvl.monsters: for monster in lvl.monsters:
weight = 20 y_weight = 20 if monster.rect.bottom < player_y else 10
if monster.rect.centery < player_y + self.rect.height: monster_x = monster.rect.centerx
dist.append((sqrt((min(abs(monster.rect.left - player_x), abs(monster.rect.right - player_x)))**2 + (weight * (min(abs(monster.rect.bottom - player_y), abs(monster.rect.top - player_y))))**2), monster)) monster_y = monster.rect.centery
if (abs(player_x - monster_x) <= game_window_width / 2):
if abs(player_x - monster_x) < danger_zone_x and abs(player_y - monster_y) < danger_zone_y:
dist.append((sqrt((monster_x - player_x)**2 + (y_weight * (monster_y - player_y + random.random()))**2), monster))
else:
if player_x < monster_x:
x_dist = game_window_width - monster_x + player_x
if abs(x_dist) < danger_zone_x and abs(player_y - monster_y) < danger_zone_y:
dist.append((sqrt((x_dist)**2 + (y_weight * (monster_y - player_y + random.random()))**2), monster))
else:
x_dist = game_window_width + monster_x - player_x
if abs(x_dist) < danger_zone_x and abs(player_y - monster_y) < danger_zone_y:
dist.append((sqrt((x_dist)**2 + (y_weight * (monster_y - player_y + random.random()))**2), monster))
...@@ -173,30 +197,29 @@ class Player(Sprite, Singleton): ...@@ -173,30 +197,29 @@ class Player(Sprite, Singleton):
speed_reduction = 25 speed_reduction = 25
if not isinstance(closest_object, Monster): if not isinstance(closest_object, Monster):
platform_x = closest_object.rect.centerx platform_x = closest_object.rect.centerx
game_window_width = config.XWIN-self.rect.width if ((player_x > platform_x and abs(player_x - platform_x) <= game_window_width / 2) or
if ((player_x > platform_x and abs(player_x - platform_x) < game_window_width / 2) or
(player_x < platform_x and abs(player_x - platform_x) > game_window_width / 2)): (player_x < platform_x and abs(player_x - platform_x) > game_window_width / 2)):
self._velocity.x=-self.__startspeed * closest[0] / speed_reduction self._velocity.x=-self.__startspeed * closest[0] / speed_reduction
self._input = -1 self._input = 0
elif ((player_x < platform_x and abs(player_x - platform_x) < game_window_width / 2) or elif ((player_x < platform_x and abs(player_x - platform_x) <= game_window_width / 2) or
(player_x > platform_x and abs(player_x - platform_x) > game_window_width / 2)): (player_x > platform_x and abs(player_x - platform_x) > game_window_width / 2)):
self._velocity.x=self.__startspeed * closest[0] / speed_reduction self._velocity.x=self.__startspeed * closest[0] / speed_reduction
self._input = 1 self._input = 0
else: else:
self._velocity.x = 0
self._input = 0 self._input = 0
else: else:
monster_x = closest_object.rect.centerx monster_x = closest_object.rect.centerx
monster_y = closest_object.rect.centery monster_y = closest_object.rect.centery
danger_zone_x = self.rect.width / 2
danger_zone_y = self.rect.height / 2
if ((player_x >= monster_x and abs(closest_object.rect.right - player_x) < danger_zone_x) and abs(monster_y - player_y) < danger_zone_y): if ((player_x >= monster_x and abs(closest_object.rect.right - player_x) <= danger_zone_x) and abs(monster_y - player_y) <= danger_zone_y):
self._velocity.x=self.__startspeed * closest[0] * speed_reduction self._velocity.x=self.__startspeed * closest[0] if player_y > monster_y else -self.__startspeed * closest[0]
self._input = 1 self._input = 0
elif ((player_x <= monster_x and abs(closest_object.rect.left - player_x) < danger_zone_x) and abs(monster_y - player_y) < danger_zone_y): elif ((player_x <= monster_x and abs(closest_object.rect.left - player_x) <= danger_zone_x) and abs(monster_y - player_y) <= danger_zone_y):
self._velocity.x=-self.__startspeed * closest[0] * speed_reduction self._velocity.x=-self.__startspeed * closest[0] if player_y > monster_y else self.__startspeed * closest[0]
self._input = -1 self._input = 0
else: else:
self._velocity.x = 0
self._input = 0 self._input = 0
......
...@@ -23,11 +23,11 @@ LIGHT_BLUE = (173,216,230) ...@@ -23,11 +23,11 @@ LIGHT_BLUE = (173,216,230)
RED = (255,0,0) RED = (255,0,0)
# Player # Player
PLAYER_SIZE = (25,35) PLAYER_SIZE = (15,15)
PLAYER_COLOR = PINK_BEAN PLAYER_COLOR = PINK_BEAN
PLAYER_MAX_SPEED = 20 PLAYER_MAX_SPEED = 20
PLAYER_JUMPFORCE = 20 PLAYER_JUMPFORCE = 20
PLAYER_BONUS_JUMPFORCE = 70 PLAYER_BONUS_JUMPFORCE = 40
GRAVITY = .98 GRAVITY = .98
# Platforms # Platforms
...@@ -35,16 +35,16 @@ PLATFORM_COLOR = FOREST_GREEN ...@@ -35,16 +35,16 @@ PLATFORM_COLOR = FOREST_GREEN
PLATFORM_COLOR_LIGHT = LIGHT_BLUE PLATFORM_COLOR_LIGHT = LIGHT_BLUE
MOB_COLOR = BLACK MOB_COLOR = BLACK
MOVING_MOB_COLOR = RED MOVING_MOB_COLOR = RED
PLATFORM_SIZE = (100,10) PLATFORM_SIZE = (110,10)
MONSTER_SIZE = (20,20) MONSTER_SIZE = (15,20)
PLATFORM_DISTANCE_GAP = (50,210) PLATFORM_DISTANCE_GAP = (50,180)
MONSTER_DISTANCE_GAP = (350,500) MONSTER_DISTANCE_GAP = (350,500)
MAX_PLATFORM_NUMBER = 10 MAX_PLATFORM_NUMBER = 10
MAX_MONSTER_NUMBER = 2 MAX_MONSTER_NUMBER = 2
BONUS_SPAWN_CHANCE = 10 BONUS_SPAWN_CHANCE = 10
BREAKABLE_PLATFORM_CHANCE = 12 BREAKABLE_PLATFORM_CHANCE = 12
STATIONARY_MONSTER_CHANCE = 10 STATIONARY_MONSTER_CHANCE = 5
MOVING_MONSTER_CHANCE = 12 MOVING_MONSTER_CHANCE = 3
# Fonts # Fonts
LARGE_FONT = SysFont("",128) LARGE_FONT = SysFont("",128)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment