Skip to content

Commit ba95e3e

Browse files
AShiningRayzb3
andcommitted
lcdui: color_game: Implement Tiled Layer and Sprite based on J2ME-Loader
Implementation is heavily based on J2ME-Loader, just with some changes here and there to better fit FreeJ2ME's structure along with some patches by @zb3. Also, make those siemens color_game's classes simply mirror the current lcdui ones. If siemens requires any changes, we should add them, and only them, there. With this Jbenchmark 2's Tiled Layer test now works as intended, probably fixes games such as Arcadius as well. Co-authored-by: zb3 <[email protected]>
1 parent 61f6e1c commit ba95e3e

File tree

8 files changed

+1190
-562
lines changed

8 files changed

+1190
-562
lines changed

Diff for: src/com/siemens/mp/color_game/Layer.java

+5-28
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,11 @@
1919

2020
import javax.microedition.lcdui.Image;
2121

22-
public abstract class Layer extends javax.microedition.lcdui.game.Layer
23-
{
22+
public abstract class Layer extends javax.microedition.lcdui.game.Layer
23+
{
24+
public Layer() { super(); }
2425

25-
public Layer() { x = 0; y = 0; }
26+
public Layer(int width, int height) { super(width, height); }
2627

27-
public Layer(int w, int h) { x = 0; y = 0; width = w; height = h; }
28-
29-
public Layer(Image i) { setLayerImage(i); }
30-
31-
protected void setWidth(int w) { width = w; }
32-
33-
protected void setHeight(int h) { height = h; }
34-
35-
protected void setLayerImage(Image i)
36-
{
37-
image = i;
38-
x = 0;
39-
y = 0;
40-
width = i.getWidth();
41-
height = i.getHeight();
42-
}
43-
44-
protected void copyAllLayerVariables(Layer target)
45-
{
46-
target.setPosition(x, y);
47-
target.setWidth(width);
48-
target.setHeight(height);
49-
target.setLayerImage(image);
50-
target.setVisible(visible);
51-
}
28+
public Layer(Image i) { super(i); }
5229
}

Diff for: src/com/siemens/mp/color_game/LayerManager.java

+3-47
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,7 @@
2626
import org.recompile.mobile.Mobile;
2727
import org.recompile.mobile.PlatformGraphics;
2828

29-
public class LayerManager extends javax.microedition.lcdui.game.LayerManager
30-
{
31-
private Vector<Layer> layers;
32-
33-
public LayerManager()
34-
{
35-
layers = new Vector<Layer>();
36-
37-
width = Mobile.getPlatform().lcdWidth;
38-
height = Mobile.getPlatform().lcdHeight;
39-
40-
canvas = Image.createImage(width, height);
41-
gc = canvas.platformImage.getGraphics();
42-
}
43-
44-
public void paint(Graphics g, int xdest, int ydest)
45-
{
46-
for(int i=0; i<layers.size(); i++)
47-
{
48-
drawLayer(g, xdest, ydest, layers.get(i));
49-
}
50-
}
51-
52-
private void drawLayer(Graphics g, int dx, int dy, Layer l)
53-
{
54-
if(l.isVisible())
55-
{
56-
g.drawRegion(l.getLayerImage(), 0, 0, l.getLayerImage().getWidth(), l.getLayerImage().getHeight(), 0, dx+x+l.getX(), dy+y+l.getY(), Graphics.TOP|Graphics.LEFT);
57-
}
58-
}
59-
60-
public void append(Layer l)
61-
{
62-
try
63-
{
64-
layers.add(l);
65-
}
66-
catch(Exception e)
67-
{
68-
System.out.println("Can't Append Layer " + e.getMessage());
69-
}
70-
}
71-
72-
public void remove(Layer l)
73-
{
74-
layers.remove(l);
75-
}
29+
public class LayerManager extends javax.microedition.lcdui.game.LayerManager
30+
{
31+
public LayerManager() { super(); }
7632
}

Diff for: src/com/siemens/mp/color_game/Sprite.java

+5-224
Original file line numberDiff line numberDiff line change
@@ -28,230 +28,11 @@
2828
import javax.microedition.lcdui.Graphics;
2929
import javax.microedition.lcdui.Image;
3030

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); }
3334

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); }
25636

37+
public Sprite(Sprite s) { super(s); }
25738
}

Diff for: src/com/siemens/mp/color_game/TiledLayer.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919

2020
import javax.microedition.lcdui.Image;
2121

22-
public class TiledLayer extends javax.microedition.lcdui.game.TiledLayer
23-
{
24-
25-
public TiledLayer(int colsw, int rowsh, Image baseimage, int tilewidth, int tileheight)
26-
{
27-
super(colsw, rowsh, baseimage, tilewidth, tileheight);
28-
}
22+
public class TiledLayer extends javax.microedition.lcdui.game.TiledLayer
23+
{
24+
public TiledLayer(int colsw, int rowsh, Image baseimage, int tileWidth, int tileHeight) { super(colsw, rowsh, baseimage, tileWidth, tileHeight); }
2925
}

0 commit comments

Comments
 (0)