Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, time, random, sys
- from pygame.locals import *
- pygame.init()
- ##################################### SETTING UP THE BASIC INFOMATION FOR THE GAME WINDOW ########################################
- WINDOWWIDTH = 700
- WINDOWHEIGHT = 500
- TEXTCOLOR = (100, 255, 100)
- BACKGROUND = (0, 0, 0)
- ##################################################################################################################################
- Red = (255, 0, 0)
- clock = pygame.time.Clock()
- minutes = 0
- seconds = 0
- milliseconds = 0
- FPS = 60
- fpsClock = pygame.time.Clock()
- ############################################### SETTING UP THE TEXT WELCOME SCREEN ###############################################
- pygame.init()
- mainClock = pygame.time.Clock()
- windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
- pygame.display.set_caption("Zombie Defense")
- pygame.mouse.set_visible(False)
- pygame.font.init()
- font = pygame.font.SysFont(None, 48)
- text = font.render("Zombie Defence", 1, (0,0,0))
- ##################################################################################################################################
- ###################################################################### ASSIGNING THE IMAGES NAMES ################################
- fd = pygame.image.load("fd.png")
- bg = pygame.image.load("b.jpg")
- Bad = pygame.image.load("Untitled-1.jpg")
- player = pygame.image.load("player.png")
- zed = pygame.image.load("Zombie.png")
- bullet = pygame.image.load("Bullet.png")
- info = pygame.image.load("INFO.png")
- player2 = pygame.image.load("player2.png")
- player3 = pygame.image.load("player3.png")
- ##################################################################################################################################
- font_S = pygame.font.Font(None, 44)
- BLACK = (0,0,0)
- WHITE = (255,255,255)
- playerx = 10
- playery = 10
- dead = False
- zedx = 100
- zedy = 10
- bulletx = playerx
- bullety = 400
- pygame.key.set_repeat(10, 10)
- main_Menu = True
- def terminate():
- pygame.quit()
- sys.exit()
- ################################################# SCORE ##########################################################################
- def text_Screen1(msg, colour, Pos_X, Pos_y):
- screen_text = font_S.render(msg, True, colour)
- windowSurface.blit(screen_text, [WINDOWWIDTH/ 3, WINDOWHEIGHT/ 10])
- ##################################################################################################################################
- ######################### ALLOWS PLAYER TO EXIT BY PRESSING ESC ##################################################################
- def waitForPlayerToPressKey():
- while True:
- for event in pygame.event.get():
- if event.type == QUIT:
- terminate()
- if event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- terminate()
- return
- ##################################################################################################################################
- ##################### SETTING VALUES FOR PLAYER MOVEMENT #########################################################################
- def Start():
- b_Change = 0
- zed_Change = 0
- x_Change = 0
- playerx = 50
- playery = 400
- zedy = 10
- bullety = 450
- ##################################################################################################################################
- ######################################################### MAIN GAME LOOP #########################################################
- while True:
- pygame.display.update()
- playerx += x_Change
- zedy += zed_Change
- bullety += b_Change
- global dead
- if not dead:
- print("Test")
- windowSurface.blit(bg, (0, 0))
- windowSurface.blit(player, (playerx, playery))
- windowSurface.blit(zed, (zedx, zedy))
- # windowSurface.blit(info, (0, 0))
- windowSurface.blit(bullet, (playerx, bullety))
- elif dead:
- windowSurface.blit(fd, (0, 0))########################### GAME OVER #####################################################
- print("Nice people")
- pygame.display.update()
- fpsClock.tick(FPS)
- for event in pygame.event.get():
- if event.type == QUIT:
- terminate()
- if event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- terminate()
- return
- if event.type == KEYDOWN:
- if dead:
- if event.key == K_RETURN:
- dead = False
- if event.key == K_p:
- windowSurface.blit(bg, (0,0))######################### APPLYING BACKGROUND ########################################
- if event.key == K_d:
- #playerx += 5
- x_Change = 3
- zed_Change = 2
- if event.key == K_a:
- #playerx -= 5
- x_Change = -3
- zed_Change = 2
- if event.key == K_i:
- windowSurface.blit(info, (0, 0))######################### INFOMATION SCREEN ##########################################
- if event.key == K_SPACE:
- b_Change = -7
- if event.type == KEYUP:
- if event.key == K_d:
- x_Change = 0
- zed_Change = 0
- if event.key == K_i:
- windowSurface.blit(info,(0, 0))
- if event.key == K_a:
- x_Change = 0
- zed_Change = 0
- if zedy > 550:
- zedy = 10
- dead = True
- print ("done!")
- if event.key == K_SPACE:
- b_Change = -7
- windowSurface.blit(bullet, (playerx, bullety))
- if bullety < -50:
- bullety = playery
- b_Change = 0
- text_Screen1("Score: " , Red, 1.25, 35)
- ##################################################################################################################################
- def drawText(text, font, surface, x, y):
- textobj = font.render(text, 1, TEXTCOLOR)
- textrect = textobj.get_rect()
- textrect.topleft = (x, y)
- surface.blit(textobj, textrect)
- ################################################################################ PUTTING THE TEXT ONTO THE WINDOW ################
- drawText('Zombie Defence', font, windowSurface, (WINDOWWIDTH / 3), (WINDOWHEIGHT / 3))
- drawText('Press a key to start.', font, windowSurface, (WINDOWWIDTH / 3) - 30, (WINDOWHEIGHT / 3) + 50)
- ##################################################################################################################################
- ############################################# CALLIGN THE DEFs ###################################################################
- pygame.display.update()
- time.sleep(3)
- Start()
- waitForPlayerToPressKey()
- text_Screen1()
- ##################################################################################################################################
- player = pygame.Rect(300, 500, 40, 40)
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement