Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import pygame
  2. from pygame.locals import *
  3.  
  4. winWidth=600
  5. winHeight=480
  6. color_CYAN=(0,255,255)
  7. color_BLACK=(0,0,0)
  8. bkgs=[]
  9. bkg_texture_str="gameBkg.png"
  10. all_sprites_list = pygame.sprite.Group()
  11. clock = pygame.time.Clock()
  12.  
  13.  
  14. class Background(pygame.sprite.Sprite):
  15. x = 0
  16. y = 0
  17. maxY=0
  18. def __init__(self, texture,x=0,y=0, width = 1, height = 1):
  19. super(Background,self).__init__()
  20. #self.image = pygame.Surface([width,height])
  21. self.image=texture
  22. #self.image.set_colorkey(self.WHITE)
  23. self.x=x
  24. self.y=y
  25. self.width=width
  26. self.height=height
  27. pygame.draw.rect(self.image,(0,0,0), [self.x, self.y, width, height])
  28. self.rect = self.image.get_rect()
  29.  
  30. #self.id=id
  31. def scroll(self,speed):
  32. #print(speed)
  33. self.y+=(speed)
  34. if self.y>winHeight:
  35. self.y=-winHeight
  36.  
  37. def update(self):
  38. #super(Background).update()
  39. self.scroll(10)
  40.  
  41. def draw(self, surface):
  42. surface.blit(self.image, (self.x, self.y))
  43.  
  44.  
  45. class Ship(pygame.sprite.Sprite):
  46.  
  47. def __init__(self, texture,x=0,y=0, width = 1, height = 1):
  48. super(Ship,self).__init__()
  49.  
  50. if __name__=="__main__":
  51. pygame.init()
  52.  
  53. caption="Image Test"
  54. pygame.display.set_caption(caption)
  55.  
  56. ship= pygame.image.load("ship.png")
  57. pygame.display.set_icon(ship)
  58.  
  59. Game_Window=pygame.display.set_mode((winWidth,winHeight))
  60. Game_Window.fill(color_CYAN)
  61.  
  62. bush=pygame.transform.scale((pygame.image.load("bush.png")),(50,50))
  63. #alphaBush=(pygame.image.load("bush.png")).convert()
  64. bushes=[]
  65. i=0
  66. while i<10:
  67. bushes.append(bush.copy())
  68. i+=1
  69.  
  70. bkg_texture=pygame.transform.scale((pygame.image.load(bkg_texture_str)),(winWidth,winHeight))
  71. BkgSprite1 = Background(bkg_texture,0,winHeight*(-1))
  72. BkgSprite2 = Background(bkg_texture,0,0)
  73. BkgSprite3 = Background(bkg_texture,0,winHeight)
  74.  
  75. all_sprites_list.add(BkgSprite1)
  76. all_sprites_list.add(BkgSprite2)
  77. all_sprites_list.add(BkgSprite3)
  78. while True:
  79. for event in pygame.event.get():
  80. if event.type==QUIT:
  81. pygame.quit()
  82. exit()
  83. #bkg1.render(Game_Window)
  84. all_sprites_list.update()
  85. Game_Window.fill(color_CYAN)
  86. #all_sprites_list.draw(Game_Window)
  87. #Game_Window.blit(BkgSprite1,(BkgSprite1.x,BkgSprite1.y))
  88. BkgSprite1.draw(Game_Window)
  89. BkgSprite2.draw(Game_Window)
  90. BkgSprite3.draw(Game_Window)
  91. clock.tick(60)
  92. pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement