diff --git a/Units/__pycache__/knight.cpython-311.pyc b/Units/__pycache__/knight.cpython-311.pyc index 68c4f91..cbeee0f 100644 Binary files a/Units/__pycache__/knight.cpython-311.pyc and b/Units/__pycache__/knight.cpython-311.pyc differ diff --git a/Units/knight.py b/Units/knight.py index 58a6fea..9c6420c 100644 --- a/Units/knight.py +++ b/Units/knight.py @@ -52,11 +52,15 @@ class Knight: return gif, screen_x, screen_y def move_to(self, target): + if self.target == target and self.state == "Walk": + return self.speed = .05 self.target = target self.state = "Walk" def run_to(self, target): + if self.target == target and self.state == "Run": + return self.speed = .15 self.target = target self.state = "Run" \ No newline at end of file diff --git a/main.py b/main.py index b801d5c..97b29bd 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,8 @@ class IsometricGame: self.menu = Menu(self.canvas, tearoff=0) self.window.bind('', self.on_key_press) self.canvas.bind('', self.on_canvas_click) - self.canvas.bind('', self.on_canvas_rclick) + self.canvas.bind('', self.on_canvas_right_click) + self.canvas.bind('', self.on_canvas_double_right_click) self.canvas.bind('', self.calculate_coordinates) @@ -237,8 +238,21 @@ class IsometricGame: self.battlefield[cell_y][cell_x].walkable ^= True self.draw_battlefield() self.draw_units() + + def on_canvas_right_click(self, event): + # calculate the clicked cell's coordinates + cell_x, cell_y = self.inv_iso_transform(event.x, event.y) + self.effects.append(OrderClick(self.iso_transform(cell_x, cell_y),color="lightblue")) - + if 0 <= cell_x < self.width and 0 <= cell_y < self.height: + self.knight.move_to((cell_x, cell_y)) + + def on_canvas_double_right_click(self, event): + # calculate the clicked cell's coordinates + cell_x, cell_y = self.inv_iso_transform(event.x, event.y) + self.effects.append(OrderClick(self.iso_transform(cell_x, cell_y),color="darkblue")) + if 0 <= cell_x < self.width and 0 <= cell_y < self.height: + self.knight.run_to((cell_x, cell_y)) def set_tile(self, name, pos): # Handle option 1 selection @@ -249,15 +263,6 @@ class IsometricGame: self.battlefield[cell_y][cell_x].tile = self.tiles[name] self.draw_battlefield() - - def on_canvas_rclick(self, event): - # calculate the clicked cell's coordinates - cell_x, cell_y = self.inv_iso_transform(event.x, event.y) - self.effects.append(OrderClick(self.iso_transform(cell_x, cell_y),color="lightblue")) - if self.knight.target == (cell_x, cell_y): - return - if 0 <= cell_x < self.width and 0 <= cell_y < self.height: - self.knight.run_to((cell_x, cell_y)) def run(self): self.draw_battlefield()