initial support to change BMF color

This commit is contained in:
sillysagiri 2024-10-16 13:43:47 +07:00
parent 8df646a59b
commit 9644fa9730
8 changed files with 118 additions and 77 deletions

View File

@ -3,7 +3,7 @@
set -e # Exit immediately if any command fails
MAIN_CLASS="dothack/DotHack.java"
PROJECT_NAME="dh_musicfix"
PROJECT_NAME="dh"
SOURCE_PATH="src"
PATH_LIBRARIES="lib"
PATH_PROGUARD="/home/sillysagiri/Documents/dothack/proguard.jar"
@ -28,4 +28,4 @@ jar cvfm "build/${PROJECT_NAME}_not_preverified.jar" "${SOURCE_PATH}/META-INF/MA
java -jar $PATH_PROGUARD -microedition -injars "build/${PROJECT_NAME}_not_preverified.jar" -outjars "build/${PROJECT_NAME}.jar" -libraryjars $CLASSPATH -dontshrink -dontoptimize -dontobfuscate -target $CLASS_VERSION
# release build
# java -jar $PATH_PROGUARD -microedition -injars "build/${PROJECT_NAME}_not_preverified.jar" -outjars "build/${PROJECT_NAME}_release.jar" -libraryjars $CLASSPATH -target $CLASS_VERSION -keep "class * extends javax.microedition.midlet.MIDlet" -optimizationpasses 4 -repackageclasses "" -allowaccessmodification
java -jar $PATH_PROGUARD -microedition -injars "build/${PROJECT_NAME}_not_preverified.jar" -outjars "build/${PROJECT_NAME}_release.jar" -libraryjars $CLASSPATH -target $CLASS_VERSION -keep "class * extends javax.microedition.midlet.MIDlet" -repackageclasses ""

View File

@ -1,10 +1,12 @@
Manifest-Version: 1.0
MicroEdition-Configuration: CLDC-1.0
MIDlet-Description: MeNet21
MIDlet-Version: 1.0.0
Created-By: 1.3.0_02(Sun Microsystems Inc.)
MIDlet-Vendor: MeNet21
MicroEdition-Profile: MIDP-1.0
MIDlet-1: 닷핵,/logo/menet.png,dothack.DotHack
MIDlet-Vendor: MeNet21
MIDlet-Info-URL: http://java.sun.com/j2me
MIDlet-Name: 닷핵
MIDlet-Info-URL: http://java.sun.com/j2me/
MIDlet-Description: MeNet21
MIDlet-Version: 1.2
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.0
Sagiri-Note: music converted to pcm and removed LG MMAPI dependency
Sagiri-URL: https://sillysagiri.moe

View File

@ -23,15 +23,10 @@ public class DotHack extends MIDlet implements Runnable {
_display.setCurrent(game);
thread = new Thread(this);
thread.setPriority(Thread.MAX_PRIORITY);
// thread.setPriority(Thread.MAX_PRIORITY);
thread.start();
try {
sagiri.Set_Scene(new Intro());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sagiri.Set_Scene(new Intro());
}
public void pauseApp() {}
@ -40,20 +35,17 @@ public class DotHack extends MIDlet implements Runnable {
public void run() {
while (true) {
try
{
sagiri.time_begin = System.currentTimeMillis();
sagiri.time_begin = System.currentTimeMillis();
try { Thread.sleep(1000/sagiri.fps); }
catch (Exception e) {}
game.repaint();
game.serviceRepaints();
game.repaint();
game.serviceRepaints();
Thread.sleep(1000/sagiri.fps);
sagiri.time_delta = System.currentTimeMillis() - sagiri.time_begin;
}
catch (Exception e)
{
// TODO: catch any unhandled exception here
}
sagiri.input.Update();
sagiri.time_delta = System.currentTimeMillis() - sagiri.time_begin;
}
}
}

View File

@ -133,7 +133,7 @@ public class DotHackC extends Canvas {
public DotHackC(DotHack app) {
setFullScreenMode(true);
midlet = app;
sagiri = app.sagiri;
sagiri = Sagiri._instance;
bG = Image.createImage(120, 133);
bgG = bG.getGraphics();
@ -151,27 +151,27 @@ public class DotHackC extends Canvas {
sagiri.Update(g);
}
protected void keyPressed(int keycode)
public final void keyPressed(int keyCode)
{
sagiri.input.HandleKeyDown(keycode);
sagiri.input.HandleKeyDown(keyCode);
}
protected void keyReleased(int keycode)
public final void keyReleased(int keyCode)
{
sagiri.input.HandleKeyUp(keycode);
sagiri.input.HandleKeyUp(keyCode);
}
protected void pointerPressed(int x, int y)
public final void pointerPressed(int x, int y)
{
sagiri.input.HandleTouch(Sagiri.TOUCH_BEGIN, x, y);
}
protected void pointerReleased(int x, int y)
public final void pointerReleased(int x, int y)
{
sagiri.input.HandleTouch(Sagiri.TOUCH_END, x, y);
}
protected void pointerDragged(int x, int y)
public final void pointerDragged(int x, int y)
{
sagiri.input.HandleTouch(Sagiri.TOUCH_DRAG, x, y);
}
@ -238,7 +238,7 @@ public class DotHackC extends Canvas {
this.useK = 0;
}
public void paint2(Graphics g) {
/* public void paint2(Graphics g) {
// probably to render bellow device built-in ui
// doesnt need this anymore since midp2.0 allow to do fullscreen
// if (getHeight() == 143)
@ -2474,7 +2474,7 @@ public class DotHackC extends Canvas {
}
} catch (Exception exception) {}
}
*/
public void infoWinPaint(int paramInt1, String paramString1, String paramString2, int paramInt2, int paramInt3, int paramInt4, int paramInt5, Image paramImage, Graphics paramGraphics) {
paramGraphics.drawImage(paramImage, paramInt2, paramInt3, 20);
paramGraphics.setColor(255, 0, 0);

View File

@ -22,10 +22,30 @@ public class BMF {
public short base;
public short[][] chars;
public BMF(String path_img, String path_fnt) throws Exception
public BMF()
{
img = Image.createImage(path_img);
}
public static final BMF Create(String path_img, String path_fnt) throws Exception
{
BMF bmf = new BMF();
bmf.img = Image.createImage(path_img);
bmf.Parse_fnt(path_fnt);
return bmf;
}
public static final BMF Create(Image img, String path_fnt) throws Exception
{
BMF bmf = new BMF();
bmf.img = img;
bmf.Parse_fnt(path_fnt);
return bmf;
}
protected void Parse_fnt(String path_fnt) throws Exception
{
InputStream in = this.getClass().getResourceAsStream(path_fnt);
byte[] header = new byte[4];
@ -126,6 +146,25 @@ public class BMF {
}
}
/*
* this is cpu intensive process
* consider creating new BMF for each color instead
*
* limitation:
* currently can only be used once
* since its replacing white pixel with tinted color
*/
public void SetColor(int rgb)
{
int[] buffer = new int[img.getWidth()*img.getHeight()];
img.getRGB(buffer, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
for (int i=0; i<buffer.length; i++)
if (buffer[i] == 0xFFFFFFFF) buffer[i] = rgb;
img = Image.createRGBImage(buffer, img.getWidth(), img.getHeight(), true);
}
// TODO: handle multiline
public short[] Measure(String str)
{

View File

@ -13,7 +13,7 @@ public class Sagiri
public Input input;
public int fps = 20;
public int fps = 10;
private Scene _scene_current = null;
public long time_begin = 0;
@ -38,8 +38,6 @@ public class Sagiri
_scene_current.Update(time_delta, g);
}
input.Update();
}
public Scene Get_Scene() { return _scene_current; }

View File

@ -1,11 +1,15 @@
package sillysagiri.scene;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import sillysagiri.BMF;
import sillysagiri.Easing;
import sillysagiri.Input;
import sillysagiri.KeyCode;
import sillysagiri.Scene;
import sillysagiri.Utils;
@ -13,30 +17,34 @@ public class Intro extends Scene {
private long counter = 0;
private int state = 0;
private BMF bmf_normal;
private BMF bmf_black;
private BMF bmf_outline;
private Image img_logo = null;
private Image img_ez = null;
private Image img_theworld = null;
private Image img_vol1 = null;
private Image img_project = null;
public Intro() throws IOException
{
super();
img_logo = Image.createImage("/t_1.png");
img_ez = Image.createImage("/pEZ.png");
}
public void Preload() {
try
{
bmf_normal = BMF.Create("/silly/bmf/nds12_0.png", "/silly/bmf/nds12.fnt");
bmf_outline = BMF.Create("/silly/bmf/onds12_0.png", "/silly/bmf/onds12.fnt");
bmf_black = BMF.Create("/silly/bmf/nds12_0.png", "/silly/bmf/nds12.fnt");
bmf_black.SetColor(0xFF000000);
img_logo = Image.createImage("/t_1.png");
}
catch(Exception e)
{
sagiri.Set_Scene(new DeathError(e));
}
}
public void Destroy()
{
img_logo = null;
img_ez = null;
img_theworld = null;
img_vol1 = null;
img_project = null;
bmf_normal = null;
bmf_black = null;
bmf_outline = null;
}
public void Update(long dt, Graphics g)
@ -84,10 +92,11 @@ public class Intro extends Scene {
try {
img_logo = Image.createImage("/t_0.png");
img_theworld = Image.createImage("/t_2.png");
img_project = Image.createImage("/t_3.png");
img_vol1 = Image.createImage("/t_4.png");
}
catch(IOException e) {}
catch(IOException e)
{
sagiri.Set_Scene(new DeathError(e));
}
}
}
break;
@ -105,20 +114,25 @@ public class Intro extends Scene {
Utils.GetScreenWidth()/2, Utils.GetScreenHeight()/2,
Graphics.HCENTER | Graphics.TOP);
g.drawImage(img_project, 5, Utils.GetScreenHeight()-5, Graphics.LEFT | Graphics.BOTTOM);
g.drawImage(img_vol1, 5, 5, Graphics.LEFT | Graphics.TOP);
// TODO: fix utf-16 symbol
bmf_black.DrawEx(g,
"c Project .hack",
5, Utils.GetScreenHeight()-5,
Graphics.LEFT | Graphics.BOTTOM);
bmf_normal.Draw(g,
"VOL 1 - v0.1-silly",
5, 5);
if (counter >= 600) counter = 0;
if (counter < 400)
g.drawImage(
img_ez,
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.75),
bmf_outline.DrawEx(g,
"PRESS ANY KEY",
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.7),
Graphics.VCENTER | Graphics.HCENTER);
if (sagiri.input.IsKeyDownAny())
{
sagiri.Set_Scene(new MainMenu());
}
}
break;

View File

@ -15,15 +15,13 @@ public class MainMenu extends Scene {
private Image img_bg;
private Image img_bandai;
private Image img_ez;
private BMF bmf;
public void Preload() {
try {
bmf = new BMF("/silly/bmf/nds12.png", "/silly/bmf/nds12.fnt");
bmf = BMF.Create("/silly/bmf/onds12_0.png", "/silly/bmf/onds12.fnt");
Image img_loop = Image.createImage("/m_2.png");
img_bandai = Image.createImage("/c_0.png");
img_ez = Image.createImage("/pEZ.png");
int loopCount = (int)Math.ceil((float)Utils.GetScreenHeight()/img_loop.getHeight());
@ -60,13 +58,11 @@ public class MainMenu extends Scene {
if (counter >= 600) counter = 0;
if (counter < 400)
g.drawImage(
img_ez,
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.75),
bmf.DrawEx(g,
"PRESS ANY KEY",
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.7),
Graphics.VCENTER | Graphics.HCENTER);
bmf.Draw(g, "hello world\nthis is test text!\nthe fox jumped over the lazy dog", 5, 10);
if (sagiri.input.IsKeyDownAny())
{
counter = 0;