forked from Apreche/Project-DORF
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f24025
commit 493968f
Showing
4 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import random | ||
|
||
class Mover(object): | ||
""" A renderable object with a location, color, and movement method. """ | ||
def __init__(self, grid, location, color): | ||
self.grid = grid | ||
self.node = grid.get_node_at(location) | ||
self.color = color | ||
|
||
def move(self): | ||
pass | ||
|
||
def get_location(self): | ||
return self.node.location | ||
|
||
def render(self, area, surface): | ||
surface.fill(self.color, area) | ||
|
||
|
||
class RandomMover(Mover): | ||
""" A mover that moves randomly between adjacent nodes. """ | ||
def __init__(self, grid, location, color=(255, 0, 0)): | ||
Mover.__init__(self, grid, location, color) | ||
|
||
def move(self): | ||
neighbors = self.grid.neighbors(self.node) | ||
self.node = random.choice(neighbors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
493968f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, now you can add and remove random movers for testing purposes. Left click on a grid square to add one, right click to remove it.
Space bar will move all movers on the grid one step - hold it down if you want them to move faster.