# Array or not array that is the question

`````` //get movment restrictions
//row 1 at or above platform 1
//down
if (locy + 15 == p1y) { //if 1px above plat 1
if (locx + 16 < p1x) { cgd = 0;  } //changed back to 16
if (locx > (p1x + p1w)) { cgd = 0; } //reset cgd if right of plat 1
if (locx <= (p1x + p1w) && (locx + 16 >= p1x)) { cgd = 1; } //stop from going down
}
//if ((locy + 15) < (p1y) or locy > p1y && locy <= p1y +16 ) {
if ((locy == p1y + 2) or  locy + 16 == p1y) { //reset cgd if below pl1 or above pl1
cgd = 0;
}
//cgu
if (locy >= p1y && locy < (p1y +1)) {
if (locx + 16 < p1x) { cgu = 0;  } //changed back to 16
if (locx > (p1x + p1w)) { cgu = 0; } //reset cgu if right of plat 1
if (locx <= (p1x + p1w) && (locx + 16 >= p1x)) { cgu = 1; } //stop from going down
}
//if ((locy + 15) < (p1y) or locy > p1y && locy <= p1y +16 ) {
if ((locy == p1y + 2) or  locy + 16 == p1y) { //reset cgu if more than 1 below pl1 and above pl2
cgu = 0;
}

//cgl or cgr

if (locy >= (p1y - 15) && locy < (p1y)) { // removed +1 from the latter
//cgl
if (locx > (p1x + p1w)) { cgl = 0;  } //reset cgl if to right of plat 1
if ((locx) == (p1x + p1w)) { cgl = 1; } //stop from going left if at plat 1
//cgr
if ((locx + 16) < p1x) { cgr = 0;  } //reset cgr if to left of plat 1
if ((locx + 16) == (p1x)) { cgr = 1; } //stop from going left if at plat 1
}

if (((locy + 16) == (p1y - 1)) or locy == (p1y + 1)) {
cgl = 0;
cgr = 0;
}
``````

full code available here https://github.com/curlyc/arduel

ok so i am not going to bug you guys about every little thing, but could someone or multiple someones tell me how YOU would make this into an array?

if you do things diferent than the “usual” way make note of it as im trying to not only learn but learn why people do other things differently

also note that the code i posted here only relates to the first platfrom ( top platform ) this is because i want to get one working right first than move on

aaaand note my code is sloppy, im new

Well you wouldn’t use an array yet since your code is only ONE thing… array is multiple things. And you’d probably want a struct for platforms. Struct is just a data structure.

Something like:

``````struct platform {
int x;
int y;
int w;
int h;
};

platform platforms;

for (i=0; i< max_platforms; i++) {

if (platforms[i].x < 23)...
...

}
``````

So instead of repeating yourself you just loop and run the same code for all platforms.

3 Likes

well i cant quite wrap my head around thatone, … maby thatd be something good for your article, dumbing that down till newbies can understand it Which part of it?..

prety much all of it

I like the tutorials at cplusplus.com when I don’t understand something about C++.
http://www.cplusplus.com/doc/tutorial/structures/

Didn’t even know you could use `and` `or` in code, I always use && || for those.

Anyways,you use a `struct` to define the characteristics of an object. In this case a platform. Each platform has an X position and a Y position (even if it’s relative). It also has a width and a height. If you’re 100% sure a value of a characteristic well never be negative, use bytes, otherwise use ints.

``````struct Platforms {
int positionX;
int positionY;
int width;
int height;
};
``````

Now you have to “create” the amount of platforms you will maximum “see” on your screen at the same time. You can create more, but each one will take RAM, how much RAM? well 1 byte for every byte characteristic for every platform and double for every int.

`Platforms platform;`

This means create 20 platforms. If you want to change a certain characteristic of a certain platform, you do it like this:

`platform.width = 20;`

Where 5 is the platform you change and .width is the characteristic you want to change.