home *** CD-ROM | disk | FTP | other *** search
- ;-------T-------T------------------------T----------------------------------;
- ;Bouncing BOB's Demo
- ;-------------------
- ;This is a demonstration of bouncing bobs, an extension of the original
- ;Raining BOBs demo.
- ;
- ;It runs in HiRes Laced with a total of 35 large BOBs at 50 FPS ('020+FAST).
-
- INCDIR "INCLUDES:"
- INCLUDE "exec/exec_lib.i"
- INCLUDE "games/games_lib.i"
- INCLUDE "games/games.i"
-
- CALL MACRO
- jsr _LVO\1(a6)
- ENDM
-
- MAX_IMAGES = 35
-
- SECTION "BouncingBOBs",CODE
-
- ;===========================================================================;
- ; INITIALISE DEMO
- ;===========================================================================;
-
- Start: MOVEM.L A0-A6/D1-D7,-(SP)
- move.l ($4).w,a6
- lea GMS_Name(pc),a1
- moveq #$00,d0
- CALL OpenLibrary
- move.l d0,GMS_Base
- beq .Error_GMS
-
- move.l GMS_Base(pc),a6
- sub.l a0,a0
- CALL SetUserPrefs
-
- CALL AllocBlitter
- tst.w d0
- bne.s .Error_Blitter
-
- lea PIC_Bobs(pc),a1
- CALL LoadPic
- tst.w d0
- bne.s .Error_Picture
-
- lea Screen(pc),a0
- move.w PIC_Planes(a1),GS_Planes(a0)
- move.l PIC_Palette(a1),GS_Palette(a0)
-
- CALL AddScreen
- tst.w d0
- bne.s .Error_Screen
-
- moveq #2,d0 ;d0 = 2 buffers.
- move.w #MAX_IMAGES,d1 ;d1 = Maximum amount of images.
- CALL InitRestore
- move.l d0,RestoreList
- beq.s .Error_RestoreList
-
- lea BOB_InitList(pc),a1 ;Initialise the BOBs.
- CALL InitBOB
- tst.w d0
- bne.s .Error_BOB
-
- CALL ShowScreen
-
- bsr.s Main
-
- .ReturnToDOS
- move.l GMS_Base(pc),a6
- lea BOB_InitList(pc),a1
- CALL FreeBOB
- .Error_BOB
- move.l RestoreList(pc),d0
- CALL FreeRestore
- .Error_RestoreList
- lea Screen(pc),a0
- CALL DeleteScreen
- .Error_Screen
- lea PIC_Bobs(pc),a1
- CALL FreePic
- .Error_Picture
- CALL FreeBlitter
- .Error_Blitter
- move.l ($4).w,a6
- move.l GMS_Base(pc),a1
- CALL CloseLibrary
- .Error_GMS
- MOVEM.L (SP)+,A0-A6/D1-D7
- moveq #$00,d0
- rts
-
- ;===========================================================================;
- ; DEMO CODE
- ;===========================================================================;
-
- Main: move.l GMS_Base(pc),a6 ;a6 = GMSBase.
- lea Screen(pc),a0 ;a0 = GameScreen.
-
- lea BOB_Interlaced(pc),a1 ;a1 = BOB to draw.
- move.w GS_ScrWidth(a0),d0
- sub.w BOB_Width(a1),d0
- move.w d0,BOB_XCoord(a1)
- moveq #BUFFER2,d0 ;d0 = Buffer 2.
- CALL DrawBOB ;>> = Draw the BOB
- moveq #BUFFER1,d0 ;d1 = Buffer 1.
- CALL DrawBOB ;>> = Draw the BOB
-
- moveq #$00,d7
- lea BOB_Ball(pc),a1
- move.l MB_EntryList(a1),a2 ;a2 = First entry.
- move.w MB_AmtEntries(a1),d2 ;a2 = Amount of entries.
- subq.w #1,d2 ;d2 = --1 for loop.
- moveq #$00,d3
-
- .create eor.w #1,d3
-
- moveq #8,d1 ;Set Y speed here.
- CALL FastRandom
- addq.w #2,d0
- move.w d0,BE_YSpeed(a2)
-
- move.w #8,d1 ;Set X speed here.
- CALL FastRandom
- addq.w #1,d0
- move.w d0,BE_XSpeed(a2)
-
- tst.w d3
- beq.s .posx
- neg.w BE_XSpeed(a2)
- .posx
- move.w GS_ScrHeight(a0),d1 ;Starting Y coordinate.
- asr.w #1,d1
- CALL FastRandom
- asr.w #1,d1
- add.w d1,d0
- move.w d0,BE_YCoord(a2)
-
- move.w GS_ScrWidth(a0),d1 ;Starting X coordinate.
- CALL FastRandom
- move.w d0,BE_XCoord(a2)
-
- moveq #12,d1
- CALL FastRandom
- move.w d0,BE_Frame(a2)
- move.b .Sets(pc,d0.w),BE_Set+1(a2)
- move.w #1,BE_FChange(a2)
- move.w d3,BE_Locked(a2)
-
- lea NBE_SIZEOF(a2),a2
- dbra d2,.create
- bra.s Loop
-
- .Sets dc.b 0,0,0,0
- dc.b 1,1,1,1
- dc.b 2,2,2,2
-
- ;---------------------------------------------------------------------------;
-
- Loop: addq.w #1,d7
- move.l MB_EntryList(a1),a2 ;a2 = First entry.
- move.w MB_AmtEntries(a1),d2
- subq.w #1,d2
- .update bsr.s UpdateBOB
- lea NBE_SIZEOF(a2),a2
- dbra d2,.update
-
- move.l RestoreList(pc),a1 ;a1 = RestoreList.
- CALL Restore
-
- move.l a1,a2 ;a2 = RestoreList.
- lea BOB_Ball(pc),a1 ;a1 = BOB to draw.
- moveq #BUFFER2,d0
- CALL DrawBOB ;>> = Draw the BOB
-
- CALL WaitSVBL ;>> = Wait for VBL.
- CALL SwapBuffers ;>> = Swap the buffers.
-
- moveq #JPORT1,d0 ;d0 = JoyPort2
- moveq #JT_ZBXY,d1 ;d1 = Bit switch type.
- CALL ReadJoyPort ;>> = Go get port status.
- btst #MB_LMB,d0
- beq.s Loop
- rts
-
- ;===========================================================================;
- ; UPDATE A BOB
- ;===========================================================================;
- ;Function: Moves the entity according to its internal settings.
- ;Requires: a1 = BOB structure.
- ; a2 = Entry to update.
-
- GRAVITY = 1
-
- UpdateBOB:
- move.w BE_YCoord(a2),d0 ;d0 = YCoord
- add.w BE_YSpeed(a2),d0 ;d0 = (YCoord)+YSpeed
- cmp.w GS_ScrHeight(a0),d0 ;d0 = Should this BOB bounce?
- blt.s .NoBounce ;>> = No.
- neg.w BE_YSpeed(a2) ;a2 = Bounce the BOB!
- addq.w #GRAVITY,BE_YSpeed(a2) ;a2 = Gravity pushes the BOB down.
- bra.s .CheckX
- .NoBounce
- move.w d0,BE_YCoord(a2) ;d0 = Save the change.
- addq.w #GRAVITY,BE_YSpeed(a2) ;a2 = Gravity pushes the BOB down.
-
- .CheckX move.w BE_XCoord(a2),d0
- add.w BE_XSpeed(a2),d0
- cmp.w GS_ScrWidth(a0),d0
- bcs.s .NoXBounce
- neg.w BE_XSpeed(a2)
- bra.s .Animate
- .NoXBounce
- move.w d0,BE_XCoord(a2)
-
- ;---------------------------------------------------------------------------;
-
- .Animate
- tst.w BE_Locked(a2)
- beq.s .exit
- move.w d7,d6
- and.w #%00000011,d6
- bne.s .exit
- move.w BE_FChange(a2),d1
- bgt.s .Positive
-
- .Negative
- cmp.w #1,BE_Set(a2)
- bgt.s .NBlue
- beq.s .NGreen
- .NRed add.w d1,BE_Frame(a2)
- tst BE_Frame(a2)
- bge.s .exit
- move.w #1,BE_FChange(a2)
- clr.w BE_Frame(a2)
- rts
- .NGreen add.w d1,BE_Frame(a2)
- cmp.w #4,BE_Frame(a2)
- bge.s .done
- move.w #1,BE_FChange(a2)
- move.w #4,BE_Frame(a2)
- rts
- .NBlue add.w d1,BE_Frame(a2)
- cmp.w #8,BE_Frame(a2)
- bge.s .done
- move.w #1,BE_FChange(a2)
- move.w #8,BE_Frame(a2)
- .exit rts
-
- .Positive
- cmp.w #1,BE_Set(a2)
- bgt.s .PBlue
- beq.s .PGreen
- .PRed add.w d1,BE_Frame(a2)
- cmp.w #3,BE_Frame(a2)
- ble.s .done
- move.w #-1,BE_FChange(a2)
- move.w #2,BE_Frame(a2)
- rts
- .PGreen add.w d1,BE_Frame(a2)
- cmp.w #7,BE_Frame(a2)
- ble.s .done
- move.w #-1,BE_FChange(a2)
- move.w #6,BE_Frame(a2)
- rts
- .PBlue add.w d1,BE_Frame(a2)
- cmp.w #11,BE_Frame(a2)
- ble.s .done
- move.w #-1,BE_FChange(a2)
- move.w #10,BE_Frame(a2)
- .done rts
-
- ;===========================================================================;
- ; DATA
- ;===========================================================================;
-
- BOB_InitList:
- dc.l "LIST"
- dc.l BOB_Ball
- dc.l BOB_Interlaced
- dc.l LISTEND
-
- GMS_Name:
- dc.b "games.library",0
- even
- GMS_Base:
- dc.l 0
-
- RestoreList:
- dc.l 0
-
- Screen: dc.l GSV1,0 ;Structure version.
- dc.l 0,0,0 ;Screen Memory 1/2/3.
- dc.l 0 ;Screen link.
- dc.l 0 ;Address of screen palette.
- dc.l .RasterList ;Address of rasterlist.
- dc.l 0 ;Amount of colours in palette.
- dc.w 640,512 ;Screen Width and Height.
- dc.w 0,0,0 ;Picture Width, ByteWidth, Height.
- dc.w 0 ;Amount of planes.
- dc.w 0,0 ;X/Y screen offset.
- dc.w 0,0 ;X/Y picture offset.
- dc.l DBLBUFFER ;Special attributes.
- dc.w COL12BIT|HIRES|LACED ;Screen Mode.
- dc.w ILBM ;Screen Type
- even
-
- .RasterList
- COL12LIST 300,30,00,.ColourBar ;Line, Skip, Colnum, ColourList.
- RASTEND
-
- .ColourBar
- dc.w $100,$200,$300,$400,$500,$600,$700
- dc.w -1
-
- ;---------------------------------------------------------------------------;
-
- PIC_Bobs:
- dc.l PCV1,0 ;Version header.
- dc.l 0 ;Source data.
- dc.w 0,0,0 ;Width, Height.
- dc.w 0 ;Amount of Planes.
- dc.l 0 ;Amount of colours.
- dc.l 0 ;Source palette.
- dc.w LORES|COL12BIT ;Screen mode.
- dc.w ILBM ;Destination
- dc.l VIDEOMEM|GETPALETTE ;Parameters.
- dc.l .File
- .File dc.b "GAMESLIB:data/IFF.HRPulse",0
- even
-
- ;---------------------------------------------------------------------------;
-
- STRUCTURE NBE,BE_SIZEOF
- WORD BE_XSpeed
- WORD BE_YSpeed
- WORD BE_Set ;0 = Red, 1 = Green, 2 = Blue.
- WORD BE_FChange
- WORD BE_Locked
- LABEL NBE_SIZEOF
-
- BOB_Ball:
- dc.l MBV1,0 ;Structure version.
- dc.l 0,0 ;Graphics and Mask data.
- dc.w MAX_IMAGES ;Amount of entries.
- dc.l .Frames ;Pointer to frame list.
- dc.w 0 ;Modulo (skip in source) in bytes.
- dc.w 32,32/8,16 ;Width in bytes, Height in pixels.
- dc.l Images ;Coordinate and frame list.
- dc.w 0,0 ;Border restriction LeftX,TopY.
- dc.w 0,0 ;Border restrictions RightX,EndY.
- dc.w 0,0 ;Amount of planes.
- dc.l 0 ;Size of plane, not required.
- dc.l CLIP|GENMASKS|CLEAR|CLRNOMASK ;Attributes.
- dc.l PIC_Bobs ;Picture Structure (Bob Origin)
- dc.w NBE_SIZEOF ;Entry size for images.
-
- .Frames dc.w 00,16*0,0,0 ;RED
- dc.w 00,16*1,0,0
- dc.w 00,16*2,0,0
- dc.w 00,16*3,0,0
- dc.w 32,16*0,0,0 ;GREEN
- dc.w 32,16*1,0,0
- dc.w 32,16*2,0,0
- dc.w 32,16*3,0,0
- dc.w 64,16*0,0,0 ;BLUE
- dc.w 64,16*1,0,0
- dc.w 64,16*2,0,0
- dc.w 64,16*3,0,0
- dc.l -1
-
- BOB_Interlaced:
- dc.l BBV1,0 ;Structure version.
- dc.l 0,0 ;Graphics data.
- dc.w 0 ;Current frame.
- dc.l .frames ;Pointer to frame list.
- dc.w 0 ;Modulo (skip in source) in bytes.
- dc.w 96,0,7 ;Width, Width in bytes, Height.
- dc.w 0,0 ;X/Y destination.
- dc.w 0,0 ;Border restriction LeftX,TopY.
- dc.w 0,0 ;Border restrictions RightX,EndY.
- dc.w 0,0 ;Amount of planes.
- dc.l 0 ;Size of plane, not required.
- dc.l GENMASKS ;Attributes.
- dc.l PIC_Bobs ;Picture struct (Bob origin).
- .frames dc.w 000,16*4,0,0 ;0 X/Y Graphic, X/Y Mask
- dc.l -1
-
- SECTION Images,BSS
-
- Images ds.b NBE_SIZEOF*MAX_IMAGES ;X/Y/Frame/Speed/Set/FChange/Locked
-
-