Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys, random
- from pygame.locals import *
- def main():
- pygame.init()
- windowSurface = pygame.display.set_mode((750, 750), 0, 32)
- pygame.display.set_caption('colourBox')
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- RED = (255, 0, 0)
- GREEN = (0, 255, 0)
- BLUE = (0, 0, 255)
- YELLOW = (255, 255, 0)
- COLOUR = WHITE
- FILL = BLACK
- paintStreak = False
- offsetX = 0
- offsetY = 0
- SPEED = {-1 : -8, 0 : 0, 1: 8}
- x = 325
- y = 325
- basicFont = pygame.font.SysFont(None, 48)
- textcolour = 0
- upperBound = 0
- lowerBound = 700
- leftBound = 0
- rightBound = 700
- windowSurface.fill(BLACK)
- pygame.draw.rect(windowSurface, WHITE, (x, y, 50, 50))
- pygame.display.update()
- def moveBox(x, y):
- while True:
- if paintStreak == False:
- pygame.draw.rect(windowSurface, FILL, (wipeX, wipeY, 50, 50))
- pygame.draw.rect(windowSurface, COLOUR, (x, y, 50, 50))
- pygame.display.update()
- return
- while True:
- if offsetX > 1:
- offsetX = 1
- if offsetX < -1:
- offsetX = -1
- if offsetY > 1:
- offsetY = 1
- if offsetY < -1:
- offsetY = -1
- wipeX = x
- wipeY = y
- x = x + SPEED[offsetX]
- y = y + SPEED[offsetY]
- if x > rightBound:
- x = rightBound
- if y > lowerBound:
- y = lowerBound
- if x < leftBound:
- x = leftBound
- if y < upperBound:
- y = upperBound
- moveBox(x, y)
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- if event.type == KEYDOWN:
- if event.key == K_UP:
- offsetY -= 1
- if event.key == K_DOWN:
- offsetY += 1
- if event.key == K_LEFT:
- offsetX -= 1
- if event.key == K_RIGHT:
- offsetX += 1
- if event.key == K_RETURN:
- FILL = COLOUR
- windowSurface.fill(FILL)
- if event.key == K_g:
- COLOUR = GREEN
- if event.key == K_b:
- COLOUR = BLUE
- if event.key == K_r:
- COLOUR = RED
- if event.key == K_y:
- COLOUR = YELLOW
- if event.key == K_n:
- COLOUR = BLACK
- if event.key == K_w:
- COLOUR = WHITE
- if event.key == K_EQUALS:
- paintStreak = True
- if event.key == K_MINUS:
- paintStreak = False
- if event.type == KEYUP:
- if event.key == K_UP:
- offsetY += 1
- if event.key == K_DOWN:
- offsetY -= 1
- if event.key == K_LEFT:
- offsetX += 1
- if event.key == K_RIGHT:
- offsetX -= 1
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement