Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame import *
- import random
- import time
- import os
- import sys
- from pygame.locals import *
- #I tried using this code but couldn't get apscheduler module installed, try and see if u can
- #http://pypi.python.org/pypi/APScheduler/
- #so instead I used another code which depends on the screen refresh rate (not 100% accurate)
- #===============
- # from apscheduler.scheduler import Scheduler
- # # Start the scheduler
- # sched = Scheduler()
- # sched.start()
- # # Schedule job_function to be called every 5 seconds
- # @sched.interval_schedule(seconds=5)
- # def incr_score():
- # score += 100
- #=======================
- black = (0,0,0)
- white = (255,255,255)
- grey = (190,190,190)
- pygame.init()
- def game():
- def levels(Score):
- if score >= 100:
- enemies = 6
- velocity = 2
- def text(text,x_pos,color,font2=28):
- tfont = pygame.font.Font(None, font2)
- text=tfont.render(text, True, color)
- textpos = text.get_rect(centerx=back.get_width()/2)
- textpos.top = x_pos
- screen.blit(text, textpos)
- os.environ['SDL_VIDEO_CENTERED'] = '1'
- mouse.set_visible(False)
- #screen
- screen=pygame.display.set_mode((665,500),0,32)
- #load images etc.
- backdrop = pygame.image.load('bg.jpg').convert_alpha()
- menu = pygame.image.load('green.jpg').convert_alpha()
- ballpic = pygame.image.load('ball.png').convert_alpha()
- mouseball = pygame.image.load('mouseball.gif').convert_alpha()
- display.set_caption('Twerk')
- back = pygame.Surface(screen.get_size())
- start = False
- repeat = False
- while start == False:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- #break
- #falling = True
- #finish = True
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_SPACE:
- start = True
- break
- screen.blit(menu,[0,0])
- pygame.display.set_caption("TWERK")
- #Text
- #"Welcome to Escape"
- text("Twerk",60,white,300)
- #"Instructions"
- text("Instructions",310,white)
- text("------------------------------------------",320,white)
- text("Avoid the the enemies",340,white)
- text("Last as long as you can!",360,white)
- text("Press space to start",420,white)
- pygame.display.flip()
- while start == True:
- positionx=[]
- positiony=[]
- positionxmove=[]
- positionymove=[]
- falling = False
- finish = False
- score=0
- enemies=3
- velocity=1
- scoreIncrementTimer = 0
- lastFrameTicks = pygame.time.get_ticks()
- for i in range(enemies):
- positionx.append(random.randint(300,400)+random.randint(-300,200))
- positiony.append(random.randint(200,340)+random.randint(-200,100))
- for p in [positionxmove, positionymove]:
- p.append(random.randint(1,velocity))
- # Starting Twerk Screen!!
- screen.blit(backdrop, (0,0))
- text("Starting Twerk...",190,grey)
- pygame.display.update()
- time.sleep(2.5)
- while not finish or falling:
- #Game control during Game
- #----------------------
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- falling = True
- finish = True
- start = False
- #----------------------
- screen.blit(backdrop, (0,0))
- for i in range(enemies):
- screen.blit(ballpic,(positionx[i],positiony[i]))
- mousex,mousey = pygame.mouse.get_pos()
- mousex -= mouseball.get_width()/2
- mousey -= mouseball.get_height()/2
- screen.blit(mouseball, (mousex,mousey))
- #?
- pygame.display.update()
- pygame.display.set_caption("Score: %s " % (round(score)))
- levels(score)
- #=============Score System============
- thisFrameTicks = pygame.time.get_ticks()
- ticksSinceLastFrame = thisFrameTicks - lastFrameTicks
- lastFrameTicks = thisFrameTicks
- scoreIncrementTimer = scoreIncrementTimer + ticksSinceLastFrame
- if scoreIncrementTimer > 5000:
- score = score + 100
- scoreIncrementTimer = 0
- #======================================
- if falling:
- for i in range(enemies):
- positionymove[i]=1000
- positionxmove[i]=0
- for i in range(enemies):
- positionx[i]=positionx[i]+positionxmove[i]
- positiony[i]=min(600,positiony[i]+positionymove[i])
- if falling:
- falling=False
- for posy in positiony:
- if posy<600: falling=True
- if not falling:
- for i in range(enemies):
- for j in range(i+1,enemies):
- if abs(positionx[i]-positionx[j])<20 and abs(positiony[i]-positiony[j])<20:
- p[i], p[j] = p[i],p[i]
- for i in range(enemies):
- if positionx[i]>600: positionxmove[i]*=-1
- if positionx[i]<0: positionxmove[i]*=-1
- if positiony[i]>440: positionymove[i]*=-1
- if positiony[i]<0: positionymove[i]*=-1
- pygame.display.update()
- for i in range(enemies):
- if abs(positionx[i]-mousex)<40 and abs(positiony[i]-mousey)<40:
- falling = True
- finish = True
- start = False
- pygame.display.update()
- while finish == True:
- screen.blit(menu,[0,0])
- pygame.display.set_caption("TWERK")
- text("Game Over",60,white,120)
- text("Score: %s " % (round(score)),220,white,60)
- text("Press space to return to Menu",360,white)
- pygame.display.update()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_SPACE:
- game()
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement