Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Bypass verison 1. Courtney and Emma
- # In this version there will be one dot on the screen that when clicked will
- # become slected and when hoovered over will be come transparent and will look
- # opaque when no mouse action
- import pygame, sys, time, math
- from pygame.locals import *
- # User-defined classes
- # User-defined functions
- def update(opaqueColor, transparentColor, selectedColor,center,opaqueRadius,transparentRadius, selectedRadius,state, OPAQUE,TRANSPARENT,SELECTED, surface):
- # Check if the game is over. If so, end the game and
- # returnTrue. Otherwise, update the game objects, draw
- # them, and return False.
- # This is an example update function - replace it.
- # - center is a list containing the x and y int coords
- # of the center of a circle
- # - surface is the pygame.Surface object for the window
- if False: # check if the game is over
- return True
- else: # continue the game
- eraseColor= pygame.Color('black')
- # erasing the component
- pygame.draw.circle(surface, eraseColor, center, selectedRadius+2)
- drawComponent(surface,opaqueColor,transparentColor,selectedColor, opaqueRadius, transparentRadius, selectedRadius, center,state,OPAQUE,TRANSPARENT,SELECTED)
- return False
- def drawComponent(surface,opaqueColor,transparentColor,selectedColor, opaqueRadius, transparentRadius, selectedRadius, center,state,OPAQUE,TRANSPARENT,SELECTED):
- if state == OPAQUE:
- pygame.draw.circle(surface,opaqueColor,center,opaqueRadius)
- if state == TRANSPARENT:
- pygame.draw.circle(surface,opaqueColor,center,opaqueRadius)
- pygame.draw.circle(surface,transparentColor,center,transparentRadius)
- if state == SELECTED:
- pygame.draw.circle(surface,opaqueColor,center,opaqueRadius)
- pygame.draw.circle(surface,transparentColor,center,transparentRadius)
- pygame.draw.circle(surface,selectedColor,center,selectedRadius, 2)
- def handleMouseUp (OPAQUE, TRANSPARENT, SELECTED, state, position, center,opaqueRadius):
- if cursorInsideComponent(position,center,opaqueRadius):
- state = SELECTED
- return state
- else:
- state = OPAQUE
- return state
- def handleMouseMotion(OPAQUE, TRANSPARENT, SELECTED, state, position, center,opaqueRadius):
- if state == SELECTED:
- return state
- else:
- if cursorInsideComponent(position,center,opaqueRadius):
- state = TRANSPARENT
- else:
- state= OPAQUE
- return state
- def cursorInsideComponent(position,center,opaqueRadius):
- position = pygame.mouse.get_pos()
- d= math.sqrt((center[0]-position[0])**2+(center[1]-position[1])**2)
- return d < opaqueRadius
- # Main program
- # Initialize pygame
- pygame.init()
- # Set window size and title, and frame delay
- surfaceSize = (500, 400) # example window size
- windowTitle = 'Bypass' # example title
- # Create the window
- surface = pygame.display.set_mode(surfaceSize, 0, 0)
- pygame.display.set_caption(windowTitle)
- # create and initialize objects
- gameOver = False
- center = [30, 175]
- opaqueRadius = 10
- opaqueColor= pygame.Color('blue')
- transparentRadius= 5
- transparentColor= pygame.Color('yellow')
- selectedColor= pygame.Color('red')
- selectedRadius= 12
- position = pygame.mouse.get_pos()
- OPAQUE = 0
- TRANSPARENT = 1
- SELECTED = 2
- state = OPAQUE
- # Refresh the display
- pygame.display.update()
- # Loop forever
- while True:
- # Handle events
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- # Handle additional events
- if event.type == MOUSEBUTTONUP and not gameOver:
- state = handleMouseUp(OPAQUE, TRANSPARENT, SELECTED,state, position, center,opaqueRadius)
- if event.type == MOUSEMOTION and not gameOver:
- state = handleMouseMotion(OPAQUE, TRANSPARENT, SELECTED, state, position, center,opaqueRadius)
- # Update and draw objects for the next frame
- gameOver = update(opaqueColor, transparentColor, selectedColor,center,opaqueRadius,transparentRadius, selectedRadius,state, OPAQUE,TRANSPARENT,SELECTED, surface)
- # Refresh the display
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement