Reputation: 216
I'm making my first game in Java with Slick2d and I created a class plane. (i'm new with java too)
I'm not sure if it's correct to extend from Image class in my class or I'd better use a public Image attribute in my class (public to have easy access to it's methods in the rest of the proyect)
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class Plane extends Image{
private float x;
private float y;
public Plane(String path, float x, float y) throws SlickException{
super(path);
this.x = x;
this.y = y;
}
public float getX(){
return x;
}
public float getY(){
return y;
}
public void move(float hip){
float rotation = this.getRotation();
x+= hip * Math.sin(Math.toRadians(rotation));
y-= hip * Math.cos(Math.toRadians(rotation));
}
}
Upvotes: 1
Views: 490
Reputation: 667
Well, if your class extends Image, then technically your class would inherit all of the properties of the Image class and in theory become an Image.
From your code, I suggest you either:
Upvotes: 0
Reputation: 88757
I don't know slick2d but I'd say your class should not extend Image
but have an image attribute. Extending is a way of saying "Plane is an Image" which normally is not the case but rather a plane has a texture/image.
Additionally, the image should not be public but protected/private and be accessed by public getters and setters. That way you increase encapsulation and prevent problems that might arise when making the image itself public.
Upvotes: 5