Java: How to Make a Player Class in a Tile-Based RPG

Posted by A.K. on Game Development See other posts from Game Development or by A.K.
Published on 2012-06-28T18:23:44Z Indexed on 2012/06/28 21:25 UTC
Read the original article Hit count: 260

Filed under:
|
|

So I've been following a JavaHub tutorial that basically uses a pixel engine similar to MiniCraft.

I've attempted to make a Player Class as such, and I'm basically making a mock Pokemon game for learning's sake:

    package pokemon.entity;

    import java.awt.Rectangle;

    import pokemon.gfx.Screen;
    import pokemon.levelgen.Tile;
    import pokemon.entity.SpritesManage;;

    public class Player 
    {
int x, y;
int vx, vy;
public Rectangle AshRec;
public Sprite AshSprite;
Screen screen;
Sprite[][] AshSheet;

    public Player()
    {
        AshSprite = SpritesManage.AshSheet[1][0];

        AshRec = new Rectangle(0, 0, 16, 16);

        x = 0;
        y = 0;

        vx = 1;
        vy = 1;

        screen.renderSprite(0, 0, AshSprite);

    }

    public void update()
    {
        move();
        checkCollision();
    }

    private void checkCollision() 
    {

    }

    private void move() 
    {
        AshRec.x += vx;
        AshRec.y += vy;
    }

    public void render(Screen screen, int x, int y)
    {
        screen.renderSprite(x, y, AshSprite);
    }
    }

I guess what I really want to do is have the Player centered in the screen and have the sprite drawn based on an Input Handler. I'm just stumped as to how to sync these together.

© Game Development or respective owner

Related posts about java

Related posts about engine