;------------------------------------------------------------------------------- ; Trigonometry: return horizontal vector Function VectorX# ( Distance# , Angle# ) Return Sin ( Angle ) * Distance End Function ; Trigonometry: return vertical vector Function VectorY# ( Distance# , Angle# ) Return Sin ( Angle - 90 ) * Distance End Function ; Trigonometry: return distance using vector Function VectorDistance# ( X# , Y# ) Return Sqr ( X * X + Y * Y ) End Function ; Trigonometry: return angle using vector Function VectorAngle# ( X# , Y# ) Return 180 - ATan2 ( X , Y ) End Function ;------------------------------------------------------------------------------- ; Blitz graphics window mode states Const WindowMode_AutoDetect = 0 Const WindowMode_FullScreen = 1 Const WindowMode_Windowed = 2 Const WindowMode_Scaled = 3 ; Desired screen settings Const ScreenWidth = 640 Const ScreenHeight = 480 Const ColorDepth = 0 Const WindowMode = WindowMode_AutoDetect ; Bullet control Const KeySpace = 57 ; Game control Const KeyEsc = 1 ;------------------------------------------------------------------------------- ; Bullet spawning distance from player image hotspot in pixels Const BulletDistance = 24 ; Bullet time to live in milliseconds Const BulletTime = 5000 ; Bullet velocity in pixels Const BulletSpeed = 4 ; Ship is pointing upwards Const ShipAngle = 0 ;------------------------------------------------------------------------------- Type Bullet ; Time of creation Field TimeCreated ; Duration of life Field TimeToLive ; Position Field PosX# Field PosY# ; Velocity Field VelX# Field VelY# End Type ;------------------------------------------------------------------------------- ; Smart timing wrapper Global MilliSecs ; Simple bullet image Global BulletImage ;------------------------------------------------------------------------------- Function CreateBullet ( PosX , PosY , VelX# , VelY# ) Local This.Bullet This = New Bullet This\PosX = PosX This\PosY = PosY This\VelX = VelX This\VelY = VelY This\TimeCreated = MilliSecs ; Use default time to live This\TimeToLive = BulletTime End Function Function UpdateBullets () Local This.Bullet For This = Each Bullet ; Update position This\PosX = This\PosX + This\VelX This\PosY = This\PosY + This\VelY ; Time to die If MilliSecs - This\TimeCreated >= This\TimeToLive Delete This End If Next End Function Function DrawBullets () Local This.Bullet For This = Each Bullet DrawImage BulletImage , This\PosX , This\PosY Next End Function ;----------------------------------------------------------------------- ; Original ship image (pointing upwards) Local ShipImage ; Bullet starting position & speed vector Local BulletPosX Local BulletPosY Local BulletVelX# Local BulletVelY# ; Ship position Local ShipPosX Local ShipPosY ;------------------------------------------------------------------------------- ; Setup screen Graphics ScreenWidth , ScreenHeight , ColorDepth , WindowMode SetBuffer BackBuffer () ; Load bullet image BulletImage = LoadImage ( "Bullet.BMP" ) MidHandle BulletImage ; Load and center ship image ShipImage = LoadImage ( "Ship Pre Final.PNG" ) MidHandle ShipImage ; Place ship in the lower half in the center of the screen ShipPosX = ScreenWidth / 2 ShipPosY = ScreenHeight * 3 / 4 Repeat ; Timing MilliSecs = MilliSecs () ; Input If KeyDown ( KeySpace ) ; Calculate where to create bullet in front of ship BulletPosX = ShipPosX + VectorX ( BulletDistance , ShipAngle ) BulletPosY = ShipPosY + VectorY ( BulletDistance , ShipAngle ) ; Initial bullet velocity vector BulletVelX = VectorX ( BulletSpeed , ShipAngle ) BulletVelY = VectorY ( BulletSpeed , ShipAngle ) CreateBullet BulletPosX , BulletPosY , BulletVelX , BulletVelY EndIf ; Update UpdateBullets ; Render Cls DrawImage ShipImage , ShipPosX , ShipPosY DrawBullets Flip Until KeyHit( KeyEsc ) ; Blitz automagically cleans up End ;~IDEal Editor Parameters: ;~C#Blitz3D198