Java Game Programming - Level Editor

preview_player
Показать описание
In this episode of Java Game Programming we begin implementing a robust level editor into our Tower Defense game using double integer arrays.
Рекомендации по теме
Комментарии
Автор

Very cool series to follow. I've learned a lot from you. Thank you very much.

dragonv
Автор

Awsome cant wait for the new ones to come out, been great following your series man appreciate all the effort you put into it.

SyWill
Автор

Hi there, i'd just like to say thanks for the tutorials.
I have a very great idea on setting a single tile without adding in a big double array.
This method can also be used during the game (e.g say someone mows the grass, then turn it to dirt.)

This goes in the TileGrid class:

public void setTile(int x, int y, TileType type){
map[x][y].setType(type);
}

You will also need to change the texture of the tile when doing setType(), otherwise you will not be able to see the texture(but the tiletype is what is specified).
So in the setType() method in the Tile class, change the texture:

public void setType(TileType type) {
this.type = type;
this.texture =
}

Example in the boot class:

TileGrid grid = new TileGrid();
grid.setTile(0, 0, TileType.DIRT);

grid.setTile(1, 3, TileType.DIRT);

grid.setTile(3, 4, TileType.DIRT);


grid.draw();
Display.update();
Display.sync(60);

}

markatash
Автор

If I have a hexagonal grid (which I can program), and want to make a big map, what free tile editor can I use?

TeeMee
Автор

Why did you put all the zero's rather than declare the variable or use a nested for loop to fill it up??

svg-dbaum
Автор

@Cross Coast Gaming can you tell me what is wrong with my code. I think it has something to do with my map command, because when I take it out of the TileGrid grid = new TileGrid(map); the program shows all grass tiles, but I need the map command to move forward.Here are the errors I'm getting:
Exception in thread "main" 15
at
at
at Data.Boot.main(Boot.java:47)

I will post Code:

package Data;

import static helpers.Artist.BeginSession;
import org.lwjgl.opengl.Display;

public class Boot {

public Boot() {

BeginSession();

int[][] map = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
};

TileGrid grid = new TileGrid(map);
{

grid.Draw();

Display.update();
Display.sync(60);

}

Display.destroy();
}

public static void main(String[] args) {

new Boot(); 
}
}


package Data;

import static helpers.Artist.DrawQuadTex;

public class TileGrid {

public Tile[][] map;

public TileGrid() {
map = new Tile[20][15];
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++){
map[i][j] = new Tile(i * 64, j * 64, 64, 64, TileType.Grass);
}
}
}

public TileGrid(int[][] newMap) {
map = new Tile[20][15];
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map.length; j++) {
switch (newMap[j][i]) {
case 0:
= new Tile(i * 64, j *64, 64, 64, TileType.Grass);

case 1:
= new Tile(i * 64, j *64, 64, 64, TileType.Dirt);

}
}
}
}

public void Draw() {
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
Tile t = map[i][j];
DrawQuadTex(t.getTexture(), t.getX(), t.getY(), t.getWidth(), t.getHeight());
}
}
}
}

beg
Автор

I wrote a question here, but I see now that it kind of had an obvious answer (I facepalmed).

But while I'm here, I might as well ask another question:

What would be the best way to make a 2d platformer game in a way that makes it almost never lag (basically, any tips?)?

ThatEntityGirl
Автор

codeing is like a girl.. you can always count on it to argue

Danielstarcate
Автор

my one opens then shuts down instantly and the console says: Exception in thread "main" java.lang.RuntimeException: Resource not found: res/grass64.png
at
at
at
at
at
at
at Data.Boot.main(Boot.java:25)


please help

FastAssassin