STARLEAP / SPIKE PRIME PYTHON / 2026–27
Build 2026.09.22-090630-0400
On this page
Project 12: Tabletop Score Shooter
You need: a LEGO SPIKE Prime set and the SPIKE App Python editor.
Goal
Make the Table Top Game player shoot after the hub is tapped.
Build
Build Table Top Game from the LEGO SPIKE Prime building instructions.
Starting port:
- shooter arm motor: Port A
Set up a goal and mark a shooting line about 10 inches away.
Using the code: gray lines are already in your program; dark lines are the edit. Keep the shown indentation. Replace a displayed main() definition as a whole, keeping imports and the final start call.
What You Will Learn
- A function can name one robot action.
main()can call functions in order.- A motion sensor gesture can start the routine.
- Tuning one number can change a physical result.
Step 1: Three Action Functions
Open a new Python project named Score Shooter.
Start with this short code:
from hub import port
import runloop
import motor
arm_motor = port.A
async def raise_arm():
await motor.run_to_absolute_position(
arm_motor, 270, 300, direction=motor.COUNTERCLOCKWISE,
)
async def shoot():
await motor.run_for_degrees(arm_motor, 260, 300)
async def lower_arm():
await motor.run_to_absolute_position(
arm_motor, 0, 300, direction=motor.COUNTERCLOCKWISE,
)
async def main():
await raise_arm()
await shoot()
await lower_arm()
runloop.run(main())
Run the program.
Observe: The player raises, shoots, and lowers.
Step 2: Tune The Shot
Replace the movement line inside shoot(). This changes only its degrees from 260 to 240:
async def shoot():
await motor.run_for_degrees(arm_motor, 240, 300)
Run the program after each change.
Observe: Which value gets the puck closer to the goal?
Step 3: Wait For A Tap
Change the first import:
from hub import port, motion_sensor
Add this function above main(), with its def line at the left edge:
def is_tapped():
return motion_sensor.gesture() == motion_sensor.TAPPED
Change main():
async def main():
await runloop.until(is_tapped)
await raise_arm()
await shoot()
await lower_arm()
Run the program.
Observe: Nothing should happen until you tap the hub.
Physical Challenge: Score From The Line
- Level 1: shoot after a tap
- Level 2: score from the 10-inch line
- Level 3: score twice from the same line
- Level 4: put the tap-and-shoot routine inside
while True
Teacher Check
Show your teacher:
raise_arm()shoot()- the tap wait line
- the number you tuned for the shot
Before You Put The Kit Away
Save your program. Stop the program before moving wires or changing the build. Show the teacher your working behavior, point to one changed line, and explain what it controls. Keep your place for next time.