APPLICATIONSPROGRAMMATION ★ Make a video nasty! ★

Sprite System (CPC Computing)Applications Programmation
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

IAN SHARPE shows you how to succeed in sprites without really trying

AS promised last month. I'm following the assembly language sprite routine with a ready-made Mode 0 package for Basic programmers. You don't need any knowledge of machine code to understand it, just an average level of competence in Basic.

Having typed in Program I - Sprite System - the idea is that you can use it to design sprites with a simple editor. The sprites can then be saved as a binary file, and along with the shape data is the machine code. You can load ie sprite file into Basic, and the machine code can be called to move the sprites around the screen.

It's all pretty straightforward, and I'll begin with a run down on the designer.

When you run it you will see a display similar to Figure I. At the bottom left is a list of the pen numbers - 0 to 15 - with the colours assigned to them. To change the colours in a pen, move the pointer to the one required using Shift with the up and down cursor keys. Then use the left and right arrow keys in conjunction with Shift or Control to alter the colours.

The numbers you see are the same ones used in Basic's INK command, and you must remember to note them down so you can set them up in your game.

After deciding on your palette, it's time to start designing. Down the right hand edge of the screen is a bank of 25 blocks, and each is a pigeon hole for a sprite.

If you want to store the sprite you've just designed, move the pointer to the slot you want to put it in with Control and the up and down arrow keys, and press Control P (for Put). If you want to edit a previously defined sprite, move the pointer to the one you want, and press Control G (for Get).

The editing area is completely independent of the sprite bank, so don't forget to put the sprite back when you have finished editing it.

The editing area consists of an 8x8 grid which, being in fat-pixel Mode 0, is twice as wide as it is high. You can move a cursor round with the arrow keys, and pressing the spacebar plots that pixel in the currently selected pen. The Del key will delete it.

If you want to reflect the sprite horizontally or vertically. Control M (for Mirror) and Control V (for Vertical mirror) do the trick. If you can't remember which keys do what, Control H brings up a Help screen with all the commands listed.

When you've finished an editing session, press Control S (for Save) to save the sprite set to tape or disc. This file can be reloaded next time with Control L (for Load), though disc users may find the operating system has added .bin to the filename. The file can also be loaded from a Basic program to provide the means of printing and moving the characters around.

Get moving!

Early in your program you should set up the ink values you noted down

from the editor, and include these few lines:

100 MEMORY &7FFF
110 LOAD"sprites.bin",&8032
120 CALL &8032

The line numbers aren't significant, and, of course, you may have given the sprite file a different name when you saved it.

How do you now use your sprites? There are two ways of calling the machine code:

CALL &804C,x,y,n
CALL &804C,ox,oy,on,nx,ny,nn

The first case is where you put the sprite on the screen in the first place. You specify the x and y coordinates which are exactly the same as the text coordinates in:

LOCATE x,y

The number n is the number of the sprite you want to print, and as you'll see in Figure I the numbers are shown next to the sprites in the editor. As an example, let's suppose you want to print sprite 3 at 10,5:

CALL &8040,10,5,3

You can also use this call to remove a sprite by overprinting it with a blank block. I suggest you define this as sprite zero.

The second call is for moving the sprite from one character cell to another. The character is at location ox,oy and it is being moved to nx,ny. As I said, you should define a sprite -preferably zero - as a blank block. This can then be used as on to erase the old sprite. If we were moving sprite 6 from 10,5 to 11,5, the command would be:

CALL &8040,10,5,0,11,5,6

You may be wondering why I make you specify a block number with which to erase the old sprite. This is to make the system more flexible. Most of the time you may be running your characters around on a blank background, but if you were writing a Pac-Man type game, there would be places where the sprites move to uncover a dot, not a blank.

With a little thought you will see that these calls directly substitute for the:

LOCATE x,y:PRINT chr$(n);
LOCATE ox,oy:PRINT " ";:LOCATE nx,ny:
PRINT CHR$(nn)

type constructions.

I realise that this sprite system is very rudimentary, but there's still a lot of fun to be had with it. If you typed in Tiffany's Save Santa from the January 1988 issue, you will have seen that it is possible to write games of a publishable standard with this utility.

Save Santa wasn't actually created with Sprite System because it didn't exist then - but it could have been, and in less time. Sprite System gives you an improved version of the machine code I wrote for Tiff, so you can see that the results can be good.

Now I'll give you an example of the system in action. Program II creates a sprite file on tape or disc, and you should type this in and run it before going on to Program III. You can load the resulting file into Sprite System for editing if you want to, though you'll have to alter the ink values to those shown in the data near the start of Program III.

The demonstration - Program III -has a missile launcher which can be moved left or right with the cursor keys. The spacebar fires a rocket, and the object is to kill the invaders which descend from the top of the screen. This isn't intended to be a full game, just an example, though if I'd written it seven years ago, I'd have made a mint. Ah, those were the days!

And there I'll leave it. I've been talking about arcade games, but this system can be used effectively any time you want multi-coloured Mode 0 characters printed easily and quickly. It doesn't have to be an invaders or Pac-Man clone.

No doubt many of you aren't at a stage where you can understand the example or program your own, so if enough of you write in asking for a follow-up article on this aspect I'll cover it at a later date. Also, I've been working on more advanced sprites which are able to move over and behind screen objects, and where the background shows through holes and right up to the edge.

The techniques are quite advanced, involving machine code, so I'd like to know how many are interested before inflicting reams of assembler on the unsuspecting public.

CPC Computing

★ PUBLISHER: CPC Computing
★ YEAR: 1988
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LICENCE: LISTING
★ AUTHOR: Ian C. Sharpe

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
  » Sprite  System    (CPC  Computing)    ENGLISHDATE: 2020-07-31
DL: 0 fois
TYPE: ZIP
SIZE: 7Ko
NOTE: 40 Cyls
.HFE: NON

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Amsprite
» Applications » Panda Sprites
» Applications » Sprites Tool (Tilt)
» Applications » Sprite Handler/Sprite Definer (CPC Computing)
» Applications » RSX - Amsprites
» Applications » Spriter (Hydris)

QUE DIT LA LOI FRANÇAISE:

L'alinéa 8 de l'article L122-5 du Code de la propriété intellectuelle explique que « Lorsque l'œuvre a été divulguée, l'auteur ne peut interdire la reproduction d'une œuvre et sa représentation effectuées à des fins de conservation ou destinées à préserver les conditions de sa consultation à des fins de recherche ou détudes privées par des particuliers, dans les locaux de l'établissement et sur des terminaux dédiés par des bibliothèques accessibles au public, par des musées ou par des services d'archives, sous réserve que ceux-ci ne recherchent aucun avantage économique ou commercial ». Pas de problème donc pour nous!

CPCrulez[Content Management System] v8.7-desktop/cache
Page créée en 209 millisecondes et consultée 24 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.