Slick2D - Entities and rendering

Posted by Zarkopafilis on Game Development See other posts from Game Development or by Zarkopafilis
Published on 2013-10-20T12:50:14Z Indexed on 2013/10/20 16:11 UTC
Read the original article Hit count: 346

Filed under:
|
|
|

I have been trying to create my very first game for quite a while, followed some tutorials and stuff, but I am stuck at creating my entity system. I have made a class that extends the Entity class and here it is:

  public class Lazer extends Entity{//Just say that it is some sort of bullet

private Play p;//Play class(State)
private float x;
private float y;
private int direction;

public Lazer(Play p, float x , float y, int direction){
    this.p = p;
    this.x = x;
    this.y = y;
    this.direction = direction;
    p.ent.add(this);
}

public int getDirection(){
    return direction; //this one specifies what value will be increased (x/y) at update
}
public float getX(){
    return x;
}
public float getY(){
    return y;
}
public void setY(float y){
    this.y = y;
}
public void setX(float x){
    this.x = x;
}
     }

The class seems pretty good , after speding some hours googling what would be the right thing. Now, on my Play class. I cant figure out how to draw them. (I have added them to an arraylist) On the update method , I update the lazers based on their direction:

public void moveLazers(int delta){
       for(int i=0;i<ent.size();i++){
           Lazer l = ent.get(i);
           if(l.getDirection() == 1){
               l.setX(l.getX() + delta * .1f);
           }else if(l.getDirection() == 2){
               l.setX(l.getX() - delta * .1f);
           }else if(l.getDirection() == 3){
               l.setY(l.getY() + delta * .1f);
           }else if(l.getDirection() == 4){
               l.setY(l.getY() - delta * .1f);
           }


       }
   }

Now , I am stuck at the render method. Anyway , is this the correct way of doing this or do I need to change stuff? Also I need to know if collision detection needs to be in the update method. Thanks in advance ~ Teo Ntakouris

© Game Development or respective owner

Related posts about java

Related posts about lwjgl