• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Retro Game Coders

Retro Game Coders

Retro computer/console game + dev community

  • About
    • Retro Computer Collection
    • Contact
  • Blog
  • Retro Resources
    • Retro Gaming Timeline
    • Online Retro IDE
    • Retro Pixel Art Editor
    • Dungeon Loom Map Editor
    • 6502 Programmer’s Reference
    • Emulators
      • Acorn Electron
      • Amstrad CPC Emulator
      • Online BBC Micro Emulator
      • Commodore PET Emulator
      • Browser C64 Emulator
      • DOSBox/DOS PC emulator
      • Tandy CoCo/Dragon
    • Best Retro YouTube Channels
    • New Retro Books
    • Raspberry Pi Amiga Emulation
    • MiSTer FPGA Tutorial
    • BMC64 C64 Pi
  • Community

Home » Retro Game Coders Blog » Programming

Atari ST Programming: STOS BASIC Sprite Movement

Programming Atari ST game sprites with STOS BASIC

In the last part of this STOS BASIC Tutorial we loaded a sprite but it just sat there, let’s fix that …

▶ Try sprite movement in your browser

Run these sprite examples in our in-browser Atari ST IDE (EmuTOS + STOS). Hit Run and watch STOS drive the motion at 50Hz:

  • sprite-test-minimal.asc (smallest possible sprite test)
  • sprite-move-path.asc (sprite following a path with Move X / Move Y)

One of the ways that STOS BASIC helps us to build interactive programs and games is in the sprite movement features because they are not only easy, but they do their thing without our constant input.

STOS checks and changes each sprite 50 times per second unless you tell it otherwise, and this happens on interrupts, independent of whatever your code is doing at the same time.

Why is this useful?

Consider a shoot ’em up game where your player fires a missile. In a regular coding environment, you might have to check for collisions or if it flew off screen based on the x/y coordinates of the missile in relation to other game objects and move it incrementally as part of your game loop.

In STOS, however, you can simply tell the missile the direction to move and how fast, limiting it to the screen area, and only check collisions with objects using the built-in sprite collision features.

Join Retro Game Coders Community
Join the Retro Game Coders Community

Simple STOS Sprite Movement

STOS offers both Move X and Move Y for horizontal and vertical movement.

cls : mode 0 : curs off : hide on
colour 11,$0
load "c:sprite.mbk"
sprite 1,100,100,1
move y 1,"(1,-4,5)(1,-1,20)(10,-1,10)(10,1,10)(1,1,20)L"
move on
wait key
default 

Here we specify that it is sprite 1 we wish to move, then a sequence of movement commands in (brackets). Each movement command has a timing, how many pixels to move, and how many times to do that movement.

At the end I added the special command L which tells STOS to loop the movements until told to stop.

You can also set an endpoint which is a pixel row, for example, 199 which would stop that sprite’s movement when the sprite reaches that exact row of pixels.

You can now follow the tutorials and edit the code right in your web browser with the Online Retro IDE

– No downloads, configuration, etc necessary, and it is free!

Custom Mouse Pointer

Another fun option is to set the mouse pointer to your sprite:

cls : mode 0 : curs off 
colour 11,$0
load "c:sprite.mbk"
change mouse 4
b=0
while b=0
b=mouse key
wend
default 

The first three mouse pointers (arrow, hand, clock) are built-in so your custom sprite number 1 would be mouse 4, and so on.

In my example we wait for a mouse click instead of a keypress by checking if any buttons are down in a continuous loop, if the result is anything other than zero then we continue.

Joystick Control

Just learn from my mistake and ensure your controller is enabled before you spend hours banging your head against your keyboard in frustration!

As you would no doubt expect, STOS also has routines for joystick control (or in my case, a SNES style joypad).

Screen Shot 2022-04-04 at 13.50.49.png
cls : mode 0 : curs off : hide on
colour 11,$0
load "c:sprite.mbk"
j=0 : q=0 : x=100 : y=100
while q=0
j=joy
if fire then q=1
if jleft then x=x-1
if jright then x=x+1
if jup then y=y-1
if jdown then y=y+1
sprite 1,x,y,1
wend
default

This simple program continuously checks for the fire button to see if we should quit, otherwise, it checks each joystick direction and increments or decrements our character’s position accordingly.

💬 Questions or comments? Head over to the community to discuss!

Keyboard Control

Back in the day, even with the Atari ST, keyboard controls were popular with games. First of all, with any wedge-shaped computer-in-a-keyboard system everyone was guaranteed to own a keyboard, which couldn’t be said for joysticks, and secondly keyboard control offered a lot more opportunities for complex control systems that require more than just directions and fire (consider flight simulators and adventure games).

If your keyboard controls are found in the ASCII character set, you can simply check if it matches the key being pressed like so:

cls : mode 0 : curs off : hide on
colour 11,$0
load "c:sprite.mbk"
k$="" : q=0 : x=100 : y=100
while q=0
k$=inkey$
if k$ = "q" then q=1
if k$ = "a" then x=x-1
if k$ = "d" then x=x+1
if k$ = "w" then y=y-1
if k$ = "s" then y=y+1
sprite 1,x,y,1
wend
default

What if the key you want to look for does not have a character representation? For example the escape key, cursor keys, function keys?

In that case STOS fills the scancode with the numeric representation of the key that was pressed, otherwise scancode contains 0.

cls : mode 0 : curs off : hide on
colour 11,$0
load "c:sprite.mbk"
k$="" : q=0 : x=100 : y=100
while q=0
k$=inkey$
if k$ = "q" then q=1
if k$ = "a" then x=x-1
if k$ = "d" then x=x+1
if k$ = "w" then y=y-1
if k$ = "s" then y=y+1
locate 0,0
print scancode;
sprite 1,x,y,1
wend
default
Screen Shot 2022-04-04 at 14.24.02.png

Next Up

Now the fun begins, next time we will put everything together and start building simple STOS games so we can get truly interactive!
Category: ProgrammingTag: Atari ST, basic programming, stos
Previous Post:Atari ST Graphics Programming with STOS BASIC
Next Post:Atari ST Programming: A Simple Game in STOS

Retro Game Coders

Retro computer/console game + dev programming community by Chris Garrett

  • Bluesky
  • Threads
  • Facebook
  • Instagram
  • YouTube
  • Mastodon

Maker Hacks ・ D6Combat・chrisg.com

© Copyright 2026 Chris Garrett

Privacy ﹒ Terms of Service

Return to top