anasazhar

pipe.py

Nov 9th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import pygame
  2. from pygame.sprite import Sprite
  3.  
  4.  
  5. class Head:
  6.  
  7.     def __init__(self):
  8.         self.width = 60
  9.         self.height = 25
  10.         self.head_rect = pygame.Rect(0, 0, self.width, self.height)
  11.  
  12.  
  13. class Pipe(Sprite):
  14.  
  15.     def __init__(self, Arena_Game):
  16.         super().__init__()
  17.  
  18.         self.screen = Arena_Game.screen
  19.         self.screen_rect = self.screen.get_rect()
  20.         self.settings = Arena_Game.game_settings
  21.  
  22.         self.pipe_image = pygame.Rect(0, 0, self.settings.pipe_width, self.settings.pipe_height)
  23.         self.pipe_image.topright = self.screen_rect.topright
  24.  
  25.         #self.pipe_image.x -= 50
  26.         self.x = self.pipe_image.x
  27.  
  28.         #set posisi awal pipe
  29.         self.resetposition()
  30.         ###HEAD
  31.         self.head = Head()
  32.         #self.head.head_rect.midbottom = self.pipe_image.midbottom
  33.  
  34.  
  35.     def resetposition(self):
  36.         self.x = self.screen_rect.right + 100
  37.         self.pipe_image.x = self.x
  38.  
  39.     def move(self):
  40.         self.x -= self.settings.pipe_speed
  41.         self.pipe_image.x = self.x
  42.         self.head.head_rect.centerx = self.pipe_image.centerx
  43.  
  44.  
  45.     def show_pipe(self):
  46.         pygame.draw.rect(self.screen, self.settings.pipe_color, self.pipe_image)
  47.         pygame.draw.rect(self.screen, self.settings.pipe_color, self.head.head_rect)
  48.  
Advertisement
Add Comment
Please, Sign In to add comment