Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os.path
- import base64, lzma, random
- import pygame
- titleZIP = b'/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAQELiVBORw0KGgoAAAANSUhEUgAAAEIAAAALBAMAAAA5LUZ\
- AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAPUExURQAAANuqAbxYIaqFBP///5E0qmAAAACbSURBVBjTdY6B\
- DcQgCEU/7QISFzBOYGIHuP2nugfaNrnkiH7o50mRu8tcqoVUJXkR1aAYollDLkFcWFQoYvWT925WWVlCWKlrRlwPx+NY\
- oZ2flB4E3m2tLdy0CY9FAvMg3LegSeQz+yHmZG2dyMw0CfIc45xhST1nH42qkY5OYB6dcjVfAgci0H+EeL2I1hPv2gMf\
- gj+0vgk9xBdehhKMcdGEzAAAAABJRU5ErkJgggCQOMXDkH/P4wABpAKMAgAAqAkTn7HEZ/sCAAAAAARZWg=='
- if not os.path.exists("pygame.png"):
- print("Writing title image...", end = "")
- data = lzma.decompress(base64.b64decode(titleZIP))
- r = open("pygame.png", "bw")
- r.write(data)
- r.close()
- print("Done!")
- pygame.init()
- PDR = pygame.Rect(0, 0, 1280, 720)
- PDS = pygame.display.set_mode(PDR.size)
- FPS = 120
- GRAVITY = 0.1
- CUBE_DIMENSIONS = pygame.Rect(0, 0, 10, 10)
- TIMER = FPS / 2
- class drop:
- class cube:
- def __init__(s, color, x, floor):
- global CUBE_DIMENSIONS
- s.floor = floor * CUBE_DIMENSIONS.h
- s.speed = 0
- s.prevImpactSpeed = 0
- s.r = pygame.Rect((x * CUBE_DIMENSIONS.w, -CUBE_DIMENSIONS.h), CUBE_DIMENSIONS.size)
- s.color = color
- class column:
- def __init__(s):
- global CUBE_DIMENSIONS, TIMER
- s.cubes = []
- s.timer = random.randint(0, TIMER)
- def __init__(s, imageSurface):
- global PDS, PDR
- global CUBE_DIMENSIONS
- s.r = imageSurface.get_rect()
- cx = int(PDR.w / CUBE_DIMENSIONS.w) / 2 - s.r.centerx
- cy = int(PDR.h / CUBE_DIMENSIONS.h) / 2 - s.r.centery
- s.statics = []
- pa = pygame.PixelArray(imageSurface)
- s.columns = []
- for x in range(s.r.w):
- s.columns.append(s.column())
- for y in range(s.r.h):
- if pa[x][y] != 0: #16777215 (white)
- s.columns[x].cubes.append(s.cube(PDS.unmap_rgb(pa[x][y]), cx + x, cy + y))
- pa.close()
- def do(s):
- global PDS, GRAVITY, TIMER
- for static in s.statics:
- pygame.draw.rect(PDS, static.color, static.r)
- for c in s.columns:
- if not c.cubes: continue
- if c.timer:
- c.timer -= 1
- continue
- currentCube = c.cubes[-1]
- pygame.draw.rect(PDS, currentCube.color, currentCube.r)
- currentCube.r.y += currentCube.speed
- currentCube.speed += GRAVITY
- if currentCube.r.bottom >= currentCube.floor:
- currentCube.r.bottom = currentCube.floor
- if currentCube.prevImpactSpeed == 0:
- currentCube.prevImpactSpeed = currentCube.speed
- currentCube.prevImpactSpeed /= 3
- currentCube.speed = -currentCube.prevImpactSpeed
- if currentCube.prevImpactSpeed <= 0.5:
- s.statics.append(c.cubes.pop(-1))
- c.timer = random.randint(0, TIMER)
- c = drop(pygame.image.load("pygame.png").convert())
- while True:
- events = pygame.event.get()
- for e in events:
- if e.type == pygame.QUIT: sys.exit()
- PDS.fill((0, 0, 0))
- c.do()
- pygame.display.update()
- pygame.time.Clock().tick(FPS)
- pygame.quit()
- sys.exit()
Add Comment
Please, Sign In to add comment