[comp.sys.amiga.tech] Simple sprite help please

gregm@csd4.milw.wisc.edu (Gregory Jerome Mumm) (12/31/88)

I program in Modula-2 (benchmark) and need some help with a program
that I'm working on. What I need to know is how to use Sprites. The
program will have two sprites that are always on the screen. A space
ship on the top and one on the bottom of the screen. I need to know
how to define the sprites and then move them with a simple procedure
like so:

         MoveTopSprite(left)

which would cause the sprite at the top of the screen to move left one
pixel. 

The next thing I need is a sprite 'missle' that moves from the top
of the screen to the bottom of the screen (and visa versa) without
my controlling it. In other words the 'missle' keeps going without
me having to keep move it one pixel at a time. I envision a procedure
some like this:

         FireMissle();

Last but not least I need to know when a missle hits one of the space ships.
I am a complete beginner to programming on the Amiga so be easy on me when
you explain. If you don't know Modula-2 (or don't like it) please feel
free to give examples in C. THANKS!!!

Internet: gregm@csd4.milw.wisc.edu  Uucp: uwvax!uwmcsd1!uwmcsd4!gregm 
Csnet:	  gregm%uwmcsd4@uwm	             Greg Mumm 
--

Internet: gregm@csd4.milw.wisc.edu  Uucp: uwvax!uwmcsd1!uwmcsd4!gregm 
Csnet:	  gregm%uwmcsd4@uwm	             Greg Mumm 

cs161agc@sdcc10.ucsd.EDU (John Schultz) (12/31/88)

In article <160@csd4.milw.wisc.edu> gregm@csd4.milw.wisc.edu (Gregory Jerome Mumm) writes:
[stuff deleted]
>my controlling it. In other words the 'missle' keeps going without
>me having to keep move it one pixel at a time. I envision a procedure
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  You're gonna have to move it yourself, as there is no "Magic" way
of doing it in parallel.  The code can look like this:

  INC(MissileX,deltaX);
  INC(MissileY,deltaY);
  MoveSprite(ViewPort,MissileSprite,MissileX,MissileY);

  You'll need to do bounds/collision checking too.
  Just place in your main animation loop.   

>Last but not least I need to know when a missle hits one of the space ships.

  If you are only using 2 opposing spaceships, each with independent
missiles, then you can check the Sprite Hardware Collision Register
(Explained in the back of the Hardware manual) for collisions.  Only certain
pairs register collisions, so choose carefully.
  For more complex animation, use a "Proximity" equation like:

  PROCEDURE proximity(x,y,enemyx,enemyy, 
                      width,height      : INTEGER): BOOLEAN;
  BEGIN
    RETURN (ABS(x-enemyx) < width) AND (ABS(y-enemyy) < height);
  END proximity;

  This function will return TRUE when the "rectangles" defining your
shapes overlap.

>Csnet:	  gregm%uwmcsd4@uwm	             Greg Mumm 

  Hope this helps.

  
  John Schultz