Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 4.57 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Mouse control not responding  [closed]
  2. import pygame
  3. from pygame import *
  4. import random
  5. import time
  6. import os
  7. import sys
  8. from pygame.locals import *
  9.  
  10.  
  11. black = (0,0,0)
  12. white = (255,255,255)
  13.  
  14. pygame.init()
  15.  
  16. def game():
  17.  
  18. os.environ['SDL_VIDEO_CENTERED'] = '1'
  19. mouse.set_visible(False)
  20. screen = display.set_mode((800,500))
  21. backdrop = pygame.image.load('bg.jpg').convert_alpha()
  22. menu = pygame.image.load('green.jpg').convert_alpha()
  23. ballpic = pygame.image.load('ball.gif').convert_alpha()
  24. mouseball = pygame.image.load('mouseball.gif').convert_alpha()
  25. display.set_caption('Twerk')
  26. back = pygame.Surface(screen.get_size())
  27.  
  28. def text(text,x_pos,color,font2=28):
  29.     tfont = pygame.font.Font(None, font2)
  30.  
  31.     text=tfont.render(text, True, color)
  32.     textpos = text.get_rect(centerx=back.get_width()/2)
  33.     textpos.top = x_pos
  34.     screen.blit(text, textpos)
  35.  
  36.  start = False
  37.  repeat = False
  38. while start == False:
  39.     for event in pygame.event.get():
  40.         if event.type == pygame.QUIT:
  41.             start = True
  42.             #falling = True
  43.             #finish = True
  44.  
  45.         if event.type == pygame.KEYDOWN:
  46.             if event.key == pygame.K_SPACE:
  47.                 start = True
  48.     #game over screen
  49.     screen.blit(menu,[0,0])
  50.     pygame.display.set_caption("TWERK")
  51.  
  52.     #Text
  53.     #"Welcome to Escape"
  54.     #needs replacing with logo
  55.     text("Twerk",60,white,300)
  56.  
  57.     #"Instructions"
  58.     text("Instructions",310,white)
  59.     text("----------------------------------------------------------------------------------------",320,white)
  60.     text("Avoid the the enemies",340,white)
  61.     text("Last as long as you can!",360,white)
  62.     text("Press space to start",420,white)
  63.     pygame.display.flip()
  64.  
  65.  
  66. while start == True:
  67. positionx=[]
  68. positiony=[]
  69. positionxmove=[]
  70. positionymove=[]
  71. falling = False
  72. finish = False
  73. score=0
  74. enemies=1
  75. velocity=1
  76.  
  77. for i in range(enemies):
  78.   positionx.append(random.randint(300,400)+random.randint(-300,200))
  79.   positiony.append(random.randint(200,340)+random.randint(-200,100))
  80.   positionxmove.append(random.randint(1,velocity))
  81.   positionymove.append(random.randint(1,velocity))
  82.  
  83.  
  84. font = pygame.font.Font(None, 28)
  85. text = font.render('Starting Twerk... ', True, (100,100,100))
  86. textRect = text.get_rect()
  87. textRect.centerx = screen.get_rect().centerx
  88. textRect.centery = screen.get_rect().centery
  89.  
  90. screen.blit(backdrop, (0,0))
  91. screen.blit(text, textRect)
  92. pygame.display.update()
  93. game=time.localtime()
  94.  
  95. while start == True:
  96.   end=time.localtime()
  97.   score= (end[1]-game[1])*3600 + (end[4]-game[4])*60 + end[5]-game[5]
  98.   if score > 1: break
  99.  
  100. first=True
  101. strtTime=time.localtime()
  102.  
  103. while not finish or falling:
  104.   screen.blit(backdrop, (0,0))
  105.   for i in range(enemies):
  106.     screen.blit(ballpic,(positionx[i],positiony[i]))
  107.     (mousex,mousey)=mouse.get_pos()
  108.     screen.blit(mouseball,(mousex,mousey))
  109.     display.update()
  110.     strt = time.localtime()
  111.  
  112.   if first:
  113.     while True:
  114.       end=time.localtime()
  115.       score= (end[3]-strt[3])*3600 + (end[4]-strt[4])*60 + end[5]-strt[5]
  116.       if score > 3: break
  117.     first = False
  118.  
  119.   if falling:
  120.     for i in range(enemies):
  121.       positionymove[i]=1000
  122.       positionxmove[i]=0
  123.  
  124.  
  125.   for i in range(enemies): positionx[i]=positionx[i]+positionxmove[i]
  126.   for i in range(enemies): positiony[i]=min(600,positiony[i]+positionymove[i])
  127.  
  128.   if falling:
  129.     falling=False
  130.     for posy in positiony:
  131.       if posy<600: falling=True
  132.  
  133.  
  134.   if not falling:
  135.     for i in range(enemies):
  136.       for j in range(i+1,enemies):
  137.         if abs(positionx[i]-positionx[j])<20 and abs(positiony[i]-positiony[j])<20:
  138.           temp=positionxmove[i]
  139.           positionxmove[i]=positionxmove[j]
  140.           positionxmove[j]=temp
  141.           temp=positionymove[i]
  142.           positionymove[i]=positionymove[j]
  143.           positionymove[j]=temp
  144.  
  145.     for i in range(enemies):  
  146.       if positionx[i]>600: positionxmove[i]*=-1
  147.       if positionx[i]<0: positionxmove[i]*=-1
  148.       if positiony[i]>440: positionymove[i]*=-1
  149.       if positiony[i]<0: positionymove[i]*=-1
  150.  
  151.     for i in range(enemies):
  152.       if abs(positionx[i]-mousex)<40 and abs(positiony[i]-mousey)<40:
  153.  
  154.         endTime=time.localtime()
  155.         score= (endTime[3]-strtTime[3])*3600 + (endTime[4]-strtTime[4])*60 + endTime[5]-strtTime[5]
  156.         falling = True
  157.         finish = True
  158. game()
  159.        
  160. def quit():
  161.     pygame.quit(); sys.exit()
  162. def GetInput():
  163.     key = pygame.key.get_pressed()
  164.     for event in pygame.event.get():
  165.         if   event.type == QUIT: quit()
  166.         elif event.type == KEYDOWN:
  167.             if   event.key == K_ESCAPE: quit()
  168. def Draw():
  169.     pygame.display.flip()
  170. def main():
  171.     Clock = pygame.time.Clock()
  172.     while True:
  173.         GetInput()
  174.         Draw()
  175.         Clock.tick(60)