Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64, lzma
- import pygame
- class player:
- def __init__(s):
- s.x, s.y, s.vx, s.vy = (0, 0, 0, 0)
- s.jumping = False
- def spawn(s, x, y):
- global TILE_SIZE
- s.x, s.y, s.vx, s.vy = (x * TILE_SIZE, y * TILE_SIZE, 0, 0)
- s.jumping = False
- def draw(s):
- global PDS, TILE_SIZE
- pygame.draw.rect(PDS, WHITE, (s.x, s.y - TILE_SIZE, TILE_SIZE, TILE_SIZE))
- def update(s, tm):
- global GRAVITY, TILE_SIZE, TILEMAP_RES
- onPlatform = False
- x1 = int(s.x // TILE_SIZE)
- y1 = int(s.y // TILE_SIZE)
- for y in range(y1, y1 + 2):
- for x in range(x1, x1 + 2):
- if x < 0 or x >= TILEMAP_RES[0] or y < 0 or y >= TILEMAP_RES[1]: continue
- if tm[y][x]:
- # tilePosX = x * TILE_SIZE
- tilePosY = y * TILE_SIZE
- if s.y <= tilePosY and s.y + s.vy >= tilePosY:
- onPlatform = True
- s.jumping = False
- s.y = tilePosY
- s.vy = 0
- if not onPlatform:
- s.jumping = True
- s.vy += GRAVITY
- s.y += s.vy
- k = pygame.key.get_pressed()
- if k[pygame.K_RIGHT]: s.vx = 4
- elif k[pygame.K_LEFT]: s.vx = -4
- else:
- s.vx = 0
- s.x += s.vx
- if k[pygame.K_SPACE] and not s.jumping:
- s.jumping = True
- s.vy = -11
- def createTilemap(lzma64):
- global TILEMAP_RES
- data = list(bytes(lzma.decompress(base64.b64decode(lzma64))))
- return [data[i : i + TILEMAP_RES[0]] for i in range(0, len(data), TILEMAP_RES[0])]
- BLACK = (0, 0, 0)
- WHITE = (255, 255, 255)
- RED = (128, 0, 0)
- GREEN = (0, 128, 0)
- BLUE = (0, 0, 128)
- GRAY = (128, 128, 128)
- DARK_GRAY = (64, 64, 64)
- PDV = (1280, 800)
- TILE_SIZE = 32
- TILEMAP_RES = (PDV[0] // TILE_SIZE, PDV[1] // TILE_SIZE)
- FPS = 120
- GRAVITY = 0.5
- tilemap_LZMA64 = b'/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4APnAC1dAACAQCtotkpfGorGP6lXd8DSBXD8vbJFntLka7G7CZaVPZGEfipxYUhTFwUpAAAAAAB3f+pq22lYrwABSegHAAAA3jtxbrHEZ/sCAAAAAARZWg=='
- tilemap = createTilemap(tilemap_LZMA64)
- p = player()
- p.spawn(1, 1)
- pygame.init()
- PDS = pygame.display.set_mode(PDV)
- while True:
- events = pygame.event.get()
- for e in events:
- if e.type == pygame.QUIT: sys.exit()
- PDS.fill(BLACK)
- for y in range(TILEMAP_RES[1]):
- for x in range(TILEMAP_RES[0]):
- tileID = tilemap[y][x]
- if not tileID: continue
- x1 = x * TILE_SIZE
- pygame.draw.rect(PDS, GRAY, (x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE))
- p.draw()
- pygame.display.update()
- pygame.time.Clock().tick(FPS)
- p.update(tilemap)
- pygame.quit()
Add Comment
Please, Sign In to add comment