#The FPS or frame per second or more explicitly set_caption ( 'snake game' ) #initializing () which controls init () WIN_X = 800 WIN_Y = 600 WIN = pygame. Import sys, random import pygame pygame. Let's go ahead and implement our game loop As we didn't define any game loop, the window was visible for a moment, but then the program ended, and so the game screen was also gone. Ī game loop is just an infinite loop, that goes on forever until the user exits or closes it. Ĭan you guess why this happens ?, well cause we didn't define any game loop. Now if you run this code, you will see the game screen for a short time, and then it exits the program. In the end, I just set up a caption or label for the game window using _caption() method passing in the caption string, you can pass any string you want here ?. Next, we set up our game window, or tell pygame to initialize our game window with _mode() method passing in our screen dimensions in a tuple (? The reason we need this is that pygame creates a game window and we need to declare the width and height of it, you can choose any width and height, I am choosing 800圆00) We make two variables or constants, WIN_X and WIN_Y to store our screen dimensions or our screen width and screen height,
We import pygame and some other local modules, then use the init method on pygame to start our game or start pygame.Enter fullscreen mode Exit fullscreen mode