lonestar

0x10c-inspired space game based on the DCPU-16
git clone git://squid-tech.com/lonestar.git
Log | Files | Refs | README

commit 7ae8b2275dce4dbaaf848c725a6edc9e9e8c9bf6
parent fa3018d25dbff20cb0cc33d2ce423166c6fcd98b
Author: Josh Moore <jxm5210@rit.edu>
Date:   Sun, 24 Nov 2019 17:35:56 -0500

Fill hull bounds when the user is done drawing hull

Diffstat:
Mutils/shipdraw/shipdraw.py | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/utils/shipdraw/shipdraw.py b/utils/shipdraw/shipdraw.py @@ -13,12 +13,15 @@ done = False drawgrid = True shiphull = [] +scaledhullpoints = [] drawingHull = True # handle mouse clicks def clicked(event): global drawingHull global shiphull + global scaledhullpoints + if drawingHull: hullpos = tuple(round(i / GRID_STEP) for i in event.pos) @@ -29,8 +32,9 @@ def clicked(event): if len(shiphull) > 1 and shiphull[-1] == shiphull[0]: drawingHull = False + scaledhullpoints = [(p[0] * GRID_STEP, p[1] * GRID_STEP) for p in shiphull] -# draw the ship's outline (aka hull) +# draw the ship's outline while hull-drawing is occuring def drawOutline(hull, preview): for i in range(1, len(hull)): hullPos = (hull[i][0] * GRID_STEP, hull[i][1] * GRID_STEP) @@ -130,13 +134,12 @@ while not done: for x in range(0, SCREEN_WIDTH + 1, GRID_STEP): for y in range(0, SCREEN_HEIGHT + 1, GRID_STEP): pygame.draw.circle(screen, (100,100,100), (x, y), 2) - - # draw ship hull - drawOutline(shiphull, False) # draw grid cursor for both the mouse position and last placed hull point # also draw preview to next point if drawingHull: + drawOutline(shiphull, False) + unitMousePos = tuple(round(i / GRID_STEP) for i in pygame.mouse.get_pos()) hullCursor(unitMousePos) if len(shiphull) > 0: @@ -144,5 +147,8 @@ while not done: # draw path preview drawOutline(hullPath(unitMousePos), True) + else: + pygame.draw.polygon(screen, (200,200,200), scaledhullpoints) + pygame.draw.polygon(screen, (0,0,0), scaledhullpoints, 3) pygame.display.flip() \ No newline at end of file