|
28 | 28 | import javax.microedition.lcdui.Graphics;
|
29 | 29 | import javax.microedition.lcdui.Image;
|
30 | 30 |
|
31 |
| -public class Sprite extends Layer |
32 |
| -{ |
| 31 | +public class Sprite extends javax.microedition.lcdui.game.Sprite |
| 32 | +{ |
| 33 | + public Sprite(Image image) { super(image); } |
33 | 34 |
|
34 |
| - public static final int TRANS_MIRROR = 2; |
35 |
| - public static final int TRANS_MIRROR_ROT180 = 1; |
36 |
| - public static final int TRANS_MIRROR_ROT270 = 4; |
37 |
| - public static final int TRANS_MIRROR_ROT90 = 7; |
38 |
| - public static final int TRANS_NONE = 0; |
39 |
| - public static final int TRANS_ROT180 = 3; |
40 |
| - public static final int TRANS_ROT270 = 6; |
41 |
| - public static final int TRANS_ROT90 = 5; |
42 |
| - |
43 |
| - |
44 |
| - private int refX = 0; |
45 |
| - private int refY = 0; |
46 |
| - |
47 |
| - private int hitX; |
48 |
| - private int hitY; |
49 |
| - private int hitWidth; |
50 |
| - private int hitHeight; |
51 |
| - |
52 |
| - private int transform; |
53 |
| - |
54 |
| - private Vector<Integer> sequence = new Vector<Integer>(); |
55 |
| - |
56 |
| - private int frame=0; |
57 |
| - private int frameWidth; |
58 |
| - private int frameHeight; |
59 |
| - private int frameCount=1; |
60 |
| - private int imgWidth; |
61 |
| - private int imgHeight; |
62 |
| - |
63 |
| - public int rowCount=1; |
64 |
| - public int colCount=1; |
65 |
| - |
66 |
| - public Sprite() |
67 |
| - { |
68 |
| - System.out.println("Sprite A"); |
69 |
| - } |
70 |
| - |
71 |
| - public Sprite(Image img) |
72 |
| - { |
73 |
| - //System.out.println("Sprite B"); // used in wizardry.jar |
74 |
| - setImage(img, img.getWidth(), img.getHeight()); |
75 |
| - imgWidth = img.getWidth(); |
76 |
| - imgHeight = img.getHeight(); |
77 |
| - frameWidth = imgWidth; |
78 |
| - frameHeight = imgHeight; |
79 |
| - colCount = 1; |
80 |
| - rowCount = 1; |
81 |
| - frameCount = 1; |
82 |
| - } |
83 |
| - |
84 |
| - public Sprite(Image img, int frameW, int frameH) |
85 |
| - { |
86 |
| - //System.out.println("Sprite C"); // used in wizardry.jar |
87 |
| - //System.out.println("Sprite C: "+frameW+", "+frameH+" of "+img.getWidth()+", "+img.getHeight()); |
88 |
| - setImage(img, frameW, frameH); |
89 |
| - imgWidth = img.getWidth(); |
90 |
| - imgHeight = img.getHeight(); |
91 |
| - frameWidth = frameW; |
92 |
| - frameHeight = frameH; |
93 |
| - colCount = (int)(imgWidth/frameWidth); |
94 |
| - rowCount = (int)(imgHeight/frameHeight); |
95 |
| - frameCount = rowCount * colCount; |
96 |
| - } |
97 |
| - |
98 |
| - public Sprite(Sprite s) |
99 |
| - { |
100 |
| - System.out.println("Sprite D"); |
101 |
| - image = s.image; |
102 |
| - } |
103 |
| - |
104 |
| - public boolean collidesWith(Image img, int x, int y, boolean pixelLevel) |
105 |
| - { |
106 |
| - return false; |
107 |
| - } |
108 |
| - |
109 |
| - public boolean collidesWith(Sprite s, boolean pixelLevel) |
110 |
| - { |
111 |
| - int Ax = (x+refX) + hitX; |
112 |
| - int Ay = (y+refY) + hitY; |
113 |
| - int Aw = hitWidth; |
114 |
| - int Ah = hitHeight; |
115 |
| - |
116 |
| - int Bx = (s.getX()+s.getRefPixelX()) + s.getHitX(); |
117 |
| - int By = (s.getY()+s.getRefPixelY()) + s.getHitY(); |
118 |
| - int Bw = s.getHitWidth(); |
119 |
| - int Bh = s.getHitHeight(); |
120 |
| - |
121 |
| - if( (Ax+Aw)>Bx && Ax<(Bx+Bw) && (Ay+Ah)>By && Ay<(By+Bh) ) |
122 |
| - { |
123 |
| - return true; |
124 |
| - } |
125 |
| - |
126 |
| - return false; |
127 |
| - } |
128 |
| - |
129 |
| - public boolean collidesWith(TiledLayer t, boolean pixelLevel) |
130 |
| - { |
131 |
| - return false; |
132 |
| - } |
133 |
| - |
134 |
| - public void defineCollisionRectangle(int x, int y, int width, int height) |
135 |
| - { |
136 |
| - hitX = x; |
137 |
| - hitY = y; |
138 |
| - hitWidth = width; |
139 |
| - hitHeight = height; |
140 |
| - } |
141 |
| - |
142 |
| - public void defineReferencePixel(int x, int y) |
143 |
| - { |
144 |
| - refX = x; |
145 |
| - refY = y; |
146 |
| - } |
147 |
| - |
148 |
| - public int getFrame() { return frame; } |
149 |
| - |
150 |
| - public int getFrameSequenceLength() { return sequence.size(); } |
151 |
| - |
152 |
| - public int getRawFrameCount() { return frameCount; } |
153 |
| - |
154 |
| - public int getRefPixelX() { return refX; } |
155 |
| - |
156 |
| - public int getRefPixelY() { return refY; } |
157 |
| - |
158 |
| - public void nextFrame() |
159 |
| - { |
160 |
| - if(frame<sequence.size()-1) |
161 |
| - { |
162 |
| - frame++; |
163 |
| - } |
164 |
| - else |
165 |
| - { |
166 |
| - frame=0; |
167 |
| - } |
168 |
| - } |
169 |
| - |
170 |
| - public void paint(Graphics g) |
171 |
| - { |
172 |
| - try |
173 |
| - { |
174 |
| - int f = sequence.get(frame); |
175 |
| - int r = frameHeight * ((int)(f/colCount)); |
176 |
| - int c = frameWidth * ((int)(f % colCount)); |
177 |
| - g.drawRegion(image, c, r, frameWidth, frameHeight, transform, x, y, 0); |
178 |
| - } |
179 |
| - catch (Exception e) |
180 |
| - { |
181 |
| - System.out.println("Problem drawing sprite"); |
182 |
| - } |
183 |
| - } |
184 |
| - |
185 |
| - public void prevFrame() |
186 |
| - { |
187 |
| - if(frame>0) |
188 |
| - { |
189 |
| - frame--; |
190 |
| - } |
191 |
| - else |
192 |
| - { |
193 |
| - frame=sequence.size()-1; |
194 |
| - } |
195 |
| - } |
196 |
| - |
197 |
| - public void setFrame(int sequenceIndex) { frame = sequenceIndex; } |
198 |
| - |
199 |
| - public void setFrameSequence(int[] fsequence) |
200 |
| - { |
201 |
| - //System.out.println("Set Frame Sequence"); |
202 |
| - try |
203 |
| - { |
204 |
| - frame = 0; |
205 |
| - sequence.clear(); |
206 |
| - for(int i=0; i<fsequence.length; i++) |
207 |
| - { |
208 |
| - sequence.add(fsequence[i]); |
209 |
| - } |
210 |
| - } |
211 |
| - catch (Exception e) |
212 |
| - { |
213 |
| - System.out.println("Problem with Sequence"); |
214 |
| - } |
215 |
| - } |
216 |
| - |
217 |
| - public void setImage(Image img, int frameW, int frameH) |
218 |
| - { |
219 |
| - image = img; |
220 |
| - frameWidth = frameW; |
221 |
| - frameHeight = frameH; |
222 |
| - |
223 |
| - hitX = 0; |
224 |
| - hitY = 0; |
225 |
| - hitWidth = frameWidth; |
226 |
| - hitHeight = frameHeight; |
227 |
| - |
228 |
| - double spriteW = image.platformImage.width; |
229 |
| - double spriteH = image.platformImage.height; |
230 |
| - |
231 |
| - colCount = (int)Math.floor(spriteW/(double)frameW); |
232 |
| - rowCount = (int)Math.floor(spriteH/(double)frameH); |
233 |
| - |
234 |
| - frameCount = colCount * rowCount; |
235 |
| - |
236 |
| - sequence.clear(); |
237 |
| - |
238 |
| - for(int i=0; i<frameCount; i++) |
239 |
| - { |
240 |
| - sequence.add(i); |
241 |
| - } |
242 |
| - } |
243 |
| - |
244 |
| - public void setRefPixelPosition(int x, int y) |
245 |
| - { |
246 |
| - refX = x; |
247 |
| - refY = y; |
248 |
| - } |
249 |
| - |
250 |
| - public void setTransform(int value) { transform = value; } |
251 |
| - |
252 |
| - public int getHitX() { return hitX; } |
253 |
| - public int getHitY() { return hitY; } |
254 |
| - public int getHitWidth() { return hitWidth; } |
255 |
| - public int getHitHeight() { return hitHeight; } |
| 35 | + public Sprite(Image image, int frameWidth, int frameHeight) { super(image, frameWidth, frameHeight); } |
256 | 36 |
|
| 37 | + public Sprite(Sprite s) { super(s); } |
257 | 38 | }
|
0 commit comments