10 December 2015, 01:35 | #1 |
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 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. |
26 December 2015, 10:17 | #2 |
Registered User
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! |
26 December 2015, 12:10 | #3 |
Total Chaos forever!
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.
|
26 December 2015, 14:11 | #4 |
Registered User
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. |
26 December 2015, 21:16 | #5 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
The team leader had major back surgery and is still recovering.
|
26 December 2015, 22:02 | #6 |
Registered User
Join Date: May 2003
Location: mercury
Posts: 577
|
oh,.. hope he gets well soon.
|
26 December 2015, 23:41 | #7 | |
Glastonbridge Software
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
|
Quote:
|
|
27 December 2015, 13:51 | #8 | |
Registered User
Join Date: May 2003
Location: mercury
Posts: 577
|
Quote:
First I did the vertical scroller, then I converted everything to an horizonal scroller.. maybe I did something wrong. |
|
27 December 2015, 14:13 | #9 |
Phone Homer
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. |
27 December 2015, 14:58 | #10 |
Glastonbridge Software
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,243
|
i can't see the images
|
27 December 2015, 15:20 | #11 | |
Banned
Join Date: May 2011
Location: Spain
Posts: 519
|
Quote:
|
|
27 December 2015, 15:45 | #12 |
Phone Homer
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. |
27 December 2015, 15:54 | #13 |
Glastonbridge Software
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!
|
27 December 2015, 15:59 | #14 |
Phone Homer
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 |
27 December 2015, 16:28 | #15 | |
Banned
Join Date: May 2011
Location: Spain
Posts: 519
|
Quote:
in case yes what you recomend http://www.mapeditor.org/ http://www.tilemap.co.uk/mappy.php https://tilemapkit.com/tilemap-resources/ |
|
27 December 2015, 17:02 | #16 |
Glastonbridge Software
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. |
27 December 2015, 17:43 | #17 |
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. |
27 December 2015, 18:11 | #18 |
Glastonbridge Software
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
|
27 December 2015, 18:18 | #19 | |
Phone Homer
Join Date: Jun 2006
Location: 5150
Posts: 5,773
|
Nicely put.
Quote:
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. |
|
27 December 2015, 20:44 | #20 |
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.
|
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 |
|
|