added a Entity.java class that handles position rotation and collition. collition has jet not been made.
This commit is contained in:
parent
dbee794932
commit
0044d4fff4
17 changed files with 154 additions and 55 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue