def main_menu(window, main_clock, PATH_TO_ROOT): # Set variables title = txt.menu_title.render("HORSE", 1, cval.black) running = True # load image assets background = pygame.image.load(MENU) img_twitter = pygame.image.load(TWITTER_ICON) while running: window.fill(cval.black) # Default to fill window with black window.blit(background, (0, 0)) # Overlay background image # Window height and width win_width, win_height = window.get_size() # Place Title in top center loc_x = win_width / 2 - title.get_width() / 2 loc_y = win_height / 3 - title.get_height() / 2 window.blit(title, (loc_x, loc_y)) # Create and position play button btn_width = 90 btn_height = 50 loc_x = win_width / 4 - btn_width / 2 loc_y = win_height * 2 / 3 - btn_height / 2 play_btn = Button(cval.white, loc_x, loc_y, btn_width, btn_height, "Play") # Create and position options button loc_x = win_width * 3 / 4 - btn_width / 2 loc_y = win_height * 2 / 3 - btn_height / 2 team_menu_btn = Button(cval.white, loc_x, loc_y, btn_width, btn_height, "Credits") # Create and position hacked screen loc_x = 20 loc_y = 20 hacked_screen_btn = Button(cval.white, loc_x, loc_y, btn_width, btn_height, "Hacked") # Twitter icon btn_width = 56 btn_height = 56 loc_x = win_width - 60 loc_y = win_height - 60 twitter_btn = Button(cval.white, loc_x, loc_y, btn_width, btn_height, "") # Display menu buttons play_btn.draw(window) team_menu_btn.draw(window) hacked_screen_btn.draw(window) twitter_btn.draw(window) window.blit(img_twitter, (win_width - 64, win_height - 64)) # Get mouse position mx, my = pygame.mouse.get_pos() # Check for key press or mouse click event clicked = False for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: clicked = True # React to mouse click if clicked: # Check for click location if play_btn.mouse_over((mx, my)): game(window, main_clock) if team_menu_btn.mouse_over((mx, my)): credits_screen(window, main_clock, PATH_TO_ROOT) if hacked_screen_btn.mouse_over((mx, my)): hacked_screen(window, main_clock, PATH_TO_ROOT) if twitter_btn.mouse_over((mx, my)): twit = Twitter(PATH_TO_ROOT) twit.open_login_window() login_status = twit.login_screen(window, main_clock) if login_status == True: twit.tweet_advertisement() twit.thank_user_window(window, main_clock) pygame.display.update() main_clock.tick(60)
def robotInit(self): self.sd = NetworkTable.getTable('SmartDashboard') # #INITIALIZE JOYSTICKS## self.joystick1 = wpilib.Joystick(0) self.joystick2 = wpilib.Joystick(1) self.ui_joystick = wpilib.Joystick(2) self.pinServo = wpilib.Servo(6) # hello # #INITIALIZE MOTORS## self.lf_motor = wpilib.Talon(0) self.lr_motor = wpilib.Talon(1) self.rf_motor = wpilib.Talon(2) self.rr_motor = wpilib.Talon(3) # #ROBOT DRIVE## self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor) self.robot_drive.setInvertedMotor( wpilib.RobotDrive.MotorType.kFrontRight, True) self.robot_drive.setInvertedMotor( wpilib.RobotDrive.MotorType.kRearRight, True) # #INITIALIZE SENSORS# self.sweeper_relay = wpilib.Relay(0) self.gyro = wpilib.Gyro(0) self.tote_motor = wpilib.CANTalon(5) self.can_motor = wpilib.CANTalon(15) self.sensor = Sensor(self.tote_motor, self.can_motor) self.tote_forklift = ToteForklift(self.tote_motor, self.sensor, 2) self.can_forklift = CanForklift(self.can_motor, self.sensor, 3) self.calibrator = Calibrator(self.tote_forklift, self.sensor) self.next_pos = 1 self.backSensor = SharpIRGP2Y0A41SK0F(6) self.drive = drive.Drive(self.robot_drive, self.gyro, self.backSensor) self.align = alignment.Alignment(self.sensor, self.tote_forklift, self.drive) self.components = { 'tote_forklift': self.tote_forklift, 'can_forklift': self.can_forklift, 'drive': self.drive, 'align': self.align, 'sensors': self.sensor } self.control_loop_wait_time = 0.025 self.automodes = AutonomousModeSelector('autonomous', self.components) # #Defining Buttons## self.canUp = Button(self.joystick1, 3) self.canDown = Button(self.joystick1, 2) self.canTop = Button(self.joystick1, 6) self.canBottom = Button(self.joystick1, 7) self.toteUp = Button(self.joystick2, 3) self.toteDown = Button(self.joystick2, 2) self.toteTop = Button(self.joystick2, 6) self.toteBottom = Button(self.joystick2, 7) self.ui_joystick_tote_down = Button(self.ui_joystick, 4) self.ui_joystick_tote_up = Button(self.ui_joystick, 6) self.ui_joystick_can_up = Button(self.ui_joystick, 5) self.ui_joystick_can_down = Button(self.ui_joystick, 3) self.reverseDirection = Button(self.joystick1, 1) #self.alignTrigger = Button(self.joystick2, 1) self.toteTo = 0 self.oldTote = 0 self.canTo = 0 self.oldCan = 0 self.reverseRobot = False self.oldReverseRobot = False self.autoLift = False self.sd.putNumber('liftTo', 0) self.sd.putNumber('binTo', 0) self.sd.putBoolean('autoLift', False) self.sd.putBoolean('reverseRobot', False)