I have a Mob class that is derived from the Atom class. I always loop through atoms and I have a function isMob() to tell if an Atom is a Mob or not. My question is is there any shorthand for being able to reference the mobs vars?
E.G.
class Atom{
float var1,var2,var3;
Atom(){}
Boolean isMob(){return false;}
}
class Mob extends Atom{
float var4,var5;
Mob(){super();}
Boolean func1(){return true;}
Boolean isMob(){return true;}
}
setup(){
Atom atom=new Mob();
atom<Mob>.func1(); //This doesn't work but is there proper syntax for this or do I have to make a Mob var?
I have an ArrayList of a custom class of mine Atoms(I need it to be an ArrayList because the size will be dynamic and constantly fluxulating). But I have no idea how to convert the objects I get from ArrayList.get() back into my Atom class. I've tried typecasting by doing
Atom(ArrayList.get(0)) but the compiler tells me that Atom() is a uknown function. Any Ideas?
I come from a C++/AS3 background and I just picked up processing to see what its capable of. Unfortunatly I keep running into a brick wall with this issue. What is the best way to overwrite subclass variables?
class Atom{
String icon="";
Atom(float _x,float _y){
x=_x;
y=_y;
atoms.add(this);
if(!icon.equals("")){
println(icon); //Will be blank
PImage img=loadImage(icon);
image(img,x,y);
bounds[2]=img.width;
bounds[3]=img.height;
}
}
class Mob extends Atom{
String icon="guy.png"; //The problem is if the variable is initialized like this in Atom() it will read icon as ""
Mob(float _x,float _y){
super(_x,_y);
println(icon); //WIll be "guy.png"
}
}
void setup(){
size(600,600);
new Mob(50,50);
noLoop();
}
void draw(){
}
Is there a better approach or is this language fatally flawed?