2015-01-14 13:49:29

hi
I want a map that is 10 by 10, with walls preventing you from going in certain directions and obsticals in other places:
for example
x axis=letters
y axis=numbers
a2 wall a3 wall a7 rcks h3 rocks

what sought of codingdo I need is there an example of this code somewhere?
is it like void map() {
map_size=(10,10);
rocks=1,2;
}

help!

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2015-01-14 15:50:54

Now i do not know the language at hand, so i can not tell you what a propper and good solution to the rock parts should be. However, the first part is very simple. You define a function that checks the upper and lower bound.

x_len  := 10
y_len  := 10
array = int[y, x]

func IsLegalMove(x, y int) bool {
    if x > 0 and y > 0 and x < x_len and y < y_len {
        return true
    }
    return false
}

Now, there are several ways you can approach the rock part. In this example you could define the rock type as being a specific value, for example 4. If this is the case you change the method above to the following below. Be aware that this is probably not the best solution depending on your language.

func IsLegalMove(x, y int) bool {
    if x > 0 and y > 0 and x < x_len and y < y_len {
        if array[y, x[ = 4 {
            return false
        ]
        return true
    }
    return false
}

2015-01-14 18:18:28

That, as far as I'm aware, isn't bgt. I could maybe do this given a bit of time, currently at school right now, if I get the time I will make the example and post it.

2015-01-14 20:23:42

I like string arrays, because then it's more like drawing. This only works if you have a good spatial / tactile / visual imagination (braille helps, and as a bonus, you don't even need to be good at reading it).
But there's too much processing involved in saving a map as a string array directly. Especially given that BGT doesn't seem to distinguish between single-character strings and individual characters (the latter would be fast; the former is slow).

So you could just draw a map like so:
string[] map={
"----------",
"-        -",
"-  rrr   -",
"- r     r-",
"-        -",
"-  r r   -",
"-      r -",
"- r   r  -",
"-        -",
"----------"
};

Where hyphens are walls, 'r's are rocks, and spaces are clear.
You can get the value at an individual tile in BGT like so:

string tile_to_check=map[row][column];

To be quicker, you might want to do this:

if(map[target_y][target_x]=="-") do_not_move();
else if(map[target_y][target_x]=="r") hit_rock();
else move();

For some reason, though, this method feels wrong by itself. Maybe it's that strings are generally bulky; this wouldn't be a problem in, say, C, but in most higher-level languages, they are both slower and larger.
(I usually just write a function that loops through a string array and converts it to an int array, if I'm using this method.)

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-01-14 21:45:11

hey y'all firstly if anh example could be posted, great!
that method you mentioned there k jones looks good
i could visualise how that map would work then
but how would i tell the game r is a rock, and if you move there you play a bonk sound
so like:
if(KEY_PRESSED(key_up)) {
x;y+1;
if(x,y=r) {
bonk.play();
}
}

just ideas probably completely and utterly wrong

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2015-01-14 22:07:17

Actually, that works, for the most part.
You'd eventually want a function for moving, so you don't have to maintain redundant code for each possible direction.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-01-16 15:58:53

could you correct this this is just made up and is probably wrong:
sound bonk;
sound crash;
"----------",
"-        -",
"-  rrr   -",
"- r     r-",
"-        -",
"-  r r   -",
"-      r -",
"- r   r  -",
"-        -",
"----------"
}
void game() {
if(KEY_PREESSED(key_up)) {
if(x==1)&&(y==1) {
bonk.play();
)
}
}
then you'd do left and right arrows, and do this for x2 and y2 etc

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!

2015-01-16 17:51:27

The map needs to be inside an array declaration, like,
string[] map={
(The map goes here.)
};

And you have an extra E in key_preessed.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-01-19 22:14:17

yoh
would someone mind creating a sample map for me? one that would work and uses this method, its the best way i go on and learn studying other works

Nathan Smith
Managing Director of Nathan Tech
It's not disability
It's ability!