diff --git a/Images/images.py b/Images/images.py index 0200f88..0c93581 100644 --- a/Images/images.py +++ b/Images/images.py @@ -28,7 +28,4 @@ platform_1 = pygame.image.load(img_paths['platform_1']) def draw_background(): - - screen.blit(bg_img, (0, 0)) - # screen.blit(platform_0,(0,900)) - # screen.blit(platform_0,(835,900)) + screen.blit(bg_img, (0, 0)) \ No newline at end of file diff --git a/Main/collisions.py b/Main/collisions.py index ceb7557..46b906d 100644 --- a/Main/collisions.py +++ b/Main/collisions.py @@ -1,13 +1,14 @@ import pygame -# def platform_collision(screen,character_pos, character_img): def platform_collision(): platform_list = [] - lamp = pygame.Rect(1002, 748, 185, 1) - floor = pygame.Rect(0, 900, 1792, 1) + lamp = pygame.Rect(1002, 748, 185, 2) + floor = pygame.Rect(0, 900, 1792, 2) + roof = pygame.Rect(1350, 675, 200, 2) platform_list.append(lamp) platform_list.append(floor) + platform_list.append(roof) return platform_list diff --git a/Main/main.py b/Main/main.py index 7dc9fe1..e8b74ee 100644 --- a/Main/main.py +++ b/Main/main.py @@ -27,6 +27,7 @@ def run(self,test_case=False, max_iterations=50): update_hitbox = self.player.update_hitbox(self.player.img_pos[0],self.player.img_pos[1]) self.hitbox = pygame.draw.rect(self.screen, (255, 0, 0), update_hitbox, 2) + """Method that checks for vertical collision and adjusts the character position accordingly""" platform = platform_collision() self.player.check_vertical_collision(platform, self.hitbox) diff --git a/Main/player.py b/Main/player.py index 14a820a..c0e37e5 100644 --- a/Main/player.py +++ b/Main/player.py @@ -68,7 +68,7 @@ def __init__(self, x,y): """Creating a custom hitbox to better control the character collisions""" def update_hitbox(self,x,y): - self.hitbox = (x + 53, y + 70,55,90) + self.hitbox = (x + 53, y + 71,55,90) return self.hitbox def draw_character(self): @@ -82,6 +82,8 @@ def player_movement(self): """Y axis position""" self.img_pos[1] += (self.movement_y[1] - self.movement_y[0]) * self.y_velocity + + """Main player animation loop""" for event in pygame.event.get(): if event.type == pygame.QUIT: @@ -92,6 +94,7 @@ def player_movement(self): if self.touchdown == True: if event.type == pygame.KEYDOWN and not any([self.bow, self.attack]): + """X axis""" if event.key == pygame.K_a: self.movement_x[0] = True @@ -180,21 +183,46 @@ def player_movement(self): The main movement of the character's apparatus is changing according to this variable """ def check_vertical_collision(self, platforms, hitbox): + """ + self.touchdown is set to False at the beginning of the method. + If a collision is detected, it is set to True. If no collision occurs, it remains False. + Method is being updated in every frame of the loop to ensure proper collision functionality. + """ + self.touchdown = False for platform in platforms: - if hitbox.colliderect(platform) and self.jump == False: + pygame.draw.rect(self.screen, (255, 0, 0,), platform) - self.img_pos[1] = platform.top - (self.image.get_height()) + if hitbox.colliderect(platform): + if self.jump == False: + self.movement_y[1] = False + self.img_pos[1] = platform.top - self.image.get_height() + self.peak = False - self.touchdown = True - self.peak = False - self.action, self.action_divider = 'Idle', 0 - pygame.draw.rect(self.screen, (255, 0, 0,), platform) + + self.action, self.action_divider = 'Idle', 0 + pygame.draw.rect(self.screen, (100, 100, 100,), platform) if pygame.key.get_pressed()[pygame.K_a] or pygame.key.get_pressed()[pygame.K_d]: self.action, self.action_divider = 'Running', 1 if pygame.key.get_pressed()[pygame.K_a] and pygame.key.get_pressed()[pygame.K_d]: self.action, self.action_divider = 'Idle', 0 + self.touchdown = True + break + + if not self.touchdown: + """ + If jump animation is not detected, character will now perform a 'Landing' animation, + as he is falling from the edge of the collision platform towards the ground. + """ + if not self.jump: + self.movement_y[1] = True + self.peak = True + self.action, self.action_divider = 'Landing', 6 + + + + def update_animation(self): @@ -229,7 +257,7 @@ def update_animation(self): self.peak = True self.jump = False - """Once player reaches the 'self.peak', descending sequence is initialized""" + """Once player reaches the 'self.peak', descending sequence is initialized, increasing the falling speed""" if self.peak: self.y_velocity += .5 self.action, self.action_divider = 'Landing', 6 @@ -259,12 +287,12 @@ def update_animation(self): self.attack_animation = 'Attack_1' """Helper conditions that allow fluent movement if any of the direction keys is pressed while performing the attack""" - if pygame.key.get_pressed()[pygame.K_d] and not pygame.key.get_pressed()[pygame.K_a]: + if pygame.key.get_pressed()[pygame.K_d] and not pygame.key.get_pressed()[pygame.K_q]: self.movement_x[1] = True self.motion_right = True self.flip = False - if pygame.key.get_pressed()[pygame.K_a] and not pygame.key.get_pressed()[pygame.K_d]: + if pygame.key.get_pressed()[pygame.K_a] and not pygame.key.get_pressed()[pygame.K_q]: self.movement_x[0] = True self.motion_left = True self.flip = True