Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random, time
- RUNNING = True
- WIDTH = 640
- HEIGHT = 480
- RED = 255, 0, 0
- GREEN = 0, 255, 0
- BLUE = 0, 0, 255
- BLACK = 0, 0, 0
- WHITE = 255, 255, 255
- CHARPOS = [320, 384]
- OBSTACLE = [175, 20, 50, 50] # This is now a list so we can edit it later
- FPS = 30
- CLOCK = pygame.time.Clock()
- def DRAWRECT(): # We don't create anything, we draw.
- pygame.draw.rect(SURFACE, BLUE, OBSTACLE)
- SURFACE = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption("SIDEY SIDE GAME")
- try:
- while RUNNING:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- RUNNING = False
- pygame.quit()
- exit()
- #SIDEWAYS CONTROL
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_RIGHT:
- CHARPOS[0] += 25
- elif event.key == pygame.K_LEFT:
- CHARPOS[0] -= 25
- #KEEPS FROM GOING OFF SCREEN
- if CHARPOS[0] > WIDTH:
- CHARPOS[0] = 640
- elif CHARPOS[0] <= 0:
- CHARPOS[0] = 0
- # No longer inside a "while True:", and indented properly :)
- OBSTACLE[1] += 1
- SURFACE.fill(BLACK)
- #pygame.draw.circle(SURFACE, RED, (int(WIDTH / 2), (int(HEIGHT * 0.8))), 50)
- pygame.draw.circle(SURFACE, RED, (CHARPOS), 50)
- DRAWRECT()
- CLOCK.tick(FPS)
- pygame.display.flip()
- except Exception as e:
- print(e)
- exit()
Advertisement
Add Comment
Please, Sign In to add comment