I am currently coding a 2D game and I am trying to copy Zelda:Link to the Past as closely as I can. Not because I am trying to make a clone of the game, but because I loved nearly everything about the game as a kid, and I would like my game "engine" to function in a very similar way. The end result should be entirely different from Zelda. Instead of having the map built out of many tiles, I want to have the map made up of one large image. If you remember from LtP, when the player moved, the map moved with him.
The biggest problem I am having right now, is trying to figure out the most effective way to draw the map.
Currently, I have one large image which is displayed on the screen and everything(player/scenery/ai sprites) is layered on top of that. If the player moves close enough to either side of the screen, instead of the player moving, the screen is pushed in that direction (every time the game timer runs, it checks the player coordinates and whether or not the directional keys are being pressed.
It appears that this works well enough for my purpose. I place ai/scenery objects(things with collision) by using pixel coordinates. Each object has its own set of X,Y values and functions that can set/get them. Each time the map moves because of the player, every item has its coordinates reset.
Before implementing this, I assumed that it would work pretty well. Once I actually got it working though, it appears that the game timer runs too fast for this method to work very well, because the items slowly begin to get out of alignment and you can tell that the background and the scenery items are not one image.
If I limit my game to the size of the screen, this is obviously not a problem. I could make it into a bunch of tiles and every time the player goes off screen the next tile is loaded but this is not what I want to do, and it ruins the ideas that I have for this game.
example:
Control Class(this code runs at set intervals and acts as the game timer):
int camera = 150;
public void gameTimer(){
if(player.getX() < camera && player.getLeft()==true){
backgroundX+=1;
adjustX=1;
adjustY=0;
}
scenery.move(adjustX,adjustY);
}
Scenery Class:
public void move(int tempX, int tempY){
x+=tempX;
y+=tempY;
}
This obviously not the entire game and massive parts have been excluded. I felt it would be easier to explain if I showed some simple code. I don't need help writing code, just the concepts behind it. This is Java by the way.
Long story short, does anyone know of a more efficient way to draw the map and populate it with scenery that stays in put? If so, could you please explain? If you could explain how Link to the Past did it that would be even better. Or, is my concept solid and I am just implementing it incorrectly? Although I doubt it, because it seems like it is horribly inefficient to just change the coordinates of everything.
I can post example code of what I have currently but this is mostly conceptual and I would just like to hear of some people's ideas.

New Topic/Question
Reply



MultiQuote





|