Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: bonfire89 on January 11, 2004, 01:11:47 AM



Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 01:11:47 AM
I would like to write one of those games where the character remains in the middle, and the background scrolls right to left.

Can anyone give me any hints, or point me to a tutorial on how to accomplish this?


Thank You.


Title: Scolling Background
Post by: adosorken on January 11, 2004, 01:13:55 AM
Hint: tile scrolling engine. Information on building them is everywhere, as well as example sourcecode. :)


Title: Scolling Background
Post by: Zack on January 11, 2004, 01:22:34 AM
I've been thinking of that lately.
Actually (weirdly), I think it's easier to make a side-scroller engine (like Keene, for instance), than it is to make a normal Zelda-style scroller. My own weird logic tells me that. :roll:


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 01:34:24 AM
I wouldn't know.

Im in grade 11 programming at school. And we really havn't done much graphics at all, but we just recieved our game assignment which will be due pretty much at the end of the year.


Title: Scolling Background
Post by: Zack on January 11, 2004, 01:40:54 AM
If you're new at QB, you shouldn't begin with something so advanced...
My suggestion is a nice space-fighter, or a Tetris game with twists. Or Arkanoid.


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 01:45:33 AM
not that new, grade 10 was all qb too.

I've made graphics move around the screen.. Made a bouncing ball that got smaller and smaller using parabolas, and a bunch of other things.

I think I can pull it off as long as I can figure out how to get the scolling background


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 02:13:34 AM
I was just thinking, to make tones and tones of columns of of psets and using a 2d arrary


dim thing(left to right position, y for pset)


then normally it it may show left to righ position of  0 to 800

but then when a user presses the right button it may advance it to 0+1  to 800 + 1


and then you could put it in a for loop




for i = 0 + times pressed right button to 800  + times pressed right button
  for z = 0 to screen heigh
    pset (thing(i), thing(z))
  next z
next i



then of course I'd have to deal with colour some how.



in anyevent, I would assume this is garbage since the screen would just flicker horribly

or am I wrong?


then along with that, there can be an array wich would hold anything that it could possibly collide with.


actually this would be the perfect way to do it I think, as long as there is a way to stop the flicker








woa, just been reading on, maybe I need some type of buffer?


Title: Scolling Background
Post by: Anonymous on January 11, 2004, 09:58:08 AM
first off, hi :) havent seen you around good ta have ya.

but yeah. zelda style isnt *that* hard, but its not real easy either. Your idea with PSET is alright, but you gotta realize QB PSET is sloooooooow... you gotta learn how to poke to &HA000 to do anything remotely fast enough. (i think anyways) Really, it's soooo much easier to use tiles when doing pxp. if your tiles are 16x16 you just PSETd 256 pixels in the time you couldve done one ;) (well almost the same time but still). Ill give you a basic idea of pxp.

by the way you need a 'camera' to do that effectively, so ill show you how to do that too.

you have an x and y coord

in order to keep ur char in the middle of the screen we...

1. assume camera is upperleftmost postion on screen (actually we need camx and camy to do this)

2. Make sure CamX is Xpos - 160 (half the distance so its in the middle) CamY - YPos = 100 keep in mind this is 13h good luck going any other mode ;)

so now, you have to figure out where you are in the lay of things.

Lets say our tiles are 16x16

Code:

CamXTile = CamX \ 16 (\ = integer division; much faster)
CamYTile = CamY \ 16
YOffset = CamY MOD 16
XOffset = CamX MOD 16


now to put these tiles, you have to use this info, and you have to put an extra tile since one will be cut 15 out of 16 times.

Code:
FOR YPut = 0 to 200 step 16
FOR XPut = 0 to 320 step 16

Use your routine to put here at XPut - XOff, YPut - YOff

NEXT
NEXT


Keep in mind the CamXTile, CamYTiles are really only there for ease of getting your info out of your map array. Oh, and you cant just use QB PUT for this one, cause it goes off the screen. better read up how to do that ;)... or get a lib :P. This maybe isn't anything how you wanted to do it, but hey i tried ;) Oh, by the way

to put ur char, you do something like this...

Code:
XPos - Camx, YPos - CamY


and when you update your camera (which should be every iteration, just in case ;)) you gotta throw in something like this.

Code:
if CamY < 0 then CamY = 0
if CamX < 0 then CamX = 0


plus checking for the right and lower side as well.. since i dun know ur map size, i cant tell you what to use ;)

sorry if this is confusing. ;)


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 01:42:32 PM
hey thanks for the reply, I'm brand new here. But have to create a game for school, so I'll probably be around more from now on.


Thanks for the reply, I just woke and groggy, so I shall give it another read in a bit

Thanks


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 02:29:00 PM
ooOOOooo

I have just advanced my knowledge to know tiles. I could do what I was prevously thinking, but using tiles.

That will require thousands of tiles though.

And I would have to load all of them into get things

I have sort have read that I can do that, with out it ever having to display that on the screen with somthing to do with screen7

also, I know what you mean if a tile is partly on the screen...  Ihave to learn how to deal with that.



can you havea dynamic variable name?

eg


for i = 1 to 10
put (1,1), tile i %, pset
next i


and then that would work out to be
put (1,1), tile1%, pset
put (1,1), tile2%, pset
put (1,1), tile3%, pset
put (1,1), tile4%, pset
put (1,1), tile5%, pset
put (1,1), tile6%, pset
put (1,1), tile7%, pset
put (1,1), tile8%, pset
put (1,1), tile9%, pset
put (1,1), tile10%, pset


Title: Scolling Background
Post by: Anonymous on January 11, 2004, 03:23:41 PM
not unles youre using qb7.1

im coming out with a top-secret way of doing this :D:D:D but im not gonna release it till the game im working on comes out... sorry :D


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 03:40:01 PM
how soon till your game is released? lol

I think some how I would have to convert a string into a array name


Title: Scolling Background
Post by: Anonymous on January 11, 2004, 03:43:21 PM
not for a while ;p sorry..

no offense to you i dont know ur level of codage, but its a bit complex... if you want help making your game though i could prolly give you some pointers if i know specifics... but yeah others here could help you way more im sure ;)


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 03:50:25 PM
I know what I am trying to accomplish is a little beyond me, but I would like to give it a shot, before I settle for a game with a non moving background which I have the knowledge for, for sure.


Right now the way I am thinking would work I'd think. But I would need to be able to variable names change dynamicly


it would be awsome if I could do somthing like

GET (10,10)-(30,30),imagearray(5)

but I tryed that and recieved an error




I could code it all with no loops, typing out each array name and that would work.. It wouldn't be too bad acctually, I know ASP and I could just code somthing that gives the output I want, and then copy paste it into QB


Title: Scolling Background
Post by: Anonymous on January 11, 2004, 03:56:41 PM
yeah dude... thats how i was doing it for a while... select case arraynumber :P

that sux!!! can you use 7.1? if so you can dim types with arrays in em


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 04:30:21 PM
Ill ask my teacher on tuesday about the version of QB that has to be used.

what is theis select case arraynumber stuff? you can acctually use GET (10,10)-(30,30),imagearray(5)

sorry about my longer replies.. studying up for physics


Title: Scolling Background
Post by: Agamemnus on January 11, 2004, 04:56:55 PM
powerbasic7.02


Title: Scolling Background
Post by: adosorken on January 11, 2004, 05:11:48 PM
bonfire, you can put multiple sprites into a single array and then PUT them using an offset. For example:

Code:
offset = 10 * 10 / 2 + 1 'the standard 13h method of sprite size calculation
DIM sprite(11 * offset) AS INTEGER 'the sprite array
GET (0, 0) - (9, 9), sprite(10 * offset) 'get the sprite
PUT (50, 50), sprite(10 * offset) 'put it down elsewhere

The offset calculation is different depending on what screenmode you're in. The 13h one I just showed takes the height and width of the sprite (10x10) and multiplies it to get the number of bytes the sprite will be, then divides it in half (remember, an integer array has 2 bytes per element), and then add 1 to hold the sprite header (again, 2 bytes, so add 1). Hope this isn't too confusing for you, and hope it puts you in the right direction. :)


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 05:26:37 PM
so the sprite would be the entire background, and then you just shift it over everytime the character moves?


Title: Scolling Background
Post by: red_Marvin on January 11, 2004, 06:03:44 PM
I think you misunderstood that... tiles is like Lego(r),
you use many small pieces to build a big

..uh something, perhaps a castle?


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 06:35:38 PM
lol yeah, thats what I thought.

so. I have tones and tones of tiles, that all fit together to make my background.


as far as I know, I would have to store each tile in its own array

DIM tile1%(w*h)
DIM tile2%(w*h)
DIM tile3%(w*h)

.
.
.
DIM tile5000%(w*h)


now that is a lot of dimming, and since doing somthing like


for i = 1 to 5000
   put (1,1), tile i %, PSET
next i


is not possible as far as I know (although it has been said otherwise but it is a secrete for now) I would have to type each one out manually, which is okay since I have ASP at my disposal



Im thinking each tile can be the entire height of the screen and for this example one pixel wide.


if the screen res is set so the width is 640pixels I could say

display tiles 1 to 640

and then when the user pressed the move right key it would display tiles 2 to 641


Title: Scolling Background
Post by: Agamemnus on January 11, 2004, 06:44:21 PM
Hi again. Would this help? -- use two dimensions. IE:

tile%(h * w - 1, amount - 1)

-1 is there 'cuz you have 0 as the first subscript by default, so a(0) has one number/pixel, and tile%(h * w - 1, amount - 1) has h * w * amount pixels.


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 06:48:56 PM
ahh got it to work!

OH MY


THANK YOU!


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 07:26:44 PM
so Im trying to just put up enough vertical bars to fill the screen right now.

Code:

SCREEN 7

OPTION BASE 1
DIM tiles%(200, 1 TO 320)

