so, i hear "distance" and "offsets" again and can only offer the same as above with Lasers now added to the ends of the guns and a re-write of the Move() function to emphasize the use of SIN/-COS * Distance# to maintain the player's "offset" from the center of the screen (a given pivot point)
SIN/COS(Angle#) was in the last code but not the focus):
// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
GLOBAL Ship
Ship = CreateSprite(0) : SetSpriteSize(Ship,32,64)
Type Gun
ID, x, y
EndType
GLOBAL Gun1 as Gun
Gun1.ID = CreateSprite(0) : SetSpriteSize(Gun1.ID, 8,32)
SetSpriteOffset(Gun1.ID,4,30) : SetSpriteColor(Gun1.ID,255,0,0,255)
Gun1.x = -10 : Gun1.y = 20 //offset from ship (offset) aka,. Left Rear gun
GLOBAL Gun2 as Gun
Gun2.ID = CloneSprite(Gun1.ID) : SetSpriteOffset(Gun2.ID,4,30)
Gun2.x = 10 : Gun2.y = 20 //Right Rear gun
Type Laser //these will "attach" to the ends of respective guns, wherever they may be.
ID, x, y
EndType
GLOBAL Laser1 as Laser
Laser1.ID = CreateSprite(0) : SetSpriteSize(Laser1.ID, 4,300)
SetSpriteOffset(Laser1.ID,2,300) : SetSpriteColor(Laser1.ID,255,255,0,255)
Laser1.x = 0 : Laser1.y = -30 //Offset per gun (based on gun's current x,y rotation point)
GLOBAL Laser2 as Laser
Laser2.ID = CreateSprite(0) : SetSpriteSize(Laser2.ID, 4,300)
SetSpriteOffset(Laser2.ID,2,300) : SetSpriteColor(Laser2.ID,255,255,0,255)
Laser2.x = 0 : Laser2.y = -30
GLOBAL Distance# = 300.0 //change this "offset from center" with Up/Downkey - see MoveShip()
Green = MakeColor(0,255,0) //distance visual
do
If GetRawKeyState(27) then End
Distance# = Distance# + GetRawKeyState(38) - GetRawKeyState(40) //Up/Down Keys
MoveShip() : DrawLine(640,360,GetSpriteXByOffset(Ship), GetSpriteYByOffset(Ship),0,255,0)
Ready()
Aim()
If GetPointerState() //Fire Lasers
SetSpriteVisible(Laser1.ID,1)
SetSpriteVisible(Laser2.ID,1)
Fire()
Else
SetSpriteVisible(Laser1.ID,0)
SetSpriteVisible(Laser2.ID,0)
EndIf
Print("Aim with Mouse")
Print("LMB to Fire Lasers")
Print("Up/Down to set Distance from Center (Offset): " + STR(Distance#,0))
Sync()
loop
Function Fire()
LaserX# = GetWorldXFromSprite(Gun1.ID,Laser1.x, Laser1.y)
LaserY# = GetWorldYFromSprite(Gun1.ID,Laser1.x, Laser1.y)
SetSpritePositionByOffset(Laser1.ID,LaserX#,LaserY#)
SetSpriteAngle(Laser1.ID,GetSpriteAngle(Gun1.ID))
LaserX# = GetWorldXFromSprite(Gun2.ID,Laser2.x, Laser2.y)
LaserY# = GetWorldYFromSprite(Gun2.ID,Laser2.x, Laser2.y)
SetSpritePositionByOffset(Laser2.ID,LaserX#,LaserY#)
SetSpriteAngle(Laser2.ID,GetSpriteAngle(Gun2.ID))
EndFunction
Function Aim()
Angle# = ATanFull(GetPointerX()- GetSpriteXByOffset(Ship), GetPointerY() - GetSpriteYByOffset(Ship))
SetSpriteAngle(Gun1.ID,Angle#)
SetSpriteAngle(Gun2.ID,Angle#)
EndFunction
Function MoveShip()
Angle# = GetSpriteAngle(Ship) - 90 + 1
SetSpriteAngle(Ship,Angle#+90)
X# = 640 + SIN(Angle#)*Distance#
Y# = 360 - COS(Angle#)*Distance#
SetSpritePositionByOffset(Ship, X#,Y#)
EndFunction
Function Ready()
GunX# = GetWorldXFromSprite(Ship,Gun1.x, Gun1.y)
GunY# = GetWorldYFromSprite(Ship,Gun1.x, Gun1.y)
SetSpritePositionByOffset(Gun1.ID,GunX#, GunY#)
GunX# = GetWorldXFromSprite(Ship,Gun2.x, Gun2.y)
GunY# = GetWorldYFromSprite(Ship,Gun2.x, Gun2.y)
SetSpritePositionByOffset(Gun2.ID,GunX#, GunY#)
Endfunction
otherwise, sorry if i'm being dense/not understanding. it's been a long day and this is my
current best effort
ps: more angle/distance/offset stuff in the #LowRez source code offered
HERE.