Jump to content

Recommended Posts

Hello all, I'm currently teaching myself how to program the 2600 using the 8bit workshop tutorials. Currently, I am wondering how to slow down player movement. Here is the code I am currently using for player movement.

 

; Read joystick movement and apply to object 0
MoveJoystick
; Move vertically
; (up and down are actually reversed since ypos starts at bottom)
	ldx YPos
	lda #%00100000	;Up?
	bit SWCHA
	bne SkipMoveUp
        cpx #2
        bcc SkipMoveUp
        dex
SkipMoveUp
	lda #%00010000	;Down?
	bit SWCHA 
	bne SkipMoveDown
        cpx #183
        bcs SkipMoveDown
        inx
SkipMoveDown
	stx YPos
; Move horizontally
        ldx XPos
	lda #%01000000	;Left?
	bit SWCHA
	bne SkipMoveLeft
        cpx #16
        bcc SkipMoveLeft
        dex
SkipMoveLeft
	lda #%10000000	;Right?
	bit SWCHA 
	bne SkipMoveRight
        cpx #153
        bcs SkipMoveRight
        inx
SkipMoveRight
	stx XPos
	rts

Normally, I am used to coding for the NES and I would be able to just DEX and NOP until the player slowed down, wondering what I would do here in this instance. Thank you!

 

 

And here is a link to my current test project, took me all day yesterday how to figure out the 'ground' bit of playfield 2600 Test

Edited by lerugray

Share this post


Link to post
Share on other sites

There are at least two methods:

  1. In case you have a frame counter, execute MoveJoystick only every 2nd frame.
  2. Use fractional numbers. For that you need a sum variable and a constant added to it each frame. Only call MoveJoystick when the sum variable wraps around.

The latter is more flexible as you can fine tune the speed very gradually.

Share this post


Link to post
Share on other sites
10 minutes ago, Thomas Jentzsch said:

There are at least two methods:

  1. In case you have a frame counter, execute MoveJoystick only every 2nd frame.
  2. Use fractional numbers. For that you need a sum variable and a constant added to it each frame. Only call MoveJoystick when the sum variable wraps around.

The latter is more flexible as you can fine tune the speed very gradually.

Thank you Thomas!

 

I think I can visualize your first example, but would you mind providing a short example of your second please?

Share this post


Link to post
Share on other sites

Sure.

  lda moveSum
  clc
  adc #SPEED      ; e.g. 128 for 50% or 192 for 75% speed
  sta moveSum
  bcc .skipMove
  jsr MoveJoystick
.skipMove

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2/18/2021 at 8:55 AM, Thomas Jentzsch said:

Sure.

  lda moveSum
  clc
  adc #SPEED      ; e.g. 128 for 50% or 192 for 75% speed
  sta moveSum
  bcc .skipMove
  jsr MoveJoystick
.skipMove

 

Not sure if I am doing this incorrectly but I can't seem to get it to work on my end

MoveSpeed
	lda MoveSum
	clc
        adc #128
        sta MoveSum
        bcc MoveSpeed
        jsr MoveJoystick

 

Adversary(1).a

Share this post


Link to post
Share on other sites

You are branching to "MoveSpeed", but you should branch after "jsr MoveJoystick"

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
2 minutes ago, Thomas Jentzsch said:

You are branching to "MoveSpeed", but you should branch after "jsr MoveJoystick"

Thank you for your patience with me, I think I'm still getting confused though as to what you mean. where should I be branching to after jsr MoveJoystick if not MoveSpeed to use it as a counter?

 

MoveSpeed
	lda MoveSum
	clc
        adc #128
        sta MoveSum
        jsr MoveJoystick
        bcc MoveSpeed

 

Share this post


Link to post
Share on other sites
  bcc .skipMove
  jsr MoveJoystick
.skipMove

This is the correct code in question again. Hope it helps.

  • Like 1

Share this post


Link to post
Share on other sites
5 minutes ago, Thomas Jentzsch said:
  bcc .skipMove
  jsr MoveJoystick
.skipMove

This is the correct code in question again. Hope it helps.

This worked! Dont know what I was thinking, thanks!

Share this post


Link to post
Share on other sites

Hi there,

On 2/18/2021 at 8:04 AM, lerugray said:

Hello all, I'm currently teaching myself how to program the 2600 using the 8bit workshop tutorials. Currently, I am wondering how to slow down player movement.

If the true intent is to control the player movement then you should move this code into the joystick routine where you are moving the player. In its current position you are controlling when to poll for the joystick input instead.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/21/2021 at 3:35 PM, DEBRO said:

Hi there,

If the true intent is to control the player movement then you should move this code into the joystick routine where you are moving the player. In its current position you are controlling when to poll for the joystick input instead.

Doesn't it get caught in an endless loop though given it jumps right back to the Joystick routine? Thanks for your help

Share this post


Link to post
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...