New line box class
This commit is contained in:
parent
e3b9e3165a
commit
1958c7aa7e
3 changed files with 156 additions and 6 deletions
|
|
@ -49,12 +49,12 @@ public class Fade extends Entity{
|
||||||
*/
|
*/
|
||||||
public void update(){
|
public void update(){
|
||||||
if(fadeOut){
|
if(fadeOut){
|
||||||
if(life > 0)life -= fade;
|
if(life > 0)
|
||||||
else life = 0;
|
life -= fade;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(life < 1)life += fade;
|
if(life < 1)
|
||||||
else life = 1;
|
life += fade;
|
||||||
}
|
}
|
||||||
entity.update();
|
entity.update();
|
||||||
System.out.println(life);
|
System.out.println(life);
|
||||||
|
|
@ -64,6 +64,20 @@ public class Fade extends Entity{
|
||||||
entity = e;
|
entity = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the fade is done else false
|
||||||
|
* @return True if the fade is done else false
|
||||||
|
*/
|
||||||
|
public boolean isDone(){
|
||||||
|
if(life <= 0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(life >= 1){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the time of the fade
|
* Set the time of the fade
|
||||||
*
|
*
|
||||||
|
|
|
||||||
130
src/ei/engine/scene/LineBox.java
Normal file
130
src/ei/engine/scene/LineBox.java
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
package ei.engine.scene;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import ei.engine.texture.Texture;
|
||||||
|
import ei.engine.texture.TextureLoader;
|
||||||
|
|
||||||
|
public class LineBox extends Entity{
|
||||||
|
/** The texture that stores the image for this sprite */
|
||||||
|
private Texture texture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new empty sprite
|
||||||
|
*
|
||||||
|
* @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 LineBox(String name) {
|
||||||
|
super(name);
|
||||||
|
texture = new Texture();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new sprite from a specified texture.
|
||||||
|
*
|
||||||
|
* @param name The name of the sprite
|
||||||
|
* @param texture The texture to use
|
||||||
|
*/
|
||||||
|
public LineBox(String name, Texture texture) {
|
||||||
|
super(name);
|
||||||
|
this.texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new sprite from a specified image.
|
||||||
|
*
|
||||||
|
* @param name The name of the sprite
|
||||||
|
* @param ref A reference to the image on which this sprite should be based
|
||||||
|
*/
|
||||||
|
public LineBox(String name, String ref) {
|
||||||
|
super(name);
|
||||||
|
this.texture = TextureLoader.getTextureLoaderInstance().getTexture(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the width of this sprite in pixels
|
||||||
|
*
|
||||||
|
* @return The width of this sprite in pixels
|
||||||
|
*/
|
||||||
|
public int getWidth() {
|
||||||
|
if(texture == null){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return texture.getImageWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the height of this sprite in pixels
|
||||||
|
*
|
||||||
|
* @return The height of this sprite in pixels
|
||||||
|
*/
|
||||||
|
public int getHeight() {
|
||||||
|
if(texture == null){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return texture.getImageHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the texture
|
||||||
|
* @return The texture
|
||||||
|
*/
|
||||||
|
public Texture getTexture(){
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw the sprite
|
||||||
|
*/
|
||||||
|
public void render() {
|
||||||
|
if(texture != null){
|
||||||
|
// store the current model matrix
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
|
||||||
|
//Sets the location
|
||||||
|
super.setTranslationGL();
|
||||||
|
//the rotation
|
||||||
|
super.setRotationGL(texture.getImageWidth()/2,texture.getImageHeight()/2);
|
||||||
|
//Sets the scale of the sprite
|
||||||
|
super.setScaleGL();
|
||||||
|
|
||||||
|
// bind to the appropriate texture for this sprite
|
||||||
|
texture.bindGL();
|
||||||
|
|
||||||
|
// draw a quad textured to match the sprite
|
||||||
|
GL11.glBegin(GL11.GL_LINES);
|
||||||
|
{
|
||||||
|
//Vertex at the upper left
|
||||||
|
GL11.glTexCoord2f(0, 0);
|
||||||
|
GL11.glVertex2f(0, 0);
|
||||||
|
//Vertex at the down left
|
||||||
|
GL11.glTexCoord2f(0, texture.getHeight());
|
||||||
|
GL11.glVertex2f(0, texture.getImageHeight());
|
||||||
|
//Vertex at the upper right
|
||||||
|
GL11.glTexCoord2f(texture.getWidth(), texture.getHeight());
|
||||||
|
GL11.glVertex2f(texture.getImageWidth(),texture.getImageHeight());
|
||||||
|
//Vertex at the down right
|
||||||
|
GL11.glTexCoord2f(texture.getWidth(), 0);
|
||||||
|
GL11.glVertex2f(texture.getImageWidth(),0);
|
||||||
|
}
|
||||||
|
GL11.glEnd();
|
||||||
|
|
||||||
|
// restore the model view matrix to prevent contamination
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the bound of this class
|
||||||
|
*/
|
||||||
|
public Rectangle getBound() {
|
||||||
|
return new Rectangle(
|
||||||
|
(int)getLocation().getX(),
|
||||||
|
(int)getLocation().getY(),
|
||||||
|
texture.getImageWidth(),
|
||||||
|
texture.getImageHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -84,8 +84,14 @@ public class Texture {
|
||||||
* @param gl The GL context to bind to
|
* @param gl The GL context to bind to
|
||||||
*/
|
*/
|
||||||
public void bindGL() {
|
public void bindGL() {
|
||||||
GL11.glBindTexture(target, textureID);
|
if(target > 0){
|
||||||
GL11.glColor4f(color.getR(),color.getG(),color.getB(),color.getA());
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
|
GL11.glBindTexture(target, textureID);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
GL11.glColor4f(color.getR(),color.getG(),color.getB(),color.getA());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue