Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.57 KB | None | 0 0
  1. import pygame
  2. from random import randint
  3. pygame.init()
  4.  
  5. #Constants
  6.  
  7. #Colors
  8. BLACK = (0, 0, 0)
  9. RED = (255, 0, 0)
  10. BLUE = (0, 0, 255)
  11. WHITE = (255, 255, 255)
  12.  
  13. #Pygame
  14. SCREEN = 0
  15. CLOCK = 0
  16. FPS = 30
  17. FONT = pygame.font.SysFont('cambriacambriamath', 20, False, False)
  18.  
  19. #Gameplay
  20. totLengthX = 21
  21. totLengthY = 12
  22. totGifts = 4
  23.  
  24. MAXSCORE = 125
  25.  
  26. EMPTY = "00"
  27. WALL = "01"
  28. UNSPEC = "02"
  29.  
  30.  
  31. OPENINGS = ["NW", "NS", "NE", "WS", "WE", "SE", "SOLID"]
  32. OPENINGSFALLEN = ["NWa", "NSa", "NEa", "WSa", "WEa", "SEa", "SOLIDa"]
  33. OPENINGSIMGS = [pygame.image.load("imgs//"+str(i)+".png") for i in OPENINGS]
  34. OPENINGSFALLENIMGS = [pygame.image.load("imgs//"+str(i)+".png") for i in OPENINGSFALLEN]
  35. BGIMG = pygame.image.load("imgs//background.png")
  36. BGIMG = pygame.transform.scale(BGIMG,(1600,900))
  37. PLAYERIMG = pygame.image.load("imgs//Santa.png")
  38. GIFTIMG = pygame.image.load("imgs//Gift.png")
  39.  
  40. AMOUNTGIFTS = 10
  41.  
  42. BLOCKS = \
  43. [
  44. [["NW", "SOLID"],
  45. ["SOLID", "SOLID"]],
  46. [["NS", "SOLID"],
  47. ["NW", "SOLID"]],
  48. [["NS", "SOLID"],
  49. ["NS", "SOLID"]],
  50. [["NS", "SOLID"],
  51. ["NE", "WS"]],
  52. [["NS", "SOLID"],
  53. ["NE", "WS"]],
  54.  
  55. [["NS", "SOLID", "SOLID", "SOLID"]],
  56. [["SOLID", "NS", "SOLID", "SOLID"]],
  57. [["NW", "SOLID", "SOLID", "SOLID"]],
  58. [["SOLID", "SOLID", "SOLID", "NE"]],
  59. [["SOLID", "NE", "WS", "SOLID"]],
  60. [["SOLID", "NE", "NW", "SOLID"]],
  61. [["NE", "WS", "SOLID", "SOLID"]],
  62. [["NE", "NW", "SOLID", "SOLID"]],
  63. [["WE", "WE", "WS", "SOLID"]],
  64. [["WE", "WE", "NW", "SOLID"]],
  65. [["WE", "WE", "WE", "WS"]],
  66. [["WE", "WE", "WE", "NW"]],
  67. [["WE", "WE", "WE", "WE"]],
  68.  
  69.  
  70. [[EMPTY, "NW", EMPTY],
  71. ["SOLID", "SOLID", "SOLID"]],
  72. [[EMPTY, "WE", EMPTY],
  73. ["SOLID", "SOLID", "SOLID"]],
  74. [[EMPTY, "NE", EMPTY],
  75. ["SOLID", "SOLID", "SOLID"]],
  76. [[EMPTY, "NS", EMPTY],
  77. ["SOLID", "NS", "SOLID"]],
  78. [[EMPTY, "NS", EMPTY],
  79. ["SOLID", "NS", "SOLID"]],
  80. [[EMPTY, "NS", EMPTY],
  81. ["NE", "NW", "SOLID"]],
  82. [[EMPTY, "NS", EMPTY],
  83. ["WE", "NW", "SOLID"]],
  84. [[EMPTY, "NS", EMPTY],
  85. ["SE", "NW", "SOLID"]],
  86. [[EMPTY, "NS", EMPTY],
  87. ["SOLID", "NE", "NW"]],
  88. [[EMPTY, "NS", EMPTY],
  89. ["SOLID", "NE", "WE"]],
  90. [[EMPTY, "NS", EMPTY],
  91. ["SOLID", "NE", "WS"]],
  92.  
  93. [[EMPTY, "SOLID", EMPTY],
  94. ["NS", "SOLID", "SOLID"]],
  95. [[EMPTY, "SOLID", EMPTY],
  96. ["WS", "SOLID", "SOLID"]],
  97. [[EMPTY, "SOLID", EMPTY],
  98. ["NW", "SOLID", "SOLID"]],
  99. [[EMPTY, "SOLID", EMPTY],
  100. ["NE", "WS", "SOLID"]],
  101. [[EMPTY, "SOLID", EMPTY],
  102. ["SE", "WE", "NW"]],
  103. [[EMPTY, "SOLID", EMPTY],
  104. ["SE", "WE", "WE"]],
  105. [[EMPTY, "SOLID", EMPTY],
  106. ["SE", "WE", "WS"]],
  107.  
  108. [[EMPTY, "SOLID", "NS"],
  109. ["SOLID", "SOLID", EMPTY]],
  110. [[EMPTY, "SOLID", "SE"],
  111. ["SOLID", "SOLID", EMPTY]],
  112. [[EMPTY, "NE", "WE"],
  113. ["SOLID", "SOLID", EMPTY]],
  114. [[EMPTY, "WE", "WE"],
  115. ["SOLID", "SOLID", EMPTY]],
  116. [[EMPTY, "SE", "WE"],
  117. ["SOLID", "NS", EMPTY]],
  118. [[EMPTY, "SE", "WE"],
  119. ["SE", "NW", EMPTY]],
  120.  
  121.  
  122. [["NS", "SOLID", EMPTY],
  123. [EMPTY, "SOLID", "SOLID"]],
  124. [["NW", "SOLID", EMPTY],
  125. [EMPTY, "SOLID", "SOLID"]],
  126. [["WS", "SOLID", EMPTY],
  127. [EMPTY, "SOLID", "SOLID"]],
  128. [["NE", "WE", EMPTY],
  129. [EMPTY, "SOLID", "SOLID"]],
  130. [["NE", "NW", EMPTY],
  131. [EMPTY, "SOLID", "SOLID"]],
  132. [["NE", "WS", EMPTY],
  133. [EMPTY, "NW", "SOLID"]],
  134.  
  135. [["SOLID", "SOLID", "NS"],
  136. ["SOLID", EMPTY, EMPTY]],
  137. [["SOLID", "SOLID", "SE"],
  138. ["SOLID", EMPTY, EMPTY]],
  139. [["SOLID", "SE", "WS"],
  140. ["SOLID", EMPTY, EMPTY]],
  141. [["WE", "WE", "WS"],
  142. ["SOLID", EMPTY, EMPTY]],
  143. [["NE", "WE", "WS"],
  144. ["SOLID", EMPTY, EMPTY]],
  145. [["SE", "WE", "WS"],
  146. ["NS", EMPTY, EMPTY]],
  147. [["SOLID", "NS", "SOLID"],
  148. ["SOLID", EMPTY, EMPTY]],
  149.  
  150.  
  151. [["NS", "SOLID", "SOLID"],
  152. [EMPTY, EMPTY, "SOLID"]],
  153. ]
  154.  
  155.  
  156.  
  157. #variables
  158. running = True
  159. count = 0
  160. countmodifier = 1
  161. cooldownCount = 0
  162. A = [["00" for j in range(12)] for i in range(21)]
  163. curBlock = [[]]
  164.  
  165. curX1Block = 0
  166. curY1Block = 0
  167. curX2Block = 0
  168. curY2Block = 0
  169. lengthXBlock = 0
  170. lengthYBlock = 0
  171. curXPlayer = 5
  172. curYPlayer = 20
  173.  
  174. Score = 0
  175.  
  176.  
  177.  
  178. #classes
  179. class Gift:
  180. def __init__(self):
  181. self.x = randint(3,totLengthX-2)
  182. self.y = randint(1,totLengthY-3)
  183. y = self.y
  184. def giftGet(self):
  185. global Score
  186. Score = Score + int(1.25**(totLengthX-self.x))
  187. print(Score)
  188.  
  189. AllGifts = []
  190.  
  191. #global UNSPEC, BLOCKS, OPENINGS, OPENINGSFALLEN, EMPTY, WHITE, BGIMG, RED, OPENINGSIMGS, OPENINGSFALLENIMGS, PLAYERIMG, getpos, GIFTIMG, BLACK, checkMovePlayer, checkMove, moveBlock, RotateBlock, CheckRotate, MovePlayer, IFEL, deleteLines, dropAll, setup
  192.  
  193. #standard functions
  194. def getpos(req, a):
  195. count = 0
  196. for i in a:
  197. count = count + 1
  198. if i == req:
  199. return count
  200.  
  201. #A[y][x]. It's like economics :-(.
  202. def setup():
  203. global UNSPEC, BLOCKS, OPENINGS, OPENINGSFALLEN, EMPTY, WHITE, BGIMG, RED, OPENINGSIMGS, OPENINGSFALLENIMGS, PLAYERIMG, getpos, GIFTIMG, BLACK, checkMovePlayer, checkMove, moveBlock, RotateBlock, CheckRotate, MovePlayer, IFEL, deleteLines, dropAll, setup
  204. global WALL, AMOUNTGIFTS, SCREEN, CLOCK, gift, Gift, randint, totLengthY, totLengthX, spawnBlock, BLOCKS
  205. pygame.mixer.music.load("background.mp3")
  206. pygame.mixer.music.play(-1)
  207. global SCREEN, CLOCK
  208. SCREEN = pygame.display.set_mode((1600,900))
  209. CLOCK = pygame.time.Clock()
  210.  
  211. global A
  212. for i in range(len(A)):
  213. for j in range(len(A[i])):
  214. if j == 0 or j == (len(A[i])-1):
  215. A[i][j] = WALL
  216. if i == len(A)-1:
  217. A[i][j] = WALL
  218. print(A[i])
  219. global AllGifts
  220. for i in range(AMOUNTGIFTS):
  221. AllGifts.append(Gift())
  222. for i in range(AMOUNTGIFTS):
  223. AllGifts.pop(0)
  224. for i in range(AMOUNTGIFTS):
  225. AllGifts.append(Gift())
  226. spawnBlock(randint(0,len(BLOCKS)-1))
  227.  
  228. def spawnBlock(a):
  229. global UNSPEC, BLOCKS, OPENINGS, OPENINGSFALLEN, EMPTY, WHITE, BGIMG, RED, OPENINGSIMGS, OPENINGSFALLENIMGS, PLAYERIMG, getpos, GIFTIMG, BLACK, checkMovePlayer, checkMove, moveBlock, RotateBlock, CheckRotate, MovePlayer, IFEL, deleteLines, dropAll, setup
  230. global MAXSCORE, Ded
  231. global A
  232. global curBlock, lengthXBlock, lengthYBlock
  233. global curX1Block, curX2Block, curY1Block, curY2Block
  234.  
  235. global UNSPEC, OPENINGS, OPENINGSFALLEN, EMPTY, WHITE
  236.  
  237. print(BLOCKS[a])
  238. lengthXBlock = len(BLOCKS[a][0])
  239. lengthYBlock = len(BLOCKS[a])
  240. print("SPAWN")
  241. print(lengthXBlock)
  242. print(lengthYBlock)
  243. curBlock = BLOCKS[a]
  244. CHOICES = []
  245. x = 0
  246. y = 0
  247. print("SPAWN 2")
  248. ra = randint(1, 4)
  249. k = 0
  250. for i in curBlock:
  251. x = 0
  252. y = y + 1
  253. for j in i:
  254. x = x + 1
  255. if j == UNSPEC:
  256. k = k + 1
  257. curBlock[y - 1][x - 1] = "SOLID"
  258.  
  259.  
  260.  
  261. curBlock[y-1][x-1] = OPENINGS[randint(0,len(OPENINGS)-2)]
  262.  
  263. print("ra = " + str(ra))
  264. print(curBlock)
  265.  
  266. curX1Block = 5
  267. curY1Block = 0
  268. curX2Block = 5+lengthXBlock
  269. curY2Block = lengthYBlock
  270.  
  271. for i in range(len(curBlock)):
  272. for j in range(len(curBlock[i])):
  273. if A[i][j+5] == EMPTY:
  274. A[i][j+5] = curBlock[i][j]
  275. if A[i][j+5] in OPENINGSFALLEN:
  276. Ded()
  277.  
  278.  
  279. #Just display in here. Do not modify the computations in this function
  280. def updateDisplay():
  281. global UNSPEC, BLOCKS, OPENINGS, OPENINGSFALLEN, EMPTY, WHITE, BGIMG, RED, OPENINGSIMGS, OPENINGSFALLENIMGS, PLAYERIMG, getpos, GIFTIMG, BLACK, checkMovePlayer, checkMove, moveBlock, RotateBlock, CheckRotate, MovePlayer, IFEL, deleteLines, dropAll, setup
  282. global A
  283. global FONT
  284. SCREEN.fill(WHITE)
  285. SCREEN.blit(BGIMG,(0,0))
  286.  
  287. cubz = 33
  288. for i in range(totLengthX):
  289. for j in range(totLengthY):
  290. if A[i][j] == WALL:
  291. pygame.draw.rect(SCREEN, RED, pygame.Rect(j*(cubz+2)+cubz+200, i*(cubz+2)+cubz+130, cubz, cubz))
  292. elif(A[i][j] in OPENINGS):
  293. p = getpos(A[i][j], OPENINGS)-1
  294. SCREEN.blit(OPENINGSIMGS[p],(j*(cubz+2)+cubz+200, i*(cubz+2)+cubz+130))
  295. elif(A[i][j] in OPENINGSFALLEN):
  296. p = getpos(A[i][j], OPENINGSFALLEN)-1
  297. SCREEN.blit(OPENINGSFALLENIMGS[p],(j*(cubz+2)+cubz+200, i*(cubz+2)+cubz+130))
  298. SCREEN.blit(PLAYERIMG, ((curXPlayer*(cubz+2)+cubz+200, (curYPlayer-1)*(cubz+2)+cubz+130)))
  299. for i in range(AMOUNTGIFTS):
  300. SCREEN.blit(GIFTIMG, ((AllGifts[i].y * (cubz + 2) + cubz + 200, (AllGifts[i].x - 1) * (cubz + 2) + cubz + 130)))
  301. scoreDisp = FONT.render(str("Score: ") + str(Score) + "/" + str(MAXSCORE), True, (BLACK), SCREEN)
  302. SCREEN.blit(scoreDisp, (1400, 600))
  303.  
  304. pygame.display.flip()
  305.  
  306.  
  307. #Just computations in here. Do not modify the display in this function.
  308. def updateComputations():
  309. global A
  310. global lengthXBlock, lengthYBlock
  311. global countmodifier
  312. global curXPlayer, curYPlayer
  313. global Score
  314. lengthXBlock = len(curBlock[0])
  315. lengthYBlock = len(curBlock)
  316.  
  317. if Score >= MAXSCORE:
  318. YouWin()
  319.  
  320. global count, cooldownCount
  321. keys = pygame.key.get_pressed()
  322. #left
  323. if keys[pygame.K_a] and cooldownCount == 5:
  324. cooldownCount = 0
  325. if (checkMove(1)):
  326. moveBlock(1)
  327. #right
  328. elif keys[pygame.K_d] and cooldownCount == 5:
  329. cooldownCount = 0
  330. if (checkMove(2)):
  331. moveBlock(2)
  332. #rotate
  333. elif keys[pygame.K_w] and cooldownCount == 5:
  334. cooldownCount = 0
  335. print(CheckRotate())
  336. if (CheckRotate()):
  337. RotateBlock()
  338. lengthXBlock = len(curBlock[0])
  339. lengthYBlock = len(curBlock)
  340. elif keys[pygame.K_UP] and cooldownCount == 5:
  341. cooldownCount = 0
  342. if checkMovePlayer(0):
  343. MovePlayer(0)
  344. elif keys[pygame.K_LEFT] and cooldownCount == 5:
  345. cooldownCount = 0
  346. if checkMovePlayer(1):
  347. MovePlayer(1)
  348. elif keys[pygame.K_DOWN] and cooldownCount == 5:
  349. cooldownCount = 0
  350. if checkMovePlayer(2):
  351. MovePlayer(2)
  352. elif keys[pygame.K_RIGHT] and cooldownCount == 5:
  353. cooldownCount = 0
  354. if checkMovePlayer(3):
  355. MovePlayer(3)
  356. #Main menu
  357. elif keys[pygame.K_ESCAPE]:
  358. pygame.mixer.music.pause()
  359. exec(open('Test.py').read())
  360. pygame.QUIT
  361. #reset
  362. elif keys[pygame.K_r]:
  363. A = [["00" for j in range(12)] for i in range(21)]
  364. Score = 0
  365. curXPlayer = 5
  366. curYPlayer = 20
  367. setup()
  368. #Mute
  369. elif keys[pygame.K_m]:
  370. if pygame.mixer.music.get_volume() == 0:
  371. pygame.mixer.music.set_volume(0.5)
  372. else:
  373. pygame.mixer.music.set_volume(0)
  374. elif keys[pygame.K_h]:
  375. HelpPlay()
  376. #fastdrop
  377. elif keys[pygame.K_s]:
  378. countmodifier = 5
  379. elif not keys[pygame.K_s]:
  380. countmodifier = 1
  381.  
  382. if cooldownCount < 5:
  383. cooldownCount = cooldownCount + 1
  384.  
  385.  
  386. if count < FPS/(2*countmodifier):
  387. count = count + 1
  388. if count >= FPS/(2*countmodifier):
  389. count = 0
  390. if (checkMove(0)):
  391. moveBlock(0)
  392. else:
  393. IFEL()
  394. spawnBlock(randint(0,len(BLOCKS)-1))
  395.  
  396. for i in range(AMOUNTGIFTS):
  397. if AllGifts[i].y == curXPlayer and AllGifts[i].x == curYPlayer:
  398. AllGifts[i].giftGet()
  399. AllGifts.pop(i)
  400. AllGifts.append(Gift())
  401.  
  402. checkMovePlayer(-1)
  403.  
  404. # 0 = down
  405. # 1 = left
  406. # 2 = right
  407. def checkMove(direction):
  408. move = False
  409. for i in range(lengthYBlock):
  410. for j in range(lengthXBlock):
  411. if(curBlock[i][j] in OPENINGS):
  412. #Down
  413. if (direction == 0):
  414. if ((A[i+curY1Block+1][j+curX1Block] == WALL or A[i+curY1Block+1][j+curX1Block] in OPENINGSFALLEN)):
  415. return False
  416. else:
  417. move = True
  418. #Left
  419. elif (direction == 1):
  420. if ((A[i+curY1Block][j+curX1Block-1] == WALL or A[i+curY1Block][j+curX1Block-1] in OPENINGSFALLEN)):
  421. return False
  422. else:
  423. move = True
  424. #Right
  425. elif (direction == 2):
  426. if ((A[i+curY1Block][j+curX1Block+1] == WALL or A[i+curY1Block][j+curX1Block+1] in OPENINGSFALLEN)):
  427. return False
  428. else:
  429. move = True
  430.  
  431. return move
  432.  
  433. # 0 = down
  434. # 1 = left
  435. # 2 = right
  436. def moveBlock(direction):
  437. global A
  438. global curX1Block, curY1Block, curX2Block, curY2Block
  439. for i in range(curX2Block-curX1Block):
  440. for j in range(curY2Block-curY1Block):
  441. if A[curY1Block + j][curX1Block + i] in OPENINGS:
  442. A[curY1Block + j][curX1Block + i] = EMPTY
  443. #Down
  444. if (direction == 0):
  445. for i in range(curX2Block-curX1Block):
  446. for j in range(curY2Block-curY1Block):
  447. if not curBlock[j][i] == EMPTY:
  448. A[curY1Block+j+1][curX1Block+i] = curBlock[j][i]
  449. curY1Block = curY1Block+1
  450. curY2Block = curY2Block+1
  451. #Left
  452. if (direction == 1):
  453. for i in range(curX2Block-curX1Block):
  454. for j in range(curY2Block-curY1Block):
  455. if not curBlock[j][i] == EMPTY:
  456. A[curY1Block+j][curX1Block+i-1] = curBlock[j][i]
  457. curX1Block = curX1Block-1
  458. curX2Block = curX2Block-1
  459. #Right
  460. if (direction == 2):
  461. for i in range(curX2Block-curX1Block):
  462. for j in range(curY2Block-curY1Block):
  463. if not curBlock[j][i] == EMPTY:
  464. A[curY1Block+j][curX1Block+i+1] = curBlock[j][i]
  465. curX1Block = curX1Block+1
  466. curX2Block = curX2Block+1
  467.  
  468. def CheckRotate():
  469. x = False
  470. if curY2Block > totLengthX-lengthXBlock+1:
  471. return False
  472. else:
  473. x = True
  474. if curX2Block > totLengthY-lengthYBlock+1:
  475. return False
  476. else:
  477. x = True
  478. return x
  479.  
  480. def RotateBlock():
  481. global curBlock
  482. global lengthXBlock, lengthYBlock
  483. global curX1Block, curY1Block, curX2Block, curY2Block
  484. tempBlock = [["00" for j in range(lengthYBlock)] for i in range(lengthXBlock)]
  485. print(tempBlock)
  486. print(curBlock)
  487. x = 0
  488. y = 0
  489. for i in range(curX2Block-curX1Block):
  490. for j in range(curY2Block-curY1Block):
  491. if curBlock[j][i] in OPENINGS and not curBlock[j][i] == "SOLID":
  492. if curBlock[j][i] == "WE":
  493. curBlock[j][i] = "NS"
  494. elif curBlock[j][i] == "NS":
  495. curBlock[j][i] = "WE"
  496. elif curBlock[j][i] == "NE":
  497. curBlock[j][i] = "SE"
  498. elif curBlock[j][i] == "SE":
  499. curBlock[j][i] = "WS"
  500. elif curBlock[j][i] == "WS":
  501. curBlock[j][i] = "NW"
  502. elif curBlock[j][i] == "NW":
  503. curBlock[j][i] = "NE"
  504.  
  505. for i in curBlock:
  506. y = 0
  507. for j in i:
  508. tempBlock[y][x] = curBlock[len(curBlock)-x-1][y]
  509. y = y + 1
  510. x = x + 1
  511. for i in range(totLengthX):
  512. for j in range(totLengthY):
  513. if A[i][j] in OPENINGS:
  514. A[i][j] = EMPTY
  515.  
  516. print(tempBlock)
  517. curBlock = tempBlock
  518. lengthXBlock = len(curBlock[0])
  519. lengthYBlock = len(curBlock)
  520.  
  521. tempvar = curX2Block
  522. curX2Block = curX1Block+lengthXBlock
  523. curY2Block = curY1Block+lengthYBlock
  524. for i in range(curX2Block-curX1Block):
  525. for j in range(curY2Block-curY1Block):
  526. A[curY1Block+j][curX1Block+i] = curBlock[j][i]
  527. #0 = Up
  528. #1 = Left
  529. #2 = Down
  530. #3 = Right
  531. def checkMovePlayer(direction):
  532. global curYPlayer, curXPlayer
  533. PlayerBlock = (A[curYPlayer-1][curXPlayer])
  534. P1 = False
  535. if PlayerBlock == EMPTY:
  536. if A[curYPlayer][curXPlayer] == EMPTY:
  537. MovePlayer(2)
  538. return False
  539. if direction == 1 and A[curYPlayer-1][curXPlayer-1] in OPENINGSFALLEN and A[curYPlayer-2][curXPlayer-1] == EMPTY:
  540. curXPlayer = curXPlayer - 1
  541. curYPlayer = curYPlayer - 1
  542. return False
  543. if direction == 3 and A[curYPlayer-1][curXPlayer+1] in OPENINGSFALLEN and A[curYPlayer-2][curXPlayer+1] == EMPTY:
  544. curXPlayer = curXPlayer + 1
  545. curYPlayer = curYPlayer - 1
  546. return False
  547. P1 = True
  548. elif direction == 0 and (PlayerBlock == "NEa" or PlayerBlock == "NSa" or PlayerBlock == "NWa"):
  549. P1 = True
  550. print("True")
  551. elif direction == 1 and (PlayerBlock == "NWa" or PlayerBlock == "WEa" or PlayerBlock == "WSa"):
  552. P1 = True
  553. print("True")
  554. elif direction == 2 and (PlayerBlock == "NSa" or PlayerBlock == "SEa" or PlayerBlock == "WSa"):
  555. P1 = True
  556. print("True")
  557. elif direction == 3 and (PlayerBlock == "NEa" or PlayerBlock == "WEa" or PlayerBlock == "SEa"):
  558. P1 = True
  559. print("True")
  560.  
  561.  
  562. if (P1):
  563. DestBlock = "0"
  564. if direction == 0:
  565. DestBlock = A[curYPlayer-2][curXPlayer]
  566. if PlayerBlock == EMPTY and DestBlock == EMPTY:
  567. return False
  568. if DestBlock == "NSa" or DestBlock == "SEa" or DestBlock == "WSa":
  569. return True
  570. if direction == 1:
  571. DestBlock = A[curYPlayer-1][curXPlayer-1]
  572. if DestBlock == "NEa" or DestBlock == "WEa" or DestBlock == "SEa":
  573. return True
  574. if direction == 2:
  575. DestBlock = A[curYPlayer][curXPlayer]
  576. if DestBlock == "NEa" or DestBlock == "NSa" or DestBlock == "NWa":
  577. return True
  578. if direction == 3:
  579. DestBlock = A[curYPlayer-1][curXPlayer+1]
  580. if DestBlock == "NWa" or DestBlock == "WEa" or DestBlock == "WSa":
  581. return True
  582. if DestBlock == EMPTY:
  583. return True
  584. return False
  585.  
  586.  
  587.  
  588. #0 = Up
  589. #1 = Left
  590. #2 = Down
  591. #3 = Right
  592. def MovePlayer(direction):
  593. global curYPlayer, curXPlayer
  594. if direction == 0:
  595. curYPlayer = curYPlayer - 1
  596. if direction == 1:
  597. curXPlayer = curXPlayer - 1
  598. if direction == 2:
  599. curYPlayer = curYPlayer + 1
  600. if direction == 3:
  601. curXPlayer = curXPlayer + 1
  602.  
  603. #IFEL over LIFE. Welcome to the cringe cave.
  604. def IFEL():
  605. print("IFAL")
  606. for i in range(curX2Block-curX1Block):
  607. for j in range(curY2Block-curY1Block):
  608. CurPos = getpos(curBlock[j][i], OPENINGS)
  609. if (curBlock[j][i] in OPENINGS):
  610. A[curY1Block + j][curX1Block + i] = OPENINGSFALLEN[CurPos-1]
  611. deleteLines()
  612. print("IFEL")
  613.  
  614. def deleteLines():
  615. global curYPlayer, curXPlayer
  616. AmountEmpty = [0 for j in range(totLengthX-1)]
  617. for i in range(totLengthX-1):
  618. AmountEmpty[i] = 0
  619. for j in range(totLengthY):
  620. if A[i][j] == EMPTY:
  621. AmountEmpty[i] = AmountEmpty[i] + 1
  622. print(AmountEmpty)
  623. k = 0
  624. h = 0
  625. global Score
  626. for i in AmountEmpty:
  627. if i == 0:
  628. for j in range(totLengthY):
  629. if not A[k][j] == WALL:
  630. A[k][j] = EMPTY
  631. dropAll(k-1)
  632. h = h + 1
  633. k = k + 1
  634. Score = Score + h
  635.  
  636. def dropAll(line):
  637. for i in range(line):
  638. for j in range(1, totLengthY-1):
  639. if not (A[line-i+1][j] == WALL):
  640. A[line - i+1][j] = A[line-i][j]
  641. A[line - i][j] = EMPTY
  642.  
  643. #F
  644. def Ded():
  645. pygame.mixer.music.pause()
  646. WinImg = pygame.image.load("Tetded.png")
  647. global SCREEN
  648. keys = pygame.key.get_pressed()
  649. SCREEN.blit(WinImg,(0,0))
  650. pygame.display.flip()
  651. if (keys[pygame.K_ESCAPE]):
  652. exec(open('Test.py').read())
  653. CLOCK.tick(FPS)
  654.  
  655. def YouWin():
  656. pygame.mixer.music.pause()
  657. WinImg = pygame.image.load("Tetwin.png")
  658. global SCREEN
  659. keys = pygame.key.get_pressed()
  660. SCREEN.blit(WinImg,(0,0))
  661. pygame.display.flip()
  662. if (keys[pygame.K_ESCAPE]):
  663. exec(open('Test.py').read())
  664. CLOCK.tick(FPS)
  665.  
  666.  
  667.  
  668.  
  669. def HelpPlay():
  670. pygame.mixer.music.pause()
  671. exec(open('tethelp.py').read())
  672.  
  673.  
  674. #Main
  675. setup()
  676.  
  677. while running:
  678. for event in pygame.event.get():
  679. if event.type == pygame.QUIT:
  680. running = False
  681.  
  682. updateDisplay()
  683. updateComputations()
  684. CLOCK.tick(FPS)
  685.  
  686. pygame.QUIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement