import java.awt.*;
import java.applet.*;
public class Pathfinding01 extends Applet {
short map[][] ={{0,0,0,0,1,0,0,0,0,0},
{0,0,0,0,1,0,1,1,1,0},
{0,1,1,1,1,0,1,0,1,0},
{0,0,0,0,1,0,1,0,1,0},
{0,1,1,0,1,0,1,0,1,0},
{0,0,1,0,1,0,1,0,1,0},
{0,0,1,0,0,0,1,0,1,0},
{0,0,1,1,1,1,1,0,1,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0}};
public void init() {
}
public void paint(Graphics g) {
//g.drawString("Welcome to Java!!", 50, 60 );
for(int x = 0; x < map.length; x++){
for(int y = 0; y < map[0].length; y++){
if(map[x][y]==1){
g.fillRect(x*32,y*32,32,32);
}
}}
}
}
Learning how to program/code video games step by step in Java. Platformers, Shooters, Turn Based Strategy, Real Time Strategy.
donderdag 14 april 2011
Tilemap with Multidimensional array example
I was looking through sourcecode and discovered how to use multidimensional arrays to store map data. Below the example.
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten
Opmerking: Alleen leden van deze blog kunnen een reactie posten.