home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-09-28 | 12.4 KB | 354 lines |
- '***************************
- '* AMOS Professional *
- '* *
- '* HARDWARE SPRITES *
- '* *
- '* (c) Europress Software *
- '* *
- '* Ronnie Simpson *
- '***************************
- '
- '-------------------
- 'GENERAL
- '-------------------
- 'The Amiga supports a total of 8 hardware sprites which are 16 pixels wide
- 'and up to 255 pixels high.
- '
- 'The hardware sprites are numbered 0-7 but since it is very unlikely that
- 'you will ever need a sprite which is 255 pixels high, each of the hardware
- 'sprites can be split into sections allowing up to 64 sprites to be displayed.
- 'These computed sprites which use the numbers 8-63 are dealt with in the
- 'second of the sprite tutorials.
- '
- 'A single hardware sprite can only be displayed using up to 3 colours (colour
- '(0 is treated as transparent) but by overlaying two hardware sprites then
- 'up to 15 colours can be used, this obviously reduces the total number that
- 'can be displayed.
- '
- 'The same is also true for sprites which use images greater than sixteen
- 'pixels wide, the sprites required to be combined are 'grabbed' by the
- 'hardware and do not require any further software or user control.
- '
- 'Sprites are independant from the screen and are automatically overlaid
- 'in any screen mode including HAM and Extra Half Bright.
- '
- '-------------------
- 'SPRITE BASICS
- '-------------------
- ' +---->(sprite identification number)
- ' | +---->(hardware x coordinate)
- ' | | +---->(hardware y coordinate)
- ' | | | +---->(image number to be used)
- ' | | | |
- ' Sprite 1,200,150,5
- '
- 'Sprite positions are measured in hardware coordinates from the image hot
- 'spot, these hardware coordinates are independant of the screen mode and
- 'the functions X Hard, Y Hard and X Screen, Y Screen are provided for
- 'converting between the different modes.
- '
- 'Any number of parameters can be ommited from the Sprite instruction as long
- 'as the commas are included in the correct place.
- '
- 'Sprites use the same images as the bobs and any number of sprites can use
- 'the same image number, it is also possible to grab the image required from
- 'the existing screen graphics using the Get Sprite instruction.
- '
- 'eg. Get Sprite 1,10,10 To 26,26 (grab image number 1 from current screen)
- '
- 'By default hardware sprite number 0 is used by the mouse pointer but this
- 'can be released for use by the Hide instruction.
- '
- '-------------------
- 'SPRITE LIMITATIONS
- '-------------------
- 'A maximum width of 8*16=128 pixels is possible if all sprites are joined
- 'together in the 3 colour mode.
- '
- 'A maximum width of 4*16=64 pixels is possible if all sprites are joined
- 'together in the 15 colour mode.
- '
- 'When using 32 colour,HAM or Extra Half Bright screen modes setting the
- 'colours for your 3 colour sprites can be a problem as the hardware sprites
- 'use the colour indexes 16 to 31.
- '
- 'The hardware sprites are grouped in pairs as follows:-
- '
- ' numbers 0 and 1 use colour indexes 17,18,19 (16 treated as transparent)
- ' numbers 2 and 3 use colour indexes 21,22,23 (20 treated as transparent)
- ' numbers 4 and 5 use colour indexes 25,26,27 (24 treated as transparent)
- ' numbers 6 and 7 use colour indexes 29,30,31 (28 treated as transparent)
- '
- 'When joining sprites the computer automatically grabs the images using the
- 'above pairs so always try to give your 15 colour (or wide sprites) even
- 'numbers to avoid wasting sprites.
- '
- 'The Get Sprite Palette instruction loads the entire palette from the sprite
- 'bank and an optional mask can be used to load only a selection.
- '
- 'eg Get Sprite Palette (load entire palette)
- ' Get Sprite Palette %1010 (load only some colours)
- '
- 'If the optional mask is used then each of the 32 colour registers are
- 'represented by one bit which can be either set or clear, if set then
- 'that colour will be loaded.
- '
- '-------------------
- 'OTHER SPRITE INSTRUCTIONS
- '-------------------
- 'Get Sprite
- '
- 'grab a section of the screen to the sprite bank
- '
- 'eg. Get Sprite 1,10,20 To 30,40
- '
- 'The above would grab image number 1 from the current screen from the
- 'given coordinates.
- '
- 'An optional screen number can be added BEFORE the image number if you wish
- 'to grab from another opened screen
- '
- 'eg. Get Bob 2,1,10,20 To 30,40 (grab from screen number 2)
- '
- 'Hot Spot
- '
- 'The hot spot of an object is used as the reference point for coordinate
- 'calculations. There are two versions of the Hot Spot instruction the first
- 'of which moves the hot spot to one of nine pre-defined positions:-
- '
- ' +--->number of sprite image in the bank
- ' | +--->new position of Hot Spot
- ' Hot Spot 1,&00
- ' +-------------+
- ' here are the nine |$00 $10 $20|
- ' possible positions |$01 $11 $21|
- ' |$02 $12 $22|
- ' +-------------+
- '
- 'The second version of this instruction lets you position the hot spot
- 'to an x,y position which may even lie outside the area of the bob, all
- 'measurements are from the top left hand corner.
- '
- ' +--->number of sprite image in the bank
- ' | +--->the new position of Hot Spot
- ' Hot Spot 1,x,y
- '
- 'To save a little memory sprites can be set to a maximum height using the
- 'Set Sprite Buffer instruction. The size can be set between 16 and 256
- 'pixels and the size of the buffer is calculated by multiplying the height
- 'required by 96.
- '
- 'eg Set Sprite Buffer 1536 (set max. height to 16 pixels)
- '
- 'To remove one or all sprites from the display use the Sprite Off instruction.
- '
- 'eg. Sprite Off (no parameters removes all sprites)
- ' Sprite Off 1 (remove sprite number 1)
- '
- 'Two functions are provided for returning a sprites coordinates X sprite and
- 'Y Sprite.
- '
- 'eg. X=X Sprite(2) (get hardware X coordinate of sprite number 2)
- ' Y=Y Sprite(4) (get hardware Y coordinate of sprite number 4)
- '
- 'The function I Sprite returns the current image number that is being used
- 'by a particular sprite.
- '
- 'eg. I=I Sprite(5)
- '
- 'This function can be usefull for synchronising sound with
- 'sprite animations etc.
- '
- '-------------------
- 'FINAL NOTE
- '-------------------
- 'A 3 colour sprite is a sprite which uses only 2 bitplanes, so when grabbing
- 'your images make sure that the screen mode is 4 colour or less or you may
- 'inadvertantly grab an image which requires more colours (or bitplanes), this
- 'would result in the sprite being displayed as a 15 colour with the resulting
- 'loss of a sprite.
- '
- '-------------------
- 'WORKING EXAMPLES
- '-------------------
- Rem *** dimension arrays which hold coordinates and directions
- '
- Dim X(7),Y(7),XD(7),YD(7)
- Global X(),Y(),XD(),YD()
- '
- '
- Rem *** load some sprite images
- '
- Load "AMOSPro_Tutorial:Objects/Sprites.abk"
- '
- '
- Rem *** tidy up screen
- '
- Screen Open 0,640,200,4,Hires : Flash Off
- Palette $0,$F00,$F0,$F
- Curs Off : Cls 0 : Paper 0 : Pen 2
- Reserve Zone 6
- '
- '
- Rem *** set up some buttons
- '
- Locate 0,1 : Centre Border$(Zone$("EIGHT 3 COLOURED SPRITES",1),1)
- Locate 0,5 : Centre Border$(Zone$("FOUR 15 COLOURED SPRITES",2),1)
- Locate 0,9 : Centre Border$(Zone$("ONE MAX. WIDTH 3 COLOURED SPRITE",3),1)
- Locate 0,13 : Centre Border$(Zone$("ONE MAX. WIDTH 15 COLOURED SPRITE",4),1)
- Locate 0,17 : Centre Border$(Zone$("SPRITES ON A HAM SCREEN",5),1)
- Locate 0,21 : Centre Border$(Zone$("SPRITES ON A EXTRA HALF BRIGHT SCREEN",6),1)
- Pen 1 : Locate 0,24 : Centre "TAKE YOUR PICK WITH THE LEFT MOUSE KEY RIGHT MOUSE KEY TO QUIT"
- '
- '
- Rem *** start main loop
- '
- Do
- Repeat
- Until Mouse Key=0
- Repeat
- M=Mouse Zone
- If Mouse Key=2 Then Exit 2
- Until Mouse Key=1 and M>0
- On M Proc EIGHTX3,FOURX16,BIGX3,BIGX15,HAM,EXB
- Loop
- '
- '
- Edit
- '
- '
- Rem *** the sprite procedures
- '
- Procedure EIGHTX3
- Screen Open 1,320,200,8,Lowres : Flash Off : Curs Off : Get Sprite Palette
- Set Pattern 24 : Ink 3,0 : Paint 1,1 : Hide
- Pen 3 : Locate 0,24 : Centre "press right mouse key to continue"
- For N=0 To 7
- X(N)=Rnd(260)+150 : Y(N)=Rnd(150)+50
- Sprite N,X(N),Y(N),1
- XD(N)=2 : If Rnd(1)=0 Then XD(N)=-XD(N)
- YD(N)=2 : If Rnd(1)=0 Then YD(N)=-YD(N)
- Next
- Do
- For N=0 To 7
- Add X(N),XD(N) : If X(N)>410 or X(N)<150 Then XD(N)=-XD(N)
- Add Y(N),YD(N) : If Y(N)>220 or Y(N)<50 Then YD(N)=-YD(N)
- Sprite N,X(N),Y(N),1
- Next
- Exit If Mouse Key=2
- Loop
- Sprite Off : Screen Close 1 : Show On
- End Proc
- Procedure FOURX16
- Screen Open 1,320,200,16,Lowres : Flash Off : Curs Off : Get Sprite Palette
- Set Pattern 5 : Ink 3,0 : Paint 1,1 : Hide
- Pen 9 : Locate 0,24 : Centre "press right mouse key to continue"
- For N=0 To 6 Step 2
- X(N)=Rnd(260)+150 : Y(N)=Rnd(150)+50
- Sprite N,X(N),Y(N),2
- XD(N)=2 : If Rnd(1)=0 Then XD(N)=-XD(N)
- YD(N)=2 : If Rnd(1)=0 Then YD(N)=-YD(N)
- Next
- Do
- For N=0 To 6 Step 2
- Add X(N),XD(N) : If X(N)>410 or X(N)<150 Then XD(N)=-XD(N)
- Add Y(N),YD(N) : If Y(N)>220 or Y(N)<50 Then YD(N)=-YD(N)
- Sprite N,X(N),Y(N),2
- Next
- Exit If Mouse Key=2
- Loop
- Sprite Off : Screen Close 1 : Show On
- End Proc
- Procedure BIGX3
- Screen Open 1,320,200,4,Lowres : Flash Off : Curs Off : Get Sprite Palette
- Set Pattern 30 : Ink 3,0,1 : Set Paint 1 : Box 0,0 To 127,95 : Paint 1,1 : Hide
- X(0)=Rnd(260)+150 : Y(0)=Rnd(150)+50
- Get Sprite 7,0,0 To 128,96
- Set Pattern 7 : Ink 3,0 : Cls 0 : Paint 1,1 : Hide
- Pen 3 : Locate 0,24 : Centre "press right mouse key to continue"
- Sprite N,X(0),Y(0),7
- XD(0)=2 : If Rnd(1)=0 Then XD(0)=-XD(0)
- YD(0)=2 : If Rnd(1)=0 Then YD(0)=-YD(0)
- Do
- Add X(0),XD(0) : If X(0)>410 or X(0)<130 Then XD(0)=-XD(0)
- Add Y(0),YD(0) : If Y(0)>220 or Y(0)<50 Then YD(0)=-YD(0)
- Sprite N,X(0),Y(0),7
- Exit If Mouse Key=2
- Wait Vbl
- Loop
- Sprite Off : Screen Close 1 : Show On
- End Proc
- Procedure BIGX15
- Screen Open 1,320,200,16,Lowres : Flash Off : Curs Off : Get Sprite Palette
- Set Pattern 9 : Ink 7,9 : Paint 1,1 : Hide
- X(0)=Rnd(260)+150 : Y(0)=Rnd(150)+50
- Set Pattern 10 : Ink 3,0 : Cls 0 : Paint 1,1 : Hide
- Pen 11 : Locate 0,24 : Centre "press right mouse key to continue"
- Sprite N,X(0),Y(0),6
- XD(0)=2 : If Rnd(1)=0 Then XD(0)=-XD(0)
- YD(0)=2 : If Rnd(1)=0 Then YD(0)=-YD(0)
- Do
- Add X(0),XD(0) : If X(0)>410 or X(0)<130 Then XD(0)=-XD(0)
- Add Y(0),YD(0) : If Y(0)>220 or Y(0)<50 Then YD(0)=-YD(0)
- Sprite N,X(0),Y(0),6
- Exit If Mouse Key=2
- Wait Vbl
- Loop
- Sprite Off : Screen Close 1 : Show On
- End Proc
- Procedure HAM
- Screen Open 1,320,290,4096,Lowres
- Curs Off : Cls 0 : Flash Off : Hide
- For B=0 To 15
- Colour B,B : Ink B : Bar 32,B*7+32 To 288,B*7+39
- For R=0 To 15
- For L1=32 To 39 : Ink 32+R : Plot R*16+33,B*7+L1 : Next L1
- For G=0 To 15
- Ink 48+G : Draw R*16+G+34,B*7+32 To R*16+G+34,B*7+39
- Next G
- Next R
- Next B
- Pen 13 : Locate 0,24 : Centre "press right mouse key to continue"
- For N=0 To 6 Step 2
- X(N)=Rnd(260)+150 : Y(N)=Rnd(150)+50
- Sprite N,X(N),Y(N),5
- XD(N)=2 : If Rnd(1)=0 Then XD(N)=-XD(N)
- YD(N)=2 : If Rnd(1)=0 Then YD(N)=-YD(N)
- Next
- Do
- For N=0 To 6 Step 2
- Add X(N),XD(N) : If X(N)>410 or X(N)<150 Then XD(N)=-XD(N)
- Add Y(N),YD(N) : If Y(N)>220 or Y(N)<50 Then YD(N)=-YD(N)
- Sprite N,X(N),Y(N),5
- Next
- Exit If Mouse Key=2
- Loop
- Sprite Off : Screen Close 1 : Show On
- End Proc
- Procedure EXB
- Screen Open 1,320,200,64,Lowres : Curs Off : Flash Off : Cls 0 : Paper 0 : Hide
- Palette 0,$FFF,$DDD,$BBB,$999,$F00,$D00,$B00,$900,$90,$B0,$D0,$F0,$9,$B,$D,$F
- For X=0 To 319 Step 2
- Add C,1,1 To 63
- Ink C
- Draw 0-X/2,0 To X,199
- Ink C+32
- Draw 0-X/2,0 To X+1,199
- Next
- Pen 3 : Locate 0,24 : Centre "press right mouse key to continue"
- For N=0 To 7
- X(N)=Rnd(260)+150 : Y(N)=Rnd(150)+50
- Sprite N,X(N),Y(N),1
- XD(N)=2 : If Rnd(1)=0 Then XD(N)=-XD(N)
- YD(N)=2 : If Rnd(1)=0 Then YD(N)=-YD(N)
- Next
- Do
- For N=0 To 7
- Add X(N),XD(N) : If X(N)>410 or X(N)<150 Then XD(N)=-XD(N)
- Add Y(N),YD(N) : If Y(N)>220 or Y(N)<50 Then YD(N)=-YD(N)
- Sprite N,X(N),Y(N),1
- Next
- Exit If Mouse Key=2
- Loop
- Sprite Off : Screen Close 1 : Show On
- End Proc