title: how do I make my player collide with the bottom of my platform
body: <p>So I'm trying to know how to make it so that when my player collides with the bottom of my platform it dose not just teleport to the top of my platform and it will make the player act like the platform bottom is there. I have tried using the same thing I did for the sides of my platform but changing it up to collide with the bottom of my platform but that did not work for me.</p>
  <p>What is happeneing: <a href="https://gyazo.com/0854093887dfa2ada9e22da18d9ef751" rel="nofollow noreferrer">https://gyazo.com/0854093887dfa2ada9e22da18d9ef751</a></p>
  <p>My Platform class</p>
  <pre><code>class Platform:
      def __init__(self,x,y,width,height,color):
          self.x = x
          self.y = y
          self.width = width
          self.height = height
          self.color = color
          self.stone = pygame.image.load(&quot;stone.png&quot;)
          self.stone = pygame.transform.scale(self.stone,(self.stone.get_width()+28,self.stone.get_height()+28))
          self.rect = pygame.Rect(x,y,width,height)
      def get_rect(self):
          self.rect.topleft = (self.x,self.y)
          return self.rect
      def draw(self):
          self.rect.topleft = (self.x,self.y)
          pygame.draw.rect(window,self.color,self.rect)
  
          platform_rect = self.stone.get_rect(center = self.get_rect().center)
          platform_rect.centerx += 2
          platform_rect.centery += 0
          window.blit(self.stone,platform_rect)
  </code></pre>
  <p>My full code</p>
  <pre><code>import pygame
  pygame.init()
  # The screen width and height
  window = pygame.display.set_mode((700,500))
  # The name of the screen
  pygame.display.set_caption(&quot;Game&quot;)
  
  # Player class
  class Player():
      def __init__(self,x,y,width,height,color):
          self.x = x
          self.y = y
          self.width = width
          self.height = height
          self.color = color
          # Animation for player
          self.idle = [pygame.image.load(&quot;HRI1.png&quot;),
                      pygame.image.load(&quot;HRI2.png&quot;),
                      pygame.image.load(&quot;HRI3.png&quot;),
                      pygame.image.load(&quot;HRI4.png&quot;),]
                      
          self.idlel = [pygame.image.load(&quot;HLI1.png&quot;),
                        pygame.image.load(&quot;HLI2.png&quot;),
                        pygame.image.load(&quot;HLI3.png&quot;),
                        pygame.image.load(&quot;HLI4.png&quot;)]
          
          self.walk = [pygame.image.load(&quot;HRW1.png&quot;),
                       pygame.image.load(&quot;HRW2.png&quot;),
                       pygame.image.load(&quot;HRW3.png&quot;),
                       pygame.image.load(&quot;HRW4.png&quot;),
                       pygame.image.load(&quot;HRW5.png&quot;),
                       pygame.image.load(&quot;HRW6.png&quot;)]
          
          self.lwalk = [pygame.image.load(&quot;HLW1.png&quot;),
                        pygame.image.load(&quot;HLW2.png&quot;),
                        pygame.image.load(&quot;HLW3.png&quot;),
                        pygame.image.load(&quot;HLW4.png&quot;),
                        pygame.image.load(&quot;HLW5.png&quot;),
                        pygame.image.load(&quot;HLW6.png&quot;)]
          
          self.jump = [pygame.image.load(&quot;HRJ1.png&quot;),
                       pygame.image.load(&quot;HRJ2.png&quot;),
                       pygame.image.load(&quot;HRJ3.png&quot;)]
  
          self.ljump = [pygame.image.load(&quot;HLJ1.png&quot;),
                       pygame.image.load(&quot;HLJ2.png&quot;),
                       pygame.image.load(&quot;HLJ3.png&quot;)]
  
          self.direction = &quot;idle&quot;
          self.direction = &quot;idlel&quot;
          self.direction = &quot;walk&quot;
          self.direction = &quot;lwalk&quot;
          self.direction = &quot;jump&quot;
          self.direction = &quot;ljump&quot;
          
          self.speed =5
          self.isJump = False
          self.JumpCount = 10
          self.fall = 0
          self.rect = pygame.Rect(x,y,width,height)
          self.next_frame_time = 0
          self.fps = 10
          self.clock = pygame.time.Clock
          self.anim_index = 0
          self.idle = [pygame.transform.scale(image,(image.get_width()*3,image.get_width()*3))for image in self.idle]
          self.idlel = [pygame.transform.scale(image,(image.get_width()*3,image.get_width()*3))for image in self.idlel]
          self.walk = [pygame.transform.scale(image,(image.get_width()*3,image.get_width()*3))for image in self.walk]
          self.lwalk = [pygame.transform.scale(image,(image.get_width()*3,image.get_width()*3))for image in self.lwalk]
          self.jump = [pygame.transform.scale(image,(image.get_width()*3,image.get_width()*3))for image in self.jump]
          self.ljump = [pygame.transform.scale(image,(image.get_width()*3,image.get_width()*3))for image in self.ljump]
  
      def get_rect(self):
          self.rect.topleft = (self.x,self.y)
          return self.rect
      def draw(self):
          self.rect.topleft = (self.x,self.y)
          pygame.draw.rect(window,self.color,self.rect)
  
          if self.direction == &quot;idle&quot;:
              image_list = self.idle
          if self.direction == &quot;idlel&quot;:
              image_list = self.idlel
          if self.direction == &quot;walk&quot;:
              image_list = self.walk
          if self.direction == &quot;lwalk&quot;:
              image_list = self.lwalk
          if self.direction == &quot;jump&quot;:
              image_list = self.jump
          if self.direction == &quot;ljump&quot;:
              image_list = self.ljump
          # Is it time to show next frame?
          time_now = pygame.time.get_ticks()
          if (time_now &gt; self.next_frame_time):
              # time till the nect frame
              inter_time_delay = 1000 // self.fps
              self.next_frame_time = time_now + inter_time_delay
              # Show the next frame
              self.anim_index += 1
              if self.anim_index &gt;= len(image_list):
                  self.anim_index = 0
  
          if self.anim_index &gt;= len(image_list):
              self.anim_index = 0
          player_image = image_list[self.anim_index]
  
          player_rect = player_image.get_rect(center = self.get_rect().center)
          player_rect.centerx += 3
          player_rect.centery -= 3
          window.blit(player_image, player_rect)
      
              
          
          
  
  # Platform class
  class Platform:
      def __init__(self,x,y,width,height,color):
          self.x = x
          self.y = y
          self.width = width
          self.height = height
          self.color = color
          self.stone = pygame.image.load(&quot;stone.png&quot;)
          self.stone = pygame.transform.scale(self.stone,(self.stone.get_width()+28,self.stone.get_height()+28))
          self.rect = pygame.Rect(x,y,width,height)
      def get_rect(self):
          self.rect.topleft = (self.x,self.y)
          return self.rect
      def draw(self):
          self.rect.topleft = (self.x,self.y)
          pygame.draw.rect(window,self.color,self.rect)
  
          platform_rect = self.stone.get_rect(center = self.get_rect().center)
          platform_rect.centerx += 2
          platform_rect.centery += 0
          window.blit(self.stone,platform_rect)
          
  
  
  
          
  
  # The color of **** hitbox
  white = (255,255,255)
  
  # Player size,cords, and hitbox color
  playerman = Player(255,255,40,40,white)
  
  # Platform size,cords,and hitbox color
  platform1 = Platform(255,255,40,40,white)
  
  
  
  # Platform list
  platforms = [platform1]
  
  
  #redrawing window so player and other stuff dose not make the screen a mess
  def redrawwindow():
      window.fill((0,0,0))
  
      playerman.draw()
  
      # making it so I do not have to draw every platform 1 by 1
      for Platform in  platforms:
          Platform.draw()
  
      
  # Fps of the game
  fps = 30
  clock = pygame.time.Clock()
  
  # Runing the game/ the main loop
  run = True
  while run:
      # Making game run with fps
      clock.tick(fps)
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              run = False
  
  
  
  
          
  
      
  
  
  
     
          
      
  
      # telling what to do when we say the word 'key'
      keys = pygame.key.get_pressed()
  
      # Shortining playerman.x and playerman.y
      px,py = playerman.x,playerman.y
  
  
  
      # player 'A' movment
      if keys[pygame.K_a] and px &gt; playerman.speed:
          px -= playerman.speed
          playerman.direction = &quot;lwalk&quot;
          
      # player 'D' movment
      elif keys[pygame.K_d] and playerman.x &lt; 700 - playerman.width - playerman.speed:
          px += playerman.speed
          playerman.direction = &quot;walk&quot;
  
   
      # Playing idle animation
      else:
          if playerman.direction == &quot;walk&quot;:
              playerman.direction = &quot;idle&quot;
          else:
              if playerman.direction == &quot;lwalk&quot;:
                  playerman.direction = &quot;idlel&quot;
  
      
                      
  
      
      
      
      # player 'W' movment
      if keys[pygame.K_w] and py &gt; playerman.speed:
          py -= playerman.speed
  
      # player 'S' movment
      if keys[pygame.K_s] and py &lt; 500 - playerman.height - playerman.speed:
          py += playerman.speed
  
  
      platform_rect_list = [p.rect for p in platforms]
      player_rect = playerman.get_rect()
      player_rect.topleft = (px, py)
  
  
          
      playerman.y = py
      if player_rect.collidelist(platform_rect_list) &lt; 0:
          playerman.x = px
  
  
      if not playerman.isJump:
          playerman.y += playerman.fall
          playerman.fall += 0.5
          playerman.isJump = False
          
  
      # For player to get on top of platform
          collide = False
          for Platform in platforms:
              if playerman.get_rect().colliderect(Platform.rect):
                  collide = True
                  playerman.isJump = False
                  playerman.y = Platform.rect.top - playerman.height
                  if playerman.rect.right &gt; Platform.rect.left and playerman.rect.left &lt; Platform.rect.left - playerman.width:
                      playerman.x = Platform.rect.left - playerman.width
                  if playerman.rect.left &lt; Platform.rect.right and playerman.rect.right &gt; Platform.rect.right + playerman.width:
                      playerman.x = Platform.rect.right
   
  
              # Making it so player wont fall out of the map 
              if playerman.rect.bottom &gt;= 500:
                  collide = True
                  playerman.isJump = False
                  playerman.JumpCount = 10
                  playerman.y = 500 - playerman.height
  
          # Player jumping
          if collide:
              if keys[pygame.K_SPACE]:
                  playerman.isJump = True
              playerman.fall = 0
  
          # What will happen when player jumps
      else:
          if playerman.JumpCount &gt;= 0:    
              playerman.y -= (playerman.JumpCount*abs(playerman.JumpCount))*0.3
              playerman.JumpCount -= 1
          else:
              playerman.isJump = False
              playerman.JumpCount = 10
  
  
      # redrawing the window
      redrawwindow()
      # updating the game
      pygame.display.update()
  # quiting the game
  pygame.quit()
  
  
  
  </code></pre>