Jump to content
IGNORED

FastBasic cursor movement with acceleration


Recommended Posts

How would you move a sprite representing a pointer/cursor with acceleration?

 

This is my classic code but the cursor is too fast.

At first it should move slowly then accelerate.

 

proc READ_JOYSTICK
    j=stick(0)
    if (J & 8) = 0 then x0 = x0 + 1
    if (J & 4) = 0 then x0 = x0 - 1
    if (J & 2) = 0 then y0 = y0 + 1
    if (J & 1) = 0 then y0 = y0 - 1
    endproc

proc CHECK_BOUNDARIES
    if x0>203 then x0=203
    if x0<44 then x0=44
    if y0>230 then y0=230
    if y0<8 then y0=8
    endproc  

proc MOVE_SPRITES
     poke 53248,x0
     move adr(Player0),pmbp0+y0,18
     endproc 

 

Link to comment
Share on other sites

I think you would need to read the joystick value, store it, on the next read, see if it's the same value

maybe set a counter so you can accelerate movement if same direction for "n" reads.

 

I did something similar in an Art program I wrote in BASIC many moons ago, will see if I can find

it, it moves a sprite pointer based on joystick reads too 

  • Like 2
Link to comment
Share on other sites

2 hours ago, Philsan said:

This is my classic code but the cursor is too fast.

At first it should move slowly then accelerate.

You can just apply some kind of pause, put into the function "READ_JOYSTICK".

If the stick isn't moved at all (=15) set the duration of the pause to a high value, else reduce the value as long as you think it's enough.

This way you can also move the object fast arround, as long there is only a transition, not a break, in movement.

  • Like 1
Link to comment
Share on other sites

18 hours ago, Philsan said:

How would you move a sprite representing a pointer/cursor with acceleration?

Quite often you can use a co-ordinate range larger than that of the screen, e.g. x4, and then quick divide to put in range when you want to draw.

 

Then you use a 'velocity' variable, i.e. 0 is stationary. When you detect movement, increment this and then set a countdown delay (e.g. # of vb cycles).

So the increment can work only if the delay is zero and less than the cap, e.g. 4.

 

Then each vb you can add the velocity to x,y coordinates, so you have one velocity each for up/down, left/right and hence negative for up/left.

 

You then have the option of ceasing movement (joystick centred) either resetting the velocities to zero (immediate stop) or use the vb to move the velocity toward zero based on another counter to provide deceleration.  

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...