Jump to content

How can I store multiple areas in one array?


Cockiezi

Recommended Posts

Hi I'm new at this.

 

idk how to say this, I'm trying to store multiple areas in an array.

like

 

placeA[3] <-- My array.

 

placeA[0] = topLeftX, topLeftY, botRightX, botRightY

placeA[1] = same as above but different values.

placeA[2] = same as aboev but different values.

 

http://i.imgur.com/Xz9iuHO.jpg

 

 

I want to make this so I can check if my character is inside any of them.

Edited by Cockiezi
Link to comment
Share on other sites

How would that work.. I'm confused biggrin.png

give me a sec i got you

 

edit:

public enum Location {
//your pre-definding the value of whatever you need.
    AREA_ONE(new Area(3092, 3246, 3095, 3240)),
    AREA_TWO (new Area(3215, 9623, 3219, 9620)),
    AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)),
    ;

    //these are the private fields you pre-definded
    private Area area;

    //constructor add what values you need to pre-define
    private Location(Area area){
        this.area = area;
    }

    //these are simple getter methods.
    //setter method arent allowed because the values are pre-fined so they are basically static.
    public Area getArea(){
        return this.area;
    }
}

example of an enum. You pre-define the value and use them like so 

 

Location.AREA_ONE give you the variable from location and then your allowes to use the getter methods.

Location.values() give your an array of all the variables in the enum

 

You can also use an enum as a type. For oop ideas

Edited by josedpay
Link to comment
Share on other sites

Hi I'm new at this.

 

idk how to say this, I'm trying to store multiple areas in an array.

like

 

placeA[3] <-- My array.

 

placeA[0] = topLeftX, topLeftY, botRightX, botRightY

placeA[1] = same as above but different values.

placeA[2] = same as aboev but different values.

 

http://i.imgur.com/Xz9iuHO.jpg

 

 

I want to make this so I can check if my character is inside any of them.

 

 

See this post I made, it should help you out. It basically has everything you are looking for, you can just change the area implementation. 

http://osbot.org/forum/topic/64420-banking-enum-with-areas-and-methods/#entry707698

Link to comment
Share on other sites

give me a sec i got you

 

edit:

public enum Location {
//your pre-definding the value of whatever you need.
    AREA_ONE(new Area(3092, 3246, 3095, 3240)),
    AREA_TWO (new Area(3215, 9623, 3219, 9620)),
    AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)),
    ;

    //these are the private fields you pre-definded
    private Area area;

    //constructor add what values you need to pre-define
    private Location(Area area){
        this.area = area;
    }

    //these are simple getter methods.
    //setter method arent allowed because the values are pre-fined so they are basically static.
    public Area getArea(){
        return this.area;
    }
}

example of an enum. You pre-define the value and use them like so 

 

Location.AREA_ONE give you the variable from location and then your allowes to use the getter methods.

Location.values() give your an array of all the variables in the enum

 

You can also use an enum as a type. For oop ideas

 

 

spoonfeed.jpg

  • Like 1
Link to comment
Share on other sites

Soo would I be doing it the wrong way if I did this instead:

 

if (placeA_A1.contains(myPlayer().getPosition()) || (placeA_A2.contains(myPlayer().getPosition()))){
return State.placeA;
}
 
Ofc I'd still need to define the areas, but it gets the job done. One problem with this is that when there's many areas in placeX, the if statement would get veeeeery long.
 
Link to comment
Share on other sites

Well i don't see the point in coding more than you have to... :/

 

Sure this:

public enum Location {
//your pre-definding the value of whatever you need.
    AREA_ONE(new Area(3092, 3246, 3095, 3240)),
    AREA_TWO (new Area(3215, 9623, 3219, 9620)),
    AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)),
    ;

    //these are the private fields you pre-definded
    private Area area;

    //constructor add what values you need to pre-define
    private Location(Area area){
        this.area = area;
    }

    //these are simple getter methods.
    //setter method arent allowed because the values are pre-fined so they are basically static.
    public Area getArea(){
        return this.area;
    }
}

Looks great and all but why when

Area AREA_ONE = new Area(3092, 3246, 3095, 3240);
Area AREA_TWO = new Area(3215, 9623, 3219, 9620);
Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216);

Would do the same thing :/
or even storing it it a lil nooby class like

public class Areas {
    static Area AREA_ONE = new Area(3092, 3246, 3095, 3240);
    static Area AREA_TWO = new Area(3215, 9623, 3219, 9620);
    static Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216);
}

would do the same thing :/ It might just be me being super lazy but i see no point in over complicating the situation :(

Someone plz enlighten me.
 

 

Link to comment
Share on other sites

Use PositionPolygon?

we were never explained how to use it. 

 

 

Or he could use the Banks class to use the exact polygons of the banks instead of arbitrary rectangles wink.png

he never say anything about banks. I use that enum above as an example.

 

 

Well i don't see the point in coding more than you have to... :/

 

Sure this:

public enum Location {
//your pre-definding the value of whatever you need.
    AREA_ONE(new Area(3092, 3246, 3095, 3240)),
    AREA_TWO (new Area(3215, 9623, 3219, 9620)),
    AREA_WHATEVER_YOU WANT (new Area(3207, 3220, 3210, 3216)),
    ;

    //these are the private fields you pre-definded
    private Area area;

    //constructor add what values you need to pre-define
    private Location(Area area){
        this.area = area;
    }

    //these are simple getter methods.
    //setter method arent allowed because the values are pre-fined so they are basically static.
    public Area getArea(){
        return this.area;
    }
}

Looks great and all but why when

Area AREA_ONE = new Area(3092, 3246, 3095, 3240);
Area AREA_TWO = new Area(3215, 9623, 3219, 9620);
Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216);

Would do the same thing :/

or even storing it it a lil nooby class like

public class Areas {
    static Area AREA_ONE = new Area(3092, 3246, 3095, 3240);
    static Area AREA_TWO = new Area(3215, 9623, 3219, 9620);
    static Area AREA_WHATEVER_YOU_WANT = new Area(3207, 3220, 3210, 3216);
}

would do the same thing :/ It might just be me being super lazy but i see no point in over complicating the situation sad.png

Someone plz enlighten me.

 

with an enum you can loop through the variables rather than having a nested if statement.  

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...