Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualPsychotikRabbit

Posted 20 April 2013 - 07:48 AM

The problem with this is that the obstacle class i another abstract class that I made for objects that does not have "life" as in moving etc, they are static. such as Walls.

While the entity class is supposed to be for Entities such as "living things" that are moving, etc!



It's simple, you can use Entity as the base class. Entity is anything that has a position,a size and is renderable in the game.
Then for your "living things" you can create a MovingEntity class which extends from Entity.

Now with that, all your entities/obstacles descend from Entity.

 

Entity.java
---------------------------
public class Entity {
    int position x;
    int position y;
    int width;
    int height;
    
    //Here go your getters/setters and contructors
}


 

MovableEntity.java
---------------------------------------
public class MovableEntity extends Entity {
    int speed;

    //Here goes your setters/getters/constructors

    public void update() {
        //Detect collision and move
    }
}


Now your walls can now extends from Entity or directly be directly a Entity.
Your ball/paddle/ai can extends from MovableEntity or be directly a MovableEntity.


#1PsychotikRabbit

Posted 20 April 2013 - 07:47 AM

The problem with this is that the obstacle class i another abstract class that I made for objects that does not have "life" as in moving etc, they are static. such as Walls.

While the entity class is supposed to be for Entities such as "living things" that are moving, etc!



It's simple, you can use Entity as the base class. Entity is anything that has a position,a size and is renderable in the game.
Then for your "living things" you can create a MovingEntity class which extends from Entity.

Now with that, all your entities/obstacles descend from Entity.

 
Entity.java
---------------------------
public class Entity {
    int position x;
    int position y;
    int width;
    int height;
    
    //Here go your getters/setters and contructors
}


 

MovableEntity.java
---------------------------------------
public class MovableEntity extends Entity {
    int speed;

    //Here goes your setters/getters/constructors

    public void update() {
        //Detect collision and move
    }
}


Now your walls can now extends from Entity or directly be directly a Entity.
Your ball/baddle/ai can extends from MovableEntity or be directly a MovableEntity.


PARTNERS