Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import time
- import random
- pygame.init()
- width = 800
- height = 600
- white = (255,255,255)
- black = (0,0,0)
- gameDisplay = pygame.display.set_mode((width, height))
- pygame.display.set_caption('Moving image')
- clock = pygame.time.Clock()
- image = pygame.image.load('67.png').convert()
- def moving_image(x, y):
- gameDisplay.blit(image,(x, y))
- def text_objects(text, font):
- textSurface = font.render(text, True, black)
- return textSurface, textSurface.get_rect()
- def message_display(text):
- largeText = pygame.font.Font('freesansbold.ttf', 115)
- TextSurf, TextRect = text_objects(text, largeText)
- TextRect.center = ((width/2),(height/2))
- gameDisplay.blit(TextSurf, TextRect)
- pygame.display.update()
- time.sleep(2)
- def things(thingx, thingy, thingw, thingh, color):
- pygame.draw.rect(gameDisplay, color, [thingx,thingy,thingw,thingh])
- def crash():
- message_display('Hello')
- pygame.quit()
- quit()
- def game_loop():
- x = (width * 0.35)
- y = (height * 0.8)
- x_change = 0
- image_width = 67
- x2 = x + image_width #### this line of code
- thing_startx = random.randrange(0, width)
- thing_starty = -600
- thing_speed = 7
- thing_width = 100
- thing_height = 100
- game_exit = False
- while not game_exit:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_LEFT:
- x_change = -5
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_RIGHT:
- x_change = 5
- if event.type == pygame.KEYUP:
- if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
- x_change = 0
- gameDisplay.fill(white)
- moving_image(x, y)
- x += x_change
- things(thing_startx, thing_starty, thing_width, thing_height, black)
- thing_starty += thing_speed
- if thing_starty > height:
- thing_starty = 0 - thing_height
- thing_startx = random.randrange(0, width)
- x2 = x + image_width #### this line of code
- if x2 > width or x < 0:
- crash()
- pygame.display.update()
- clock.tick(59)
- game_loop()
- pygame.quit()
- quit()
Add Comment
Please, Sign In to add comment