Here's a basic example I just knocked together:
Rem Basic Sprite Firing Example In DBC
Rem (c) TDK_Man Jan 2007
Gosub Setup
Rem ***** Main Loop *****
Do
Mx=MouseX(): My=MouseY(): Mc=MouseClick()
If Mc=1 Then Gosub Fire_Bullet
If Upkey() Then Dec SpritePosY: Sprite 1,SpritePosX,SpritePosY,1
If Downkey() Then Inc SpritePosY: Sprite 1,SpritePosX,SpritePosY,1
If Leftkey() Then Dec SpritePosX: Sprite 1,SpritePosX,SpritePosY,1
If Rightkey() Then Inc SpritePosX: Sprite 1,SpritePosX,SpritePosY,1
Sync
Loop
End
Fire_Bullet:
EndPointX=Mx: EndPointY=My: Speed# = 8.0: Left=0: Up=0
BulletPosX# = SpritePosX: BulletPosY# = SpritePosY
XDist# = ABS(EndPointX-SpritePosX)
YDist# = ABS(EndPointY-SpritePosY)
Show Sprite 2
If XDist# > YDist#: Rem X axis is longest distance
Ratio# = (YDist#/XDist#)*Speed#
If EndPointX<BulletPosX# Then Speed#=0-Speed#: Left=1: Rem Bullet moving left
If EndPointY<BulletPosY# Then Ratio#=0-Ratio#: Up=1: Rem Bullet moving up
X# = BulletPosX#: Rem Start X position of bullet
If Left=0
Repeat
Sprite 2,X#,BulletPosY#,2
Inc X#,Speed#
Inc BulletPosY#,Ratio#
Sync
Until X# >= EndPointX
Else
Repeat
Sprite 2,X#,BulletPosY#,2
Inc X#,Speed#
Inc BulletPosY#,Ratio#
Sync
Until X# <= EndPointX
Endif
Else: Rem Y axis is longest distance
Ratio# = (XDist#/YDist#)*Speed#
If EndPointX<BulletPosX# Then Ratio#=0-Ratio#: Left=1: Rem Bullet moving left
If EndPointY<BulletPosY# Then Speed#=0-Speed#: Up=1: Rem Bullet moving up
Y# = BulletPosY#: Rem Start X position of bullet
If Up=0
Repeat
Sprite 2,BulletPosX#,Y#,2
Inc Y#,Speed#
Inc BulletPosX#,Ratio#
Sync
Until Y# >= EndPointY
Else
Repeat
Sprite 2,BulletPosX#,Y#,2
Inc Y#,Speed#
Inc BulletPosX#,Ratio#
Sync
Until Y# <= EndPointY
Endif
Endif
Hide Sprite 2
Return
Setup:
Set Display Mode 800,600,16
Sync On: Sync Rate 0: CLS 0
SpritePosX = 400: SpritePosY = 300
Rem Create Hidden Screen To Create Sprite Images
Create Bitmap 1,320,200
Rem Base Sprite
CLS RGB(255,0,0)
Ink RGB(0,255,0),0
Box 1,1,9,9
Get Image 1,0,0,11,11
Sprite 1,SpritePosX,SpritePosY,1
Rem Bullet Sprite
CLS 0
Ink RGB(255,255,255),0
Box 0,0,3,3
Get Image 2,0,0,4,4
Sprite 2,SpritePosX,SpritePosY,2
Hide Sprite 2
Rem Return To Main Screen & Delete Hidden Screen
Set Current Bitmap 0
Delete Bitmap 1
Return
It's written in DBC - you didn't say which version of DB you were using
- and needs more work, but it should point you in the right direction.
Cursor keys move the main sprite and the left mouse button fires.
I should work in DBP but might be a bit fast.
TDK_Man