Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Simple Ball: Lesson1a resource for "The Story of a Game" Tutorials
- # Begin Programming in Python and Progress to Android App
- # Import Libraries
- import pygame
- pygame.init()
- import math
- # Intitialize Global Variables
- Width = 800
- Height = 600
- ball_pos = [int(Width / 2), int(Height / 2)]
- Ball_Radius = 15
- white = (240,240,255)
- black = (40,40,40)
- red = (212,64,28)
- green = (40,181,73)
- blue = (21,29,176)
- ball_color = "red"
- # define event handler for mouse click, draw
- def draw(mainDisplay):
- mainDisplay.fill(green)
- pygame.draw.circle(mainDisplay, ball_color, ball_pos, Ball_Radius)
- mainDisplay.blit(text, textRect)
- # create a font object.
- # 1st parameter is the font file
- # which is present in pygame.
- # 2nd parameter is size of the font
- font = pygame.font.Font('freesansbold.ttf', 32)
- # create a text suface object,
- # on which text is drawn on it.
- text = font.render('The Story of a Game', True, green, blue)
- # create a rectangular object for the
- # text surface object
- textRect = text.get_rect()
- # set the center of the rectangular object.
- textRect.center = (Width // 2, Height // 4)
- # Set up display area
- mainDisplay = pygame.display.set_mode((Width,Height))
- mainDisplay.fill(green)
- pygame.display.set_caption('simpleBall')
- mainDisplay.blit(text, textRect)
- # pygame.draw.line(mainDisplay, red, (100,200), (300,450), 2)
- ball_color = red
- #pygame.draw.circle(mainDisplay, ball_color, ball_pos, Ball_Radius)
- # Main Loop
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- elif event.type == pygame.MOUSEBUTTONDOWN:
- ball_pos = event.pos
- mainDisplay.fill(green)
- draw(mainDisplay)
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement