Advertisement
Guest User

Untitled

a guest
May 27th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. # Bypass verison 1. Courtney and Emma
  2. # In this version there will be one dot on the screen that when clicked will
  3. # become slected and when hoovered over will be come transparent and will look
  4. # opaque when no mouse action
  5.  
  6. import pygame, sys, time, math
  7. from pygame.locals import *
  8.  
  9. # User-defined classes
  10.  
  11. # User-defined functions
  12.  
  13. def update(opaqueColor, transparentColor, selectedColor,center,opaqueRadius,transparentRadius, selectedRadius,state, OPAQUE,TRANSPARENT,SELECTED, surface):
  14. # Check if the game is over. If so, end the game and
  15. # returnTrue. Otherwise, update the game objects, draw
  16. # them, and return False.
  17. # This is an example update function - replace it.
  18. # - center is a list containing the x and y int coords
  19. # of the center of a circle
  20. # - surface is the pygame.Surface object for the window
  21.  
  22. if False: # check if the game is over
  23. return True
  24. else: # continue the game
  25. eraseColor= pygame.Color('black')
  26. # erasing the component
  27. pygame.draw.circle(surface, eraseColor, center, selectedRadius+2)
  28. drawComponent(surface,opaqueColor,transparentColor,selectedColor, opaqueRadius, transparentRadius, selectedRadius, center,state,OPAQUE,TRANSPARENT,SELECTED)
  29. return False
  30.  
  31. def drawComponent(surface,opaqueColor,transparentColor,selectedColor, opaqueRadius, transparentRadius, selectedRadius, center,state,OPAQUE,TRANSPARENT,SELECTED):
  32. if state == OPAQUE:
  33. pygame.draw.circle(surface,opaqueColor,center,opaqueRadius)
  34. if state == TRANSPARENT:
  35. pygame.draw.circle(surface,opaqueColor,center,opaqueRadius)
  36. pygame.draw.circle(surface,transparentColor,center,transparentRadius)
  37. if state == SELECTED:
  38. pygame.draw.circle(surface,opaqueColor,center,opaqueRadius)
  39. pygame.draw.circle(surface,transparentColor,center,transparentRadius)
  40. pygame.draw.circle(surface,selectedColor,center,selectedRadius, 2)
  41.  
  42. def handleMouseUp (OPAQUE, TRANSPARENT, SELECTED, state, position, center,opaqueRadius):
  43. if cursorInsideComponent(position,center,opaqueRadius):
  44. state = SELECTED
  45. return state
  46. else:
  47. state = OPAQUE
  48. return state
  49. def handleMouseMotion(OPAQUE, TRANSPARENT, SELECTED, state, position, center,opaqueRadius):
  50. if state == SELECTED:
  51. return state
  52. else:
  53. if cursorInsideComponent(position,center,opaqueRadius):
  54. state = TRANSPARENT
  55. else:
  56. state= OPAQUE
  57. return state
  58. def cursorInsideComponent(position,center,opaqueRadius):
  59. position = pygame.mouse.get_pos()
  60. d= math.sqrt((center[0]-position[0])**2+(center[1]-position[1])**2)
  61. return d < opaqueRadius
  62. # Main program
  63.  
  64. # Initialize pygame
  65. pygame.init()
  66.  
  67. # Set window size and title, and frame delay
  68. surfaceSize = (500, 400) # example window size
  69. windowTitle = 'Bypass' # example title
  70.  
  71.  
  72. # Create the window
  73. surface = pygame.display.set_mode(surfaceSize, 0, 0)
  74. pygame.display.set_caption(windowTitle)
  75.  
  76. # create and initialize objects
  77. gameOver = False
  78. center = [30, 175]
  79. opaqueRadius = 10
  80. opaqueColor= pygame.Color('blue')
  81. transparentRadius= 5
  82. transparentColor= pygame.Color('yellow')
  83. selectedColor= pygame.Color('red')
  84. selectedRadius= 12
  85. position = pygame.mouse.get_pos()
  86.  
  87. OPAQUE = 0
  88. TRANSPARENT = 1
  89. SELECTED = 2
  90. state = OPAQUE
  91. # Refresh the display
  92. pygame.display.update()
  93.  
  94. # Loop forever
  95. while True:
  96. # Handle events
  97. for event in pygame.event.get():
  98. if event.type == QUIT:
  99. pygame.quit()
  100. sys.exit()
  101. # Handle additional events
  102. if event.type == MOUSEBUTTONUP and not gameOver:
  103. state = handleMouseUp(OPAQUE, TRANSPARENT, SELECTED,state, position, center,opaqueRadius)
  104.  
  105. if event.type == MOUSEMOTION and not gameOver:
  106. state = handleMouseMotion(OPAQUE, TRANSPARENT, SELECTED, state, position, center,opaqueRadius)
  107.  
  108.  
  109. # Update and draw objects for the next frame
  110. gameOver = update(opaqueColor, transparentColor, selectedColor,center,opaqueRadius,transparentRadius, selectedRadius,state, OPAQUE,TRANSPARENT,SELECTED, surface)
  111. # Refresh the display
  112. pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement