Type Ship
Field id:Int
Field Name:String
Field ObjType:String
Field ShipClass:String
Field ShipModel:Int
Field MaxHP:Int
Field HP:Int
Field Mass:Int
Field Thrust:Int
Field MaxSpeed:Int
Field TurnSpeed:Int
Field Vector:Vector
Field Facing:Int
Field X:Int
Field Y:Int
Method DoThrust(DirFlag:Int=1)
Local ThrustVector:Vector
ThrustVector = New Vector
ThrustVector.Angle = Facing
ThrustVector.Speed = Thrust*DirFlag
Vector = VectorThrust(Vector,ThrustVector,Mass)
If Vector.Speed > MaxSpeed Then Vector.Speed = MaxSpeed
EndMethod
Method Update()
'Vector = VectorDecay(Vector,1,Mass)
debugtext("Evaluating Ship ID: "+id)
debugtext("Calculating Gravity")
CalcStellarGravity()
CheckStellarCollision()
X = X + Vector.XOffset()
Y = Y + Vector.YOffset()
debugtext("MyX:"+X+" MyY:"+Y)
EndMethod
Method DoControl()
If KeyDown(KEY_UP) Then DoThrust()
If KeyDown(KEY_DOWN) Then DoThrust(-1)
If KeyDown(KEY_RIGHT) Then Facing = Facing + TurnSpeed
If KeyDown(KEY_LEFT) Then Facing = Facing - TurnSpeed
PlayerShip.Update()
EndMethod
Method HPPercent:Float()
Local Percent:Float = Float(HP)/Float(MaxHP)
Return Percent
EndMethod
Method CalcStellarGravity()
Local ObjStellar:StellarBody
Local GravVector:Vector = New Vector
Local TempDistance:Float
For ObjStellar:StellarBody = EachIn ObjectList
GravVector.Angle = CalcAngle(X,Y,ObjStellar.X,ObjStellar.Y)
TempDistance = Sqr(CalcDistance(X,Y,ObjStellar.X,ObjStellar.Y)-ObjStellar.Radius())
If TempDistance < 1 Then TempDistance = 1
GravVector.Speed = (ObjStellar.Gravity() / TempDistance)/30
debugtext("GravSpeed:"+GravVector.Speed)
Vector = VectorThrust(Vector,GravVector,Mass)
Next
EndMethod
Method CheckStellarCollision()
Local ObjStellar:StellarBody
Local TempX:Float
Local TempY:Float
Local TempDistance
Local ShipScale:Float
Local TempFlag
Local FixedAngle
Local AngleDifference
Select ShipClass
Case "pod"
ShipScale = PODSCALE
Case "friggate"
ShipScale = FRIGGATESCALE
Case "fighter"
ShipScale = FIGHTERSCALE
Case "cruiser"
ShipScale = CRUISERSCALE
Case "battleship"
ShipScale = BATTLESHIPSCALE
Case "mothership"
ShipScale = MOTHERSHIPSCALE
Case "freight"
ShipScale = FREIGHTSCALE
EndSelect
ShipScale = (ShipScale * 256) / 2
For ObjStellar:StellarBody = EachIn ObjectList
TempFlag = 0
TempX = Vector.XOffset() + X
TempY = Vector.YOffset() + Y
TempDistance = CalcDistance(TempX,TempY,ObjStellar.X,ObjStellar.Y)
TempDistance = TempDistance - ShipScale - ObjStellar.Radius()
If TempDistance < 0 Then
FixedAngle = CalcAngle(TempX,TempY,ObjStellar.X,ObjStellar.Y)
AngleDifference = FixedAngle - Vector.Angle
Vector.Angle = Vector.Angle + (AngleDifference*2)
EndIf
Next
EndMethod
EndType