Advertisement
chrisCNG

SimpleBall1a

Jul 25th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. # Simple Ball: Lesson1a resource for "The Story of a Game" Tutorials
  2. # Begin Programming in Python and Progress to Android App
  3.  
  4. # Import Libraries
  5. import pygame
  6. pygame.init()
  7. import math
  8.  
  9. # Intitialize Global Variables
  10. Width = 800
  11. Height = 600
  12. ball_pos = [int(Width / 2), int(Height / 2)]
  13. Ball_Radius = 15
  14. white = (240,240,255)
  15. black = (40,40,40)
  16. red = (212,64,28)
  17. green = (40,181,73)
  18. blue = (21,29,176)
  19. ball_color = "red"
  20.  
  21. # define event handler for mouse click, draw
  22. def draw(mainDisplay):
  23.  
  24.  
  25.     mainDisplay.fill(green)
  26.     pygame.draw.circle(mainDisplay, ball_color, ball_pos, Ball_Radius)
  27.     mainDisplay.blit(text, textRect)
  28.  
  29. # create a font object.
  30. # 1st parameter is the font file
  31. # which is present in pygame.
  32. # 2nd parameter is size of the font
  33. font = pygame.font.Font('freesansbold.ttf', 32)
  34.  
  35. # create a text suface object,
  36. # on which text is drawn on it.
  37. text = font.render('The Story of a Game', True, green, blue)
  38.  
  39. # create a rectangular object for the
  40. # text surface object
  41. textRect = text.get_rect()
  42.  
  43. # set the center of the rectangular object.
  44. textRect.center = (Width // 2, Height // 4)
  45.  
  46. # Set up display area
  47. mainDisplay = pygame.display.set_mode((Width,Height))
  48.  
  49. mainDisplay.fill(green)
  50. pygame.display.set_caption('simpleBall')
  51.  
  52. mainDisplay.blit(text, textRect)
  53.  
  54. # pygame.draw.line(mainDisplay, red, (100,200), (300,450), 2)
  55. ball_color = red
  56. #pygame.draw.circle(mainDisplay, ball_color, ball_pos, Ball_Radius)
  57.  
  58. # Main Loop
  59. while True:
  60.     for event in pygame.event.get():
  61.         if event.type == pygame.QUIT:
  62.             pygame.quit()
  63.             quit()
  64.         elif event.type == pygame.MOUSEBUTTONDOWN:
  65.  
  66.             ball_pos = event.pos
  67.             mainDisplay.fill(green)
  68.  
  69.  
  70.  
  71.     draw(mainDisplay)
  72.  
  73.     pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement