Was using a book to learn a bit of Python. Trying out one of the programs in it returns an error. Have tried checking over the code and I can’t fire out what Im botching up. Would appreciate any help with this matter. Also I’m using PyCharm to edit the program.
import sys
import pyjama
class AlienInvasion:
def _init_(self):
pygame.init()
self.screen = pygame.display.set_mode((1200,800))
pygame.display.set_caption("Alien Attack)
def run_game(self):
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.display.flip()
if __name__ == '__main__':
ai = AlienInvasion()
ai.run_game()
I get the following error when running this.
pygame 2.4.0 (SDL 2.26.4, Python 3.11.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/Users/bijumathew/PycharmProjects/AchusGame/AchusGame.py", line 22, in <module>
ai.run_game()
File "/Users/bijumathew/PycharmProjects/AchusGame/AchusGame.py", line 14, in run_game
for event in pygame.event.get():
^^^^^^^^^^^^^^^^^^
pygame.error: video system not initialized
Process finished with exit code 1
Would appreciate any help with this.