Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, sys, random, time
- from pygame.locals import *
- pygame.init()
- MC = pygame.time.Clock()
- Score = 0
- WW = 400
- WH = 400
- T = True
- windowSurface = pygame.display.set_mode((WW, WH), 0,32)
- pygame.display.set_caption("Trump Chase")
- # colorvariables
- #font = pygame.font.SysFont('Comic Sans MS', 14)
- black = 0,0,0
- blue = 0,0,255
- gray = 128,128,128
- green = 0,128,0
- purple = 128,0,128
- red = 255,0,0
- white = 255,255,255
- yellow = 255,255,0
- # Player and Food Structer
- FC = 0 # Starting Number of food
- NF = 20 # Number or loops before more cubes
- FS = 20 # Size of food
- trump = pygame.Rect(0,0,50,50)
- player = pygame.Rect(300,100,50,50)
- #image
- playerImage = pygame.image.load('Mexican.jpg')
- pSI = pygame.transform.scale(playerImage, (50,50))
- foodImage = pygame.image.load('Burrito.png')
- foodStretchedImage = pygame.transform.scale(foodImage, (FS, FS))
- trumpImage = pygame.image.load('Trump Picture.jpg')
- tSI = pygame.transform.scale(trumpImage, (50,50))
- #sound
- SB = [pygame.mixer.Sound('fin.wav'), pygame.mixer.Sound('mexico_pays.wav')]
- pickUpSound = pygame.mixer.Sound('chime.wav')
- trumpHitSound = SB[random.randint(0,1)]
- pygame.mixer.music.load('trumptrap.mp3')
- pygame.mixer.music.play(-1,0.0)
- MP = True
- # This code will keep track of the cubits
- foods = []
- for i in range(20):
- foods.append(pygame.Rect(random.randint(0, WW - FS), random.randint(0, WH - FS), FS , FS))
- # Movement Variables
- ML = False
- MR = False
- MU = False
- MD = False
- MS = 6
- # Game Loop
- print('Score:')
- while T :
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- # Here are the keyboard variables
- if event.type == KEYDOWN:
- x = event.key
- if x == K_LEFT or x == K_a:
- MR = False
- ML = True
- if x == K_RIGHT or x == K_d:
- ML = False
- MR = True
- if x == K_UP or x == K_w:
- MD = False
- MU = True
- if x == K_DOWN or x == K_s:
- MU = False
- MD = True
- if event.type == KEYUP:
- if event.key == K_ESCAPE:
- pygame.quit()
- sys.exit()
- x = event.key
- if x == K_LEFT or x == K_a:
- ML = False
- if x == K_RIGHT or x == K_d:
- MR = False
- if x == K_UP or x == K_w:
- MU = False
- if x == K_DOWN or x == K_s:
- MD = False
- # Teleportation Flow Controls
- if event.key == K_x:
- player.top = random.randint(0, WH - player.height)
- player.left = random.randint(0, WW - player.width)
- # Mouse Click Controls
- # if event.type == MOUSEBUTTONUP:
- # foods.append(pygame.Rect(event.pos[0], event.pos[1], FS, FS))
- # Food Counter
- FC += 1
- if FC >= NF:
- FC = 0
- foods.append(pygame.Rect(random.randint(0, WW - FS),random.randint(0, WH - FS), FS, FS))
- # kinda important to just be laying around
- windowSurface.fill(white)
- # These are player movement controls
- if MD and player.bottom < WH:
- player.top += MS
- if MU and player.top > 0:
- player.top -= MS
- if ML and player.left > 0:
- player.left -= MS
- if MR and player.right < WW:
- player.right += MS
- #Check for eaten food squares, and remove them. Also the score code.
- for food in foods[:]:
- if player.colliderect(food):
- Score += 1
- if MP:
- pickUpSound.play()
- foods.remove(food)
- print(Score)
- if Score == 420:
- print('You Win!')
- T = False
- #------------------------------------------------------------------------------------------
- if player.colliderect(trump):
- MD = False
- ML = False
- MU = False
- MR = False
- trumpHitSound.play()
- print("Game Over")
- pygame.quit()
- sys.exit()
- # Draw the food
- for food in foods:
- windowSurface.blit(foodStretchedImage, food)
- # Draws players
- MS = 6
- UL = (25,25)
- UR = (375, 25)
- DL = (25,375)
- DR = (375,375)
- #Trump AI
- #----------------------------------------------------------------------------------
- if (trump.centerx ,trump.centery) == UL:
- trump.right += MS
- trump.bottom += MS
- if (trump.centerx ,trump.centery) == UR:
- trump.left -= MS
- trump.bottom += MS
- if (trump.centerx ,trump.centery) == DL:
- trump.up -= MS
- trump.right += MS
- if(trump.centerx ,trump.centery) == DR:
- trump.up -= MS
- trump.right += MS
- # Prevents Trump from going through wall
- if trump.top < 0:
- if trump == UL:
- trump = DR
- if trump == UR:
- trump = DL
- if trump.left < 0:
- if trump == UL:
- trump = DR
- if trump == DL:
- trump = UR
- if trump.right > WW:
- if trump == UR:
- trump = DL
- if trump == DR:
- trump = UL
- if trump.bottom > WH:
- if trump == DR:
- trump = UR
- if trump == DL:
- trump = UL
- #----------------------------------------------------------
- windowSurface.blit( pSI, player)
- windowSurface.blit( tSI, trump)
- # Updates Display and Main Clock gives game constant speed no matter the device
- pygame.display.update()
- MC.tick(40)
Advertisement
Add Comment
Please, Sign In to add comment