Skip to content

Commit

Permalink
add function to load objects described in ASCII text files
Browse files Browse the repository at this point in the history
  • Loading branch information
generic-github-user committed Jan 9, 2023
1 parent f0c8c97 commit 572c830
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions untitled-game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,25 @@ def simulate(self, frames: int, steps=1, delay=0.1):
self.renderer.close()


def load_schematic(path: str) -> Object:
key, layout = String(Path(path).read_text()).split('\n\n')
# return layout.lines().map(lambda l: l.chars())
result = Object(Point([0, 0]), Vector([0, 0]), Angle(0), Angle(0), List(), 1)
for y, line in layout.lines().enum():
for x, char in line.chars().enum():
if char != '_':
result.add(Matter(Square(Point([x, y]), 2), None))
# breakpoint()
return result


def main():
print('starting...')
Scene(List([Object(Point([0, 0]), Vector([5, 5]), Angle(0), Angle(0), List([Matter(Circle(Point([0, 0]), 10), None)]), 1)]),
Vector([60, 30])).simulate(6000)
Scene(List([
#Object(Point([0, 0]), Vector([5, 5]), Angle(0), Angle(0),
# List([Matter(Circle(Point([0, 0]), 10), None)]), 1),
load_schematic('./untitled-game/ship2')]),
Vector([60, 30])).simulate(6)


main()

0 comments on commit 572c830

Please sign in to comment.