MarteEngine Tile Collision
Posted
by
opiop65
on Game Development
See other posts from Game Development
or by opiop65
Published on 2012-10-03T23:38:53Z
Indexed on
2012/10/04
3:54 UTC
Read the original article
Hit count: 256
I need to add collision to my tile map using MarteEngine. MarteEngine is built of of slick2D. Here's my tile generation code: Code:
public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException
{
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
map[x][y] = AIR;
air.draw(x * GameWorld.tilesize, y * GameWorld.tilesize);
}
}
for (int x = 0; x < 16; x++) {
for (int y = 7; y < 8; y++) {
map[x][y] = GRASS;
grass.draw(x * tilesize, y * tilesize);
}
}
for (int x = 0; x < 16; x++) {
for (int y = 8; y < 10; y++) {
map[x][y] = DIRT;
dirt.draw(x * tilesize, y * tilesize);
}
}
for (int x = 0; x < 16; x++) {
for (int y = 10; y < 16; y++) {
map[x][y] = STONE;
stone.draw(x * tilesize, y * tilesize);
}
}
super.render(gc, game, g);
}
And one of my tile classes (they're all the same, the image names are just different): Code:
package MarteEngine;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import it.randomtower.engine.entity.Entity;
public class Grass extends Entity {
public static Image grass = null;
public Grass(float x, float y) throws SlickException {
super(x, y);
grass = new Image("res/grass.png");
setHitBox(0, 0, 50, 50);
addType(SOLID);
}
}
I tried to do it like this: Code:
for (int x = 0; x < 16; x++) {
for (int y = 7; y < 8; y++) {
map[x][y] = GRASS;
Grass.grass.draw(x * tilesize, y * tilesize);
}
}
But it gave me a NullPointerException. No idea why, everything looks initialized right? I would be very grateful for some help!
© Game Development or respective owner