Sign in to follow this  
juba

Editor Primitivo [render maps 32x32, DEMO]

Recommended Posts

juba    116

Hello, I would like to share a Java class that did, serves to render maps 32x32, was very simple and easy to understand so I'm posting.

The class renders what should be seen as soon as it consumes very little memory. [old version]

    package com.primedi.ig;
    import java.awt.Color;
    public class Mapa extends JFrame {
    private static final long serialVersionUID = 1L;
    public String nomeMapa = null;
    private JPanel panMapa;
    private JScrollPane brPanMapa;
    // alcance da tela em tiles *
    private static final int alcanceX = 20;
    private static final int alcanceY = 15;
    // alcance da tela em tiles
    private JLabel[][] tilesImaginarios = new JLabel[alcanceX][alcanceY];
    //public static int X_POS_TILE = -1;
    //public static int Y_POS_TILE = -1;
    private Arquivo arqMapa = null;
    public Mapa(String nomeMapa){
    this.nomeMapa = nomeMapa;
    inicializarJanela();
    setVisible(true);
    processosCons();
    }
    private void criarJanela(){
    //setTitle("zMeck - Início");
    setSize(1352, 594);
    getContentPane().setLayout(null);
    setResizable(false);
    setLocationRelativeTo(null);
    setUndecorated(true);
    getContentPane().setBackground(Color.BLACK);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    private void criarPaineis(){
    panMapa = new JPanel();
    panMapa.setLayout(null);
    panMapa.setBackground(Color.BLACK);
    }
    private void criarBarrasDeRolagem(){
    brPanMapa = new JScrollPane(panMapa);
    brPanMapa.setBounds(0, 0, 658, 498);
    brPanMapa.getHorizontalScrollBar().setUnitIncrement(16);
    }
    private void adicionarComponentes(){
    getContentPane().add(brPanMapa);
    }
    private void inicializarJanela(){
    criarJanela();
    criarPaineis();
    criarBarrasDeRolagem();
    adicionarComponentes();
    carregarInfosMapa();
    }
    private void carregarInfosMapa(){
    arqMapa = new Arquivo("mapas", nomeMapa + ".pmp");
    arqMapa.carregarArquivo();
    Dimension d = new Dimension((arqMapa.lerLinha(0).length() * 32), arqMapa.pegarNumeroLinhas() * 32);
    panMapa.setPreferredSize(d);
    panMapa.setVisible(true);
    for(int j = 0; j < alcanceY; j++){
    for(int i = 0; i < alcanceX; i++){
    tilesImaginarios[i][j] = new JLabel(new ImageIcon("tiles/tile2.PNG"));
    tilesImaginarios[i][j].setBounds((i * 32) + 658, j * 32, 32, 32);
    getContentPane().add(tilesImaginarios[i][j]);
    }
    }
    }
    private void altImg(int x, int y){
    for(int j = 0; j < alcanceY; j++){
    for(int i = 0; i < alcanceX; i++){
    tilesImaginarios[i][j].setIcon(new ImageIcon("tiles/tile" + arqMapa.lerLinha(y + j).charAt(x + i) + ".PNG"));
    }
    }
    }
    private void processosCons(){
    Timer t = new Timer();
    t.schedule(new TimerTask() {
    int posInicialScrollX = 0;
    int posInicialScrollY = 0;
    int c32 = 32;
    int c32y = 32;
    public void run() {
    if(brPanMapa.getViewport().getViewPosition().x != posInicialScrollX){
    posInicialScrollX = brPanMapa.getViewport().getViewPosition().x;
    if(posInicialScrollX > c32){
    altImg(C32.pixelPara32(brPanMapa.getViewport().getViewPosition().x), C32.pixelPara32(brPanMapa.getViewport().getViewPosition().y));
    c32 += 32;
    return;
    }
    if(posInicialScrollX < c32){
    altImg(C32.pixelPara32(brPanMapa.getViewport().getViewPosition().x), C32.pixelPara32(brPanMapa.getViewport().getViewPosition().y));
    c32 -= 32;
    return;
    }
    }
    if(brPanMapa.getViewport().getViewPosition().y != posInicialScrollY){
    posInicialScrollY = brPanMapa.getViewport().getViewPosition().y;
    if(posInicialScrollY > c32y){
    altImg(C32.pixelPara32(brPanMapa.getViewport().getViewPosition().x), C32.pixelPara32(brPanMapa.getViewport().getViewPosition().y));
    c32y += 32;
    return;
    }
    if(posInicialScrollY < c32y){
    altImg(C32.pixelPara32(brPanMapa.getViewport().getViewPosition().x), C32.pixelPara32(brPanMapa.getViewport().getViewPosition().y));
    c32y -= 32;
    return;
    }
    }
    }
    }, 1, 1);
    }
    } 

Since a 5x5 map would be:

00000
00000
00000
00000
00000

The project already has some new updates, latest video project:

http://www.youtube.com/watch?v=Za6mYKac3tc

note: i'm using google translator, but my english is understandable. [:

Share this post


Link to post
Share on other sites
krinosx    606

Hum... as your code is written in Portuguese, has no indentation and no comments, its hard to understand it...

( I also speak Portuguese, but its a English forum, so you may try to use english to express yourself... )

 

If you are trying to promote your project here ( there is no question in your post, so I think you are just trying to show your work in progress ) you may try to write your code with 'english' function names, and maybe some comments, indentation, etc....

 

 

Btw... your editor appears to be interesting ( as I can see in the video ), I am working with a project that can use something like it in near future...

 

Keep the good work you are doing!! You can get a good tool for your games with its project!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this