View Javadoc
1   package com.jed.state;
2   
3   import com.jed.actor.AbstractEntity;
4   import com.jed.util.Vector2f;
5   import org.lwjgl.opengl.GL11;
6   
7   import com.jed.actor.Boundary;
8   
9   import javax.annotation.Nonnull;
10  
11  /**
12   * 
13   * @author jlinde, Peter Colapietro
14   *
15   */
16  public class MapTile extends AbstractEntity {
17  
18      /**
19       * 
20       */
21      private float glTexX;
22  
23      /**
24       *
25       */
26      private float glTexY;
27  
28      /**
29       *
30       */
31      private final float glTexWidth;
32  
33      /**
34       *
35       */
36      private final float glTexHeight;
37      
38      /**
39       * 
40       */
41      private int tileId;
42  
43      /**
44       * 
45       */
46      private final GameMap map;
47  
48      /**
49       * 
50       */
51      //TODO: TEMPORARY!
52      private boolean colliding;
53      
54      /**
55       * 
56       */
57      private boolean evaluating;
58  
59      /**
60       * FIXME, the parameters is too damn high.
61       * @param position FIXME Javadoc
62       * @param bounds FIXME Javadoc
63       * @param glTexX FIXME Javadoc
64       * @param glTexY FIXME Javadoc
65       * @param glTexWidth FIXME Javadoc
66       * @param glTexHeight FIXME Javadoc
67       * @param tileId FIXME Javadoc
68       * @param map FIXME Javadoc
69       */
70      public MapTile( Vector2f position,
71                      @Nonnull Boundary bounds,
72                      float glTexX,float glTexY,
73                      float glTexWidth,
74                      float glTexHeight,
75                      int tileId,
76                      GameMap map) {
77          super(position, new Vector2f(0, 0), bounds);
78  
79          this.glTexX = glTexX;
80          this.glTexY = glTexY;
81          this.tileId = tileId;
82  
83          this.glTexWidth = glTexWidth;
84          this.glTexHeight = glTexHeight;
85  
86          this.map = map;
87      }
88  
89      /**
90       * 
91       * @return glTexX
92       */
93      public float getGlTexX() {
94          return glTexX;
95      }
96  
97      /**
98       * 
99       * @param glTexX glTexX
100      */
101     public void setGlTexX(float glTexX) {
102         this.glTexX = glTexX;
103     }
104 
105     /**
106      * 
107      * @return glTexY
108      */
109     public float getGlTexY() {
110         return glTexY;
111     }
112 
113     /**
114      * 
115      * @param glTexY glTexY
116      */
117     public void setGlTexY(float glTexY) {
118         this.glTexY = glTexY;
119     }
120 
121     /**
122      * 
123      * @return tileId
124      */
125     public int getTileId() {
126         return tileId;
127     }
128 
129     /**
130      * 
131      * @param tileId tileId
132      */
133     public void setTileId(int tileId) {
134         this.tileId = tileId;
135     }
136 
137     @Override
138     public void update() {
139     }
140 
141     @Override
142     public void render() {
143         //TODO: Tile collision coloring is temporary...
144         if (colliding) {
145             GL11.glColor3f(0, 0, 1f);
146         } else if (evaluating) {
147             GL11.glColor3f(1f, 0, 1f);
148         } else {
149             GL11.glColor3f(1, 1, 1);
150         }
151 
152 
153         GL11.glEnable(GL11.GL_TEXTURE_2D);
154         GL11.glBegin(GL11.GL_QUADS);
155         GL11.glTexCoord2f(glTexX, glTexY);
156         map.drawChildVertex2f(getPosition().x, getPosition().y);
157 
158         GL11.glTexCoord2f(glTexX + glTexWidth, glTexY);
159         map.drawChildVertex2f(getPosition().x + getBounds().getWidth(), getPosition().y);
160 
161         GL11.glTexCoord2f(glTexX + glTexWidth, glTexY + glTexHeight);
162         map.drawChildVertex2f(getPosition().x + getBounds().getWidth(), getPosition().y + getBounds().getHeight());
163 
164         GL11.glTexCoord2f(glTexX, glTexY + glTexHeight);
165         map.drawChildVertex2f(getPosition().x, getPosition().y + getBounds().getHeight());
166 
167         GL11.glEnd();
168     }
169 
170     /**
171      *
172      * @param colliding colliding
173      */
174     public void setColliding(boolean colliding) {
175         this.colliding = colliding;
176     }
177 
178     /**
179      *
180      * @param evaluating evaluating
181      */
182     public void setEvaluating(boolean evaluating) {
183         this.evaluating = evaluating;
184     }
185 }