English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. AMOS

 
 
Thread Tools
Old 10 December 2015, 01:35   #1
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
Smooth vertical scrolling in AMOS

It seems people have asked about how to achieve smooth scrolling in AMOS, so I thought I'd share the code I sweated together a few years ago. Further comments below the code:
Code:
Set Buffer 32 : Rem Enlarge variable space to contain a larger map 

MAPPATH$="Data:AMOS/bana.txt" : Rem -- Path to map file in ascii format

' Open main screen. It should be twice as tall as the visible portion, plus 32 pixels
Screen Open 0,320,512+32,16,Lowres
Screen Hide : Curs Off : Flash Off : Cls 0 : Colour Back $F : Hide : Screen Show 
' Open small screen for debug output 
Screen Open 1,320,8,2,Lowres
Screen Hide : Curs Off : Flash Off : Cls 0 : Colour Back $F : Hide : Screen Show 
Screen Display 0,135,50,320,256
Screen Display 1,135,40,320,8
Screen 0

LäNGD=500 : Rem          -- Length of map  
Dim MAP(9,LäNGD) : Rem   -- Set up map array  
Global LäNGD,JAG_X,JAG_Y,FI_X,FI_Y,SK_Y,MAP(),VROW,VPOS,_DRAWX,_DRAWY,MAPPATH$
INIT : Rem               -- Initial setup 
MAIN : Rem               -- Jump to main routine  

Procedure INIT
   MAPDRAW : Rem                     -- Load and render map 
   JAG_X=160-8 : JAG_Y=256-32 : Rem  -- Variables for player sprite
   FI_X=100 : FI_Y=10 : Rem          -- Variables for enemy sprite 
   SK_Y=256+32 : Rem                 -- Counter for screen display coord  
   VROW=8 : Rem                      -- Row in map to read 
   VPOS=LäNGD-1 : Rem                -- Row in MAP array to count from 
   _DRAWX=0 : _DRAWY=8 : Rem         -- Row and column for drawing blocks 
   Bob Update Off 
End Proc

Procedure MAPDRAW
   LADDATEXT : Rem                   -- Load map from disc  
   Load "data:amos/shmup32x32_2.abk" : Rem    -- Load tiles 
   Get Icon Palette 
   
   ' Error handling in case icon 0 is missing 
   For Y=0 To 499
      For X=0 To 9
         If MAP(X,Y)=0 Then MAP(X,Y)=1
      Next X
   Next Y
   
   ' Draw map on screen 
   Y=LäNGD-1-(512/32)
   For V=0 To 512 Step 32
      For X=0 To 9
         Paste Icon X*32,V,MAP(X,Y)
      Next X
      Inc Y
   Next V
End Proc

Procedure LADDATEXT
   ' Load a map file in pure text format from disc. 
   ' On Error Proc THEEND 
   Open In 1,MAPPATH$ : Rem          -- Open map file  
   For Y=0 To 499
      Line Input #1,ROW$
      For X=0 To 9
         CELL$=Mid$(ROW$,X*3,3)
         MAP(X,Y)=Val(CELL$)
      Next X
   Next Y
   Close 1
End Proc

Procedure MAIN
   Repeat 
      INMATNING : Rem                -- Get input from player  
      If SK_Y>0 Then Screen Offset 0,0,SK_Y Else RESETSCREEN
      Wait Vbl 
      ' Write debug information      -- Comment out line below to gain speed 
      Screen 1 : Locate 0,0 : Print "SK_Y:";SK_Y;" RX:";_DRAWX;" RY:";_DRAWY;" VR:";VROW;" VP:";VPOS;"   "; : Screen 0
      
      If SK_Y>256-64 : Rem           -- Top portion of screen not visible 
         If _DRAWY=>0
            ' Comment out this line to get smooth performance on slow systems  
            Screen 1 : Locate 36,0 : Print "/\"; : Screen 0
            ' Draw blocks from the middle upwards
            Paste Icon 32*_DRAWX,32*_DRAWY,MAP(_DRAWX,VPOS-VROW)
            ' Draw two blocks so that the scroll doesnt get ahead
            Paste Icon 32*_DRAWX+32,32*_DRAWY,MAP(_DRAWX+1,VPOS-VROW)
         End If 
      End If 
      
      If SK_Y<160 : Rem              -- Bottom portion of screen not visible 
         If _DRAWY>8
            ' Comment out this line to get smooth performance on slow systems
            Screen 1 : Locate 36,0 : Print "\/"; : Screen 0
            ' Draw two blocks from below 
            Paste Icon 32*_DRAWX,32*_DRAWY,MAP(_DRAWX,VPOS-VROW)
            Paste Icon 32*_DRAWX+32,32*_DRAWY,MAP(_DRAWX+1,VPOS-VROW)
         End If 
      End If 
      
      SPRITAR : Rem               -- Draw sprites  
      
   Until Mouse Key
   Edit 
