|
| 1 | +import pygame # Importing all the packages of the pygame |
| 2 | +import random # Importing random so that we can give random positions to our enemy |
| 3 | +import math |
| 4 | +from pygame import mixer |
| 5 | + |
| 6 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 7 | +pygame.init() # Initializes the pygame |
| 8 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 9 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 10 | +# Dimension of the screen |
| 11 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 12 | + |
| 13 | +width = 800 # Width of the SCREEN or the FRAME or the WINDOW |
| 14 | +height = 600 # Height of the SCREEN or the FRAME or the WINDOW |
| 15 | + |
| 16 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 17 | +# Colours |
| 18 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 19 | +blue = (0, 0, 255) |
| 20 | + |
| 21 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 22 | +# Creating a Screen |
| 23 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 24 | +screen = pygame.display.set_mode((width, height)) |
| 25 | + |
| 26 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 27 | +# Creating Background |
| 28 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 29 | + |
| 30 | + |
| 31 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 32 | +#backgroundSound |
| 33 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 34 | +mixer.music.load("./Sounds/spaceInvadersWar.mp3") #play the music |
| 35 | +mixer.music.play(-1) #-1 is for loop of sound |
| 36 | + |
| 37 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 38 | +# Title |
| 39 | +#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 40 | +pygame.display.set_caption("PyGame Title") # Giving the title to the Output |
| 41 | + |
| 42 | + |
| 43 | +running = True # running value i.e its true while the player is running |
| 44 | +while running: |
| 45 | + # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 46 | + screen.fill(blue) # screen is filled with color |
| 47 | + # -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + for event in pygame.event.get(): # getting all the events happening externally using loop |
| 52 | + if event.type == pygame.QUIT: # if QUIT button or X button is pressed |
| 53 | + running = False # Running value returns while loop as false and the loop breaks |
| 54 | + pygame.display.update() # Updating the screen is imp because it changes the screen for each cycle or events or the loop |
| 55 | + |
| 56 | + |
0 commit comments