i got lost in your code
sorry for not spending
too much time in it
in the end, i do believe you are simply over-shooting your target x,y and need to see if it's "close enough". i see some of your code checking distances but not sure what you're comparing it against (precisely).
anyway, take a look at this and play with it. maybe it will help?:
// Project: deal
// Created: 2019-06-09
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "deal" )
SW = 640 : SH = 480
SetWindowSize( SW, SH, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( SW, SH ) // 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
`make a card image
SetClearColor(255,255,255)
ClearScreen()
sync()
DrawBox(4,4,44,59,255,255,255,0,1)
cardIMG = GetImage(0,0,48,64)
SetClearColor(0,128,0)
deck = MakeDeck(cardImg)
targetx# = 0.0 : targety# = 100.0 : targetangle# = 0.0 `initialize target
moverate# = 20.0
do
mx# = GetPointerX() : my# = GetPointerY() : SetSpritePositionByOffset(deck,mx#,my#)
if dealing = 0
targetx# = targetx# + 64.0
if targetx# > 576.0
targetx# = 64.0
targety# = targety# + 100.0
moverate# = Random(4,10)*5.0 `randomize moverate
if targety# > 480-64.0 `table is full of cards
targety# = 100.0
DeleteAllSprites()
deck = MakeDeck(cardIMG)
SetSpritePositionByOffset(deck,mx#,my#)
endif
targetangle# = WrapAngle(targetangle# + 90.0)
endif
thiscard = CloneSprite(deck)
SetSpriteDepth(thiscard,1)
thisx# = mx# : thisy# = my#
angle# = ATanFull(targetx#-mx#,TargetY#-my#)
SetSpritePositionByOffset(thiscard,thisx#,thisy#)
dealing = 1
endif
if dealing = 1
distance# = SQRT((targetx#-thisx#)^2+(targety#-thisy#)^2)
if distance# > moverate# `to avoid over-shooting target.
thisx# = thisX# + SIN(angle#)*moverate# : thisy# = thisy# -COS(angle#)*moverate#
SetSpritePositionByOffset(thiscard,thisx#,thisy#)
SetSpriteAngle(thiscard,GetSpriteAngle(thiscard)+30) `whatever rotation rate you want
else
SetSpritePositionByOffset(thiscard,targetx#,targety#)
SetSpriteAngle(thiscard,targetangle#)
dealing = 0
thiscard = 0
endif
endif
print (ScreenFPS())
print (moverate#)
Sync()
loop
Function MakeDeck(cardIMG)
deck = CreateSprite(cardIMG)
SetSpriteDepth(deck,0)
SetSpriteOffset(deck,24,32)
SetSpriteTransparency(deck,0)
EndFunction deck
Function WrapAngle(angle#)
angle# = angle# - floor(angle#/360.0) * 360.0
EndFunction angle#
now, i don't know how precise things
should be which is why i set a generic
if distance# > moverate# limit but i am sure someone more-knowledgeable can guide you, there. alas, my method pulls off the illusion well enough?
otherwise, i'm simply showing a way to get a card from point a to b while spinning the card (hence, all the
SetSpritePositionByOffset() usage and the fact that you can define point a for each card dealt (i THINK you've got the deck (a # of sprites) all spread out in the middle of the table?)
meanwhile, 2 more thoughts:
think about
programmatically setting target x,y for each card using a base location for each player? IE, apply whatever x,y offset from the base for subsequent cards?
in general, it's a bad habit to make as many (identical) calls as you seem to be. IE the multitude of:
GetVirtualWidth()/2 + (GetVirtualHeight()/2 * tan(PlayerAngle[i])) - GetSpriteWidth(i) -type lines, for example .
do the virtual screen dimensions and sprite widths (of the cards) change? if not, set up some variables & define them, then utilize the variables throughout the rest of the loop (at least). otherwise, you stand to return some unexpected results (a common one is to grab the mouse x & y more than once per loop which can return different values each time within the same loop).
hope some of that helps
add: JosephB addressed some of my thoughts while i was posting:
Quote: "establish the starting card position for each player and then have all the remaining cards offset from that position"
and, yes, i do tend to deal off the bottom of the deck; an old habit of mine...