diff --git a/src/ei/engine/scene/AnimatedSprite.java b/src/ei/engine/scene/AnimatedSprite.java deleted file mode 100644 index f61291e..0000000 --- a/src/ei/engine/scene/AnimatedSprite.java +++ /dev/null @@ -1,172 +0,0 @@ -package ei.engine.scene; - -import java.awt.Rectangle; -import java.util.HashMap; - -import org.lwjgl.opengl.GL11; - -import ei.engine.texture.Texture; -import ei.engine.texture.TextureLoader; - -/** - * Implementation of sprite that uses an OpenGL quad and a texture - * to render a given image to the screen. - * - * @author Kevin Glass - * @author Brian Matzon - * @author Ziver Koc - */ -public class AnimatedSprite extends Entity { - /** The texture that stores the image for this sprite */ - private HashMap textures; - private String currentAnimation; - private int textureId; - - /** - * Create a new empty AnimatedSprite - * - * @param window The window in which the sprite will be displayed - * @param ref A reference to the image on which this sprite should be based - */ - public AnimatedSprite(String name) { - super(name); - textures = new HashMap(); - currentAnimation = null; - textureId = -1; - } - - /** - * Adds a vector of textures to the AnimationSprite - * - * @param name The name of the animation - * @param t The vector of textures - * @return true if successful else false - */ - public boolean addAnimation(String name, Texture[] t){ - if(!textures.containsKey(name)){ - textures.put(name,t); - return true; - } - return false; - } - - /** - * Adds a vector of textures to the AnimationSprite - * - * @param name The name of the animation - * @param t The path to the textures - * @return true if successful else false - */ - public boolean addAnimation(String name, String[] s){ - Texture[] t = new Texture[s.length]; - - for(int i=0; i= textureId){ - textureId = 0; - } - } - } - - /** - * Returns the bound of this class - */ - public Rectangle getBound() { - return new Rectangle( - (int)getLocation().getX(), - (int)getLocation().getY(), - textures.get(currentAnimation)[textureId].getImageWidth(), - textures.get(currentAnimation)[textureId].getImageHeight()); - } -} \ No newline at end of file diff --git a/src/ei/engine/scene/Sprite.java b/src/ei/engine/scene/Sprite.java index 35059c6..a896039 100644 --- a/src/ei/engine/scene/Sprite.java +++ b/src/ei/engine/scene/Sprite.java @@ -101,7 +101,6 @@ public class Sprite extends Entity { // bind to the appropriate texture for this sprite texture.bindGL(); - GL11.glColor3f(1,1,1); // draw a quad textured to match the sprite GL11.glBegin(GL11.GL_QUADS); diff --git a/src/ei/engine/texture/AnimatedTexture.java b/src/ei/engine/texture/AnimatedTexture.java new file mode 100644 index 0000000..c1cd562 --- /dev/null +++ b/src/ei/engine/texture/AnimatedTexture.java @@ -0,0 +1,172 @@ +package ei.engine.texture; + +import java.util.HashMap; + + +/** + * Uses a sequence of images to "Animate" + * + * @author Ziver Koc + */ +public class AnimatedTexture extends Texture { + /** The texture that stores the image for this sprite */ + private HashMap textures; + private String currentAnimation; + private int textureId; + + /** + * Create a new empty AnimatedSprite + * + * @param window The window in which the sprite will be displayed + * @param ref A reference to the image on which this sprite should be based + */ + public AnimatedTexture(String name) { + super(); + textures = new HashMap(); + currentAnimation = null; + textureId = -1; + } + + /** + * Adds a vector of textures to the AnimationSprite + * + * @param name The name of the animation + * @param t The vector of textures + * @return true if successful else false + */ + public boolean addAnimation(String name, Texture[] t){ + if(!textures.containsKey(name)){ + textures.put(name,t); + return true; + } + return false; + } + + /** + * Adds a vector of textures to the AnimationSprite + * + * @param name The name of the animation + * @param t The path to the textures + * @return true if successful else false + */ + public boolean addAnimation(String name, String[] s){ + Texture[] t = new Texture[s.length]; + + for(int i=0; i= textureId){ + textureId = 0; + } + } + } + + /** + * Set the height of the image + * + * @param height The height of the image + */ + public void setHeight(int height) { + textures.get(currentAnimation)[textureId].setHeight(height); + } + + /** + * Set the width of the image + * + * @param width The width of the image + */ + public void setWidth(int width) { + textures.get(currentAnimation)[textureId].setWidth(width); + } + + /** + * Get the target of the buffer + * + * @return The target of the buffer + */ + public int getGLTarget() { + return textures.get(currentAnimation)[textureId].getGLTarget(); + } + + /** + * Get the height of the original image + * + * @return The height of the original image + */ + public int getImageHeight() { + return textures.get(currentAnimation)[textureId].getImageHeight(); + } + + /** + * Get the width of the original image + * + * @return The width of the original image + */ + public int getImageWidth() { + return textures.get(currentAnimation)[textureId].getImageWidth(); + } + + /** + * Get the height of the physical texture + * + * @return The height of physical texture + */ + public float getHeight() { + return textures.get(currentAnimation)[textureId].getHeight(); + } + + /** + * Get the width of the physical texture + * + * @return The width of physical texture + */ + public float getWidth() { + return textures.get(currentAnimation)[textureId].getWidth(); + } + + /** + * Set the height of this texture + * + * @param texHeight The height of the texture + */ + public void setTextureHeight(float texHeight) { + textures.get(currentAnimation)[textureId].setTextureHeight(texHeight); + } + + /** + * Set the width of this texture + * + * @param texWidth The width of the texture + */ + public void setTextureWidth(float texWidth) { + textures.get(currentAnimation)[textureId].setTextureWidth(texWidth); + } +} \ No newline at end of file diff --git a/src/ei/engine/texture/Texture.java b/src/ei/engine/texture/Texture.java index 4750130..45ecbf4 100644 --- a/src/ei/engine/texture/Texture.java +++ b/src/ei/engine/texture/Texture.java @@ -33,6 +33,15 @@ public class Texture { /** The ratio of the height of the image to the texture */ private float heightRatio; + /** + * Create a empty texture + * + */ + public Texture(){ + this.target = -1; + this.textureID = -1; + } + /** * Create a new texture * @@ -51,6 +60,7 @@ public class Texture { */ public void bindGL() { GL11.glBindTexture(target, textureID); + GL11.glColor3f(1,1,1); } /**