15: BACKGROUND GRAPHICS 207 ------------------------------ Nowadays, it's not uncommon for an arcade game to contain hunderds of different screens. With compaction, it's possible to crap a single 32 colour screen into about 30k of memory. So 100 screens would be the equivalent of about 3 Megabytes of data. Imagine how difficult this would be to fit into a standard A500! The classic way of avoiding this restriction, is to construct your backgrounds out of a set of simple building blocks. Once these "tiles" have been created, they can be placed on the screen in any order you like. So the same set of tiles can be reused to generate a vast number of potential screens. Each screen is now stored as a simple list of its components, and requires a tiny fraction of the original memory. In order to exploit this system, you'll obviously need some way of defining your various screen maps. As you might have guessed, we've helpfully provided you with a powerful map definer accessory on the AMOS program disc. Full details can be found in the accompanying documentation file. AMOS Basic also includes a number of special instructions for drawing your tiles on the screen. These make it easy to generate the fast scrolling backgrounds that are the hallmark of a modern arcade game. Icons ===== Icons are separate images which have been especially designed for producing your background screens. Once you've drawn an icon, it's fixed permanently into place. So you can't move it to a new position using the AMAL animation system. All icons are stored in their own AMOS memory bank (#2). This bank is created using the Sprite definer accessory (on the AMOS Program disk), and will be automatically saved along with your Basic programs. Like Bobs, Icons are displayed using the Amiga's amazing Blitter chip. But since Icons are essentally static objects, they are usually drawn in REPLACE mode. Your icons will therefore totally erase any existing graphics at the current screen position. PASTE ICON (draw an icon) PASTE ICON x,y,n Draws icon number n on the screen at GRAPHIC coordinates x,y. n is the number of the icon which is to be displayed. This must have been previously stored in the ICON bank. Icons can be freely positioned anywhere on the screen, subject to the normal clipping rules. Example: Load "AMOS_DATA:Icons/Map_icons.abk" Screem Open 0,320,256,32,Lowres : Cls 0 : Get Icon Palette For X=1 To 11 : Paste Icon X*32,0,1 : Next X For Y=1 To 6 : Paste Icon 0,Y*32+11 : Paste Icon 288,Y*32,1 Next Y For X=1 To 11 : Paste Icon X*32,223,1 : Next X Note that if you're using double buffering, a copy of your icons will be drawn into both the physical and logical screens. Since this is rather slow, it's common practive to add a call to AUTOBACK 0 before drawing your icons on the screen. This restricts straight to the physical screen using SCREEN COPY, saving a considerable amount of time. For a further example, see the MAPVIEW program on the AMOS DATA disc. This displays a background screen you've created using the AMOS Map Editor. GET ICON (create an icon) 208 GET ICON [s,] i,tx,ty TO bx,by Captures an image from the screen and loads it into icon "i". If this icon does not presently exist, it will be created for you in bank 2. This bank will be automatically reserved by the system if required. i is the number of your icon, starting from 1. tx,ty to bx,by define the rectangular zone which encloses the selected region. s determines the number of the screen which will be used as the source of your image. If it's omitted, the image will be taken from the current screen instead. Example: Erase 2 F$=Fsel$("*.*","","Load a screen") : If F$="" Then Direct If Exist(f$) Then Load Iff f$,0 Else Direct SH=Screen Height : H=SH/32-1 : SW=Screen Width : W=SW/32-1 For Y=0 to H For X=0 to W Get Icon X+Y*W+1,X*32,Y*32 To X*32+31,Y*32+31 Next X Next Y Cls 0 Do Paste Icon Rnd(Sw-1),Rnd(SH-1),Rnd/(H*W)+1 Loop GET ICON PALETTE (get icon colours) GET ICON PALETTE Grabs the colours of the icon images in bank 2, and loads them into the current screen palette. This command is normally used to initialize the screen after you'be loaded some icons from the disc. Example: Load "AMOS_DATA:Icons/Map_icons.abk" Get Icon Palette Paste Icon 100,100,1 DEL ICON (deletes icons) 209 DEL ICON n[ TO m] Deletes one or more icons from the icon bank. n is the number of the first icon to be removed. m is the optional number of the last icon to be deleted in the list. If it's included all the icons from first to last will be erased one after another. When the final icon in a bank has been deleted, the entire bank will be removed from memory. MAKE ICON MASK (set colour zero to transparent) MAKE ICON MASK [n] Normally, any icons you draw on the screen will completely replace the existing background. The icon will seem to be displayed in a rectangular box filled with colour zero. If you want to avoid this effect and overlay your icons directly over the current graphics, you'll need to create a *mask* for your icons. This informs AMOS that colour zero should be treated as transparent. n is the number of the icon to be affected. If it's omitted, a mask will be defined for all icons in the bank. See EXAMPLE 15.1 Screen blocks ============= AMOS Basic supplies you with a set of powerful BLOCK commands which allow you to grab part of an image into memory and paste it anywhere on the screen. These instructions are mainly used for holding temporary data, since your blocks cannot be saved along with your Basic programs. Blocks are especially effective in the construction of dialogue boxes, as they can be used to save the background areas before displaying your new graphics. They can also be exploited in puzzle games like Split Personalities. Each block can be loaded with a single section of your image. You can then jumble your pictures by rearranging the blocks on the screen with PUT BLOCK. GET BLOCK (grab a screen block into memory) GET BLOCK n,tx,ty,w,h[,mask] GET BLOCK grabs a rectangular area in block number n, starting at coordinates tx,ty. n is the number of the block ranging from 1-65535. tx, ty set the coordinates of the top left hand corner of your block. w,y hold the width and height of the block respectively. "mask" is a flag which chooses whether a mask will be created for your new block. mask=0 Replace mode. When the block is drawn on the screen, it will totally destroy any graphics at that current position. mask=1 Calculates a mask for the block. Colour zero will now be treated as if it were transparent. PUT BLOCK (copies a previously created 210 block onto the screen) PUT BLOCK n[,x,y] PUT BLOCK n,x,y,planes[,minterms] PUT BLOCK copies block number n to the current screen. x,y specify the position of your new block on the screen. If they are omitted the block will be redrawn at its original screen coordinates. Note that all drawing operations will be clipped to fit into the current screen, starting from the nearest 16 pixel boundary. For a demostration of the BLOCK commands see the routine in EXAMPLE 15.2. We've also provided experienced programmers with a couple of optional extras. These are not needed for the vast majority of applications, they're only required when you want to achieve weird special effects on the screen! "planes" holds a bit-map which sets the range of colours which will be drawn in your block. The Amiga's screen is divided up into segments known as bit-planes. Each plane contains a single bit for every point on the Amiga's screen. When the Amiga's hardware displays this point, it combines the bits from each plane to calculate the required colour number. Each bit in "planes" represents the status of a single bit-plane. If it's set to one, then the selected plane will be drawn by the instruction, otherwise it will be completely ignored. The first plane is represented by bit zero, the second by bit one, etc. Usually, the block will be displayed in all the available bit-planes. The corresponds to a bit-pattern of %111111 "minterm" selects the blitter mode used to copy your block on the screen. A full description of the possible drawing modes can be found in the section on SCREEN COPY. The best way to loearn about these options is to experiment! DEL BLOCK (delete a screen block) DEL BLOCK n Deletes one or more blocks and restores the memory used to AMOS Basic. DEL BLOCK Erases *all* current blocks DEL BLOCK n Deletes block number n. GET CBLOCK (save and compact a screen image) 211 GET BLOCK n,x,y,sx,sy The GET BLOCK command saves and compacts a rectangular area of the screen. The compaction system used by this command has been especially optimized for speed. So it's nowhere near as efficient as the dedicated AMOS compression routines provided by the PACK or SPACK instructions. CBLOCKS are often used to grab the area underneath your dialogue boxes. After the dialogue has been completed, the screen can quickly restored back to its original state. See EXAMPLE 15.3. n specifies the number of your block and can range between 1-65535. x,y are the top left coordinates. The x coordinate is rouded to the nearest multiple of 8. w,h hold the dimensios of the area to be saved. The width is always rounded to an exact multiple of 8. PUT CBLOCK (displays a block created using CBLOCK) PUT CBLOCK n [,x,y] Places block n on the current screen at coordinates x,y. If the target coordinates are omitted, the block will be redrawn at its original screen position. Also note that x is automatically rounded to the nearest eight pixel boundary. DEL CBLOCK (deletes a screen block defined with GET CBLOCK) DEL CBLOCK [n] Erases all blocks from memory. If n is present only block n will be deleted.