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:

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

Step 1: Three Action Functions

Open a new Python project named Score Shooter.

Start with this short code:

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:

EDIT VIEW · Gray = already there; dark = add or change
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:

CODE
from hub import port, motion_sensor

Add this function above main(), with its def line at the left edge:

CODE
def is_tapped():
    return motion_sensor.gesture() == motion_sensor.TAPPED

Change main():

EDIT VIEW · Gray = already there; dark = add or change
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

Teacher Check

Show your teacher:

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.