Jump to content
IGNORED

Slower horizontal scrolling?


Retro Lord

Recommended Posts

Fiddling with a sideproject, a homage of Adventure Island for the NES and I was wondering, how do I slow down the horizontal scrolling?

   set kernel_options player1colors playercolors pfcolors

   dim rand16 = z

   pfhline 8 5 23 on

   COLUPF = $CE



 playfield:
 ................................
 ................................
 .......X...X.............X...X..
 ......X.XXX.X...........X.XXX.X.
 .........X.................X....
 .........X.................X....
 .........X.................X....
 .........X.................X....
 .........X.................X....
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end





  rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME...


   player0color:
    $3E
    $3E
    $3E
    $D8
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $0E
    $0E
    $0E
end


   player1:
   %00000000
   %00000011
   %11111001
   %00011111
   %10011111
   %11111111
   %00000011
   %00000011
   %00000011
   %11000011
   %11111111
   %10011111
   %11111111
end
   player1x = 255 : player1y = 255

__Main_Loop


  f=f+1

  if f = 10 then player0:
        %00011100
        %00011000
        %00011000
        %00011100
        %00000100
        %00110110
        %01110110
        %01101100
        %01111000
        %00111100
        %00111000
        %00111110
        %00110100
        %00111111
        %00111100
        %00111100
end
   player0x = 40 : player0y = 72

  if f = 20 then player0:
        %01000011
        %01100110
        %00111100
        %00000100
        %00110100
        %00110100
        %01101110
        %01101110
        %01111000
        %00111100
        %00111000
        %00111110
        %00110100
        %00111111
        %00111100
        %00111100
end

 if f=20 then f=0

   pfcolors:
   $D6
   $D6
   $D6
   $D6
   $FC
   $FC
   $FC
   $FC
   $FC
   $D6
   $FC
end

   if joy0up then player0y=player0y-1
   if joy0down then player0y=player0y+1
   if joy0right then pfscroll left


   drawscreen

   goto __Main_Loop

DEMO - default.bas.bin

Link to comment
Share on other sites

Here's one way to do it:

   set kernel_options player1colors playercolors pfcolors

   dim _Scroll_Control = a.b
   dim rand16 = z


   COLUPF = $CE



 playfield:
 ................................
 ................................
 .......X...X.............X...X..
 ......X.XXX.X...........X.XXX.X.
 .........X.................X....
 .........X.................X....
 .........X.................X....
 .........X.................X....
 .........X.................X....
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end





  rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME...


   player0color:
    $3E
    $3E
    $3E
    $D8
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $0E
    $0E
    $0E
end


   player1:
   %00000000
   %00000011
   %11111001
   %00011111
   %10011111
   %11111111
   %00000011
   %00000011
   %00000011
   %11000011
   %11111111
   %10011111
   %11111111
end
   player1x = 255 : player1y = 255

__Main_Loop


  f=f+1

  if f = 10 then player0:
        %00011100
        %00011000
        %00011000
        %00011100
        %00000100
        %00110110
        %01110110
        %01101100
        %01111000
        %00111100
        %00111000
        %00111110
        %00110100
        %00111111
        %00111100
        %00111100
end
   player0x = 40 : player0y = 72

  if f = 20 then player0:
        %01000011
        %01100110
        %00111100
        %00000100
        %00110100
        %00110100
        %01101110
        %01101110
        %01111000
        %00111100
        %00111000
        %00111110
        %00110100
        %00111111
        %00111100
        %00111100
end

 if f=20 then f=0

   pfcolors:
   $D6
   $D6
   $D6
   $D6
   $FC
   $FC
   $FC
   $FC
   $FC
   $D6
   $FC
end

   if joy0up then player0y=player0y-1
   if joy0down then player0y=player0y+1
   if !joy0right then goto __Skip_JR
   _Scroll_Control = _Scroll_Control + 0.45
   if _Scroll_Control > 1 then pfscroll left : _Scroll_Control = 0
__Skip_JR

   drawscreen

   goto __Main_Loop

_

Right now it is scrolling at 0.45. If you want it to scroll faster, use a larger number such as 0.56 or 0.62 or 0.70 or whatever (I just picked some random numbers). If you want it even slower, use a smaller number such as 0.30 or 0.28 or 0.15 or whatever (I just picked some random numbers).

Link to comment
Share on other sites

