Gornova / MarteEngine

MarteEngine is a Java Engine for videogames
http://randomtower.blogspot.com
Other
74 stars 20 forks source link

Removing Entity`s #80

Closed pcrossy closed 12 years ago

pcrossy commented 12 years ago

Hello im new in Marte Engine development and just got a hard problem in removing the f***** Entity if i remove like in the Tutorial said im getting the awesome NullPointerExeception my Code

public class Feuerball extends Entity{

Feuerball feuerball;

public Feuerball(float x, float y) throws SlickException { super(x, y); define ("ATTACK",Input.KEY_W); define ("REMOVE",Input.KEY_K); Image fire = ResourceManager.getImage("xxx"); setGraphic(fire);

}
@Override
public void update(GameContainer container, int delta)
        throws SlickException {
    super.update(container, delta);

 x = x + 2 ;
 if(check("ATTACK")){feuerball = new Feuerball(500,500);world.add(feuerball);System.out.println("Entity erstellt!!");}
 if (check("REMOVE")){world.remove(feuerball);System.out.println("Deleted!!");feuerball.active = false;}

}

@Override
public void render(GameContainer container, Graphics g)
        throws SlickException {
    super.render(container, g);
}

}

public class Welt extends World{

Image background;
Image ground1;

public Welt (int id,GameContainer container)
{
super(id,container);
}

@Override
public void init(GameContainer container, StateBasedGame game)
        throws SlickException {try {ResourceManager.loadResources("data/resources.xml");} catch (IOException e) {e.printStackTrace();}
        super.init(container, game);

    background = new Image("data/backgroundbluesky.png");
    ground1 = new Image("data/grassfloor2.png");
    Spieler spieler = new Spieler(30,616);
    add(spieler);
    Feuerball feuerball = new Feuerball(spieler.x,spieler.y);
    add(feuerball);

Hope i copied all the code please help me it´s annoying and could you please make a API Doc this would be chilled.

Gornova commented 12 years ago

well, it's not a MarteEngine problem, because this part of the code:

if(check("ATTACK")){feuerball = new Feuerball(500,500);world.add(feuerball);System.out.println("Entity erstellt!!");} if (check("REMOVE")){world.remove(feuerball);System.out.println("Deleted!!");feuerball.active = false;}

if you check attack and add a new entity "feuerball" is not null, you can remove it, but if you don't add feuerball to world before remove it, you have nullpointer.. but not on remove, on "feuerball.active", because feuerball is null, right?

pcrossy commented 12 years ago

Ye sorry i knew that this is no issue currently ,but now i fixed the code to get the nullpointer out ,but its still not removing the entity`s.Now i changed this

 if(check("ATTACK")){feuerball = new Feuerball(500,500);world.add(feuerball);System.out.println("Entity erstellt!!");feuerballcounter= feuerballcounter + 1;}
 if (check("REMOVE") && feuerballcounter >= 1){world.remove(feuerball);feuerballcounter = feuerballcounter - 1;}

I don`t know what is going wrong now i made the code really simple.

pcrossy commented 12 years ago

Ok now i know where my problem is!!How can i explain that only 2 fireballs can be in world at once?I tried this but it´s not working cause when I press the my ATTACK its producing much fireballs whether i set the counter to 2 or 1 .Im saving all my fireballs in 1 fireball so if I press attack it ´s generating 10 fireballs if i now press my remove button its only removing the last generated fireball can you help me fixing this problem i dont know how maybe i`m just to dummie.

Gornova commented 12 years ago

Yeah no problem :D when you press attack, you can count how many fireball type there is in a world using this:

https://github.com/Gornova/MarteEngine/blob/master/src/it/marteEngine/World.java#L256

pcrossy commented 12 years ago

You See that's why i need a API Doc XD Gonna try it tomorrow!! Thanks Closed