Guest User

Untitled

a guest
Feb 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. import pygame
  2. import sys
  3. from pygame.locals import *
  4.  
  5. pygame.init()
  6.  
  7. screen = pygame.display.set_mode((700,700)) #Window Size
  8. screen.fill((100,100,0))
  9. pygame.display.update()
  10. background = pygame.image.load("space.gif") # Background
  11.  
  12. class Character(pygame.sprite.Sprite):
  13. def __init__(self,position):
  14. pygame.sprite.Sprite.__init__(self)
  15. self.image = pygame.image.load('Tanks.png')
  16. self.rect = self.image.get_rect()
  17. self.right = False
  18. self.left = False
  19. self.mass = 60 #kg
  20. self.velocity = 0
  21. self.rect.topleft = position
  22. self.lives = 3
  23.  
  24. def update(self):
  25. if self.right:
  26. self.velocity += .02
  27. elif self.velocity > 0:
  28. self.velocity -= .01
  29. if self.left:
  30. self.velocity -= .02
  31. elif self.velocity < 0:
  32. self.velocity += .01
  33. if self.velocity > 2:
  34. self.velocity = 2
  35. if self.velocity < -2:
  36. self.velocity = -2
  37. self.rect.right += self.velocity
  38. if self.rect.right >= 700:
  39. self.rect.right = 700
  40. if self.rect.left <= 0:
  41. self.rect.left = 0
  42.  
  43.  
  44. class Platform(pygame.sprite.Sprite):
  45. def __init__(self,position):
  46. pygame.sprite.Sprite.__init__(self)
  47. self.image = pygame.image.load('platform.png')
  48. self.rect = self.image.get_rect()
  49. self.topleft = position
  50.  
  51. def player_input():
  52. for event in pygame.event.get():
  53. if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
  54. pygame.quit()
  55. if event.type == KEYDOWN and event.key == K_a:
  56. character.left=True
  57. if event.type == KEYDOWN and event.key == K_d:
  58. character.right=True
  59. if event.type == KEYUP and event.key == K_a:
  60. character.left=False
  61. if event.type == KEYUP and event.key == K_d:
  62. character.right=False
  63. if event.type == MOUSEBUTTONDOWN and event.button == 1: #left
  64. print 'check'
  65. if event.type == MOUSEBUTTONDOWN and event.button == 3: #right
  66. print 'rcheck'
  67.  
  68. screen.blit(background, (0,0))
  69. pygame.display.update()
  70. character = Character((450,450))
  71. platform = Platform((500,500))
  72. screen.blit(platform.image, platform.rect.topleft)
  73. pygame.display.update()
  74.  
  75. while True:
  76. screen.blit(background, (0,0))
  77. player_input()
  78. character.update()
  79. screen.blit(character.image, character.rect.topleft)
  80. pygame.display.update()
Add Comment
Please, Sign In to add comment