FOR i = 1 TO 320
  count = count + 1

  IF count > 10 THEN 'this is for the first 10 colors
    count = 1
  END IF

  FOR z = 1 TO 200
    PSET (i, z), count
  NEXT z
  GET (i, 1)-(i, 200), tiles%(199 * 1, i)
NEXT i





for some reason I can only do like 5 bars though, by the end, Im going to want thousands

im thinking I have to do somthing special for huge arrays


Title: Scolling Background
Post by: na_th_an on January 11, 2004, 07:49:46 PM
It seems that you are storing in arrays 1x200 pixels sprites of the same colour. Why don't you just use LINE to draw lines?


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 08:09:48 PM
right now this is just for testing purposes. eventually this will be a background which scrolls and will not be solid lines


Title: Scolling Background
Post by: na_th_an on January 11, 2004, 08:16:32 PM
you haven't understood the concept of tiles. Usually, tiles are 16x16, 8x8, 20x20 or something like that. The idea is not to spend memory in a whole screen, but storing only the necessary. For example, if your background is a castle, you have a tile with a wall, a tile with floor, a tile with a window and you build a map using those tiles to get the background.

To make it scroll, you just have a camera position and draw your tiles from that position. You will need a PUT routine with clipping, and QB's own PUT doesn't have one, so go finding a graphics library or code yourself.


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 08:31:44 PM
in anyevent. This is all I know, and in theory it should work. But it isn't.


Title: Scolling Background
Post by: Anonymous on January 11, 2004, 08:46:55 PM
tip 1: dont do lines dude. its dumb. do what youre gonna do. the more you learn wrong the more youre gonna have to 'unlearn' when you wanna actually do it. just make colored boxes if anything

tip2 : i think maybe youre assuming that each 'tile' (or line) is only taking up one index of the array. its actually taking up the number of pixels \ 2 + 2. that may be your problem.


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 09:05:18 PM
is there a maximum size to an array?


because if I put

DIM tiles%(200, 1 TO 5)

it works (that line only)

but I want

DIM tiles%(200, 1 TO 320)



and later on, instead of 320, ill want somthing like 5000


Title: Scolling Background
Post by: Anonymous on January 11, 2004, 10:20:04 PM
you could have arr(1 to 32767)... arr(1 to 32768)... thats just crazy talk :)


Title: Scolling Background
Post by: Agamemnus on January 11, 2004, 10:33:15 PM
5000 different tiles?

You must be hoppin' mad. :)


Title: Scolling Background
Post by: bonfire89 on January 11, 2004, 11:51:04 PM
lol.. oh man.

could I load like 500?

and then unload them?


Title: Scolling Background
Post by: Agamemnus on January 12, 2004, 12:08:47 AM
What you need is an array MAP and a tile set. THe array map holds specific tile indexes for each location in the...map.

The tile set is ideally loaded in before the game begins and then is put on the screen. That is accomplished by using an external library's graphics functions or just using QB's GET and PUT, but apparently they don't clip as na_th_an said. Clipping is when a graphic is only partly visible on the screen (for instance, on the edges).

You can use PSET and a set of integers, but it will be slow as you have no doubt noticed, as PSET is the slowest pixel plotter ever.

Now, everyone is plotting pixels in the end, but what gives PUT and library graphics functions an edge is that they put a chunk of pixels at one time. Less data has to be transferred across the computer, theoretically.

Bad example:

Code:

FOR i% = 1 TO 1000
hi$ = "H" + "i"
PRINT hi$
NEXT i%

'versus:
hi$ = "Hi"
FOR i% = 1 TO 1000
PRINT hi$
NEXT i%



Title: Scolling Background
Post by: bonfire89 on January 12, 2004, 12:43:44 AM
example makes sense..

Kinda like like put objects in a box, then bringing the box somewhere compared to bring each object at a time.

Ill try and look up some info on maps then.

as long as I get it figured out by saturday, I have to hand in my game proposal one monday.

And If I can't get this cleared up, Ill have to goto a game without a scrolling background.


Title: Scolling Background
Post by: adosorken on January 12, 2004, 01:13:42 AM
When I was working on beta 0.60 of WOS back in the "olden days", I had implemented a 6400 tile storage method...but not in conventional memory...it used XMS, and I did use all 6400 tile slots.

Anyways.

bonfire...I heavily HEAVILY suggest downloading some sourcecode and seeing how this all is done. You can find a great number of examples here on qbasicnews or over at qbnz.com. There are file archives everywhere that you can learn from. All you gotta do is look around and be willing to learn. :)


Title: Scolling Background
Post by: relsoft on January 12, 2004, 02:22:02 AM
Show this to your teacher:

http://rel.betterwebber.com/junk.php?id=16

And tell him its harder that he thinks. ;*)


Title: Scolling Background
Post by: bonfire89 on January 12, 2004, 10:02:15 AM
thanks for all the help people  :D

learned a fair amount in the last few days


and think you for that link on the scrolling

the teacher isn't requiring it at all, but it is somthing I want to do. Hopefully I can figure out what is going on there..

If not, ah well.

Thanks