Advertisement
snowden_web

Untitled

Aug 13th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. from pygame import *
  2. from random import randint
  3.  
  4. CELL_WIDTH = 8
  5. CELL_HEIGHT = 8
  6. BLACK = (0,0,0)
  7.  
  8. class Tank:
  9. def __init__(self, direction, x, y, file_image):
  10. self.direction = direction
  11. self.health = 100
  12. self.x = x
  13. self.y = y
  14. self.speed = (0, 0)
  15. self.image = image.load(file_image).convert()
  16. self.rect = self.image.get_rect()
  17.  
  18. def draw(self):
  19. global screen
  20. screen.blit(self.image, (self.x, self.y))
  21.  
  22.  
  23. class Game:
  24. def __init__(self):
  25. global screen
  26. init()
  27. display.set_caption("Battle City")
  28. screen = display.set_mode((480, 416))
  29. self.clock = time.Clock()
  30.  
  31. # level
  32. self.player = Tank(0, 100, 100, "images/mytank.png")
  33.  
  34. def draw(self):
  35. global screen
  36.  
  37. screen.fill(BLACK)
  38. self.player.draw()
  39. # Bullets
  40. # Score/Health
  41.  
  42. display.flip()
  43.  
  44. def start(self):
  45. while True:
  46. time_passed = self.clock.tick(60)
  47.  
  48. for e in event.get():
  49. if e.type == QUIT:
  50. quit()
  51. elif e.type == KEYDOWN:
  52. if e.key == K_LEFT:
  53. self.player.speed = [-1, 0]
  54.  
  55. if e.key == K_RIGHT:
  56. self.player.speed = [1, 0]
  57.  
  58. if e.key == K_UP:
  59. self.player.speed = [0, -1]
  60.  
  61. if e.key == K_DOWN:
  62. self.player.speed = [0, 1]
  63.  
  64. elif e.type == KEYUP:
  65. self.player.speed = (0, 0)
  66.  
  67.  
  68. screen = None
  69. game = Game()
  70. game.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement