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.

86 lines
2.0KB

  1. import arcade
  2. CELL = 25
  3. HEIGHT = 600
  4. WIDTH = 900
  5. images = [
  6. ["res/tiles_0.png", 0, 0, 75, 100],
  7. ["res/tiles_0.png", 75, 0, 75, 100],
  8. ["res/tiles_1.png", 0, 0, 75, 100],
  9. ]
  10. positions = [
  11. [9, 1],
  12. [14, 1],
  13. [19, 1],
  14. [24, 1],
  15. [9, 7],
  16. [14, 7],
  17. [19, 7],
  18. [24, 7],
  19. [9, 13],
  20. [14, 13],
  21. [19, 13],
  22. [24, 13],
  23. [9, 19],
  24. [14, 19],
  25. [19, 19],
  26. [24, 19],
  27. ]
  28. textures = None
  29. deselected_tiles = []
  30. selected_tiles = []
  31. class Window(arcade.Window):
  32. def __init__(self):
  33. super().__init__(WIDTH, HEIGHT, "OGS Memory")
  34. arcade.set_background_color(arcade.color.WHITE)
  35. self.all_sprites = arcade.SpriteList()
  36. textures = load_textures(images)
  37. deselected_tiles = create_deselected_tiles(positions, textures)
  38. for t in deselected_tiles:
  39. self.all_sprites.append(t)
  40. #selected_tiles = create_selected_tiles(positions, textures)
  41. def on_draw(self):
  42. arcade.start_render()
  43. self.all_sprites.draw()
  44. def on_mouse_press(self, x, y, button, key_modifiers):
  45. print("click", x, y)
  46. sprites = arcade.get_sprites_at_point([x, y], self.all_sprites)
  47. if len(sprites) == 1:
  48. print("selected: ", sprites[0].guid)
  49. def on_update(self, delta):
  50. self.all_sprites.update_animation()
  51. def load_textures(images):
  52. ts = []
  53. for (id, img) in enumerate(images):
  54. tex = arcade.load_texture(img[0], x = img[1], y = img[2], width = img[3], height = img[4])
  55. ts.append(tex)
  56. return ts
  57. def create_deselected_tiles(positions, textures):
  58. tiles = []
  59. for (id, p) in enumerate(positions):
  60. tile = arcade.AnimatedTimeBasedSprite()
  61. tiles.append(tile)
  62. tile.guid = id
  63. tile.texture = textures[0]
  64. # Animation between two textures.
  65. a1 = arcade.sprite.AnimationKeyframe(0, 700, textures[0])
  66. a2 = arcade.sprite.AnimationKeyframe(1, 700, textures[1])
  67. tile.frames.append(a1)
  68. tile.frames.append(a2)
  69. # Position.
  70. tile.center_x = CELL * 2 + p[0] * CELL
  71. tile.center_y = HEIGHT - CELL * 2 - p[1] * CELL
  72. return tiles