thanatos1 -3 Light Poster

Hey guys, i'll try to give you a brief background, then my question.

I've been trying to write a copy of a pokemon game that came out in the 90's (blue/red) and i've come across a couple issues when it comes to how to deal with events and how to properly draw tiles on to the screen.

My game essentially has an arraylist of all the images (tiles 32 x 32px) that the game will use, and when i want to load a map, i read a text file with tokens that decide the order in which i will be drawing and populates the corresponding images into a new arraylist that has only the images which exist on that particular map, and the proper order to draw it in.

Here's my map drawer class,

package tiles;

import java.awt.*;
import world.World;


/**
    The TileMapRenderer class draws a TileMap on the screen.
    It draws all tiles.

    <p>This TileMapRender uses a tile size of 32.
*/
public class TileMapRenderer 
{
    
    /**
     * Number of tiles current being worked on.
     */
    private int tile_number = 0;
    /**
        Draws the specified TileMap.
    */
    public void draw(Graphics2D g)
    {
        String currentMap = TileMap.getName();
        for (int y = 0; y < TileMap.getHeight(); y++) 
        {
            for (int x = 0; x < TileMap.getWidth(); x++) 
            {
                //first layer of the current map.
                if (TileMap.getFirstLayer(tile_number) != 0)
                {
                    g.drawImage(TileMap.getTile(TileMap.getFirstLayer(tile_number) - 1),World.getCoordinateX(currentMap) ,World.getCoordinateY(currentMap),null);
                }
                //second layer of the current map.
                if (TileMap.getSecondLayer(tile_number) != 0)
                {
                    g.drawImage(TileMap.getTile(TileMap.getSecondLayer(tile_number) - 1),World.getCoordinateX(currentMap) ,World.getCoordinateY(currentMap),null);
                }
                tile_number++;
                World.updateCounterX();
            }
            World.resetX();
            World.updateCounterY();
        }
        tile_number = 0;
        World.resetX();
        World.resetY();
    }

}

the draw method loops however many tiles the current map has, and calls drawImage on each arraylist that has the correct order, each map has 2 layers so i must draw the first layer first, then the second (think of it as drawing grass first, then drawing a post sign or something in the same location, that way it looks like the post is on the grass).

however, my problem is the following, i was trying to draw the entire world, but my program ran at an unplayable fps, most likely because this draw method loops the size of the current map's tiles, (and if we're talking about the entire world here, that's humongous, roughly 3k images per method call), and that seems to be some hugely wasted time, since i've set the clipsize to be only of the monitor, so perhaps when i call drawImage and i attempt to draw outside of the monitor area, it won't be drawn, so that's a loop wasted.

How would you fix a problem like this, perhaps by using multidimentional arrays?

Also, my second problem is that for example, let's say i draw a door right? cool, now how do i know what that door's action is supposed to be, is it supposed to spawn you at a different location? and if so, to where? I could go like if (player's x and y are 10 and 20) then you go to here and there, but that seems very non-OO, how would you go about fixing this issue?

I know it's a long read but just give me some ideas, i've been stuck here for a decent amount of time and perhaps what i need is a little push.

Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.