Jump to content
IGNORED

*embarrassed* anyone got a fractional motion example?


tschak909

Recommended Posts

I've been messing around trying to do my own fractional motion routine, so I can provide some inertia to my joystick controls... does anyone have a little snippet of code to jog my head?

 

*embarrassed*

 

(funny enough, one of my iterative attempts created a situation where you would hold the joystick in direction, and after half a second, it would scoot and then stop, like somebody lifting a REALLY heavy boulder, moving it, and then slamming it back down again.)

 

What they say about coding truly is spot on... I either feel like a god...or I need my drool cup changed. :P

 

-Thom

Link to comment
Share on other sites

The fractional bit is easy enough. It's just 16-bit addition or subtraction, and you use the high byte as the coordinate.

 

 clc
 lda playerx+1
 adc #32 ; or some other value, to give value/256 fractional addition
 sta playerx+1
 lda playerx
 adc #0
 sta playerx

But you mention inertia, which is a bit more complex. For inertia, you need variables for velocity. When the player moves in a direction, the velocity value is subtly increased. Every frame, the velocity gets added to the player position.

 

Something like...

 

 bit SWCHA
 bmi SkipJoyRight
 clc
 lda velocityx
 adc #5 ; just small arbitrary amount of thrust or impetus
 sta velocityx
SkipJoyRight
 bit SWCHA
 bvs SkipJoyLeft
 sec
 lda velocityx
 sbc #5
 sta velocityx
SkipJoyLeft

 ; [misc game logic]

 ; add velocity to the player position every frame...
 clc
 lda playerx+1
 adc velocityx 
 sta playerx+1
 lda playerx
 adc #0
 sta playerx

It's a bit more tricky if you want to add drag, or angular thrust, but those are just additional wrinkles on this basic system.

Link to comment
Share on other sites

(funny enough, one of my iterative attempts created a situation where you would hold the joystick in direction, and after half a second, it would scoot and then stop, like somebody lifting a REALLY heavy boulder, moving it, and then slamming it back down again.)

I must be weird but I think a serendipitous result like that is difference between programming being art vs science. Movement like that could provide inspiration for a game idea. Got me thinking.

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...