Skip to main content
Engineering LibreTexts

6.3: The Usual Starting Stuff

  • Page ID
    13592
  • # Simulate (a Simon clone)
    # By Al Sweigart al@inventwithpython.com
    # http://inventwithpython.com/pygame
    # Released under a "Simplified BSD" license
    
    import random, sys, time, pygame
    from pygame.locals import *
    
    FPS = 30
    WINDOWWIDTH = 640
    WINDOWHEIGHT = 480
    FLASHSPEED = 500 # in milliseconds
    FLASHDELAY = 200 # in milliseconds
    BUTTONSIZE = 200
    BUTTONGAPSIZE = 20
    TIMEOUT = 4 # seconds before game over if no button is pushed.
    
    #                R    G    B
    WHITE        = (255, 255, 255)
    BLACK        = (  0,   0,   0)
    BRIGHTRED    = (255,   0,   0)
    RED          = (155,   0,   0)
    BRIGHTGREEN  = (  0, 255,   0)
    GREEN        = (  0, 155,   0)
    BRIGHTBLUE   = (  0,   0, 255)
    BLUE         = (  0,   0, 155)
    BRIGHTYELLOW = (255, 255,   0)
    YELLOW       = (155, 155,   0)
    DARKGRAY     = ( 40,  40,  40)
    bgColor = BLACK
    
    XMARGIN = int((WINDOWWIDTH - (2 * BUTTONSIZE) - BUTTONGAPSIZE) / 2)
    YMARGIN = int((WINDOWHEIGHT - (2 * BUTTONSIZE) - BUTTONGAPSIZE) / 2)
    

    Here we set up the usual constants for things that we might want to modify later such as the size of the four buttons, the shades of color used for the buttons (the bright colors are used when the buttons light up) and the amount of time the player has to push the next button in the sequence before the game times out.

    • Was this article helpful?