masters-project/pygame_control.py
2021-04-22 15:15:07 +01:00

58 lines
1.5 KiB
Python

import pygame
pygame.init()
pygame.font.init()
font_name = pygame.font.get_default_font()
font = pygame.font.Font(font_name, 20)
window = pygame.display.set_mode((500, 500))
pygame.display.set_caption("RAH Visual Controller V0.1")
run = True
armed = False
prev_x = 0
prev_y = 0
def update_and_send_pos_to_odrive():
pass
while run:
pygame.time.delay(20)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
mouse_x, mouse_y = pygame.mouse.get_pos()
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
armed = True
window.fill((64, 0, 0))
idkwhatthisis_2 = font.render(f"Armed: {armed}", True, (255, 0, 0))
prev_x = mouse_x
prev_y = mouse_y
# clear where the striker currently is
else:
armed = False
window.fill((10, 10, 10))
pygame.draw.circle(window, (255, 0, 0), (prev_x, prev_y), (20))
idkwhatthisis_2 = font.render(f"Armed: {armed}", True, (200, 200, 200))
# draw where the striker currently is
# window.fill((0, 0, 0))
pygame.draw.circle(window, (255, 0, 0), (mouse_x, mouse_y), (20))
pygame.draw.rect(window, (0, 255, 0), (mouse_x, 0, 1, 500))
pygame.draw.rect(window, (0, 128, 255), (0, mouse_y, 500, 1))
idkwhatthisis = font.render(f"X: {mouse_x} | Y: {mouse_y}", True, (255, 255, 255))
window.blit(idkwhatthisis, (0, 0))
window.blit(idkwhatthisis_2, (0, 480))
pygame.display.update()
if armed:
update_and_send_pos_to_odrive()
pygame.font.quit()
pygame.quit()