Fixed issues with rectangle rendering
This commit is contained in:
1 parent
bec941d624
commit
dd0ab3d64b
1 file changed
+9
-9
+9
-9
@@ -2,13 +2,13 @@ import pygame
|
|||||||
|
|
||||||
#Functions
|
#Functions
|
||||||
def drawRects(rects):
|
def drawRects(rects):
|
||||||
|
#Get rid of old rectangles
|
||||||
|
screen.fill((0, 0, 0))
|
||||||
for rectangle in rects:
|
for rectangle in rects:
|
||||||
#(Surface, color [A], rect, width)
|
#(Surface, color [A], rect, width)
|
||||||
pygame.draw.rect(screen, (255, 255, 255, 1), rectangle, width=0)
|
pygame.draw.rect(screen, (255, 255, 255, 1), rectangle, width=0)
|
||||||
#update screen
|
if len(rects) == 0:
|
||||||
pygame.display.update(rectangle)
|
screen.fill((0, 0, 0))
|
||||||
print(f"I have displayed the rectangle")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
def removeRect(rects, pos):
|
def removeRect(rects, pos):
|
||||||
print(f"I am removing rectangle at {pos}")
|
print(f"I am removing rectangle at {pos}")
|
||||||
@@ -17,8 +17,9 @@ def removeRect(rects, pos):
|
|||||||
rects.remove(rectangle)
|
rects.remove(rectangle)
|
||||||
print(f"I have removed the rectangle")
|
print(f"I have removed the rectangle")
|
||||||
#update screen
|
#update screen
|
||||||
pygame.display.update(rectangle)
|
drawRects(rects)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +38,6 @@ while running:
|
|||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip() # Update the display
|
pygame.display.flip() # Update the display
|
||||||
clock.tick(30) # Maintain 30 FPS
|
clock.tick(30) # Maintain 30 FPS
|
||||||
#Intro Screen
|
#Intro Screen
|
||||||
@@ -53,7 +53,7 @@ while running:
|
|||||||
pygame.draw.line(screen, (0, 0, 60), (0, y), (screen.get_width(), y))
|
pygame.draw.line(screen, (0, 0, 60), (0, y), (screen.get_width(), y))
|
||||||
|
|
||||||
#Get mouse input
|
#Get mouse input
|
||||||
mousePos = (pygame.mouse.get_pos()[0] - 10, pygame.mouse.get_pos()[1] - 10)
|
mousePos = (pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1])
|
||||||
mouseInput = pygame.mouse.get_pressed()
|
mouseInput = pygame.mouse.get_pressed()
|
||||||
|
|
||||||
if mouseInput[0]: # Left mouse button make a white box
|
if mouseInput[0]: # Left mouse button make a white box
|
||||||
@@ -62,9 +62,9 @@ while running:
|
|||||||
if x % 10 == 0 and y % 10 == 0:
|
if x % 10 == 0 and y % 10 == 0:
|
||||||
break
|
break
|
||||||
if x % 10 != 0:
|
if x % 10 != 0:
|
||||||
x += 10 - (x % 10)
|
x -= x % 10
|
||||||
if y % 10 != 0:
|
if y % 10 != 0:
|
||||||
y += 10 - (y % 10)
|
y -= y % 10
|
||||||
#Draw rect at grid location
|
#Draw rect at grid location
|
||||||
newRect = pygame.Rect(x, y, 10, 10)
|
newRect = pygame.Rect(x, y, 10, 10)
|
||||||
if len(rects) == 0:
|
if len(rects) == 0:
|
||||||
|
|||||||
Reference in new issue
Block a user