Jump to content
IGNORED

Multidimensional arrays in batari Basic ?


jrok

Recommended Posts

Hi everyone,

 

Just to quickly introduce myself, I'm a 32 year old multimedia designer and retro graphics geek with fond memories of the Atari 2600. I'm a self-taught, halfway-decent programmer in wimpy languages like Java and Actionscipt, but I sort of skipped over the "Basic" portion of my education. I've been using bB for about a week now, and its definitely the stepping stone I need to work my way into assembly (thanks, Fred!)

 

The game I'm working on is an adventure that requires screen-to-screen movement, with new rooms to be drawn by accessing segments of a data set, (which I imaginatively named 'gamemap'). In other languages this process is pretty simple to accomplish, but I'm running into a few problems in bB, since it doesn't seem like you can nest arrays.

 

In my code, I have a sets of fifteen values that describe how to draw a room and objects inside it, including things like the span of lines to draw and arguments that are passed to certain interactive objects of the playfield for use in the gameloop. In my posted binary, my sample room object is a Teleporter activated by the button, that sends you up or down depending on which floor you are on.

 

For example:

 

 data  gamemap
137, 13, 85, 20, 12, 135, 138, 85, 20, 30, 31, 7, 2, 85, 45, //This is room 1 
end

drawElevator // This is drawing the elevator graphics in my program, and setting the animating portions to off
if gamemap[4]=12 then pfvline gamemap[9] 0 11 : pfvline gamemap[10] 0 11   
if gamemap[4]=12 then pfpixel gamemap[9] gamemap[11] off : pfpixel gamemap[10] gamemap[11] off
if gamemap[4]=12 then pfpixel gamemap[9] gamemap[12] off : pfpixel gamemap[10] gamemap[12] off 

gameloop

(...)

updateBackgroundOb
function tElevator
if x<gamemap[5] || x>gamemap[6] then playerTouching = 0 : yAdj = 0
if y>gamemap[7] || y<gamemap[8] then playerTouching = 0 : yAdj = 0
if x>=gamemap[5] && x<=gamemap[6] && y<=gamemap[7] && y>=gamemap[8] then playerTouching = 12 : yAdj = 2
end
if gamemap[4] = 12 then bgobj = tElevator : gosub Elevators

(...)

goto gameloop

 

In the above example, the gameloop finds the values it needs for the elevators by pointing to static positions of the array. As you can see in my attached BIN, this all works like a charm for a single room. But for moving from room to room, what I really need is something like the following:

 

 const roomsize = 15 //The length of a segment that describes a single room
roomvar=0

data  gamemap
137, 13, 85, 20, 12, 135, 138, 85, 20, 30, 31, 7, 2, 85, 45, //This is room 1
137, 13, 85, 20, 12, 90, 94, 85, 20, 20, 21, 7, 2, 85, 45 //This is room 2 
end  

gameloop

curroom = roomsize * roomvar //The multiplier that points to the appropriate segment of gamemap 

(...)

if x>rightside then roomvar=roomvar+1 : gosub newRoom

updateBackgroundOb
function tElevator
if x<gamemap[5+curroom] || x>gamemap[6+curroom] then playerTouching = 0 : yAdj = 0
if y>gamemap[7]+curroom || y<gamemap[8+curroom] then playerTouching = 0 : yAdj = 0
if x>=gamemap[5+curroom] && x<=gamemap[6+curroom] && y<=gamemap[7+curroom] && y>=gamemap[8+curroom] then playerTouching = 12 : yAdj = 2
end
if gamemap[4+curroom] = 12 then bgobj = tElevator : gosub Elevators

(...)

goto gameloop

newRoom

(...)

drawElevator  
if gamemap[4+curroom]=12 then pfvline gamemap[9+curroom] 0 11 : pfvline gamemap[10+curroom] 0 11   
if gamemap[4+curroom]=12 then pfpixel gamemap[9+curroom] gamemap[11+curroom] off : pfpixel gamemap[10+curroom] gamemap[11+curroom] off
if gamemap[4+curroom]=12 then pfpixel gamemap[9+curroom] gamemap[12+curroom] off : pfpixel gamemap[10+curroom] gamemap[12+curroom] off
return

 

The idea is, when you exited the room you were in, the next room would be drawn by locating the next set of fifteen values, and all the methods and functions would access to that set. Basically I thought this would be a way of simulating multidimensional arrays, but I recieve errors on the expression gameMap[somevalue + curroom]. I know that bB arrays aren't writable, but does anyone know of a good sound way I can move a pointer around in my array?

 

Thanks in advance for any help you can give me. As a side note, I'm really excited about writing my first Atari game, and if I can get my screen-to-screen movement to function, I plan to contribute to the community by writing a "level editor" in Java or Flash that would let authors quickly define playfield areas and their arguments, then output the proper bB code for insertion into projects.

 

Cheers,

Jarod

 

"Mutant Armageddon" tech demo

Instructions:

Joystick left/right - moves character

Joysick down - duck!

Button - Use/activate elevator (when standing on it)

 

EDT:

The monsters in this demo are dumb as doorknobs right now, moving in a single direction. They will be plenty smart eventually, and if I can implement my screen-to-screen technique, their positions will be updated in new rooms based on where they last left the screen, simulating map "roaming".

Mutant_Armageddon.bin

Edited by jrok
Link to comment
Share on other sites

I know that in straight assembly, this could be much easier by using a single indirect vector pointing to the start of a given room's array and using the Y register to fetch values (ala "Adventure")...but have you tried seperating all of the values to exist on dedicated arrays for that particular offset? Using all of the [1]'s in one data table, all of the [2]'s in another, etc? It seems that would be pretty speedy if you always know the offsets to be checked.

 

if x<gamemap5[roomvar] || x>gamemap6[roomvar] then playerTouching = 0 : yAdj = 0

 

 

Also, I dunno how flexible bB is in regards to offsets to be used in arrays...but you might consider calculating them fully before the IF/THEN takes place.

 

temp1 = roomsize * roomvar + 5 : temp2 = roomsize * roomvar + 6 : if x<gamemap[temp1] || x>gamemap[temp2] then playerTouching = 0 : yAdj = 0

 

Granted, this is a much slower method.

 

 

Just an observation from somebody completely in the dark about bBasic's capabilities ;)

Link to comment
Share on other sites

Thanks Nukey. Those are both really interesting ideas.

 

...but have you tried seperating all of the values to exist on dedicated arrays for that particular offset? Using all of the [1]'s in one data table, all of the [2]'s in another, etc? It seems that would be pretty speedy if you always know the offsets to be checked.

 

if x<gamemap5[roomvar] || x>gamemap6[roomvar] then playerTouching = 0 : yAdj = 0

 

So if I understand you correctly, I would end up with 15 data sets (at least, given the example I posted), each of which would have a length equal to the total number of rooms I wanted to draw? If so, that's a pretty great idea.. it also means I might want to write my "level editor" first, so i don't pull my hair out trying to remember which value goes where.

 

Just an observation from somebody completely in the dark about bBasic's capabilities ;)

 

LOL. Man, I don't even know regular Basic, so you are way, way way ahead of me. Thanks again for the great ideas.

 

Cheers,

J

Edited by jrok
Link to comment
Share on other sites

So if I understand you correctly, I would end up with 15 data sets (at least, given the example I posted), each of which would have a length equal to the total number of rooms I wanted to draw? If so, that's a pretty great idea.. it also means I might want to write my "level editor" first, so i don't pull my hair out trying to remember which value goes where.

 

That's what comments are for. Type in a brief description of the data table for that offset...with the data below it. No need to create all the rooms at once, just tack on additional values as the world grows after bugtesting a room or two.

Link to comment
Share on other sites

Assuming I understand the question properly:

 

