Skip to content

Instantly share code, notes, and snippets.

@Taresin
Created February 12, 2026 08:29
Show Gist options
  • Select an option

  • Save Taresin/b36c7c58877b484afe09a7153c7e78df to your computer and use it in GitHub Desktop.

Select an option

Save Taresin/b36c7c58877b484afe09a7153c7e78df to your computer and use it in GitHub Desktop.
# ---------------------------------------------------------------------------- #
# #
# Module: main.py #
# Author: dougy #
# Created: 2/12/2026, 11:14:38 PM #
# #
# Project: Fighter Controller #
# Description: This project upgrades the use of the controller to use #
# fighting game style inputs to control the AIM Robot #
# #
# ---------------------------------------------------------------------------- #
# Library imports
from vex import *
from vex_globals import *
# Robot should be defined by default
robot=Robot()
controller=Onestick()
sliding_window = []
# System event handlers
def fireball(force):
if not robot.has_sports_ball():
return
Thread(robot.sound.play_file, ("sound1.mp3", ))
wait(800, MSEC)
Thread(robot.kicker.kick, (force, ))
def hard_punch():
if detect_fireball(sliding_window):
fireball(HARD)
sliding_window.clear()
def medium_punch():
if detect_fireball(sliding_window):
fireball(MEDIUM)
sliding_window.clear()
controller.button_left.pressed(medium_punch)
controller.button_up.pressed(hard_punch)
def spin():
robot.turn_for(RIGHT, 360, 100)
def kick():
robot.kicker.kick(HARD)
wait(250, MSEC)
robot.kicker.kick(HARD)
wait(250, MSEC)
robot.kicker.kick(HARD)
wait(250, MSEC)
robot.kicker.kick(HARD)
wait(250, MSEC)
def spin_kick():
Thread(robot.sound.play_file, ("sound2.mp3", ))
Thread(spin)
Thread(kick)
def medium_kick():
if detect_spin_kick(sliding_window):
spin_kick()
sliding_window.clear()
controller.button_down.released(medium_kick)
def handle_joystick_input_changed():
vertical_input = controller.axis1.position()
horizontal_input = controller.axis2.position()
joystick_position = resolve_joystick_input(vertical_input, horizontal_input)
print("Joystick position: " + str(joystick_position))
handle_joystick_input(joystick_position)
controller.axis1.changed(handle_joystick_input_changed)
controller.axis2.changed(handle_joystick_input_changed)
JOYSTICK_POSITION_1 = 1
JOYSTICK_POSITION_2 = 2
JOYSTICK_POSITION_3 = 3
JOYSTICK_POSITION_4 = 4
JOYSTICK_POSITION_5 = 5
JOYSTICK_POSITION_6 = 6
JOYSTICK_POSITION_7 = 7
JOYSTICK_POSITION_8 = 8
JOYSTICK_POSITION_9 = 9
ATTACK_BUTTON_LEFT = 10
ATTACK_BUTTON_UP = 11
ATTACK_BUTTON_DOWN = 12
ATTACK_BUTTON_RIGHT = 13
def resolve_joystick_input(vertical_input, horizontal_input):
is_left = horizontal_input < -30
is_right = horizontal_input > 30
is_up = vertical_input > 30
is_down = vertical_input < -30
if is_left and is_down:
return JOYSTICK_POSITION_1
elif is_right and is_down:
return JOYSTICK_POSITION_3
elif is_down:
return JOYSTICK_POSITION_2
elif is_left and is_up:
return JOYSTICK_POSITION_7
elif is_right and is_up:
return JOYSTICK_POSITION_9
elif is_up:
return JOYSTICK_POSITION_8
elif is_left:
return JOYSTICK_POSITION_4
elif is_right:
return JOYSTICK_POSITION_6
else:
return JOYSTICK_POSITION_5
def handle_joystick_input(joystick_position):
if len(sliding_window) > 0 and sliding_window[-1] == joystick_position:
return
sliding_window.append(joystick_position)
if len(sliding_window) > 10:
sliding_window.pop(0)
def detect_fireball(sliding_window):
# Find a 2, 3, 6 pattern in the sliding window
match = any(sliding_window[i:i+3] == [2, 3, 6] for i in range(len(sliding_window) - 2))
return match
def detect_spin_kick(sliding_window):
# Find a 4, 5, 8 pattern in the sliding window
match = any(sliding_window[i:i+3] == [2, 1, 4] for i in range(len(sliding_window) - 2))
return match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment