Skip to content

Commit

Permalink
lcdui: color_game: Implement Tiled Layer and Sprite based on J2ME-Loader
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
AShiningRay and zb3 committed Sep 19, 2024
1 parent 61f6e1c commit ba95e3e
Show file tree
Hide file tree
Showing 8 changed files with 1,190 additions and 562 deletions.
33 changes: 5 additions & 28 deletions src/com/siemens/mp/color_game/Layer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,11 @@

import javax.microedition.lcdui.Image;

public abstract class Layer extends javax.microedition.lcdui.game.Layer
{
public abstract class Layer extends javax.microedition.lcdui.game.Layer
{
public Layer() { super(); }

public Layer() { x = 0; y = 0; }
public Layer(int width, int height) { super(width, height); }

public Layer(int w, int h) { x = 0; y = 0; width = w; height = h; }

public Layer(Image i) { setLayerImage(i); }

protected void setWidth(int w) { width = w; }

protected void setHeight(int h) { height = h; }

protected void setLayerImage(Image i)
{
image = i;
x = 0;
y = 0;
width = i.getWidth();
height = i.getHeight();
}

protected void copyAllLayerVariables(Layer target)
{
target.setPosition(x, y);
target.setWidth(width);
target.setHeight(height);
target.setLayerImage(image);
target.setVisible(visible);
}
public Layer(Image i) { super(i); }
}
50 changes: 3 additions & 47 deletions src/com/siemens/mp/color_game/LayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,7 @@
import org.recompile.mobile.Mobile;
import org.recompile.mobile.PlatformGraphics;

public class LayerManager extends javax.microedition.lcdui.game.LayerManager
{
private Vector<Layer> layers;

public LayerManager()
{
layers = new Vector<Layer>();

width = Mobile.getPlatform().lcdWidth;
height = Mobile.getPlatform().lcdHeight;

canvas = Image.createImage(width, height);
gc = canvas.platformImage.getGraphics();
}

public void paint(Graphics g, int xdest, int ydest)
{
for(int i=0; i<layers.size(); i++)
{
drawLayer(g, xdest, ydest, layers.get(i));
}
}

private void drawLayer(Graphics g, int dx, int dy, Layer l)
{
if(l.isVisible())
{
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);
}
}

public void append(Layer l)
{
try
{
layers.add(l);
}
catch(Exception e)
{
System.out.println("Can't Append Layer " + e.getMessage());
}
}

public void remove(Layer l)
{
layers.remove(l);
}
public class LayerManager extends javax.microedition.lcdui.game.LayerManager
{
public LayerManager() { super(); }
}
229 changes: 5 additions & 224 deletions src/com/siemens/mp/color_game/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,230 +28,11 @@
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Sprite extends Layer
{
public class Sprite extends javax.microedition.lcdui.game.Sprite
{
public Sprite(Image image) { super(image); }

public static final int TRANS_MIRROR = 2;
public static final int TRANS_MIRROR_ROT180 = 1;
public static final int TRANS_MIRROR_ROT270 = 4;
public static final int TRANS_MIRROR_ROT90 = 7;
public static final int TRANS_NONE = 0;
public static final int TRANS_ROT180 = 3;
public static final int TRANS_ROT270 = 6;
public static final int TRANS_ROT90 = 5;


private int refX = 0;
private int refY = 0;

private int hitX;
private int hitY;
private int hitWidth;
private int hitHeight;

private int transform;

private Vector<Integer> sequence = new Vector<Integer>();

private int frame=0;
private int frameWidth;
private int frameHeight;
private int frameCount=1;
private int imgWidth;
private int imgHeight;

public int rowCount=1;
public int colCount=1;

public Sprite()
{
System.out.println("Sprite A");
}

public Sprite(Image img)
{
//System.out.println("Sprite B"); // used in wizardry.jar
setImage(img, img.getWidth(), img.getHeight());
imgWidth = img.getWidth();
imgHeight = img.getHeight();
frameWidth = imgWidth;
frameHeight = imgHeight;
colCount = 1;
rowCount = 1;
frameCount = 1;
}

public Sprite(Image img, int frameW, int frameH)
{
//System.out.println("Sprite C"); // used in wizardry.jar
//System.out.println("Sprite C: "+frameW+", "+frameH+" of "+img.getWidth()+", "+img.getHeight());
setImage(img, frameW, frameH);
imgWidth = img.getWidth();
imgHeight = img.getHeight();
frameWidth = frameW;
frameHeight = frameH;
colCount = (int)(imgWidth/frameWidth);
rowCount = (int)(imgHeight/frameHeight);
frameCount = rowCount * colCount;
}

public Sprite(Sprite s)
{
System.out.println("Sprite D");
image = s.image;
}

public boolean collidesWith(Image img, int x, int y, boolean pixelLevel)
{
return false;
}

public boolean collidesWith(Sprite s, boolean pixelLevel)
{
int Ax = (x+refX) + hitX;
int Ay = (y+refY) + hitY;
int Aw = hitWidth;
int Ah = hitHeight;

int Bx = (s.getX()+s.getRefPixelX()) + s.getHitX();
int By = (s.getY()+s.getRefPixelY()) + s.getHitY();
int Bw = s.getHitWidth();
int Bh = s.getHitHeight();

if( (Ax+Aw)>Bx && Ax<(Bx+Bw) && (Ay+Ah)>By && Ay<(By+Bh) )
{
return true;
}

return false;
}

public boolean collidesWith(TiledLayer t, boolean pixelLevel)
{
return false;
}

public void defineCollisionRectangle(int x, int y, int width, int height)
{
hitX = x;
hitY = y;
hitWidth = width;
hitHeight = height;
}

public void defineReferencePixel(int x, int y)
{
refX = x;
refY = y;
}

public int getFrame() { return frame; }

public int getFrameSequenceLength() { return sequence.size(); }

public int getRawFrameCount() { return frameCount; }

public int getRefPixelX() { return refX; }

public int getRefPixelY() { return refY; }

public void nextFrame()
{
if(frame<sequence.size()-1)
{
frame++;
}
else
{
frame=0;
}
}

public void paint(Graphics g)
{
try
{
int f = sequence.get(frame);
int r = frameHeight * ((int)(f/colCount));
int c = frameWidth * ((int)(f % colCount));
g.drawRegion(image, c, r, frameWidth, frameHeight, transform, x, y, 0);
}
catch (Exception e)
{
System.out.println("Problem drawing sprite");
}
}

public void prevFrame()
{
if(frame>0)
{
frame--;
}
else
{
frame=sequence.size()-1;
}
}

public void setFrame(int sequenceIndex) { frame = sequenceIndex; }

public void setFrameSequence(int[] fsequence)
{
//System.out.println("Set Frame Sequence");
try
{
frame = 0;
sequence.clear();
for(int i=0; i<fsequence.length; i++)
{
sequence.add(fsequence[i]);
}
}
catch (Exception e)
{
System.out.println("Problem with Sequence");
}
}

public void setImage(Image img, int frameW, int frameH)
{
image = img;
frameWidth = frameW;
frameHeight = frameH;

hitX = 0;
hitY = 0;
hitWidth = frameWidth;
hitHeight = frameHeight;

double spriteW = image.platformImage.width;
double spriteH = image.platformImage.height;

colCount = (int)Math.floor(spriteW/(double)frameW);
rowCount = (int)Math.floor(spriteH/(double)frameH);

frameCount = colCount * rowCount;

sequence.clear();

for(int i=0; i<frameCount; i++)
{
sequence.add(i);
}
}

public void setRefPixelPosition(int x, int y)
{
refX = x;
refY = y;
}

public void setTransform(int value) { transform = value; }

public int getHitX() { return hitX; }
public int getHitY() { return hitY; }
public int getHitWidth() { return hitWidth; }
public int getHitHeight() { return hitHeight; }
public Sprite(Image image, int frameWidth, int frameHeight) { super(image, frameWidth, frameHeight); }

public Sprite(Sprite s) { super(s); }
}
10 changes: 3 additions & 7 deletions src/com/siemens/mp/color_game/TiledLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

import javax.microedition.lcdui.Image;

public class TiledLayer extends javax.microedition.lcdui.game.TiledLayer
{

public TiledLayer(int colsw, int rowsh, Image baseimage, int tilewidth, int tileheight)
{
super(colsw, rowsh, baseimage, tilewidth, tileheight);
}
public class TiledLayer extends javax.microedition.lcdui.game.TiledLayer
{
public TiledLayer(int colsw, int rowsh, Image baseimage, int tileWidth, int tileHeight) { super(colsw, rowsh, baseimage, tileWidth, tileHeight); }
}
Loading

0 comments on commit ba95e3e

Please sign in to comment.