End Proc

Procedure RESETSCREEN
   SK_Y=256+32 : Rem              -- Reset coarse counter   
   VROW=8 : Rem                   -- Reset row offset in map 
   _DRAWX=0 : _DRAWY=8 : Rem      -- Reset screen coordinates for pasting 
   Screen Offset 0,0,SK_Y : Rem   -- Reset screen Y offset to bottom 
End Proc

Procedure INMATNING
   ' Input handler    
   If Jup(1)
      Dec SK_Y
      Dec SK_Y
      If _DRAWX<7
         Inc _DRAWX
         Inc _DRAWX
      Else 
         _DRAWX=0
         Dec _DRAWY
         Inc VROW
      End If 
      
      If SK_Y=100
         _DRAWX=0
         VROW=0
         _DRAWY=16
         VPOS=VPOS-9
      End If 
      
      If SK_Y mod 32=0 : Rem      -- At border between blocks...
         'Bell 22 
      End If 
      
   End If 
   
   If Jleft(1) and JAG_X>112 Then Dec JAG_X
   If Jright(1) and JAG_X<418 Then Inc JAG_X
   If Fire(1) Then End 
End Proc


Procedure SPRITAR
   ' Draw player and enemy sprites  
   Sprite 0,JAG_X,JAG_Y,1
   Sprite 8,FI_X+100,FI_Y,2
   Add FI_Y,4
   If FI_Y>300
      FI_X=Rnd(300)+30
      FI_Y=30
   End If 
End Proc
How does it work? The principle is like double buffering, but on a single bitmap instead of two separate ones. The bitmap is twice the height of the visible screen, so that you may draw on the non-visible portion while scrolling the "viewport" along the bitmap. This makes for some unpretty code, since the program must decide whether to write on the upper or lower part of the screen, which also necessiates reading from different parts of the map file. The program would be a lot shorter and easier to read were it not for the requirement to handle these cases.
This example uses 32x32 pixel blocks for the background graphics. There are some debug lines for printing debug output which work on my A4000. If you remove those lines, the program scrolls smoothly even on a lowly A600.
Attached Files
File Type: lha AMOSScrollDemo.lha (11.7 KB, 368 views)
idrougge is offline  
Old 26 December 2015, 10:17   #2
JudasEZT
Registered User
 
JudasEZT's Avatar
 
Join Date: May 2003
Location: mercury
Posts: 577
Clever programming.

I want to do the same with a horizontal scroller, but seems an Amos bug doesn't permit.. I get graphics corrupted when screens are too wide.

Do you know something about that issue?

Kind Regards!
JudasEZT is offline  
Old 26 December 2015, 12:10   #3
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
Maximum width of a screen is 1024 on Amos because it is designed on Kickstart ROM version 1.3.
Samurai_Crow is offline  
Old 26 December 2015, 14:11   #4
JudasEZT
Registered User
 
JudasEZT's Avatar
 
Join Date: May 2003
Location: mercury
Posts: 577
I have problems when the screen wide exceeds 600 pixels or less. Bitplanes are displaying graphics from workbench and corrupted stuff.

I dont know, I have to redo all the stuff of horizontal scroll. When is vertical scroll I have no problem at all if, effectively, it doesn´t exceeds 1024 pixels.

Anyone know about status of next AmosPro re-development version?? I would contribute with donative or whatever.. gladly.
JudasEZT is offline  
Old 26 December 2015, 21:16   #5
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
The team leader had major back surgery and is still recovering.
Samurai_Crow is offline  
Old 26 December 2015, 22:02   #6
JudasEZT
Registered User
 
JudasEZT's Avatar
 
Join Date: May 2003
Location: mercury
Posts: 577
oh,.. hope he gets well soon.
JudasEZT is offline  
Old 26 December 2015, 23:41   #7
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
Quote:
Originally Posted by JudasEZT View Post
I have problems when the screen wide exceeds 600 pixels or less. Bitplanes are displaying graphics from workbench and corrupted stuff.

