d
This commit is contained in:
89
v5/Window.py
89
v5/Window.py
@@ -4,47 +4,54 @@ CELL = 25
|
|||||||
HEIGHT = 600
|
HEIGHT = 600
|
||||||
WIDTH = 900
|
WIDTH = 900
|
||||||
|
|
||||||
images = [
|
class Context:
|
||||||
["res/tiles_0.png", 0, 0, 75, 100],
|
def __init__(self):
|
||||||
["res/tiles_0.png", 75, 0, 75, 100],
|
self.images = [
|
||||||
["res/tiles_1.png", 0, 0, 75, 100],
|
["res/tiles_0.png", 0, 0, 75, 100],
|
||||||
]
|
["res/tiles_0.png", 75, 0, 75, 100],
|
||||||
positions = [
|
["res/tiles_1.png", 0, 0, 75, 100],
|
||||||
[9, 1],
|
]
|
||||||
[14, 1],
|
|
||||||
[19, 1],
|
|
||||||
[24, 1],
|
|
||||||
|
|
||||||
[9, 7],
|
self.positions = [
|
||||||
[14, 7],
|
[9, 1],
|
||||||
[19, 7],
|
[14, 1],
|
||||||
[24, 7],
|
[19, 1],
|
||||||
|
[24, 1],
|
||||||
|
|
||||||
[9, 13],
|
[9, 7],
|
||||||
[14, 13],
|
[14, 7],
|
||||||
[19, 13],
|
[19, 7],
|
||||||
[24, 13],
|
[24, 7],
|
||||||
|
|
||||||
[9, 19],
|
[9, 13],
|
||||||
[14, 19],
|
[14, 13],
|
||||||
[19, 19],
|
[19, 13],
|
||||||
[24, 19],
|
[24, 13],
|
||||||
]
|
|
||||||
textures = None
|
[9, 19],
|
||||||
deselected_tiles = []
|
[14, 19],
|
||||||
selected_tiles = []
|
[19, 19],
|
||||||
|
[24, 19],
|
||||||
|
]
|
||||||
|
self.textures = None
|
||||||
|
self.deselected_tiles = None
|
||||||
|
self.selected_tiles = None
|
||||||
|
|
||||||
class Window(arcade.Window):
|
class Window(arcade.Window):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(WIDTH, HEIGHT, "OGS Memory")
|
super().__init__(WIDTH, HEIGHT, "OGS Memory")
|
||||||
arcade.set_background_color(arcade.color.WHITE)
|
arcade.set_background_color(arcade.color.WHITE)
|
||||||
self.all_sprites = arcade.SpriteList()
|
self.all_sprites = arcade.SpriteList()
|
||||||
|
self.c = Context()
|
||||||
|
c = self.c
|
||||||
|
|
||||||
textures = load_textures(images)
|
c.textures = load_textures(c.images)
|
||||||
deselected_tiles = create_deselected_tiles(positions, textures)
|
c.deselected_tiles = create_deselected_tiles(c.positions, c.textures)
|
||||||
for t in deselected_tiles:
|
for t in c.deselected_tiles:
|
||||||
|
self.all_sprites.append(t)
|
||||||
|
c.selected_tiles = create_selected_tiles(c.positions, c.textures)
|
||||||
|
for t in c.selected_tiles:
|
||||||
self.all_sprites.append(t)
|
self.all_sprites.append(t)
|
||||||
#selected_tiles = create_selected_tiles(positions, textures)
|
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
arcade.start_render()
|
arcade.start_render()
|
||||||
@@ -53,8 +60,12 @@ class Window(arcade.Window):
|
|||||||
def on_mouse_press(self, x, y, button, key_modifiers):
|
def on_mouse_press(self, x, y, button, key_modifiers):
|
||||||
print("click", x, y)
|
print("click", x, y)
|
||||||
sprites = arcade.get_sprites_at_point([x, y], self.all_sprites)
|
sprites = arcade.get_sprites_at_point([x, y], self.all_sprites)
|
||||||
if len(sprites) == 1:
|
id = sprites[0].guid
|
||||||
print("selected: ", sprites[0].guid)
|
print("selected id: ", id)
|
||||||
|
#print("deselected_tiles: ", self.c.deselected_tiles)
|
||||||
|
#print("selected_tiles: ", self.c.selected_tiles)
|
||||||
|
self.c.deselected_tiles[id].visible = False
|
||||||
|
self.c.selected_tiles[id].visible = True
|
||||||
|
|
||||||
def on_update(self, delta):
|
def on_update(self, delta):
|
||||||
self.all_sprites.update_animation()
|
self.all_sprites.update_animation()
|
||||||
@@ -83,3 +94,17 @@ def create_deselected_tiles(positions, textures):
|
|||||||
tile.center_x = CELL * 2 + p[0] * CELL
|
tile.center_x = CELL * 2 + p[0] * CELL
|
||||||
tile.center_y = HEIGHT - CELL * 2 - p[1] * CELL
|
tile.center_y = HEIGHT - CELL * 2 - p[1] * CELL
|
||||||
return tiles
|
return tiles
|
||||||
|
|
||||||
|
def create_selected_tiles(positions, textures):
|
||||||
|
tiles = []
|
||||||
|
for (id, p) in enumerate(positions):
|
||||||
|
tile = arcade.Sprite()
|
||||||
|
tiles.append(tile)
|
||||||
|
tile.guid = id
|
||||||
|
tile.texture = textures[2]
|
||||||
|
# Position.
|
||||||
|
tile.center_x = CELL * 2 + p[0] * CELL
|
||||||
|
tile.center_y = HEIGHT - CELL * 2 - p[1] * CELL
|
||||||
|
# Invisible by default.
|
||||||
|
tile.visible = False
|
||||||
|
return tiles
|
||||||
|
|||||||
Reference in New Issue
Block a user