Hello!
I’m pretty much just starting out with java, but I’ve learnt most basics by now. I think.
Anyways, I’ve just started out on a somewhat simple RPG-style game in which the player is supposed to be able to do rpg-generic things like moving and fighting. Now, I’ve drafted some kind of basic layout for the program. One part handles drawing and one handles the actual game data. In the part that is supposed to handle the object-object interaction I’ve run into somewhat of a problem, and it’s this problem that forms my slightly confused question:
How do I create objects and save them to be able to paint them later on while still retaining full control of specific objects?
To clarify what I mean, my last project involved a ball and a few lines. I essentially ‘saved’ internally them like this:
private Ball ball;
private MyLine[] line = new line[10]
public ConstructorOfThisClass(){
ball = new Ball(position, size)
line[0] = new MyLine(x1, y1, x2, y2)
line[1] = new MyLine(x1, y1, x2, y2)
line[2] = ...
}
To draw this I just had to call the ball’s draw method as well as the draw method of line[ i ]
in a loop cycling through all lines for every frame.
In this rpg, there must be more than 2 kinds of things. For example I may want a few trees, the player, a house, a couple of stones and an enemy. All of these things can of course subclass some kind of overall WorldObject class and then get their unique properties in their own class files. But how is it advised that I handle them? I kinda feel that manually (or in a loop with random values) creating a whole lot of tree instances and saving them to a list somewhere is not such a good solution. Perhaps some kind of grid?
I feel that I want to be able to refer to any one object at any time as well as being able to handle them all at once, mostly for drawing them.
So, yeah, anyone got any tips or any guides it might be worthwhile for me to look at? If you want me to clarify something, please tell, as it is obvious that I might not have made my point quite clear.
Cheers!