I dont know, I have to redo all the stuff of horizontal scroll. When is vertical scroll I have no problem at all if, effectively, it doesn´t exceeds 1024 pixels.

Anyone know about status of next AmosPro re-development version?? I would contribute with donative or whatever.. gladly.
that is very strange, i have never experienced this. You are using Screen Display to limit its visible size to 320 pixels wide, right?
Mrs Beanbag is offline  
Old 27 December 2015, 13:51   #8
JudasEZT
Registered User
 
JudasEZT's Avatar
 
Join Date: May 2003
Location: mercury
Posts: 577
Quote:
Originally Posted by Mrs Beanbag View Post
that is very strange, i have never experienced this. You are using Screen Display to limit its visible size to 320 pixels wide, right?
Well, yes.. anyway is 6 months now since I did that programming. I have to take a look.

First I did the vertical scroller, then I converted everything to an horizonal scroller.. maybe I did something wrong.
JudasEZT is offline  
Old 27 December 2015, 14:13   #9
Retro1234
Phone Homer
 
Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 5,773
For me its on the vertical at a point the bob becomes distorted
http://www.ultimateamiga.co.uk/index...ic,9392.0.html

at first I used large screens as a basic scroll but 521 not that big anyway.
Retro1234 is offline  
Old 27 December 2015, 14:58   #10
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
i can't see the images
Mrs Beanbag is offline  
Old 27 December 2015, 15:20   #11
Amiten
Banned
 
Join Date: May 2011
Location: Spain
Posts: 519
Quote:
Originally Posted by idrougge View Post
It seems people have asked about how to achieve smooth scrolling in AMOS, so I thought I'd share the code I sweated together a few years ago. Further comments below the code:
Code:
Set Buffer 32 : Rem Enlarge variable space to contain a larger map 

MAPPATH$="Data:AMOS/bana.txt" : Rem -- Path to map file in ascii format

' Open main screen. It should be twice as tall as the visible portion, plus 32 pixels
Screen Open 0,320,512+32,16,Lowres
Screen Hide : Curs Off : Flash Off : Cls 0 : Colour Back $F : Hide : Screen Show 
' Open small screen for debug output 
Screen Open 1,320,8,2,Lowres
Screen Hide : Curs Off : Flash Off : Cls 0 : Colour Back $F : Hide : Screen Show 
Screen Display 0,135,50,320,256
Screen Display 1,135,40,320,8
Screen 0

LäNGD=500 : Rem          -- Length of map  
Dim MAP(9,LäNGD) : Rem   -- Set up map array  
Global LäNGD,JAG_X,JAG_Y,FI_X,FI_Y,SK_Y,MAP(),VROW,VPOS,_DRAWX,_DRAWY,MAPPATH$
INIT : Rem               -- Initial setup 
MAIN : Rem               -- Jump to main routine  

Procedure INIT
   MAPDRAW : Rem                     -- Load and render map 
   JAG_X=160-8 : JAG_Y=256-32 : Rem  -- Variables for player sprite
   FI_X=100 : FI_Y=10 : Rem          -- Variables for enemy sprite 
   SK_Y=256+32 : Rem                 -- Counter for screen display coord  
   VROW=8 : Rem                      -- Row in map to read 
   VPOS=LäNGD-1 : Rem                -- Row in MAP array to count from 
   _DRAWX=0 : _DRAWY=8 : Rem         -- Row and column for drawing blocks 
   Bob Update Off 
End Proc

Procedure MAPDRAW
   LADDATEXT : Rem                   -- Load map from disc  
   Load "data:amos/shmup32x32_2.abk" : Rem    -- Load tiles 
   Get Icon Palette 
   
   ' Error handling in case icon 0 is missing 
   For Y=0 To 499
      For X=0 To 9
         If MAP(X,Y)=0 Then MAP(X,Y)=1
      Next X
   Next Y
   
   ' Draw map on screen 
   Y=LäNGD-1-(512/32)
   For V=0 To 512 Step 32
      For X=0 To 9
         Paste Icon X*32,V,MAP(X,Y)
      Next X
      Inc Y
   Next V
End Proc

Procedure LADDATEXT
   ' Load a map file in pure text format from disc. 
   ' On Error Proc THEEND 
   Open In 1,MAPPATH$ : Rem          -- Open map file  
   For Y=0 To 499
      Line Input #1,ROW$
      For X=0 To 9
         CELL$=Mid$(ROW$,X*3,3)
         MAP(X,Y)=Val(CELL$)
      Next X
   Next Y
   Close 1
