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.

151 lines
3.4KB

  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. # Hide matching tiles
  74. #
  75. # Conditions:
  76. # 1. Time to hide matching items
  77. def desktop_hideMatchingTiles(p):
  78. if (
  79. p.c.recentField == "hideMatchingTiles"
  80. ):
  81. for id in p.c.selectedItems:
  82. p.deselectedTiles[id].visible = False
  83. p.selectedTiles[id].visible = False
  84. #}
  85. #}
  86. #}
  87. # Load tile textures
  88. def desktop_loadTextures(p):
  89. texs = []
  90. for (id, td) in enumerate(p.c.textureDescriptions):
  91. tex = arcade.load_texture(
  92. td.fileName,
  93. x = td.x,
  94. y = td.y,
  95. width = td.width,
  96. height = td.height
  97. )
  98. texs.append(tex)
  99. #}
  100. p.textures = texs
  101. #}
  102. # Load tiTLe textures
  103. def desktop_loadTitleTextures(p):
  104. texs = []
  105. for (id, td) in enumerate(p.c.titleTextureDescriptions):
  106. tex = arcade.load_texture(
  107. td.fileName,
  108. x = td.x,
  109. y = td.y,
  110. width = td.width,
  111. height = td.height
  112. )
  113. texs.append(tex)
  114. #}
  115. p.titleTextures = texs
  116. #}
  117. # Postpone deselection of mismatched tiles for better UX
  118. #
  119. # Conditions:
  120. # 1. a pair of tiles has been mismatched
  121. def desktop_scheduleDeselectionOfMismatchedTiles(p):
  122. if (
  123. p.c.recentField == "mismatchedItems"
  124. ):
  125. p.sequentialTimer.schedule("deselectMismatchedTiles", True, p.c.deselectMismatchedTilesDelay)
  126. #}
  127. #}
  128. # Postpone hiding of matching tiles for better UX
  129. #
  130. # Conditions:
  131. # 1. a pair of tiles has been matched
  132. def desktop_scheduleHidingOfMatchingTiles(p):
  133. if (
  134. p.c.recentField == "hiddenItems"
  135. ):
  136. p.sequentialTimer.schedule("hideMatchingTiles", True, p.c.hideMatchingTilesDelay)
  137. #}
  138. #}