Task: Write a Simple Program to Move a Sprite on Your Amiga Computer Using AMOS Professional BASIC
Needed: AMOS Professional BASIC, Amiga Computer or Emulator
Time: 30-60 Minutes
Introduction
I grew up programming on Atari 8-bit computers in the early 1980s and loved making sprites and moving them around the screen using player-missile graphics. The Amiga is a much more sophisticated gaming machine and has the ability to place eight sprites on the screen simultaneously with each controlled by the hardware for fast animation. AMOS Professional BASIC makes it super easy to create and animate sprites with its AMOS Animation Language (AMAL). The speed comes from automatic compilation of the code before execution and synchronization with the vertical blank after each screen is drawn.
Instructions
The first thing you need is AMOS Professional BASIC. You can download the ADF floppy disk images to load on a Gotek, for example. A much easier solution is to download and install the Amiga Game Selector (AGS) that includes AMOS in its Work directory. Press ESC from AGS to get to Workbench and then open Work and look for Programming. This is what I did.
Below is the AMOS edit window with the code to enter. I describe each line below. This program draws a square, captures it as a sprite, and then animates it back and forth across the screen. You can download the .amos file for the code below.

The first line of code opens a screen on in low resolution mode with 320 by 256 pixels and 16 colors. The 0 indicates we want a black screen color.
The second line turns off the cursor, cursor flashing, and the mouse pointer. The Cls command clears the screen.

The next two lines of code set the color of the sprite using Ink and draws a square on the screen using the Bar command. This square is 16 by 16 pixels. 16 is the maximum width of a sprite. They can be up to 255 pixels tall. Once the square is drawn we need to capture it as a sprite using the Sprite command. The first argument sets the sprite number (0 is reserved for the cursor). The next two arguments specify the X and Y location of the sprite. The last argument indicates the number of sprite image which can be reused in other sprites,. We end with a Cls 0 to clear the screen.

The next line starting with Channel sets the sprite to Channel 1 that is used by AMAL for animation.

The following five lines defines some strings that contain the animation instructions for AMAL. Start is a label that we will jump to for looping within AMAL. Next, we Move the sprite 300 pixels to the right at speed 100 (lower numbers are faster). This is followed by Moving the sprite back the left 300 pixels (demoted by the negative) at the same speed. The 0s are the Y direction which is static in this case. Finally, we issue a Jump to Start to loop the animation, so the sprite moves back and forth until a key is pressed. We combine these strings into A$.

We execute the A$ string commands on the next line with AMAL 1,A$ where the 1 indicates the object in Channel 1.
We use a Wait Key command on the next line to wait for a key press to then turn AMAL Off as well as the Sprite Off before we End the program.


Comments
This is a really simple program but it illustrates how to create a hardware sprite and then animate it using AMAL. I will do some more posts on moving sprites with a joystick and detecting collisions.