Making a space shooter game ^-^

Made the startup code

main.py

import pygame as pg

# general setup
pg.init()
pg.display.set_caption("Space Shooter")
WINDOW_WIDTH, WINDOW_HEIGHT = 1280, 720
display_surf = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
run = True

while run:
    #event loop
    for event in pg.event.get():
        if event.type == pg.QUIT:
            run = False
    
    #draw the game
    display_surf.fill('dodgerblue1')
    pg.display.update()

pg.quit()

created the window using pygame!!!!

Create a window width and height global variables for the window.

WINDOW_WIDTH, WINDOW_HEIGHT = 1280, 720

Make a display surface variable that sets the width and height for the pygame window.

display_surf = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))

Make a while loop so that it stays on the screen and so the user can close the window at any time.

while run:
    #event loop
    for event in pg.event.get():
        if event.type == pg.QUIT:
            run = False

Now instead of having a black background, change the background color using the .fill() method. After that, use the .update() method to put it on the screen

 #draw the game
    display_surf.fill('dodgerblue1')
    pg.display.update()

RESULT:

Author: Zende_

From PA. EHS 2025. Does computer programming and such. That's really it.

Leave a Reply

Your email address will not be published. Required fields are marked *