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.

169 lines
3.8KB

  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. # Load tile textures
  105. def desktop_loadTextures(p):
  106. texs = []
  107. for (id, td) in enumerate(p.c.textureDescriptions):
  108. tex = arcade.load_texture(
  109. td.fileName,
  110. x = td.x,
  111. y = td.y,
  112. width = td.width,
  113. height = td.height
  114. )
  115. texs.append(tex)
  116. #}
  117. p.textures = texs
  118. #}
  119. # Load tiTLe textures
  120. def desktop_loadTitleTextures(p):
  121. texs = []
  122. for (id, td) in enumerate(p.c.titleTextureDescriptions):
  123. tex = arcade.load_texture(
  124. td.fileName,
  125. x = td.x,
  126. y = td.y,
  127. width = td.width,
  128. height = td.height
  129. )
  130. texs.append(tex)
  131. #}
  132. p.titleTextures = texs
  133. #}
  134. # Postpone deselection of mismatched tiles for better UX
  135. #
  136. # Conditions:
  137. # 1. a pair of tiles has been mismatched
  138. def desktop_scheduleDeselectionOfMismatchedTiles(p):
  139. if (
  140. p.c.recentField == "mismatchedItems"
  141. ):
  142. p.sequentialTimer.schedule("deselectMismatchedTiles", True, p.c.deselectMismatchedTilesDelay)
  143. #}
  144. #}
  145. # Postpone hiding of matching tiles for better UX
  146. #
  147. # Conditions:
  148. # 1. a pair of tiles has been matched
  149. def desktop_scheduleHidingOfMatchingTiles(p):
  150. if (
  151. p.c.recentField == "hiddenItems"
  152. ):
  153. p.sequentialTimer.schedule("hideMatchingTiles", True, p.c.hideMatchingTilesDelay)
  154. #}
  155. #}