This doesn't look quite right:

 

   _Scroll_Control = _Scroll_Control + 0.45
   if _Scroll_Control > 1 then pfscroll left : _Scroll_Control = 0
it should be

   _Scroll_Control = _Scroll_Control + 0.45
   if _Scroll_Control >= 1 then pfscroll left : _Scroll_Control = _Scroll_Control - 1.0
With the original routine the scrolling would always happen every 3rd frame if the scroll value was between 0.3333 and 0.5, and every 2nd frame if the value was 0.50 thru 1.0. Edited by SpiceWare
  • Like 1
Link to comment
Share on other sites

This doesn't look quite right:

 

   _Scroll_Control = _Scroll_Control + 0.45
   if _Scroll_Control > 1 then pfscroll left : _Scroll_Control = 0
it should be

   _Scroll_Control = _Scroll_Control + 0.45
   if _Scroll_Control >= 1 then pfscroll left : _Scroll_Control = _Scroll_Control - 1.0
With the original routine the scrolling would always happen every 3rd frame if the scroll value was between 0.3333 and 0.5, and every 2nd frame if the value was 0.50 thru 1.0.

 

 

Thanks.

Link to comment
Share on other sites

I don't know why I decided to waste a variable, though. I guess it's because I was just working with fixed point variables. This is probably a better way to do it:

_

   set kernel_options player1colors playercolors pfcolors

   dim _Scroll_Control = a
   dim rand16 = z


   COLUPF = $CE



 playfield:
 ................................
 ................................
 .......X...X.............X...X..
 ......X.XXX.X...........X.XXX.X.
 .........X.................X....
 .........X.................X....
 .........X.................X....
 .........X.................X....
 .........X.................X....
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end





  rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME...


   player0color:
    $3E
    $3E
    $3E
    $D8
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $3E
    $0E
    $0E
    $0E
end


   player1:
   %00000000
   %00000011
   %11111001
   %00011111
   %10011111
   %11111111
   %00000011
   %00000011
   %00000011
   %11000011
   %11111111
   %10011111
   %11111111
end
   player1x = 255 : player1y = 255

__Main_Loop


  f=f+1

  if f = 10 then player0:
        %00011100
        %00011000
        %00011000
        %00011100
        %00000100
        %00110110
        %01110110
        %01101100
        %01111000
        %00111100
        %00111000
        %00111110
        %00110100
        %00111111
        %00111100
        %00111100
end
   player0x = 40 : player0y = 72

  if f = 20 then player0:
        %01000011
        %01100110
        %00111100
        %00000100
        %00110100
        %00110100
        %01101110
        %01101110
        %01111000
        %00111100
        %00111000
        %00111110
        %00110100
        %00111111
        %00111100
        %00111100
end

 if f=20 then f=0

   pfcolors:
   $D6
   $D6
   $D6
   $D6
   $FC
   $FC
   $FC
   $FC
   $FC
   $D6
   $FC
end

   if joy0up then player0y=player0y-1
   if joy0down then player0y=player0y+1
   if !joy0right then goto __Skip_JR
   if _Scroll_Control = 4 then pfscroll left : _Scroll_Control = 0 : goto __Skip_JR
   _Scroll_Control = _Scroll_Control + 1
__Skip_JR

   drawscreen

   goto __Main_Loop

_

Just change "if _Scroll_Control = 4" to a lower or higher number to change the speed.

Link to comment
Share on other sites

I think this is a great approach if the speed will be constant. If the speed will be changed at runtime there might be a more linear way to do it with a single variable.

Using assembly, I'd do something like this for a constant speed:

 

SPEED = $64

ScrollCheck:
    clc
    lda #SPEED
    adc ScrollControl ; RAM variable
    sta ScrollControl
    bcc NoScroll
    ; Carry flag was set so we need to scroll
    ; scroll logic goes here
NoScroll:

If I wanted the speed to be variable I'd do this:

ScrollCheck:
    clc
    lda CurrentSpeed ; RAM variable
    adc ScrollControl ; RAM variable
    sta ScrollControl
    bcc NoScroll
    ; Carry flag was set so we need to scroll
    ; scroll logic goes here
NoScroll:
Link to comment
Share on other sites

Nice. Just wrap it in an asm statement and you've got linear scrolling speed control with a single variable in bB.

 

 

or you could just do it in bB

 

 

 temp1 = scroll_distance
 scroll_distance = scroll_distance + scroll_speed
 if scroll_distance < temp1 then scroll 
 

 

 

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