Learn How to Scroll a Playfield in Amiga AMOS Professional BASIC (30-60 mins)

Task: Learn How to Scroll a Playfield in Amiga AMOS Professional BASIC

Needed: AMOS Professional BASIC, Amiga Computer or Emulator

Time: 30-60 Minutes

Introduction

I have previously posted about drawing and moving a sprite on the screen. This project is to draw and scroll a playfield which is quite easy in AMOS BASIC. The general idea of scrolling on any old gaming platform is that you first draw a playfield that is bigger than the screen itself so as one part of the graphics scrolls off the screen on one side the next part can scroll on and become visible on the opposite side. Programmatically, the data are stored in memory and scrolling happens by shifting where in memory the system looks when it needs to draw the next screen. AMOS BASIC makes this relatively fast and easy. You can define and draw a screen that is up to 1024 pixels and use the SCREEN OFFSET command to access it. Here, we define a low-resolution screen that is 320 pixels wide by 240 high. We will draw some circles in the visible part of the screen and then repeat them off to the right of the visible screen in the next 320 pixels so that as one scrolls off to the left the same shape scrolls on to the right seamlessly. After 320 pixels has shifted right we start over.

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. Choose and boot AMOS Professional. 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 and an ASCII text file for the code below. The .amos file can be opened using the Load and Open menu command. The ASCII file can be opened using the Merge ASCII menu command.

The first line of code opens a screen in low resolution mode with 320 by 256 pixels and 16 colors. The 0 indicates we want a black screen color.

The next three lines turn off the cursor and cursor flashing. The Cls command clears the screen. You can add Hide to hide the mouse pointer.

The five lines below set the starting positions (X1, X2, and X3) for each of the three circles we will draw. Y is the Y position. R1 is the radius for the larger middle circle and R2 is the radius for the smaller circles. Offset is used to add to the X starting position to draw the offscreen circles that will scroll on as the first set scrolls off screen. C1, C2, and C3 define the red, blue, and green colors of the circles.

These next six lines draw each circle and its offscreen twin. Ink sets the color of the circles. Paint fills in the color, so the circles are solid.

The final seven lines below perform the scrolling. We set up a DO LOOP that goes on forever offsetting the screen one pixel at a time to the right until it hits 320 pixels at which time it starts over at 0. Note that the first number of the Screen Offset command (0) defines the screen we are scrolling (i.e. Screen 1 of 1). The offset jumps at intervals of three (SCRX=SCRX+3) for faster scrolling. You can reduce that number to 1 or 2 for slower scrolling or increase it for faster. Wait Vbl waits for the vertical blank that happens when the screen is done drawing. This keeps everything in sync.

Below is a video of the scrolling demo running in AMOS Professional on my Amiga 1200.

Comments

There is more to scrolling that I hope to cover in future posts. This should get you started!