I am making a game in pygame, but the display doesn't update. I am using the update() function and am clearing the screen at the beginning of the loop with fill(). Pygame also does not load very quickly; I have to hit "quit" on the pygame application once it shows in the running applications on my mac for the screen to appear.
"Module Imports"
import pygame as pg
import shelve
"Import Classes"
from Settings import Settings
from Settings import Screen
from Settings import Save
from Random import Random
from Input import Input
from Input import Button
# Init Classes
Settings = Settings()
Screen = Screen()
Random = Random()
Save = Save()
on = True
pg.init()
event_const = pg.event.wait()
save_file = shelve.open("/Volumes/HISTORYGAME/Game_Saves/Save_File")
clock = pg.time.Clock()
MainDisplay = pg.display.set_mode((Screen.width, Screen.height))
pg.display.set_caption(Settings.title)
pg.display.init()
class Mouse:
def __init__(self):
self.left = False
self.right = False
Mouse = Mouse()
def begin_game():
players = []
num_players = input("How Many Players (enter int): ")
save_file["num_players_var"] = num_players
for pl in range(num_players):
players.append(raw_input("Enter Player Name: "))
save_file["players_var"] = players
print(players)
def intro():
intro = True
for event in pg.event.get():
if event.get == pg.QUIT:
intro = False
on = False
if event.get == pg.event.KEYDOWN:
pass
# begin_game()
test_button = Button(0, 0, 200, 200, "Enter Text Here", MainDisplay)
buttons = []
buttons.append(test_button)
loops = 0
test_x = 10
test_y = 10
while on:
MainDisplay.fill((0, 0, 0))
for event in pg.event.get():
if event.type == pg.QUIT:
On = False
pg.quit()
exit()
if event.type == pg.KEYDOWN:
if event.key == pg.K_ESCAPE:
On = False
pg.quit()
exit()
if event.key == pg.K_RIGHT:
test_x += 10
print("right")
if event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1:
Mouse.left = True
else:
Mouse.left = False
if event.type == pg.MOUSEBUTTONUP:
if event.button == 1:
Mouse.left = False
for button in buttons:
button.draw(pg.mouse.get_pos(), event_const)
if button.clicked is True:
print("True \n" * 100)
pg.draw.line(MainDisplay, (255, 0, 0), (100, 100), (600, 600))
pg.draw.rect(MainDisplay, (255, 0, 0), (test_x, test_y, 20, 20))
pg.display.flip()
pg.display.update()
clock.tick(Settings.FPS)
loops += 1
print(str(loops))
event_const = pg.event.wait(), why does the code have this? This causes pygame to wait for an event. But the main window isn't initialised - so this will either do nothing, or cause the program to hang. - Kingsleyclass Mouse) - Kingsley