Main code
#Imports & Initial
import pygame, os, sys, time
pygame.init()
x = 200
y = 200
Main problem
def enemy_movement():
global x, y
pygame.draw.rect(screen, (255,0,0), (x, y, 50, 50))
time.sleep(100)
pygame.draw.rect(screen, (0,0,0),
(x, y, 50, 50))
x += 1
y += 1
#Map
def map_():
pygame.draw.rect(screen, (255,255,255),
(0, (pygame.Surface.get_height(screen) / 2), 400, 50))
pygame.draw.rect(screen, (255,255,255),
(399, ((pygame.Surface.get_height(screen) / 2) - 150),
50, 200))
pygame.draw.rect(screen, (255,255,255),
(399.5, ((pygame.Surface.get_height(screen) / 2) -150),
400, 50))
pygame.draw.rect(screen, (255,255,255),
(799.5, ((pygame.Surface.get_height(screen) / 2) - 150),
50, 300))
pygame.draw.rect(screen, (255,255,255),
(799.5, ((pygame.Surface.get_height(screen) / 2) + 150),
740, 50))
pygame.display.update()
#spawning of tower
def tower(event):
if event.type == pygame.KEYUP and event.key == pygame.K_q:
mouse_pos = pygame.mouse.get_pos()
tower_x = mouse_pos[0]
tower_y = mouse_pos[1]
pygame.draw.rect(screen, (255,100,100), (tower_x, tower_y, 50, 50))
FPS = 60
#Creation of window
os.environ['SDL_VIDEO_CENTERED'] = '1' #called before pygame.init()
info = pygame.display.Info() #called before set_mode()
screen_width, screen_height = info.current_w, info.current_h
screen = pygame.display.set_mode((screen_width - 10, screen_height - 50))
#main loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
enemy_movement()
#map_()
#tower(event)
My code is not running, idk if its my device or code, its that the pygame window is freezing (eg closing the window takes very long)