Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

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

share|improve this question
up vote 1 down vote accepted

Using an entity system I would move the moveLasers method into the Lazer class. The idea of entities is that you got modular, kind of self managing objects and no 'super class'. You could implement a Draw and Update method in the Lazer class and just pass he calltoken from the main Update:

for(int i=0;i<ent.size();i++){

Update and Draw could be defined in the entity base class, then you main class would not even need to know what exact subtype of entity it is dealing with.

I would vote for a similar approach for your draw method. Just call each entities Draw method from the main method and pass the context into the function.

share|improve this answer
Since this is my first minigame I will not polish it that much. The second project will be less rescource consuming...also I am considering of moving into modding minecraft/opengl...thanks anyway this solved it – Zarkopafilis Oct 21 '13 at 11:26

First you need an image to represent the laser. You're going to need to add another an field to your class that holds an Image. You can use almost any image file. Then in your game class just loop through the entity array and do something like

//rotate so visual representation of the laser is facing correct direction
entity[i].sprite.rotate(desiredAngle - currentAngle);

//draw visual representation of the laser
entity[i].sprite.draw(x, y);

And to answer your question on collision detection all game logic should go in your update method.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.