End Proc

Procedure MAIN
   Repeat 
      INMATNING : Rem                -- Get input from player  
      If SK_Y>0 Then Screen Offset 0,0,SK_Y Else RESETSCREEN
      Wait Vbl 
      ' Write debug information      -- Comment out line below to gain speed 
      Screen 1 : Locate 0,0 : Print "SK_Y:";SK_Y;" RX:";_DRAWX;" RY:";_DRAWY;" VR:";VROW;" VP:";VPOS;"   "; : Screen 0
      
      If SK_Y>256-64 : Rem           -- Top portion of screen not visible 
         If _DRAWY=>0
            ' Comment out this line to get smooth performance on slow systems  
            Screen 1 : Locate 36,0 : Print "/\"; : Screen 0
            ' Draw blocks from the middle upwards
            Paste Icon 32*_DRAWX,32*_DRAWY,MAP(_DRAWX,VPOS-VROW)
            ' Draw two blocks so that the scroll doesnt get ahead
            Paste Icon 32*_DRAWX+32,32*_DRAWY,MAP(_DRAWX+1,VPOS-VROW)
         End If 
      End If 
      
      If SK_Y<160 : Rem              -- Bottom portion of screen not visible 
         If _DRAWY>8
            ' Comment out this line to get smooth performance on slow systems
            Screen 1 : Locate 36,0 : Print "\/"; : Screen 0
            ' Draw two blocks from below 
            Paste Icon 32*_DRAWX,32*_DRAWY,MAP(_DRAWX,VPOS-VROW)
            Paste Icon 32*_DRAWX+32,32*_DRAWY,MAP(_DRAWX+1,VPOS-VROW)
         End If 
      End If 
      
      SPRITAR : Rem               -- Draw sprites  
      
   Until Mouse Key
   Edit 
End Proc

Procedure RESETSCREEN
   SK_Y=256+32 : Rem              -- Reset coarse counter   
   VROW=8 : Rem                   -- Reset row offset in map 
   _DRAWX=0 : _DRAWY=8 : Rem      -- Reset screen coordinates for pasting 
   Screen Offset 0,0,SK_Y : Rem   -- Reset screen Y offset to bottom 
End Proc

Procedure INMATNING
   ' Input handler    
   If Jup(1)
      Dec SK_Y
      Dec SK_Y
      If _DRAWX<7
         Inc _DRAWX
         Inc _DRAWX
      Else 
         _DRAWX=0
         Dec _DRAWY
         Inc VROW
      End If 
      
      If SK_Y=100
         _DRAWX=0
         VROW=0
         _DRAWY=16
         VPOS=VPOS-9
      End If 
      
      If SK_Y mod 32=0 : Rem      -- At border between blocks...
         'Bell 22 
      End If 
      
   End If 
   
   If Jleft(1) and JAG_X>112 Then Dec JAG_X
   If Jright(1) and JAG_X<418 Then Inc JAG_X
   If Fire(1) Then End 
End Proc


Procedure SPRITAR
   ' Draw player and enemy sprites  
   Sprite 0,JAG_X,JAG_Y,1
   Sprite 8,FI_X+100,FI_Y,2
   Add FI_Y,4
   If FI_Y>300
      FI_X=Rnd(300)+30
      FI_Y=30
   End If 
End Proc
How does it work? The principle is like double buffering, but on a single bitmap instead of two separate ones. The bitmap is twice the height of the visible screen, so that you may draw on the non-visible portion while scrolling the "viewport" along the bitmap. This makes for some unpretty code, since the program must decide whether to write on the upper or lower part of the screen, which also necessiates reading from different parts of the map file. The program would be a lot shorter and easier to read were it not for the requirement to handle these cases.
This example uses 32x32 pixel blocks for the background graphics. There are some debug lines for printing debug output which work on my A4000. If you remove those lines, the program scrolls smoothly even on a lowly A600.
Hello, Nice Routine Here mate, any info about Map editor used for create the map?, thanks for share its real Smooth on a plain A600
Amiten is offline  
Old 27 December 2015, 15:45   #12
Retro1234
Phone Homer
 
Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 5,773
Beanbag ill have a look thanks for reply

Amiten you should be able to figure that out yourself if you want to charge money for stuff.
This isn't Amos only understand the principle first! Infact you should be able to write your own map editor.

And DO NOT! think your going to charge money for what others have writen!

Last edited by Retro1234; 27 December 2015 at 15:53.
Retro1234 is offline  
Old 27 December 2015, 15:54   #13
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
i use my own map editor... but that is using some sort of text format, which should be easy to write your own format and use any text editor to make the maps. Personally i'd load the data into an AMOS data bank and then save the bank for use in real games, otherwise you have discovered the opposite of crunching as the file sizes are bigger on disk than in the memory!
Mrs Beanbag is offline  
Old 27 December 2015, 15:59   #14
Retro1234
Phone Homer
 
Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 5,773
I just made my own map editor once you can do this you have a understanding of how to build a game I don't use txt format I never heard of using txt format on Amiga then I use my own compression based on one I nicked from NZS.

Nothing wrong with txt format
Retro1234 is offline  
Old 27 December 2015, 16:28   #15
Amiten
Banned
 
Join Date: May 2011
Location: Spain
Posts: 519
Quote:
Originally Posted by Mrs Beanbag View Post
i use my own map editor... but that is using some sort of text format, which should be easy to write your own format and use any text editor to make the maps. Personally i'd load the data into an AMOS data bank and then save the bank for use in real games, otherwise you have discovered the opposite of crunching as the file sizes are bigger on disk than in the memory!
do you think is posible to create Tiles in one of this editors and read from Amos? thanks

in case yes what you recomend

http://www.mapeditor.org/

http://www.tilemap.co.uk/mappy.php

https://tilemapkit.com/tilemap-resources/
Amiten is offline  
Old 27 December 2015, 17:02   #16
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
of course it is possible, if you know the format...

i can't recommend anything because i have never used a PC map editor, i only use the map editor i wrote in AMOS. However, i would recommend that you convert all your maps to a more sensible binary format for use in any Amiga games, you can write a little AMOS program to do that if you need to.
Mrs Beanbag is offline  
Old 27 December 2015, 17:43   #17
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
If you can't make a map editor, you can't make a game either. Everytime I've begun a game project (without advertising it all over the place), I've made a map editor in tandem — because a map editor is basically just the same routines as those used in your game with a different set of input routines (mouse for placing tiles) and a function to save your maps as well as loading them.

The attached editor was used for the above demo. It's very ad-hoc and rough around the edges since it was a throw-away thing for just mocking up a map for this demo. I'll leave it as a coding exercise for the user to make sense out of it.
Attached Files
File Type: lha Baneditor32x32.lha (12.0 KB, 244 views)
idrougge is offline  
Old 27 December 2015, 18:11   #18
Mrs Beanbag
Glastonbridge Software
 
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
Doesn't AMOS Pro come with a map editor? AMOS 1.3 did iirc, i never used it though, it wasn't great
Mrs Beanbag is offline  
Old 27 December 2015, 18:18   #19
Retro1234
Phone Homer
 
Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 5,773
Nicely put.


Quote:
Originally Posted by idrougge View Post
If you can't make a map editor, you can't make a game either. Everytime I've begun a game project (without advertising it all over the place), I've made a map editor in tandem — because a map editor is basically just the same routines as those used in your game with a different set of input routines (mouse for placing tiles) and a function to save your maps as well as loading them.

The attached editor was used for the above demo. It's very ad-hoc and rough around the edges since it was a throw-away thing for just mocking up a map for this demo. I'll leave it as a coding exercise for the user to make sense out of it.
of course you use an existing map editor but your just going to guessing how things work untill you can write your own.

I uploaded the source of one of my first attempts quick editor for a game called something like scavage but since then ive seen too many times people try and rip things off and maybe even try charging money! for them or eneter it into competitions or something like this - im also talking about existing examples and examples from books etc. so I will never upload source ever again -

Last edited by Retro1234; 27 December 2015 at 18:39.
Retro1234 is offline  
Old 27 December 2015, 20:44   #20
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
About text format: It makes sense in an early development stage when you may be editing maps by hand. Of course it isn't a good idea in the long run.
idrougge is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Smooth H-scrolling platform game in AMOS, screen copy vs screen offset? Damiga Coders. AMOS 32 24 October 2023 19:00
Horizontal vs vertical scrolling Amiga1992 Coders. General 20 26 October 2015 11:15
smooth scrolling.is it possible? kirk support.WinUAE 30 01 October 2007 13:57
smooth scrolling sink support.WinUAE 3 20 July 2007 01:16
Just can't get smooth scrolling Bobbin support.WinUAE 0 23 November 2002 00:52

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:29.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09560 seconds with 14 queries