Advertisement
cookertron

Ladybird - Python Pygame

Apr 18th, 2020
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.57 KB | None | 0 0
  1. import pygame
  2. import lzma, base64
  3. import time, math, random
  4.  
  5.  
  6. # sprites in binary format then encoded using base64
  7. LADYBIRD_SPRITES = b'/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AVrAbtdAAJgHwVq0WshYoaIhrJyex2rbCiorbp1hmiVEMM\
  8. h2lfK0a+0RSr8hVfb8UoPnlrWmZoOIhZtMIBkm6tGF2WtskMU35LTD2URe5iSj8MGMHtpeeCH5nnHEaGaoPaPnEX9vIZm60OMaMW\
  9. aValnLDtYwEEF7IvWYkEPvvplJHYvTO7EPw7Eu5bpZ8oH48IceM4+WU0lNQq5tw2V536wabip3AT+CY0z5LZq488wBHttrO4AbPn\
  10. cDMRBeIfzXPg/TiJAwAVodAlcSttVgaL0IMlMiWHRQ2HeEwRV4hOyM7iNgr8G6XHS5/VJzEXwoL9IuBnv6avNzEL8ijb45a5hKNJ\
  11. HFKPbU2rZGGpPkvW+x1X5x/nDTDOh+4hoIYvydUZCL+Bl2W4jhWE4Xcu0MjQ3JbZ1SbM2Xpq0/UNxCMJHHprI6nkjMgmfaaARA9v\
  12. jE9J/1Bj1+4iCaieMIcOr4IPzY/WX5usP3vaVeYUQqzYrkWqm+Z1E/52y8R92LSTa1tw/8dUPrrNyAR1YVUXrHEKCVrVz0IDCRW1\
  13. GQKLc2xePO5u9NQoARPbAguqvhmCAdIrAQo2JSVA3Y/Fh6D0DPiAAAADA4oH4qKJ93AAB1wPsCgAAzPnwGrHEZ/sCAAAAAARZWg=\
  14. ='
  15.  
  16. # this class recreates all of the sprites from the data above
  17. class spritesSheet:
  18.     def b(s, a):
  19.         return a[1 :], int.from_bytes(a[: 1], "big")
  20.  
  21.     def w(s, a):
  22.         return a[2 :], int.from_bytes(a[: 2], "big")
  23.  
  24.     def d(s, a):
  25.         return a[4 :], int.from_bytes(a[: 4], "big")
  26.  
  27.     def rgb(s, a):
  28.         return a[3 :], int.from_bytes(a[: 3], "big")
  29.  
  30.     def name(s, a):
  31.         sl = int.from_bytes(a[: 1], "big")
  32.         return a[1 + sl :], a[1 : sl + 1].decode("utf-8")
  33.  
  34.     def cr(s, index):
  35.         return [index % s.c * s.cw, int(index / s.c) * s.ch, s.cw, s.ch]
  36.  
  37.     def __init__(s, lz64_data):
  38.         # decompress data
  39.         data = lzma.decompress(base64.b64decode(lz64_data))
  40.  
  41.         # get image dimensions
  42.         data, s.c = s.b(data) # cols
  43.         data, s.r = s.b(data) # rows
  44.         data, s.cw = s.b(data) # cell width
  45.         data, s.ch = s.b(data) # cell height
  46.         s.iw = s.c * s.cw # image width
  47.         s.ih = s.r * s.ch # image height
  48.  
  49.         # get palette length
  50.         data, s.pl = s.b(data) # palette length
  51.  
  52.         # get palette
  53.         s.palette = []
  54.         for index in range(s.pl):
  55.             data, irgb = s.rgb(data)
  56.             s.palette.append(irgb)
  57.  
  58.         # create pygame surface to place spritesheet
  59.         s.surface = pygame.Surface((s.iw, s.ih))
  60.         pa = pygame.PixelArray(s.surface)
  61.  
  62.         # get image data length in bytes
  63.         idl = s.iw * s.ih
  64.  
  65.         # extract image data
  66.         for index in range(idl):
  67.             data, pi = s.b(data) # palette index
  68.             pa[index % s.iw][int(index / s.iw)] = s.palette[pi]
  69.         pa.close()
  70.         del pa
  71.  
  72.         # make the sprites using the assembly data
  73.         s.sprites = {}
  74.         cell = pygame.Surface((s.cw, s.ch)) # to temp store cell
  75.  
  76.         while data:
  77.             data, sn = s.name(data) # sprite name
  78.             data, sw = s.w(data) # sprite width, if width is zero then it's a copy instruction
  79.  
  80.             if sw == 0: # copy instruction?
  81.                 data, snc = s.name(data) #sprite name to copy
  82.                 data, at = s.b(data) # assembly attribute
  83.  
  84.                 # apply attribute 0 = none, 1 = h flip, 2 = v flip, 3 = rot 90, 4 = rot 180, 5 = rot 270
  85.                 if at == 0:
  86.                     s.sprites[sn] = s.sprites[snc].copy()
  87.                 elif at == 1:
  88.                     s.sprites[sn] = pygame.transform.flip(s.sprites[snc], True, False)
  89.                 elif at == 2:
  90.                     s.sprites[sn] = pygame.transform.flip(s.sprites[snc], False, True)
  91.                 elif at == 3:
  92.                     s.sprites[sn] = pygame.transform.rotate(s.sprites[snc], -90)
  93.                 elif at == 4:
  94.                     s.sprites[sn] = pygame.transform.rotate(s.sprites[snc], -180)                      
  95.                 elif at == 5:
  96.                     s.sprites[sn] = pygame.transform.rotate(s.sprites[snc], -270)  
  97.                 continue
  98.  
  99.             data, sh = s.w(data) # sprite height
  100.  
  101.             sc = math.ceil(sw / s.cw) # sprite columns
  102.             sr = math.ceil(sh / s.ch) # sprite rows
  103.             scc = sc * sr # sprite cell count
  104.             scc_index = 0
  105.  
  106.             # create a surface for the sprite
  107.             s.sprites[sn] = pygame.Surface((sw, sh))
  108.  
  109.             # cycle through assembly instructions
  110.             while scc_index < scc:
  111.                 data, ci = s.w(data) # cell index
  112.                 data, at = s.b(data) # assembly attribute
  113.  
  114.                 if at < 6: # single cell placement?
  115.                     # calc x, y coords of cell placement
  116.                     x = scc_index % sc * s.cw
  117.                     y = int(scc_index / sc) * s.ch
  118.  
  119.                     # get cell image
  120.                     cell.blit(s.surface, (0, 0), s.cr(ci))
  121.  
  122.                     # apply attribute 0 = none, 1 = h flip, 2 = v flip, 3 = rot 90, 4 = rot 180, 5 = rot 270
  123.                     if at == 0:
  124.                         s.sprites[sn].blit(cell, (x, y))
  125.                     elif at == 1:
  126.                         s.sprites[sn].blit(pygame.transform.flip(cell, True, False), (x, y))
  127.                     elif at == 2:
  128.                         s.sprites[sn].blit(pygame.transform.flip(cell, False, True), (x, y))
  129.                     elif at == 3:
  130.                         s.sprites[sn].blit(pygame.transform.rotate(cell, -90), (x, y))
  131.                     elif at == 4:
  132.                         s.sprites[sn].blit(pygame.transform.rotate(cell, -180), (x, y))                        
  133.                     elif at == 5:
  134.                         s.sprites[sn].blit(pygame.transform.rotate(cell, -270), (x, y))                        
  135.                     scc_index += 1
  136.                 else:
  137.                     data, r = s.w(data) # get range count
  138.  
  139.                     for index in range(r):
  140.                         # get x, y coords of cell placement
  141.                         x = (scc_index + index) % sc * s.cw
  142.                         y = int((scc_index + index) / sc) * s.ch
  143.                        
  144.                         # get cell image
  145.                         cell.blit(s.surface, (0, 0), s.cr(ci))
  146.                            
  147.                         # apply attribute 6 = none, 7 = h flip, 8 = v flip, 9 = rot 90, 10 = rot 180, 11 = rot 270
  148.                         if at == 6 or at == 12 or at == 18:
  149.                             s.sprites[sn].blit(cell, (x, y))
  150.                         elif at == 7 or at == 13 or at == 19:
  151.                             s.sprites[sn].blit(pygame.transform.flip(cell, True, False), (x, y))
  152.                         elif at == 8 or at == 14 or at == 20:
  153.                             s.sprites[sn].blit(pygame.transform.flip(cell, False, True), (x, y))
  154.                         elif at == 9 or at == 15 or at == 21:
  155.                             s.sprites[sn].blit(pygame.transform.rotate(cell, -90), (x, y))
  156.                         elif at == 10 or at == 16 or at == 22:
  157.                             s.sprites[sn].blit(pygame.transform.rotate(cell, -180), (x, y))                        
  158.                         elif at == 11 or at == 17 or at == 23:
  159.                             s.sprites[sn].blit(pygame.transform.rotate(cell, -270), (x, y))
  160.                        
  161.                         # increment/decrement the sprite sheet cell index
  162.                         if at > 11 and at < 18:
  163.                             ci += 1
  164.                         elif at > 17:
  165.                             ci -= 1
  166.  
  167.                     scc_index += r
  168.  
  169.     # this function sets a color to transparent for all of the sprites
  170.     def colorKey(s, color):
  171.         for key, sprite in s.sprites.items():
  172.             sprite.set_colorkey(color)
  173.  
  174. # this function creates a rectangle object x1, y1, w, h, x2, y2 to keep track of objects
  175. class rect:
  176.     def __init__(s, x, y, w, h):
  177.         s.x1, s.y1, s.w, s.h = x, y, w, h
  178.         s.x2, s.y2 = s.x1 + s.w, s.y1 + s.h
  179.  
  180.     def setX1(s, x):
  181.         s.x1 = x
  182.         s.x2 = x + s.w
  183.    
  184.     def setY1(s, y):
  185.         s.y1 = y
  186.         s.y2 = y + s.h
  187.  
  188.     def setXY(s, x, y):
  189.         s.x1, s.y1 = x, y
  190.         s.x2, s.y2 = x + s.w, y + s.h
  191.    
  192.     def setX2(s, x):
  193.         s.x2 = x
  194.         s.x1 = x - s.w
  195.    
  196.     def setY2(s, y):
  197.         s.y2 = y
  198.         s.y1 = y - s.h
  199.  
  200.     def setXY2(s, x, y):
  201.         s.x2, s.y2 = x, y
  202.         s.x1, s.y1 = x - s.w, y - s.h
  203.  
  204.     def offX1(s, x):
  205.         s.x1 += x
  206.         s.x2 = s.x1 + s.w
  207.    
  208.     def offY1(s, y):
  209.         s.y1 += y
  210.         s.y2 = s.y1 + s.h
  211.  
  212.     def pos(s, integer = False, offset = [0, 0]):
  213.         if integer: return [int(s.x1 + offset[0]), int(s.y1 + offset[1])]
  214.         return [s.x1 + offset[0], s.y1 + offset[1]]
  215.  
  216.     def rect(s, integer = False):
  217.         if integer: return [int(s.x1), int(s.y1), int(s.w), int(s.h)]
  218.         return [s.x1, s.y1, s.w, s.h]
  219.  
  220.     def box(s, integer = False):
  221.         if integer: return [int(s.x1), int(s.y1), int(s.x2), int(s.y2)]
  222.         return [s.x1, s.y1, s.x2, s.y2]
  223.  
  224.     def size(s, integer = False):
  225.         if integer: return [int(s.w), int(s.h)]
  226.         return [s.w, s.h]
  227.  
  228.     def scale(s, value):
  229.         s.x1 *= value
  230.         s.y1 *= value
  231.         s.w *= value
  232.         s.h *= value
  233.         s.x2 = s.x1 + s.w
  234.         s.y2 = s.y1 + s.h
  235.         return s
  236.    
  237.     def __str__(s):
  238.         return "x1={}, y1={}, w={}, h={} (x2={}, y2={})".format(s.x1, s.y1, s.w, s.h, s.x2, s.y2)
  239.  
  240. # how fast the ladybird accelerates on the x-axis
  241. LADYBIRD_ACCELERATION = 0.1
  242.  
  243. # ladybird object
  244. class ladybird:
  245.     def __init__(s, x, y): # set the starting coordinates x = 0-30, y = 0-23
  246.         global ZX_TILE_SIZE
  247.  
  248.         # create the rectange to track position and size of ladybird object
  249.         s.rect = rect(x, y, 2, 1).scale(ZX_TILE_SIZE)
  250.  
  251.         s.vx = 0 # x velocity
  252.         s.vy = 0 # y velocity
  253.  
  254.         s.platform = None # keep track of a platform if the ladybird lands on it
  255.  
  256.         s.anim = 'lbjr' # set the name of the sprite to be use in the first instance lbjr = ladybird jump right
  257.         s.animCounter = 0 # cycle through walking frames 0-1
  258.  
  259.     def draw(s):
  260.         global ZX_SURFACE, SPRITES
  261.  
  262.         # blit the ladbird sprite to the display surface. remember s.anim is a string containing the name of the sprite
  263.         ZX_SURFACE.blit(SPRITES.sprites[s.anim], s.rect.pos(True))
  264.  
  265.     def do(s):
  266.         global SPRITES
  267.         global GRAVITY, LADYBIRD_ACCELERATION
  268.         global PLATFORMS
  269.         global ZX_TILE_SIZE
  270.  
  271.         # check if any keys are pressed
  272.         k = pygame.key.get_pressed()
  273.  
  274.         moveLegs = True # if left or right is pressed then animate the legs
  275.         if k[pygame.K_RIGHT]:
  276.             s.vx += LADYBIRD_ACCELERATION # positive acceleration moves the ladybird right
  277.         elif k[pygame.K_LEFT]:
  278.             s.vx -= LADYBIRD_ACCELERATION # negative acceleration moves the ladybird left
  279.         else:
  280.             if round(s.vx, 1) == 0: # check if the ladybird has virtually stopped, if yes then don't animate the ladybirds legs
  281.                 moveLegs = False
  282.             s.vx /= 1 + LADYBIRD_ACCELERATION # if left or right keys not pressed then deaccelerate the ladybird
  283.  
  284.         # the ladybird can only jump if on a platform. Here platform will either be None or a platform object
  285.         if k[pygame.K_SPACE] and s.platform:
  286.             s.platform = None # remove reference to the platform object
  287.             s.vy = -4 # set the starting velocity of the jump. Negative velocity moves the lady up
  288.  
  289.         # animate the legs if applicable
  290.         if moveLegs:
  291.             s.animCounter = 1 - s.animCounter # 0 or 1
  292.  
  293.         s.rect.offX1(s.vx) # apply acceleration to the ladybirds x-axis: -vx = LEFT, +vx = RIGHT
  294.  
  295.         # if the ladybird is on a platform. s.platform = None or a platform object
  296.         if s.platform:
  297.             # set the animation string for walking (remember: only if on a platform)
  298.             if s.vx > 0: # if positive x acceleration is applied (ladybird move right) then anim string is lbwr (ladybird walks right)
  299.                 s.anim = 'lbwr' + str(s.animCounter + 1) # lbwr1 or lbwr2
  300.             elif s.vx < 0:
  301.                 s.anim = 'lbwl' + str(s.animCounter + 1) # lbwl1 or lbwr1
  302.            
  303.             # check if the ladybird has walked off the platform
  304.             if s.rect.x1 > s.platform.rect.x2 - ZX_TILE_SIZE or s.rect.x2 < s.platform.rect.x1 + ZX_TILE_SIZE:
  305.                 s.platform = None # if true then remove reference to platform object
  306.         else:
  307.             # if not on a platform change the ladybird anim to jumping lbjr for positive acceleration, lbjl for negative.
  308.             # jump sprite is used to jumping up and falling
  309.             if s.vx > 0:
  310.                 s.anim = 'lbjr'
  311.             elif s.vx < 0:
  312.                 s.anim = 'lbjl'
  313.  
  314.             # apply acceleration to the y-axis. Negative acceleration moves the ladybird up, positive moves it down.
  315.             s.rect.offY1(s.vy)
  316.             s.vy += GRAVITY # apply gravity to y-axis velocity. Note there's no terminal velocity
  317.  
  318.             # check if the ladybird has collided with a platform
  319.             for p in PLATFORMS.platforms:
  320.                 if s.rect.y2 <= p.rect.y1 and s.rect.y2 + s.vy >= p.rect.y1 and not (s.rect.x1 >= p.rect.x2 - ZX_TILE_SIZE or s.rect.x2 <= p.rect.x1 + ZX_TILE_SIZE):
  321.                     # if true then y-axis acceleration become zero, the vertical position of the ladybird matches that of the platform
  322.                     # and s.platform references the platform object the ladybird has landed on
  323.                     s.vy = 0
  324.                     s.rect.setY2(p.rect.y1)
  325.                     s.platform = p
  326.        
  327. # this data helps to assemble the platforms
  328. PLATFORM_ENDS_LEFT = ['pfel1', 'pfel2'] # there are two types of 'end' for the platforms
  329. PLATFORM_ENDS_RIGHT = ['pfer1', 'pfer2'] # same as above but reflected
  330. PLATFORM_MIDDLES = ['pfm1', 'pfm2', 'pfm3'] # there are three types of 'middle' for the platforms
  331. PLATFORM_PARTS = [PLATFORM_ENDS_LEFT, PLATFORM_MIDDLES, PLATFORM_ENDS_RIGHT] # put the parts into a single list
  332. PLATFORM_FG_DECORATIONS = ['fgd1', 'fgd2', 'fgg1', 'fgg2', 'fgg3'] # there are five types of foreground decoration eg grass, mushrooms etc
  333.  
  334. # this class creates a container for the platform objects
  335. class platforms:
  336.     # this class creates a platform object
  337.     class platform:
  338.         def __init__(s, x, y, w): # specify where the platform should be placed and it's width
  339.             global PLATFORM_PARTS, PLATFORM_FG_DECORATIONS
  340.             global SPRITES
  341.             global ZX_TILE_SIZE
  342.  
  343.             # create a rect object to track position and size
  344.             s.rect = rect(x, y, w, 1).scale(ZX_TILE_SIZE)
  345.  
  346.             # create two surfaces, the foreground which contains the grass and mushrooms etc
  347.             s.foreground = pygame.Surface(s.rect.size(True), pygame.SRCALPHA)
  348.             # and the background which contains the platform itself
  349.             # it's called the background because it's always drawn behind the ladybird
  350.             s.background = s.foreground.copy()
  351.  
  352.             # build the platform
  353.             # foreground 1st
  354.             for index in range(w):
  355.                 s.foreground.blit(SPRITES.sprites[PLATFORM_FG_DECORATIONS[random.randint(0, len(PLATFORM_FG_DECORATIONS) - 1)]], (index * ZX_TILE_SIZE, 0))
  356.             # then the background, or rather the platform itself
  357.             x = 0
  358.             s.background.blit(SPRITES.sprites[PLATFORM_PARTS[0][random.randint(0, len(PLATFORM_PARTS[0]) - 1)]], (x, 0))
  359.             for index in range(w - 2):
  360.                 x += ZX_TILE_SIZE
  361.                 s.background.blit(SPRITES.sprites[PLATFORM_PARTS[1][random.randint(0, len(PLATFORM_PARTS[1]) - 1)]], (x, 0))
  362.             x += ZX_TILE_SIZE
  363.             s.background.blit(SPRITES.sprites[PLATFORM_PARTS[2][random.randint(0, len(PLATFORM_PARTS[2]) - 1)]], (x, 0))
  364.                
  365.     # initialise the platform container object
  366.     def __init__(s, count): # specify how many platforms to add to the container at the start
  367.         global ZX_WIDTH, ZX_HEIGHT, ZX_TILE_SIZE
  368.        
  369.         s.platforms = [] # create empty container list
  370.         s.platforms += [s.platform(0, 23, 32)] # add the platform represents the floor.
  371.    
  372.         # create [count] number of platforms
  373.         # each platform is not allowed to overlap another platform. Why? Because I say so!
  374.         for index in range(count):
  375.             # create and infinite loop to find space for our platforms
  376.             # if no space is found because the there are too many platforms to fit onto the 'stage'
  377.             # then the game will hang
  378.             while True:
  379.                 foundSpace = True # assume space will be found
  380.  
  381.                 # create a set of random coords and width            
  382.                 zxW = random.randint(3, 8)                
  383.                 zxX = random.randint(0, ZX_WIDTH - zxW)
  384.                
  385.                 # position the platform on planes multiple of 4 so platforms aren't stacked on top
  386.                 # of each other
  387.                 zxY = random.randint(3, (ZX_HEIGHT - 4) / 4) * 4
  388.  
  389.                 # create rect object. Not completely necessary but I've got used to working with them
  390.                 r = rect(zxX, zxY, zxW, 1).scale(ZX_TILE_SIZE)
  391.  
  392.                 # cycle through the list of platforms in the container. On first run the list contains
  393.                 # only the floor which has a rect of [0, 184, 256, 8]
  394.                 for p in s.platforms:
  395.                     # if the random platform overlaps a platform in the container list then...
  396.                     if not (r.x1 >= p.rect.x2 or r.x2 <= p.rect.x1 or r.y1 >= p.rect.y2 or r.y2 <= p.rect.y1):
  397.                         # ...we can no longer assume space will be found
  398.                         foundSpace = False
  399.                         break # break out of the for loop
  400.  
  401.                 # if the randomly selected platform somehow managed to find a space then
  402.                 # break the infinite loop
  403.                 if foundSpace: break
  404.             # add the platform to the container list and either loop to add another one or...
  405.             s.platforms += [s.platform(zxX, zxY, zxW)]
  406.             # ...exit the initialisation function, all platforms added!
  407.  
  408.     # draws the platform
  409.     def drawBKGD(s):
  410.         global ZX_SURFACE
  411.  
  412.         for p in s.platforms:
  413.             ZX_SURFACE.blit(p.background, p.rect.pos(True))
  414.  
  415.     # draws the platform decorations, grass, mushrooms etc
  416.     def drawFG(s):
  417.         global ZX_SURFACE
  418.         global ZX_TILE_SIZE
  419.         for p in s.platforms:
  420.             ZX_SURFACE.blit(p.foreground, p.rect.pos(True, [0, -ZX_TILE_SIZE]))
  421.            
  422.  
  423. # define needed color(s)
  424. BLACK = [0, 0, 0]
  425. BLUE = [116, 164, 163]
  426. DARK_GRASS = [24, 81, 34]
  427.  
  428. # the surface the sprites are blitted to is only 256 x 192 pixels
  429. # without scale this would be too small to see.
  430. SCALE = 3
  431. ZX_TILE_SIZE = 8
  432. ZX_WIDTH = 32
  433. ZX_HEIGHT = 24
  434.  
  435. # create the dimensions for the primary display surface
  436. W, H = ZX_WIDTH * ZX_TILE_SIZE, ZX_HEIGHT * ZX_TILE_SIZE
  437. HW, HH = int(W / 2), int(H / 2)
  438. FPS = 60
  439.  
  440. # initialised pygame
  441. pygame.init()
  442. DS = pygame.display.set_mode((W * SCALE, H * SCALE))
  443. ZX_SURFACE = pygame.Surface((W, H)) # this surface will be scaled to fit the primary display surface
  444. CLOCK = pygame.time.Clock()
  445.  
  446. # create/assemble all the sprites
  447. SPRITES = spritesSheet(LADYBIRD_SPRITES)
  448. SPRITES.colorKey(BLACK) # make the sprites background transparent
  449.  
  450. GRAVITY = 0.2 # set the strength of gravity
  451.  
  452. LADYBIRD = ladybird(16, 0) # creat the ladybird object
  453. PLATFORMS = platforms(5) # and the platform container object. 5 platforms will be created on initialisation
  454.  
  455. # create a surface for the background. Blue with a green strip at the bottom
  456. BACKGROUND = ZX_SURFACE.copy()
  457. BACKGROUND.fill(BLUE, [0, 0, W, H - ZX_TILE_SIZE])
  458. BACKGROUND.fill(DARK_GRASS, [0, H - ZX_TILE_SIZE, W, ZX_TILE_SIZE])
  459.  
  460. while True:
  461.     e = pygame.event.get() # read events
  462.     if pygame.key.get_pressed()[pygame.K_ESCAPE]: break # if ESC pressed then exit game
  463.  
  464.     # copy the blue background to the 256 x 192 surface
  465.     # remember: all the sprites will be drawn to ZX_SURFACE too
  466.     ZX_SURFACE = BACKGROUND.copy()
  467.  
  468.     # draw the platforms
  469.     PLATFORMS.drawBKGD()
  470.  
  471.     # if the ladybird is jumping then the decorations are drawn behind the ladybird
  472.     if LADYBIRD.vy < 0: PLATFORMS.drawFG()
  473.    
  474.     LADYBIRD.draw() # draw the ladybird
  475.    
  476.     # if ladybird is falling then draw decorations in front of ladybird
  477.     if LADYBIRD.vy >= 0: PLATFORMS.drawFG()
  478.  
  479.     # move the ladybird
  480.     LADYBIRD.do()
  481.  
  482.     # blit the sprite surface ZX_SURFACE to the primary display surface scaled up to fit it
  483.     DS.blit(pygame.transform.scale(ZX_SURFACE, (W * SCALE, H * SCALE)), (0, 0))
  484.  
  485.     # update primary display
  486.     pygame.display.update()
  487.     CLOCK.tick(FPS) # maintain frames per second (60)
  488. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement