Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.0KB

  1. import arcade
  2. from gui_aux import *
  3. from desktop_Platform import *
  4. def desktop_createDeselectedTiles(p):
  5. for (id, pos) in enumerate(p.c.tilePositions):
  6. tile = arcade.AnimatedTimeBasedSprite()
  7. p.deselectedTiles.append(tile)
  8. p.deselectedSprites.append(tile)
  9. tile.guid = id
  10. tile.texture = p.textures[0]
  11. # Animation between two textures.
  12. a1 = arcade.sprite.AnimationKeyframe(0, 700, p.textures[0])
  13. a2 = arcade.sprite.AnimationKeyframe(1, 700, p.textures[1])
  14. tile.frames.append(a1)
  15. tile.frames.append(a2)
  16. # Position.
  17. tile.left = pos[0]
  18. tile.top = pos[1]
  19. #}
  20. #}
  21. def desktop_createSelectedTiles(p):
  22. for (id, pos) in enumerate(p.c.tilePositions):
  23. tile = arcade.Sprite()
  24. p.selectedTiles.append(tile)
  25. p.selectedSprites.append(tile)
  26. tile.guid = id
  27. tile.texture = p.textures[2 + p.c.playfieldItems[id]]
  28. # Position.
  29. tile.left = pos[0]
  30. tile.top = pos[1]
  31. # Invisible by default.
  32. tile.visible = False
  33. #}
  34. #}
  35. def desktop_createTitle(p):
  36. p.title = arcade.Sprite()
  37. p.titleSprites.append(p.title)
  38. p.title.texture = p.titleTextures[0]
  39. # Position.
  40. pos = gui_aux_cellScreenPosition(p.c, p.c.titlePosition)
  41. p.title.left = pos[0]
  42. p.title.top = pos[1]
  43. # Invisible by default.
  44. p.title.visible = False
  45. #}
  46. # Deselect mismatched tiles
  47. #
  48. # Conditions:
  49. # 1. Time to deselect mismatched items
  50. def desktop_deselectMismatchedTiles(p):
  51. if (
  52. p.c.recentField == "deselectMismatchedTiles"
  53. ):
  54. for id in p.c.mismatchedItems:
  55. p.deselectedTiles[id].visible = True
  56. p.selectedTiles[id].visible = False
  57. #}
  58. #}
  59. #}
  60. # Hide deselected tile and show selected one
  61. #
  62. # Conditions:
  63. # 1. tile has just been selected
  64. def desktop_displaySelectedTile(p):
  65. if (
  66. p.c.recentField == "selectedId"
  67. ):
  68. id = p.c.selectedId
  69. p.deselectedTiles[id].visible = False
  70. p.selectedTiles[id].visible = True
  71. #}
  72. #}
  73. # Display title for the first selected tile
  74. #
  75. # Conditions:
  76. # 1. tile has just been selected and it's the first one in pair
  77. def desktop_displayTitle(p):
  78. if (
  79. p.c.recentField == "selectedId" and
  80. (
  81. len(p.c.selectedItems) == 0 or
  82. len(p.c.selectedItems) == 2
  83. )
  84. ):
  85. gid = p.c.playfieldItems[p.c.selectedId]
  86. p.title.texture = p.titleTextures[gid]
  87. p.title.visible = True
  88. #}
  89. #}
  90. # Hide matching tiles
  91. #
  92. # Conditions:
  93. # 1. Time to hide matching items
  94. def desktop_hideMatchingTiles(p):
  95. if (
  96. p.c.recentField == "hideMatchingTiles"
  97. ):
  98. for id in p.c.selectedItems:
  99. p.deselectedTiles[id].visible = False
  100. p.selectedTiles[id].visible = False
  101. #}
  102. #}
  103. #}
  104. # Hide title
  105. #
  106. # Conditions:
  107. # 1. tiles has been scheduled to hide after being matched or just mismatched
  108. def desktop_hideTitle(p):
  109. if (
  110. p.c.recentField == "hideMatchingTiles" or
  111. p.c.recentField == "mismatchedItems"
  112. ):
  113. p.title.visible = False
  114. #}
  115. #}
  116. # Load tile textures
  117. def desktop_loadTextures(p):
  118. texs = []
  119. for (id, td) in enumerate(p.c.textureDescriptions):
  120. tex = arcade.load_texture(
  121. td.fileName,
  122. x = td.x,
  123. y = td.y,
  124. width = td.width,
  125. height = td.height
  126. )
  127. texs.append(tex)
  128. #}
  129. p.textures = texs
  130. #}
  131. # Load tiTLe textures
  132. def desktop_loadTitleTextures(p):
  133. texs = []
  134. for (id, td) in enumerate(p.c.titleTextureDescriptions):
  135. tex = arcade.load_texture(
  136. td.fileName,
  137. x = td.x,
  138. y = td.y,
  139. width = td.width,
  140. height = td.height
  141. )
  142. texs.append(tex)
  143. #}
  144. p.titleTextures = texs
  145. #}
  146. # Postpone deselection of mismatched tiles for better UX
  147. #
  148. # Conditions:
  149. # 1. a pair of tiles has been mismatched
  150. def desktop_scheduleDeselectionOfMismatchedTiles(p):
  151. if (
  152. p.c.recentField == "mismatchedItems"
  153. ):
  154. p.sequentialTimer.schedule("deselectMismatchedTiles", True, p.c.deselectMismatchedTilesDelay)
  155. #}
  156. #}
  157. # Postpone hiding of matching tiles for better UX
  158. #
  159. # Conditions:
  160. # 1. a pair of tiles has been matched
  161. def desktop_scheduleHidingOfMatchingTiles(p):
  162. if (
  163. p.c.recentField == "hiddenItems"
  164. ):
  165. p.sequentialTimer.schedule("hideMatchingTiles", True, p.c.hideMatchingTilesDelay)
  166. #}
  167. #}