Hi, thanks for the welcome and the code, I knew there had to be a simpler way than the complex way I had planned in my head
for any other noobs finding this post looking for the same, heres an example of it in action
// Project: Line of Sight
// Created: 2015-03-27
// set window properties
SetWindowTitle( "Line of Sight" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
// create player
sprPlayer = CreateSprite(0)
SetSpriteColor(sprPlayer, 255, 255, 255, 255)
SetSpriteSize(sprPlayer, 32, 32)
SetSpritePosition(sprPlayer, 10, 10)
SetSpritePhysicsOn(sprPlayer, 2)
// create enemy
sprEnemy = CreateSprite(0)
SetSpriteColor(sprEnemy, 0, 255, 0, 255)
SetSpriteSize(sprEnemy, 32, 32)
SetSpritePosition(sprEnemy, 900, 600)
SetSpritePhysicsOn(sprEnemy, 2)
// create wall
sprWall = CreateSprite(0)
SetSpriteColor(sprWall, 0, 255, 0, 255)
SetSpriteSize(sprWall, 50, 500)
SetSpritePosition(sprWall, 500, 200)
SetSpritePhysicsOn(sprWall, 1)
SetSpriteGroup(sprWall, 1)
do
print("Use arraw keys to move")
x1# = GetSpriteXbyOffset(sprPlayer)
y1# = GetSpriteYbyOffset(sprPlayer)
x2# = GetSpriteXbyOffset(sprEnemy)
y2# = GetSpriteYbyOffset(sprEnemy)
hitObstacle = PhysicsRayCastGroup(1, x1#, y1#, x2#, y2#)
if hitObstacle=0
print("Player can see enemy!")
else
print("Player can NOT see enemy!")
endif
gosub _Move
Sync()
loop
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40
delta_x = 0
delta_y = 0
_Move:
x# = GetSpriteX(sprPlayer)
y# = GetSpriteY(sprPlayer)
if GetRawKeyState( KEY_LEFT )
// Move Sprite to Left
delta_x = -2
delta_y = 0
SetSpritePosition ( sprPlayer, GetSpriteX( sprPlayer ) + delta_x, GetSpriteY ( sprPlayer ) + delta_y )
elseif GetRawKeyState ( KEY_UP )
// Move Sprite Up
delta_x = 0
delta_y = -2
SetSpritePosition ( sprPlayer, GetSpriteX( sprPlayer ) + delta_x, GetSpriteY ( sprPlayer ) + delta_y )
elseif GetRawKeyState ( KEY_RIGHT )
// Move Sprite to Right
delta_x = 2
delta_y = 0
SetSpritePosition ( sprPlayer, GetSpriteX( sprPlayer ) + delta_x, GetSpriteY ( sprPlayer ) + delta_y )
elseif GetRawKeyState ( KEY_DOWN )
// Move Sprite to Down
delta_x = 0
delta_y = 2
SetSpritePosition ( sprPlayer, GetSpriteX( sprPlayer) + delta_x, GetSpriteY ( sprPlayer ) + delta_y )
endif
return