I made a pygame template but it freezes when it runs, I've compared it to pygame projects I have that work and can't figure out what's wrong.
# Imports
import pygame
import os
# Initialising variables etc
os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()
screen_width = 700
screen_height = 500
win = pygame.display.set_mode((screen_width, screen_height))
win.fill((100, 100, 100))
pygame.display.set_caption("Window title")
# Initialise variables including images
clock = pygame.time.Clock()
font = pygame.font.SysFont('timesnewroman', 25, True)
bg_space = pygame.image.load('space.png')
bg_sea = pygame.image.load('sea.png')
class Something(object):
pass
def redraw_game_window():
# draw background
win.blit(bg_space, (0, 0))
# draw playing areas
# draw texts
title_text = font.render("Title here", True, (200, 0, 0))
win.blit(title_text, (20, 20))
# draw objects
# Update display
pygame.display.update()
def main_game():
# *** mainloop ***
# Variables and lists
cooldownloop = 0
run = True
while run:
# Set game timing
clock.tick(27)
# cooldown timer (x loops through main loop)
if cooldownloop > 0:
cooldownloop += 1
if cooldownloop > 15:
cooldownloop = 0
# do stuff
# Draw everything to screen
redraw_game_window()
main_game()