added a Entity.java class that handles position rotation and collition. collition has jet not been made.

This commit is contained in:
Ziver Koc 2007-03-13 18:37:22 +00:00
parent dbee794932
commit 0044d4fff4
17 changed files with 154 additions and 55 deletions

BIN
bin/data/units/tank.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/ei/game/EI.class Normal file

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,42 @@
package ei.engine.math;
public class Vector2D {
private double x;
private double y;
public Vector2D(double x, double y){
this.x = x;
this.y = y;
}
/**
* Get the X value
*
* @return the x value in the vector
*/
public double getX(){
return x;
}
/**
* Get the Y value
*
* @return the y value in the vector
*/
public double getY(){
return y;
}
/**
* Add to the vectro
* @param i The amount to add
*/
public void add(double i){
x += i;
y += i;
}
public String toString(){
return "Vector2I["+x+","+y+"]";
}
}

View file

@ -0,0 +1,103 @@
/**
*
*/
package ei.engine.scene;
import ei.engine.math.Vector2D;
import ei.engine.math.Vector2I;
/**
* This class is the root class of all the objects that
* will show on the scrren. This class handles the position
* and rotation and the colitions of the objects.
* @author Ziver
*/
public abstract class Entity {
/** The name of this sprite */
private String name;
/** The location of this entity in pixels*/
private Vector2D location;
/** The rotation of this entity in pixels*/
private Vector2D rotation;
/** The size of this entity in pixels*/
private Vector2I size;
/**
* creates a new entity
*
* @param name The name of the entity
*/
public Entity(String name){
this.name = name;
location = new Vector2D(0,0);
}
/**
* @return The name of the entity
*/
public String getName() {
return name;
}
/**
* Get the Location of the entity
*
* @return The Location of the entity
*/
public Vector2D getLocation() {
return location;
}
/**
* set the location of this entity in pixels
*
* @param l The location of the entity
*/
public void setLocation(Vector2D l) {
location = l;
}
/**
* Get the rotation of the entity
*
* @return The Location of the entity
*/
public Vector2D getRotation() {
return rotation;
}
/**
* set the rotation of this entity in pixels
*
* @param r The rotation of the entity
*/
public void setRotation(Vector2D r) {
rotation = r;
}
/**
* Get the size of the entity
*
* @return The Location of the entity
*/
public Vector2I getSize() {
return size;
}
/**
* set the size of this entity in pixels
*
* @param s The size of the entity
*/
public void setSize(Vector2I s) {
size = s;
}
/**
* the render method shuold beimplemented for every entity
*/
public abstract void render();
}

View file

@ -4,7 +4,6 @@ import java.io.IOException;
import org.lwjgl.opengl.GL11;
import ei.engine.math.Vector2I;
import ei.engine.util.Texture;
import ei.engine.util.TextureLoader;
@ -16,15 +15,9 @@ import ei.engine.util.TextureLoader;
* @author Brian Matzon
* @author Ziver Koc
*/
public class Sprite {
public class Sprite extends Entity {
/** The texture that stores the image for this sprite */
private Texture texture;
/** The location of this sprite in pixels*/
private Vector2I location;
/** The name of this sprite */
private String name;
/**
* Create a new empty sprite
@ -33,9 +26,8 @@ public class Sprite {
* @param ref A reference to the image on which this sprite should be based
*/
public Sprite(String name) {
this.name = name;
texture = null;
location = new Vector2I(0,0);
super(name);
texture = null;
}
/**
@ -45,10 +37,9 @@ public class Sprite {
* @param texture The texture to use
*/
public Sprite(String name, Texture texture) {
this.name = name;
super(name);
this.texture = texture;
this.location = new Vector2I(texture.getImageWidth(),texture.getImageHeight());
}
}
/**
* Create a new sprite from a specified image.
@ -57,11 +48,10 @@ public class Sprite {
* @param ref A reference to the image on which this sprite should be based
*/
public Sprite(String name, String ref) {
super(name);
try {
this.name = name;
this.texture = TextureLoader.getTextureLoaderInstance().getTexture(ref);
this.location = new Vector2I(texture.getImageWidth(),texture.getImageHeight());
} catch (IOException e) {
// a tad abrupt, but our purposes if you can't find a
// sprite's image you might as well give up.
@ -94,41 +84,6 @@ public class Sprite {
return texture.getImageHeight();
}
/**
* @return The name of this sprite
*/
public String getName() {
return name;
}
/**
* Get the Location of the sprite
*
* @return The Location of the sprite
*/
public Vector2I getLocation() {
return location;
}
/**
* set the location of this sprite in pixels
*
* @param x The x coordinate of the sprite
* @param y The y coordinate of the sprite
*/
public void setLocation(int x, int y) {
setLocation(new Vector2I(x,y));
}
/**
* set the location of this sprite in pixels
*
* @param v The location of the sprite
*/
public void setLocation(Vector2I v) {
location = v;
}
/**
* Draw the sprite
*/
@ -140,7 +95,7 @@ public class Sprite {
texture.bind();
// translate to the right location and prepare to draw
GL11.glTranslatef(location.getX(), location.getY(), 0);
GL11.glTranslatef((int)getLocation().getX(), (int)getLocation().getY(), 0);
GL11.glColor3f(1,1,1);
// draw a quad textured to match the sprite

View file

@ -14,7 +14,6 @@ public class InGameState extends GameState{
rootNode = new Node("InGameNode");
s1 = new Sprite("tank","data/units/tank.png");
rootNode.add(s1);
s1.setLocation(1, 1);
}
@Override
@ -24,7 +23,7 @@ public class InGameState extends GameState{
@Override
public void update() {
s1.getLocation().add(1);
s1.getLocation().add(0.1);
}
}