Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random, sys
- from pygame.locals import *
- WINDOWWIDTH = 600
- WINDOWHEIGHT = 600
- TEXTCOLOR = (255, 255, 255)
- WHITE = (0, 0, 255)
- BGC = (0, 0, 0)
- FPS = 80
- PLAYERMOVERATE = 5
- countBy = 1
- ddd = random.randint(2, 4)
- dddd = random.randint(5, 7)
- plip = random.randint(ddd, dddd)
- ddddd = random.randint(-4, -2)
- dddddd = random.randint(-7, -5)
- pliping = random.randint(dddddd, ddddd)
- def terminate():
- pygame.quit()
- sys.exit()
- 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
- 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)
- pygame.init()
- pygame.font.init()
- font = pygame.font.SysFont(None,48)
- mainClock = pygame.time.Clock()
- background = pygame.image.load('sb.png')
- backgroundRect = background.get_rect()
- size = (width, height) = background.get_size()
- screen = pygame.display.set_mode(size)
- screen.blit(background, backgroundRect)
- pygame.display.set_caption('Mothers Day')
- pygame.mouse.set_visible(True)
- pygame.display.set_icon(pygame.image.load('gameicon.gif'))
- icon = pygame.image.load('icon.bmp').convert_alpha()
- pygame.display.set_icon(icon)
- gameStartSound = pygame.mixer.Sound('gamestart.wav')
- gameOverSound = pygame.mixer.Sound('gamestart.wav')
- pygame.mixer.music.load('background.wav')
- playerImage = pygame.image.load('starship.bmp')
- playerRect = playerImage.get_rect()
- baddieImage = pygame.image.load('enemy.bmp')
- baddieRect = baddieImage.get_rect()
- drawText('Star Trek', font, screen, (WINDOWWIDTH / 2.5), (WINDOWHEIGHT / 3))
- drawText('Press a key to start.', font, screen, (WINDOWWIDTH / 3.75), (WINDOWHEIGHT / 3) + 50)
- pygame.display.update()
- waitForPlayerToPressKey()
- MESH = ((playerRect.topright[1] + 1), (playerRect.topright[1] + 1), (playerRect.centery - 10), (playerRect.centery + 10))
- shootRect = pygame.draw.rect(screen, WHITE, MESH)
- def baddieHasHitShoot(baddieRect, shootRect):
- if baddieRect.colliderect(shootRect):
- return True
- return False
- topScore = 0
- while True:
- score = 10000
- playerRect.topleft = (0, 0)
- baddieRect.topright = (600, 0)
- moveUp = moveDown = False
- pygame.mixer.music.play(-1, 0.0)
- UPDOWN = False
- while True:
- if UPDOWN:
- baddieRect.move_ip(0, pliping)
- elif not UPDOWN:
- baddieRect.move_ip(0, plip)
- if baddieRect.bottom > WINDOWHEIGHT:
- UPDOWN = True
- elif baddieRect.top < 0:
- UPDOWN = False
- score -= countBy
- for event in pygame.event.get():
- if event.type == QUIT:
- terminate()
- if event.type == KEYDOWN:
- if event.key == K_UP:
- moveDown = False
- moveUp = True
- if event.key == ord(' '):
- pygame.draw(shootRect)
- move.ip[5, 0]
- if event.key == K_DOWN:
- moveUp = False
- moveDown = True
- if event.type == KEYUP:
- if event.key == K_ESCAPE:
- terminate()
- if event.key == K_UP or event.key == ord('w'):
- moveUp = False
- if event.key == K_DOWN or event.key == ord('s'):
- moveDown = False
- if moveUp and playerRect.top > 0:
- playerRect.move_ip(0, -1 * PLAYERMOVERATE)
- if moveDown and playerRect.bottom < WINDOWHEIGHT:
- playerRect.move_ip(0, PLAYERMOVERATE)
- screen.blit(background, backgroundRect)
- screen.blit(playerImage, playerRect)
- screen.blit(baddieImage, baddieRect)
- drawText('Score: %s' % (score), font, screen, 200, 0)
- drawText('Top Score: %s' % (topScore), font, screen, 195, 40)
- pygame.display.update()
- if baddieHasHitShoot(baddieRect, shootRect):
- if score > topScore:
- score = topscore
- break
- mainClock.tick(FPS)
- pygame.mixer.music.stop()
- gameOverSound.play()
- drawText('GAME OVER', font, screen, (WINDOWWIDTH / 3), (WINDOWHEIGHT / 3))
- drawText('Press a key to play again.', font, screen, (WINDOWWIDTH / 3) - 100, (WINDOWHEIGHT / 3) + 50)
- pygame.display.update()
- waitForPlayerToPressKey()
- gameOverSound.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement