rainet.Piece.java Source code

Java tutorial

Introduction

Here is the source code for rainet.Piece.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rainet;

import java.io.IOException;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

/**
 *
 * @author Nial8r
 */
public class Piece {
    private Texture pTexF, pTexB;
    private int sID, pID;

    public int getpID() {
        return pID;
    }

    private boolean faceUp;

    public Piece(int s, int p, boolean f) throws IOException {
        this.sID = s;
        this.pID = p;
        this.faceUp = f;
    }

    public void draw(float x, float y, float width, float height) throws IOException {
        if (pTexF == null)
            this.pTexF = TextureLoader.getTexture("PNG",
                    ResourceLoader.getResourceAsStream("res/piece" + this.sID + this.pID + "_front.png"));
        if (pTexB == null)
            this.pTexB = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(
                    "res/piece" + this.sID + this.pID + (this.sID == Game.mySide ? "_fade.png" : "_back.png")));
        (faceUp ? pTexF : pTexB).bind();
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(x + width, y);
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(x + width, y + height);
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(x, y + height);
        GL11.glEnd();
    }

    public void drawSelect(float x, float y, float width, float height) throws IOException {
        Game.selectedT.bind();
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(x + width, y);
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(x + width, y + height);
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(x, y + height);
        GL11.glEnd();
    }

}