Hello everyone, I would like to always move my character in the angle that the mouse is, if I press the W key, it moves forward in the mouse angle, if S, it moves backward in the mouse angle and etc. Does anyone know how I do this in a simple and effective way?
my code is looking like this >
// Project: MyLearnGame
// Created: 2022-01-11
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "MyLearnGame" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global sprite
sprite = CreateSprite(LoadImage("sprite_00.png"))
//SetSpriteSize(sprite, 1, 100)
SetSpriteOffset(sprite, GetSpriteWidth(sprite)/2, GetSpriteheight(sprite)/2)
SetSpritePositionByOffset(sprite, 100, 100)
do
Printc("Sprite Angle is ")
Print(Str(GetSpriteAngle(sprite),2)+" Degrees")
x# = GetPointerX()
y# = GetPointerY()
angle# = ATanFull(x# - GetSpriteXByOffset(sprite), y# - GetSpriteYByOffset(sprite))
SetSpriteAngle(sprite, angle#)
MovePlayer()
Sync()
loop
function MovePlayer()
if (GetRawKeyState ( 65 ))
SetSpritePositionByOffset(sprite,GetSpriteXByOffset(sprite)-1,GetSpriteYByOffset(sprite))
endif
if (GetRawKeyState ( 87 ))
SetSpritePositionByOffset(sprite,GetSpriteXByOffset(sprite),GetSpriteYByOffset(sprite)-1)
endif
if (GetRawKeyState ( 68 ))
SetSpritePositionByOffset(sprite,GetSpriteXByOffset(sprite)+1,GetSpriteYByOffset(sprite))
endif
if (GetRawKeyState ( 83 ))
SetSpritePositionByOffset(sprite,GetSpriteXByOffset(sprite),GetSpriteYByOffset(sprite)+1)
endif
endfunction