Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import time
- pygame.init()
- pygame.font.init()
- pygame.mixer.init()
- sc = pygame.display.set_mode((800, 600))
- lbird, lbird2 = pygame.image.load("src/loadbird.png"), pygame.image.load("src/loadbird2.png")
- fontt = "pingfang"
- font = pygame.font.SysFont(fontt, 24)
- tfont = pygame.font.SysFont(fontt, 72)
- sfont = pygame.font.SysFont(fontt, 18)
- fl = open("src/userdata", "r")
- udata = fl.read().split("\n")
- fl.close()
- def loading():
- sc.fill((0, 0, 0))
- for i in range(100):
- sc.blit(tfont.render("By Jason Chen", False, (0, 255, 255, i)), (170, 250))
- pygame.display.update()
- time.sleep(0.01)
- sc.fill((0, 0, 0))
- for ev in pygame.event.get():
- if ev.type == pygame.QUIT:
- pygame.quit()
- exit(0)
- time.sleep(0.5)
- for i in range(100):
- sc.fill((0, 255, 255))
- sc.blit(tfont.render("Block them!", False, (0, 0, 0)), (180, 150))
- pygame.draw.rect(sc, (0, 0, 255), (170, 290, i * 4, 20))
- pygame.draw.rect(sc, (255, 255, 255), (170, 290, i * 4, 20), width=10)
- if i % 16 <= 7:
- sc.blit(lbird, (150 + i * 4, 240))
- else:
- sc.blit(lbird2, (150 + i * 4, 240))
- sc.blit(font.render(f"加载中... {i}%", False, (0, 0, 0)), (340, 350))
- pygame.display.update()
- for ev in pygame.event.get():
- if ev.type == pygame.QUIT:
- pygame.quit()
- exit(0)
- time.sleep(0.015)
- rc = pygame.surface.Surface((120, 45))
- rc.fill((255, 255, 255))
- ry = 600
- diry = -10
- st = 0
- while True:
- sc.fill((0, 255, 255))
- sc.blit(tfont.render("Block them!", False, (0, 0, 0)), (180, 150))
- pygame.draw.rect(sc, (0, 0, 255), (170, 290, 100 * 4, 20))
- pygame.draw.rect(sc, (255, 255, 255), (170, 290, 100 * 4, 20), width=10)
- sc.blit(lbird, (150 + 100 * 4, 240))
- sc.blit(font.render(f"加载中... 100%", False, (0, 0, 0)), (340, 350))
- sc.blit(rc, (360, ry))
- sc.blit(font.render(f"开始游戏!", False, (0, 0, 0)), (370, ry + 5))
- if rc.get_rect().move(360, ry).collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]:
- return
- ry += diry
- if ry > 400 and diry == 1:
- diry = -1
- if ry < 390:
- diry = 1
- if st % 64 <= 31:
- sc.blit(lbird, (150 + 400, 240))
- else:
- sc.blit(lbird2, (150 + 400, 240))
- st += 1
- pygame.display.update()
- for ev in pygame.event.get():
- if ev.type == pygame.QUIT:
- pygame.quit()
- exit(0)
- time.sleep(0.01)
- worldwide, worldheight = 20, 15
- world = [[0] * worldheight for i in range(worldwide)]
- page = 0
- blank = pygame.surface.Surface((39, 39))
- blank.fill((170, 255, 255))
- nblank = pygame.surface.Surface((39, 39))
- nblank.fill((0, 0, 30))
- pflag = pygame.image.load("src/pflag.png")
- mine = pygame.surface.Surface((39, 39))
- mine.fill((0, 0, 0))
- btower = pygame.transform.scale(pygame.image.load("src/bowtower.png"), (39, 39))
- countdown = 60
- coin = 50
- tick = 0
- ticktime = 0
- loading()
- # fixme: loading
- level = -1
- levpos = [(10, 275), (80, 275), (150, 275), (220, 275), (290, 275), (360, 275), (430, 275), (500, 275), (150, 175),
- (220, 175), (290, 175), (360, 175), (430, 175), (500, 175), (570, 175), (570, 275), (640, 175)] # now end on BOSS1
- levname = ["1", "2", "3", "4", "5", "6", "7", "8", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "B1", "B2", "B3", "B4",
- "C1", "D1", "D2", "D3", "D4", "D5"]
- """
- levels:
- normal:
- 0. 1
- 1. 2
- 2. 3
- 3. 4
- 4. 5
- 5. 6
- 6. 7
- 7. 8
- night:
- 8. A1 unlock by 3
- 9. A2
- 10. A3
- 11. A4
- 12. A5
- 13. A6
- 14. A7
- Bosses:
- 15. BOSS1 unlock by 8
- 16. BOSS2 unlock by A7
- """
- lines = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (2, 8), (8, 9), (9, 10), (10, 11), (11, 12), (12, 13), (13, 14), (7, 15), (14, 16)]
- progress = [[1], [2], [3, 8], [4], [5], [6], [7], [15], [9], [10], [11], [12], [13], [14], [16], [], []]
- unlockedt = udata[2].split(",")
- night_levels = [8, 9, 10, 11, 12, 13, 14]
- innpage = 0
- # (Name, unlock level, hp, cost, surface)
- towers = [("矿洞", 0, 50, 50, mine), ("弓箭塔", 0, 50, 100, btower), ("炸药", 1, 50, 175, pygame.image.load("src/TNT.png")),
- ("砖头", 1, 150, 100, pygame.transform.scale(pygame.image.load("src/brick.png"), (39, 39))),
- ("信标", 2, 20, 225, pygame.transform.scale(pygame.image.load("src/xb.png"), (39, 39))),
- ("火把", 2, 10, 50, pygame.transform.scale(pygame.image.load("src/torch.png"), (39, 39))),
- ("铁傀儡", 6, 100, 200, pygame.transform.scale(pygame.image.load("src/iron_golem.png"), (39, 39))),
- ("高压炸药", 15, 100, 250, pygame.transform.scale(pygame.image.load("src/tntp.png"), (39, 39)))]
- thingsonhand = -1
- tntnoharm = [6]
- monster = [[0] * worldheight for i in range(worldwide)]
- hp = [[0] * worldheight for i in range(worldwide)]
- # (hp, att, spd, surface)
- monsters = [(), (30, 5, 34, pygame.transform.scale(pygame.image.load("src/zombie.png"), (29, 29))),
- (20, 10, 56, pygame.transform.scale(pygame.image.load("src/creeper.png"), (29, 29))),
- (61, 6, 66, pygame.transform.scale(pygame.image.load("src/pilliger.png"), (39, 39))),
- (60, 0, 10000000, pygame.transform.scale(pygame.image.load("src/enderman.png"), (29, 29))),
- (181, 5, 120, pygame.transform.scale(pygame.image.load("src/slime.png"), (29, 29))),
- (60, 3, 66, pygame.transform.scale(pygame.image.load("src/blaze.png"), (29, 29)))]
- lx = levpos[int(udata[1])][0] - 10
- mxcoin = int(udata[4])
- retbut = pygame.surface.Surface((120, 45))
- retbut.fill((255, 255, 255))
- retbut.blit(font.render("返回", False, (0, 0, 0)), (30, 5))
- levelmonst = [{30: [0, 0, 1], 45: [0, 5, 1], 46: [0, 8, 1], 56: [0, 9, 1], 57: [0, 14, 1], 58: [0, 0, 1], 60: -1}, # 1
- {20: [0, 0, 1], 21: [0, 14, 1], 40: [0, 1, 1], 41: [0, 13, 1], 57: [5, 0, 2], 58: [5, 14, 1],
- 59: [5, 1, 1], 60: [5, 13, 1], 61: -1}, # 2
- {15: [0, 7, 1], 25: [0, 7, 2], 26: [0, 8, 1], 38: [0, 0, 2], 39: [0, 14, 2], 40: [0, 14, 1],
- 41: [0, 0, 1], 53: [0, 7, 1], 54: [10, 7, 2], 55: [10, 8, 1], 56: [10, 6, 1], 57: -1}, # 3
- {15: [0, 7, 1], 30: [0, 7, 2], 50: [0, 7, 3], 51: [0, 0, 2], 70: [0, 14, 2], 90: [0, 8, 2], 91: -1}, # 4
- {15: [0, 7, 2], 30: [1, 7, 2], 50: [0, 7, 3], 70: [0, 0, 3], 71: [1, 14, 3], 72: [2, 7, 3], 73: -1}, # 5
- {15: [0, 14, 1], 25: [0, 0, 1], 40: [0, 9, 1], 50: [0, 0, 1], 49: [0, 0, 3], 51: [0, 7, 3], 70: [0, 5, 3], 71: -1}, # 6
- {15: [0, 7, 2], 45: [0, 9, 1], 60: [0, 7, 3], 61: [0, 8, 3], 62: [0, 14, 3], 63: [0, 0, 3], 64: [0, 1, 3], 65: -1}, # 7
- {15: [0, 7, 1], 30: [0, 7, 2], 45: [0, 7, 3], 40: [0, 7, 4], 50: [0, 7, 2], 51: [1, 8, 2], 52: [2, 9, 2], 53: [3, 6, 2], 54: [4, 5, 2], 65: [0, 0, 4], 66: [0, 14, 4], 67: [0, 8, 4], 68: [0, 7, 3], 69: [0, 0, 3], 70: [0, 14, 3], 71: -1}, # 8
- {20: [0, 7, 1], 30: [0, 5, 1], 40: [0, 8, 2], 41: [0, 0, 2], 42: [0, 14, 2], 43: [0, 7, 1], 44: -1}, # A1
- {15: [0, 8, 1], 20: [0, 2, 1], 30: [0, 12, 2], 35: [0, 1, 2], 50: [0, 7, 1], 70: [0, 7, 3], 71: -1}, # A2
- {15: [0, 8, 1], 30: [0, 7, 2], 40: [0, 7, 4], 60: [0, 1, 3], 81: [0, 13, 3], 95: [0, 7, 3], 96: [2, 7, 2], 97: -1}, # A3
- {15: [0, 8, 1], 30: [0, 1, 2], 31: [0, 14, 2], 50: [0, 1, 1], 51: [0, 2, 1], 52: [0, 3, 1], 53: [0, 4, 1], 70: [0, 5, 1], 71: [0, 6, 1], 72: [0, 7, 1], 73: [0, 8, 1], 130: [0, 8, 3], 131: [0, 1, 3], 132: [0, 14, 3], 133: [0, 5, 5], 134: [0, 10, 5], 135: -1}, # A4
- {15: [0, 8, 5], 30: [0, 8, 5], 45: [0, 8, 5], 46: [0, 8, 3], 60: [0, 1, 5], 61: [0, 14, 5], 62: [0, 1, 3], 63: [0, 4, 3], 64: [0, 4, 5], 70: [0, 3, 5], 71: [0, 11, 5], 72: [0, 3, 4], 73: [0, 11, 4], 100: [0, 11, 3], 101: [0, 4, 4], 102: [0, 8, 5], 103: -1}, # A5
- {15: [0, 8, 5], 30: [0, 8, 5], 45: [0, 8, 6], 46: [0, 1, 6], 47: [0, 14, 6], 48: [0, 8, 3], 60: [0, 3, 5], 61: [0, 14, 3], 75: [0, 2, 4], 76: [0, 13, 6], 77: [0, 12, 6], 78: [0, 2, 6], 79: [0, 3, 6], 80: [0, 8, 4], 100: [0, 8, 5], 101: [0, 8, 2], 102: [0, 1, 3], 103: [0, 13, 3], 104: [0, 3, 3], 105: [0, 8, 6], 106: -1}, # A6
- {}, # A7
- {20: [0, 8, 5], 40: [0, 9, 5], 41: [0, 2, 5], 42: [0, 7, 5], 60: [0, 5, 4], 61: [0, 8, 5], 80: [0, 2, 4], 81: [0, 13, 4], 150: [0, 1, 3], 151: [0, 8, 3], 152: [0, 14, 3], 153: [0, 4, 3], 154: [0, 11, 3], 155: [0, 8, 5], 156: [0, 8, 2], 157: [0, 8, 5], 158: [0, 8, 2], 159: [0, 8, 4], 160: [0, 8, 5], 161: [0, 8, 5], 162: [0, 8, 3], 170: -1}, # BOSS1
- {} # BOSS2
- ] # todo: levels
- winning = False
- unlockedl = [int(i) for i in udata[3].split(",")]
- while True:
- if page == 1:
- if level not in night_levels:
- sc.fill((0, 255, 255))
- else:
- sc.fill((0, 0, 30))
- else:
- sc.fill((0, 255, 255))
- ticktime = time.time()
- if page == 0:
- sc.blit(font.render(udata[0], False, (0, 0, 0)), (10, 10))
- fut = []
- for i in unlockedl:
- for j in progress[i]:
- if j not in unlockedl and j not in fut:
- fut.append(j)
- for i in lines:
- if i[0] in unlockedl and i[1] in unlockedl:
- pygame.draw.line(sc, (0, 0, 0), (levpos[i[0]][0] + lx + 25, levpos[i[0]][1] + 25),
- (levpos[i[1]][0] + lx + 25, levpos[i[1]][1] + 25))
- elif i[0] in unlockedl and i[1] in fut:
- pygame.draw.line(sc, (170, 170, 170), (levpos[i[0]][0] + lx + 25, levpos[i[0]][1] + 25),
- (levpos[i[1]][0] + lx + 25, levpos[i[1]][1] + 25))
- elif i[0] in fut and i[1] in unlockedl:
- pygame.draw.line(sc, (170, 170, 170), (levpos[i[0]][0] + lx + 25, levpos[i[0]][1] + 25),
- (levpos[i[1]][0] + lx + 25, levpos[i[1]][1] + 25))
- for i in unlockedl:
- pygame.draw.rect(sc, (255, 255, 255), (levpos[i][0] + lx, levpos[i][1], 50, 50))
- sc.blit(font.render(levname[i], False, (0, 0, 0)), (levpos[i][0] + 15 + lx, levpos[i][1] + 10))
- if pygame.rect.Rect(levpos[i][0] + lx, levpos[i][1], 50, 50).collidepoint(pygame.mouse.get_pos()) and \
- pygame.mouse.get_pressed()[0]:
- level = i
- world = [[0] * worldheight for i in range(worldwide)]
- monster = [[[0, 0, 0] for j in range(worldheight)] for i in range(worldwide)]
- world[worldwide - 1][worldheight // 2] = -1
- hp[worldwide - 1][worldheight // 2] = 10000000
- page = 1
- tick = 0
- countdown = 0
- coin = 50
- winning = False
- for i in fut:
- pygame.draw.rect(sc, (170, 170, 170), (levpos[i][0] + lx, levpos[i][1], 50, 50))
- sc.blit(font.render(levname[i], False, (0, 0, 0)), (levpos[i][0] + 15 + lx, levpos[i][1] + 10))
- keys = pygame.key.get_pressed()
- if keys[pygame.K_RIGHT] and lx >= 0:
- lx -= 5
- if keys[pygame.K_LEFT] and lx < 1000:
- lx += 5
- elif page == 1:
- tick += 1
- stillmob = True
- if coin > mxcoin:
- coin = mxcoin
- for i in range(worldwide):
- for j in range(worldheight):
- if world[i][j] == 0:
- if level not in night_levels:
- sc.blit(blank, (i * 40, j * 40))
- elif world[i][j] == -1:
- sc.blit(pflag, (i * 40, j * 40))
- elif world[i][j] > 0:
- if night_levels:
- sc.blit(blank, (i * 40, j * 40))
- sc.blit(towers[world[i][j] - 1][4], (i * 40, j * 40))
- pygame.draw.rect(sc, (0, 255, 0), (i * 40, j * 40 + 30, int(hp[i][j]/towers[world[i][j]-1][2]*39), 8))
- if world[i][j] == 1 and tick % 166 == 0:
- coin += 25
- elif world[i][j] == 2 and tick % 33 == 0:
- shooted = False
- for k in range(max(0, i - 2), min(worldwide, i + 2)):
- for l in range(max(0, j - 2), min(worldheight, j + 2)):
- if monster[k][l][0] != 0:
- monster[k][l][1] -= 2
- if monster[k][l][1] <= 0:
- monster[k][l] = [0, 0, 0]
- pygame.draw.line(sc, (0, 0, 0), (i * 40, j * 40), (k * 40, l * 40), width=10)
- shooted = True
- break
- if shooted:
- break
- elif world[i][j] == 3:
- shooted = False
- for k in range(max(0, i - 2), min(worldwide, i + 2)):
- for l in range(max(0, j - 2), min(worldheight, j + 2)):
- if monster[k][l][0] != 0 and monster[k][l][1] not in tntnoharm:
- shooted = True
- break
- if shooted:
- break
- if shooted:
- for k in range(max(0, i - 2), min(worldwide, i + 3)):
- for l in range(max(0, j - 2), min(worldheight, j + 3)):
- if monster[k][l][0] != 0 and monster[k][l][1] not in tntnoharm:
- monster[k][l][1] -= 40
- if monster[k][l][1] <= 0:
- monster[k][l] = [0, 0, 0]
- world[i][j] = 0
- hp[i][j] = -1
- elif world[i][j] == 5 and tick%33 == 0:
- for k in range(max(0, i - 2), min(worldwide, i + 3)):
- for l in range(max(0, j - 2), min(worldheight, j + 3)):
- if world[k][l] > 0 and (k != i or l != j) and hp[k][l]+3 <= towers[world[k][l]-1][2]:
- hp[k][l] += 3
- pygame.draw.line(sc, (0, 255, 0), (i * 40, j * 40), (k * 40, l * 40), width=10)
- elif world[i][j] == 6 and 8 <= level <= 15:
- for k in range(max(0, i - 3), min(worldwide, i + 4)):
- for l in range(max(0, j - 3), min(worldheight, j + 4)):
- if world[k][l] == 0:
- sc.blit(blank, (k * 40, l * 40))
- if monster[k][l][0] != 0:
- sc.blit(monsters[monster[k][l][0]][3], (k * 40, l * 40))
- elif world[i][j] == 7 and tick%66 == 0:
- shooted = False
- for k in range(max(0, i - 1), min(worldwide, i + 2)):
- for l in range(max(0, j - 1), min(worldheight, j + 2)):
- if monster[k][l][0] != 0:
- monster[k][l][1] -= 20
- if monster[k][l][1] <= 0:
- monster[k][l] = [0, 0, 0]
- pygame.draw.line(sc, (0, 0, 0), (i * 40, j * 40), (k * 40, l * 40), width=10)
- shooted = True
- break
- if shooted:
- break
- elif world[i][j] == 8 and tick%5 == 0:
- if 50 >= hp[i][j] > 0:
- shooted = False
- for k in range(max(0, i - 3), min(worldwide, i + 4)):
- for l in range(max(0, j - 3), min(worldheight, j + 4)):
- if monster[k][l][0] != 0 and monster[k][l][1] not in tntnoharm:
- shooted = True
- break
- if shooted:
- break
- if shooted:
- for k in range(max(0, i - 4), min(worldwide, i + 5)):
- for l in range(max(0, j - 4), min(worldheight, j + 5)):
- if monster[k][l][0] != 0 and monster[k][l][1] not in tntnoharm:
- monster[k][l][1] -= 130
- if monster[k][l][1] <= 0:
- monster[k][l] = [0, 0, 0]
- world[i][j] = 0
- hp[i][j] = -1
- elif hp[i][j] > 50:
- hp[i][j] -= 1
- # todo: towers
- if monster[i][j][0] != 0:
- stillmob = False
- if level not in night_levels:
- sc.blit(monsters[monster[i][j][0]][3], (i * 40, j * 40))
- if monster[i][j][0] == 2 and tick % 33 == 0:
- for k in range(max(0, i - 3), min(worldwide, i + 4)):
- for l in range(max(0, j - 3), min(worldheight, j + 4)):
- if world[k][l] > 0:
- hp[k][l] -= 5
- if hp[k][l] < 0:
- world[k][l] = 0
- elif monster[i][j][0] == 3 and tick % 100 == 0:
- ak, al = -1, -1
- for k in range(max(0, i - 3), min(worldwide, i + 4)):
- for l in range(max(0, j - 3), min(worldheight, j + 4)):
- if monster[k][l][0] == 0:
- if ak == -1 or random.randint(0, 2) == 0:
- ak, al = k, l
- if ak != -1:
- mtype = random.choice([1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 5, 5, 2, 3, 4])
- monster[ak][al] = [mtype, monsters[mtype][0], 0]
- elif monster[i][j][0] == 4 and tick % 33 == 0 and monster[i][j][2] != tick:
- shooted = False
- for k in range(max(0, i - 2), min(worldwide, i + 3)):
- for l in range(max(0, j - 2), min(worldheight, j + 3)):
- if world[k][l] != 0:
- hp[k][l] -= 10
- if hp[k][l] <= 0:
- world[k][l] = 0
- monster[i][j][2] = tick
- if random.randint(0, 3) == 0:
- rx, ry = random.randint(0, worldwide-2), random.randint(0, worldheight-1)
- rdcnt = 0
- while monster[rx][ry][0] != 0 or world[rx][ry] != 0:
- rx, ry = random.randint(0, worldwide - 2), random.randint(0, worldheight - 1)
- rdcnt += 1
- if rdcnt >= 100:
- break
- if rdcnt < 60:
- monster[rx][ry] = [4, monster[i][j][1], tick]
- monster[i][j] = [0, 0, 0]
- continue
- elif monster[i][j][0] == 6 and tick % 33 == 0:
- shooted = False
- for k in range(i, i+15):
- if k >= worldwide:
- break
- if world[k][j] != 0:
- hp[k][j] -= 5
- pygame.draw.line(sc, (231, 101, 26), (i * 40, j * 40), (k * 40, j * 40), width=10)
- if hp[k][j] <= 0:
- world[k][j] = 0
- break
- if tick % monsters[monster[i][j][0]][2] == 0 and monster[i][j][2] != tick:
- if i < worldwide - 1:
- if monster[i + 1][j] == [0, 0, 0]:
- if world[i + 1][j] <= 0:
- monster[i + 1][j] = [monster[i][j][0], monster[i][j][1], tick]
- monster[i][j] = [0, 0, 0]
- else:
- hp[i + 1][j] -= monsters[monster[i][j][0]][1]
- if hp[i + 1][j] <= 0:
- world[i + 1][j] = 0
- elif j + 1 < worldheight and monster[i][j + 1] == [0, 0]:
- if world[i][j + 1] <= 0:
- monster[i][j + 1] = [monster[i][j][0], monster[i][j][1], tick]
- monster[i][j] = [0, 0, 0]
- else:
- hp[i][j + 1] -= monsters[monster[i][j][0]][1]
- if hp[i][j + 1] <= 0:
- world[i][j + 1] = 0
- elif j - 1 >= 0 and monster[i][j - 1] == [0, 0]:
- if world[i][j - 1] <= 0:
- monster[i][j - 1] = [monster[i][j][0], monster[i][j][1], tick]
- monster[i][j] = [0, 0, 0]
- else:
- hp[i][j - 1] -= monsters[monster[i][j][0]][1]
- if hp[i][j - 1] <= 0:
- world[i][j - 1] = 0
- else:
- if j > 7:
- if monster[i][j - 1] == [0, 0, 0]:
- if world[i][j - 1] <= 0:
- monster[i][j - 1] = [monster[i][j][0], monster[i][j][1], tick]
- monster[i][j] = [0, 0, 0]
- else:
- hp[i][j - 1] -= monsters[monster[i][j][0]][1]
- if hp[i][j - 1] <= 0:
- world[i][j - 1] = 0
- elif j < 7:
- if monster[i][j + 1] == [0, 0, 0]:
- if world[i][j + 1] <= 0:
- monster[i][j + 1] = [monster[i][j][0], monster[i][j][1], tick]
- monster[i][j] = [0, 0, 0]
- else:
- hp[i][j + 1] -= monsters[monster[i][j][0]][1]
- if hp[i][j + 1] <= 0:
- world[i][j + 1] = 0
- else:
- page = 3
- # todo: monster
- if stillmob and winning:
- page = 2
- udata[1] = str(max(int(udata[1]), level + 1))
- for i in range(len(towers)):
- if str(i) not in unlockedt and towers[i][1] == level:
- unlockedt.append(str(i))
- for i in progress[level]:
- if i not in unlockedl:
- unlockedl.append(i)
- udata[2] = ",".join(unlockedt)
- udata[3] = ",".join([str(i) for i in unlockedl])
- fl = open("src/userdata", "w+")
- fl.write("\n".join(udata))
- fl.close()
- continue
- if tick % 33 == 0:
- countdown += 1
- if countdown in levelmonst[level].keys():
- if levelmonst[level][countdown] == -1:
- winning = True
- else:
- monster[levelmonst[level][countdown][0]][levelmonst[level][countdown][1]] = [
- levelmonst[level][countdown][2], monsters[levelmonst[level][countdown][2]][0], 0]
- if innpage == 1:
- sc.fill((170, 170, 170))
- rx = 50
- for i in range(len(towers)):
- if str(i) in unlockedt:
- if thingsonhand == i + 1:
- pygame.draw.rect(sc, (200, 200, 200), (rx % 750, 110 + rx // 750 * 70, 49, 49))
- sc.blit(sfont.render(f"{towers[i][0]} {towers[i][3]}$", False, (0, 0, 0)),
- (rx % 750, 151 + rx // 750 * 70))
- sc.blit(towers[i][4], (rx % 750 + 5, 110 + rx // 750 * 70 + 5))
- if towers[i][4].get_rect().move(rx % 750 + 5, 110 + rx // 750 * 70 + 5).collidepoint(
- pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]:
- thingsonhand = i + 1
- rx += 120
- else:
- if pygame.mouse.get_pressed()[2]:
- mx, my = pygame.mouse.get_pos()
- bx, by = mx // 40, my // 40
- if coin >= towers[thingsonhand - 1][3] and world[bx][by] == 0:
- world[bx][by] = thingsonhand
- coin -= towers[thingsonhand - 1][3]
- hp[bx][by] = towers[thingsonhand - 1][2]
- time.sleep(0.1)
- keys = pygame.key.get_pressed()
- if keys[pygame.K_e]:
- innpage = 1 if innpage == 0 else 0
- time.sleep(0.3)
- sc.blit(sfont.render(f"你有{coin}$/背包容量{mxcoin}$", False, (255, 155, 0)), (5, 5))
- sc.blit(sfont.render(f"现在是第{countdown}刻", False, (255, 155, 0)), (5, 25))
- elif page == 2:
- sc.blit(font.render(f"你成功的打败了所有第{levname[level]}关的怪物!", False, (0, 0, 0)), (150, 150))
- sc.blit(retbut, (200, 300))
- if retbut.get_rect().move(200, 300).collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]:
- page = 0
- time.sleep(0.2)
- elif page == 3:
- sc.blit(font.render(f"怪物摧毁了你的家园!", False, (0, 0, 0)), (150, 150))
- sc.blit(retbut, (200, 300))
- if retbut.get_rect().move(200, 300).collidepoint(pygame.mouse.get_pos()) and pygame.mouse.get_pressed()[0]:
- page = 0
- time.sleep(0.2)
- for ev in pygame.event.get():
- if ev.type == pygame.QUIT:
- pygame.quit()
- exit(0)
- pygame.display.update()
- while time.time() <= ticktime + 0.03:
- time.sleep(0.003)
Add Comment
Please, Sign In to add comment