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

241 рядки
5.3KB

  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_createTitle(p):
  47. p.title = arcade.Sprite()
  48. p.titleSprites.append(p.title)
  49. p.title.texture = p.titleTextures[0]
  50. # Position.
  51. pos = gui_aux_cellScreenPosition(p.c, p.c.titlePosition)
  52. p.title.left = pos[0]
  53. p.title.top = pos[1]
  54. # Invisible by default.
  55. p.title.visible = False
  56. #}
  57. # Deselect mismatched tiles
  58. #
  59. # Conditions:
  60. # 1. Time to deselect mismatched items
  61. def desktop_deselectMismatchedTiles(p):
  62. if (
  63. p.c.recentField == "deselectMismatchedTiles"
  64. ):
  65. for id in p.c.mismatchedItems:
  66. p.deselectedTiles[id].visible = True
  67. p.selectedTiles[id].visible = False
  68. #}
  69. #}
  70. #}
  71. # Display description for the first selected tile
  72. #
  73. # Conditions:
  74. # 1. tile has just been selected and it's the first one in pair
  75. def desktop_displayDesc(p):
  76. if (
  77. p.c.recentField == "selectedId" and
  78. (
  79. len(p.c.selectedItems) == 0 or
  80. len(p.c.selectedItems) == 2
  81. )
  82. ):
  83. gid = p.c.playfieldItems[p.c.selectedId]
  84. p.desc.texture = p.descTextures[gid]
  85. p.desc.visible = True
  86. #}
  87. #}
  88. # Hide deselected tile and show selected one
  89. #
  90. # Conditions:
  91. # 1. tile has just been selected
  92. def desktop_displaySelectedTile(p):
  93. if (
  94. p.c.recentField == "selectedId"
  95. ):
  96. id = p.c.selectedId
  97. p.deselectedTiles[id].visible = False
  98. p.selectedTiles[id].visible = True
  99. #}
  100. #}
  101. # Display title for the first selected tile
  102. #
  103. # Conditions:
  104. # 1. tile has just been selected and it's the first one in pair
  105. def desktop_displayTitle(p):
  106. if (
  107. p.c.recentField == "selectedId" and
  108. (
  109. len(p.c.selectedItems) == 0 or
  110. len(p.c.selectedItems) == 2
  111. )
  112. ):
  113. gid = p.c.playfieldItems[p.c.selectedId]
  114. p.title.texture = p.titleTextures[gid]
  115. p.title.visible = True
  116. #}
  117. #}
  118. # Hide description
  119. #
  120. # Conditions:
  121. # 1. tiles has been mismatched or timed out to to hide after matching
  122. def desktop_hideDesc(p):
  123. if (
  124. p.c.recentField == "hideMatchingTiles" or
  125. p.c.recentField == "mismatchedItems"
  126. ):
  127. p.desc.visible = False
  128. #}
  129. #}
  130. # Hide matching tiles
  131. #
  132. # Conditions:
  133. # 1. Time to hide matching items
  134. def desktop_hideMatchingTiles(p):
  135. if (
  136. p.c.recentField == "hideMatchingTiles"
  137. ):
  138. for id in p.c.selectedItems:
  139. p.deselectedTiles[id].visible = False
  140. p.selectedTiles[id].visible = False
  141. #}
  142. #}
  143. #}
  144. # Hide title
  145. #
  146. # Conditions:
  147. # 1. tiles has been mismatched or timed out to to hide after matching
  148. def desktop_hideTitle(p):
  149. if (
  150. p.c.recentField == "hideMatchingTiles" or
  151. p.c.recentField == "mismatchedItems"
  152. ):
  153. p.title.visible = False
  154. #}
  155. #}
  156. # Load description textures
  157. def desktop_loadDescTextures(p):
  158. texs = []
  159. for (id, td) in enumerate(p.c.descTextureDescriptions):
  160. tex = arcade.load_texture(
  161. td.fileName,
  162. x = td.x,
  163. y = td.y,
  164. width = td.width,
  165. height = td.height
  166. )
  167. texs.append(tex)
  168. #}
  169. p.descTextures = texs
  170. #}
  171. # Load tile textures
  172. def desktop_loadTextures(p):
  173. texs = []
  174. for (id, td) in enumerate(p.c.textureDescriptions):
  175. tex = arcade.load_texture(
  176. td.fileName,
  177. x = td.x,
  178. y = td.y,
  179. width = td.width,
  180. height = td.height
  181. )
  182. texs.append(tex)
  183. #}
  184. p.textures = texs
  185. #}
  186. # Load tiTLe textures
  187. def desktop_loadTitleTextures(p):
  188. texs = []
  189. for (id, td) in enumerate(p.c.titleTextureDescriptions):
  190. tex = arcade.load_texture(
  191. td.fileName,
  192. x = td.x,
  193. y = td.y,
  194. width = td.width,
  195. height = td.height
  196. )
  197. texs.append(tex)
  198. #}
  199. p.titleTextures = texs
  200. #}
  201. # Postpone deselection of mismatched tiles for better UX
  202. #
  203. # Conditions:
  204. # 1. a pair of tiles has been mismatched
  205. def desktop_scheduleDeselectionOfMismatchedTiles(p):
  206. if (
  207. p.c.recentField == "mismatchedItems"
  208. ):
  209. p.sequentialTimer.schedule("deselectMismatchedTiles", True, p.c.deselectMismatchedTilesDelay)
  210. #}
  211. #}
  212. # Postpone hiding of matching tiles for better UX
  213. #
  214. # Conditions:
  215. # 1. a pair of tiles has been matched
  216. def desktop_scheduleHidingOfMatchingTiles(p):
  217. if (
  218. p.c.recentField == "hiddenItems"
  219. ):
  220. p.sequentialTimer.schedule("hideMatchingTiles", True, p.c.hideMatchingTilesDelay)
  221. #}
  222. #}