You have a table where each row has 15 elements. And the the table will be made up of multiple rows, each representing one room. Assuming you have a variable keeping track of what room you are in you can do the following:

 

Assuming r is the room variable:

 

temp6 = r * 15 (note: the first row of the table would be room 0)

 

temp5 = temp6 + (whichever individual element you are trying to pull. would be 0 - 14)

 

a = array[temp5]

 

I did something similar to this in Dungeon.

Link to comment
Share on other sites

I'm no Batari basic programmer, but maybe you could do:

x=5+curroom

gamemap[x]

 

This probably doesn't make it prettier...

 

 

BTW. Your game looks very nice!

 

Thanks, man! I'm only flickering three sprites right now, but I know I'll eventually have to flicker at least four (and possibly as many as six!) to get the kind of gameplay I want. I haven't got there yet, but I might wind up having to dump pfcolors under the bus to get back my precious missile0... hopefully that won't happen.

Link to comment
Share on other sites

Thanks. This seems like another great idea.

Assuming r is the room variable:

 

temp6 = r * 15 (note: the first row of the table would be room 0)

 

temp5 = temp6 + (whichever individual element you are trying to pull. would be 0 - 14)

 

a = array[temp5]

The only thing I'm worried about is using the temp variables, since I need several of them in each function. One of my main design goals is to register whether the player's x and y positions overlap a certain area on the screen that represent game objects. (i.e. using coordinates to simulate the player "colliding" with an elevator -like in my example- or a door, a wall, a laser cannon, etc). So at the very least I assume I would need no less than four variables to define the x and y shape.

 

Do you mean that I would define the temp vars inside the function, like this?

 

data array
10, 40, 5, 20 [i] // a square shape that is 30 pixels wide and 15 pixels tall.[/i]

gameloop
(...)
gosub SomeLabel
(...)
goto gameloop

SomeLabel
function someFunction
temp1 = r * 15
temp2 = temp1 + 0 [i]// the left edge of the shape[/i] 
temp3 = temp1 + 1 [i]// the right edge of the shape[/i]
temp4 = temp1 + 2 [i]// the bottom edge of the shape [/i]
temp5 = temp1 + 3 [i]// the top edge of the shape[/i]
if x<array[temp2] || x>array[temp3] then playerCollision= 0
if y>array[temp4] || y<array[temp5] then playerCollision = 0 
if x>=array[temp2] && x<=array[temp3] && y<=array[temp4] && y>=array[temp5] then playerCollision = 1
end
return

 

Would that be the general idea? Thanks again for your insights.

 

P.S. - Dungeon is great Atari game :)

Edited by jrok
Link to comment
Share on other sites

Would that be the general idea? Thanks again for your insights.

More or less. Keep in mind you don't have to define everything then check everything. You could define temp6 (the r * 15 one) then define temp5, do a check, redefine temp5, do a check, redefine temp5, do a check, etc.

 

If you're going to do the exact same check, but on different array elements you probably want to break the check part off into a separate routine (making it as generic as possible) that you call after setting your temp vars.

 

P.S. - Dungeon is great Atari game :)
Thanks!
Link to comment
Share on other sites

Would that be the general idea? Thanks again for your insights.

More or less. Keep in mind you don't have to define everything then check everything. You could define temp6 (the r * 15 one) then define temp5, do a check, redefine temp5, do a check, redefine temp5, do a check, etc.

 

If you're going to do the exact same check, but on different array elements you probably want to break the check part off into a separate routine (making it as generic as possible) that you call after setting your temp vars.

 

P.S. - Dungeon is great Atari game :)
Thanks!

 

I really appreciate your help here, and will absolutely try this method. I think I've been spoiled for years by other languages where I'd be able to do something as simple as 'array = [room][value]', and at the same time pull a zillion variables out of my ass.

 

I really do enjoy the challenge of this language. After all, if Da Vinci had photoshop and an HD camera, we would have never gotten the Mona Lisa, right?

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