Research portable Memory game | Исследовать портируемую игру Память
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

318 рядки
6.9KB

  1. import arcade
  2. from gui_aux import *
  3. from desktop_Platform import *
  4. def desktop_createDesc(p):
  5. p.desc = arcade.Sprite()
  6. p.descSprites.append(p.desc)
  7. p.desc.texture = p.descTextures[0]
  8. # Position.
  9. pos = gui_aux_cellScreenPosition(p.c, p.c.descPosition)
  10. p.desc.left = pos[0]
  11. p.desc.top = pos[1]
  12. # Invisible by default.
  13. p.desc.visible = False
  14. #}
  15. def desktop_createDeselectedTiles(p):
  16. for (id, pos) in enumerate(p.c.tilePositions):
  17. tile = arcade.AnimatedTimeBasedSprite()
  18. p.deselectedTiles.append(tile)
  19. p.deselectedSprites.append(tile)
  20. tile.guid = id
  21. tile.texture = p.textures[0]
  22. # Animation between two textures.
  23. a1 = arcade.sprite.AnimationKeyframe(0, 700, p.textures[0])
  24. a2 = arcade.sprite.AnimationKeyframe(1, 700, p.textures[1])
  25. tile.frames.append(a1)
  26. tile.frames.append(a2)
  27. # Position.
  28. tile.left = pos[0]
  29. tile.top = pos[1]
  30. #}
  31. #}
  32. def desktop_createSelectedTiles(p):
  33. for (id, pos) in enumerate(p.c.tilePositions):
  34. tile = arcade.Sprite()
  35. p.selectedTiles.append(tile)
  36. p.selectedSprites.append(tile)
  37. tile.guid = id
  38. tile.texture = p.textures[2 + p.c.playfieldItems[id]]
  39. # Position.
  40. tile.left = pos[0]
  41. tile.top = pos[1]
  42. # Invisible by default.
  43. tile.visible = False
  44. #}
  45. #}
  46. def desktop_createSplash(p):
  47. p.splash = arcade.Sprite()
  48. p.splashSprites.append(p.splash)
  49. p.splash.texture = p.splashTextures[0]
  50. # Position.
  51. pos = gui_aux_cellScreenPosition(p.c, [0, 0])
  52. p.splash.left = pos[0]
  53. p.splash.top = pos[1]
  54. #}
  55. def desktop_createTitle(p):
  56. p.title = arcade.Sprite()
  57. p.titleSprites.append(p.title)
  58. p.title.texture = p.titleTextures[0]
  59. # Position.
  60. pos = gui_aux_cellScreenPosition(p.c, p.c.titlePosition)
  61. p.title.left = pos[0]
  62. p.title.top = pos[1]
  63. # Invisible by default.
  64. p.title.visible = False
  65. #}
  66. # Deselect mismatched tiles
  67. #
  68. # Conditions:
  69. # 1. Time to deselect mismatched items
  70. def desktop_deselectMismatchedTiles(p):
  71. if (
  72. p.c.recentField == "deselectMismatchedTiles"
  73. ):
  74. for id in p.c.mismatchedItems:
  75. p.deselectedTiles[id].visible = True
  76. p.selectedTiles[id].visible = False
  77. #}
  78. #}
  79. #}
  80. # Display description for the first selected tile
  81. #
  82. # Conditions:
  83. # 1. tile has just been selected and it's the first one in pair
  84. def desktop_displayDesc(p):
  85. if (
  86. p.c.recentField == "selectedId" and
  87. (
  88. len(p.c.selectedItems) == 0 or
  89. len(p.c.selectedItems) == 2
  90. )
  91. ):
  92. gid = p.c.playfieldItems[p.c.selectedId]
  93. p.desc.texture = p.descTextures[gid]
  94. p.desc.visible = True
  95. #}
  96. #}
  97. # Display ending splash screen
  98. #
  99. # Conditions:
  100. # 1. Time to display victory screen
  101. def desktop_displayEndingSplashScreen(p):
  102. if (
  103. p.c.recentField == "displayEndingSplashScreen"
  104. ):
  105. p.splash.texture = p.splashTextures[1]
  106. p.splash.visible = True
  107. #}
  108. #}
  109. # Hide deselected tile and show selected one
  110. #
  111. # Conditions:
  112. # 1. tile has just been selected
  113. def desktop_displaySelectedTile(p):
  114. if (
  115. p.c.recentField == "selectedId"
  116. ):
  117. id = p.c.selectedId
  118. p.deselectedTiles[id].visible = False
  119. p.selectedTiles[id].visible = True
  120. #}
  121. #}
  122. # Display title for the first selected tile
  123. #
  124. # Conditions:
  125. # 1. tile has just been selected and it's the first one in pair
  126. def desktop_displayTitle(p):
  127. if (
  128. p.c.recentField == "selectedId" and
  129. (
  130. len(p.c.selectedItems) == 0 or
  131. len(p.c.selectedItems) == 2
  132. )
  133. ):
  134. gid = p.c.playfieldItems[p.c.selectedId]
  135. p.title.texture = p.titleTextures[gid]
  136. p.title.visible = True
  137. #}
  138. #}
  139. # Hide beginning splash screen
  140. #
  141. # Conditions:
  142. # 1. Time to hide
  143. def desktop_hideBeginningSplashScreen(p):
  144. if (
  145. p.c.recentField == "hideBeginningSplashScreen"
  146. ):
  147. p.splash.visible = False
  148. #}
  149. #}
  150. # Hide description
  151. #
  152. # Conditions:
  153. # 1. tiles has been mismatched or timed out to to hide after matching
  154. def desktop_hideDesc(p):
  155. if (
  156. p.c.recentField == "hideMatchingTiles" or
  157. p.c.recentField == "mismatchedItems"
  158. ):
  159. p.desc.visible = False
  160. #}
  161. #}
  162. # Hide matching tiles
  163. #
  164. # Conditions:
  165. # 1. Time to hide matching items
  166. def desktop_hideMatchingTiles(p):
  167. if (
  168. p.c.recentField == "hideMatchingTiles"
  169. ):
  170. for id in p.c.selectedItems:
  171. p.deselectedTiles[id].visible = False
  172. p.selectedTiles[id].visible = False
  173. #}
  174. #}
  175. #}
  176. # Hide title
  177. #
  178. # Conditions:
  179. # 1. tiles has been mismatched or timed out to to hide after matching
  180. def desktop_hideTitle(p):
  181. if (
  182. p.c.recentField == "hideMatchingTiles" or
  183. p.c.recentField == "mismatchedItems"
  184. ):
  185. p.title.visible = False
  186. #}
  187. #}
  188. # Load description textures
  189. def desktop_loadDescTextures(p):
  190. texs = []
  191. for (id, td) in enumerate(p.c.descTextureDescriptions):
  192. tex = arcade.load_texture(
  193. td.fileName,
  194. x = td.x,
  195. y = td.y,
  196. width = td.width,
  197. height = td.height
  198. )
  199. texs.append(tex)
  200. #}
  201. p.descTextures = texs
  202. #}
  203. # Load beginning and ending textures
  204. def desktop_loadSplashTextures(p):
  205. texs = []
  206. for (id, td) in enumerate(p.c.splashTextureDescriptions):
  207. tex = arcade.load_texture(
  208. td.fileName,
  209. x = td.x,
  210. y = td.y,
  211. width = td.width,
  212. height = td.height
  213. )
  214. texs.append(tex)
  215. print(f"desktop_loadST: '{tex}'")
  216. #}
  217. p.splashTextures = texs
  218. #}
  219. # Load tile textures
  220. def desktop_loadTextures(p):
  221. texs = []
  222. for (id, td) in enumerate(p.c.textureDescriptions):
  223. tex = arcade.load_texture(
  224. td.fileName,
  225. x = td.x,
  226. y = td.y,
  227. width = td.width,
  228. height = td.height
  229. )
  230. texs.append(tex)
  231. #}
  232. p.textures = texs
  233. #}
  234. # Load tiTLe textures
  235. def desktop_loadTitleTextures(p):
  236. texs = []
  237. for (id, td) in enumerate(p.c.titleTextureDescriptions):
  238. tex = arcade.load_texture(
  239. td.fileName,
  240. x = td.x,
  241. y = td.y,
  242. width = td.width,
  243. height = td.height
  244. )
  245. texs.append(tex)
  246. #}
  247. p.titleTextures = texs
  248. #}
  249. # Postpone deselection of mismatched tiles for better UX
  250. #
  251. # Conditions:
  252. # 1. a pair of tiles has been mismatched
  253. def desktop_scheduleDeselectionOfMismatchedTiles(p):
  254. if (
  255. p.c.recentField == "mismatchedItems"
  256. ):
  257. p.sequentialTimer.schedule("deselectMismatchedTiles", True, p.c.deselectMismatchedTilesDelay)
  258. #}
  259. #}
  260. # Postpone display of the ending splash screen
  261. #
  262. # Conditions:
  263. # 1. just finished removing all tiles
  264. def desktop_scheduleDisplayOfEndingSplashScreen(p):
  265. if (
  266. p.c.recentField == "victory"
  267. ):
  268. p.sequentialTimer.schedule("displayEndingSplashScreen", True, p.c.splashEndDelay)
  269. #}
  270. #}
  271. # Postpone hiding of matching tiles for better UX
  272. #
  273. # Conditions:
  274. # 1. a pair of tiles has been matched
  275. def desktop_scheduleHidingOfMatchingTiles(p):
  276. if (
  277. p.c.recentField == "hiddenItems"
  278. ):
  279. p.sequentialTimer.schedule("hideMatchingTiles", True, p.c.hideMatchingTilesDelay)
  280. #}
  281. #}
  282. # Postpone hiding of the beginning splash screen
  283. #
  284. # Conditions:
  285. # 1. just launched the game
  286. def desktop_scheduleHidingOfBeginningSplashScreen(p):
  287. if (
  288. p.c.recentField == "splashBeginTimeout"
  289. ):
  290. p.sequentialTimer.schedule("hideBeginningSplashScreen", True, p.c.splashBeginTimeout)
  291. #}
  292. #}