1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| import pygame from setting import FIRST_STEP, SECOND_STEP, BG_COLOR, WIDTH, HEIGHT
def ballNum(ladderNum, time): index = 0 if FIRST_STEP <= time < SECOND_STEP: index = 1 if SECOND_STEP <= time: index = 2 numMap = [ [2, 3, 5], [3, 5, 6], [4, 6, 7] ] return numMap[ladderNum - 1][index]
def protectTime(ballsNum): if ballsNum in [2, 3, 4]: return 1 else: return 2
def howBigBallIs(ladderNum, time): index = 0 if FIRST_STEP <= time < SECOND_STEP: index = 1 if SECOND_STEP <= time: index = 2 numMap = [ [25, 20, 15], [24, 20, 16], [26, 20, 16] ] return numMap[ladderNum - 1][index]
def judgeDiff(ladderNum, time): index = 0 if FIRST_STEP <= time < SECOND_STEP: index = 1 if SECOND_STEP <= time: index = 2 numMap = [ [(30, 30, 3.5, 3.5), (28, 28, 6, 6), (26, 26, 9, 9)], [(30, 30, 4.5, 4.5), (27, 27, 8, 8), (25, 25, 10, 10)], [(30, 30, 5, 5), (26, 26, 9, 9), (24, 24, 12, 12)] ] return numMap[ladderNum - 1][index]
def makeGameBg(width, height): pygame.init() screen = pygame.display.set_mode((width, height)) pygame.display.set_caption('小球逃逃逃') background = pygame.Surface(screen.get_size()) return screen, background
def ballCome(): COME_AGAIN = pygame.USEREVENT pygame.time.set_timer(COME_AGAIN, 1000) return COME_AGAIN
def makeTips(content, size, color, position, screen): font = pygame.font.SysFont('arial', size) text_sf = font.render(content, True, color, BG_COLOR) screen.blit(text_sf, position)
def draw(screen, SCORE, TIME): screen.fill(BG_COLOR) makeTips('SCORE: ', 30, (34, 139, 34), (5, 40), screen) makeTips('TIME(s): ', 30, (64, 158, 255), (5, 75), screen) makeTips(str(int(SCORE)), 30, (34, 139, 34), (135, 40), screen) makeTips(str(int(TIME)), 30, (64, 158, 255), (135, 75), screen) if TIME in [FIRST_STEP, FIRST_STEP + 1]: makeTips('Ops! LEVEL_2~', 30, (60, 179, 113), (WIDTH / 2 - 30 * 3.5, HEIGHT / 2 - 50), screen) elif TIME in [SECOND_STEP, SECOND_STEP + 1]: makeTips('Congratulations! LEVEL_3', 25, (60, 179, 113), (WIDTH / 2 - 25 * 6.25, HEIGHT / 2 - 50), screen)
|