initial silly image implementation

This commit is contained in:
sillysagiri 2024-10-16 22:27:53 +07:00
parent 7e1f91f8a8
commit fb1246e38e
7 changed files with 70 additions and 21 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Binary file not shown.

View File

@ -23,7 +23,7 @@ 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();
sagiri.Set_Scene(new Intro());
@ -37,13 +37,13 @@ public class DotHack extends MIDlet implements Runnable {
while (true) {
sagiri.time_begin = System.currentTimeMillis();
try { Thread.sleep(1000/sagiri.fps); }
catch (Exception e) {}
game.repaint();
game.serviceRepaints();
sagiri.input.Update();
try { Thread.sleep(1000/sagiri.fps); }
catch (Exception e) {}
sagiri.time_delta = System.currentTimeMillis() - sagiri.time_begin;
}

View File

@ -1,11 +1,14 @@
package sillysagiri;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import sillysagiri.scene.DeathError;
public class BMF {
public static final byte ID = 0;
public static final byte X = 1;
@ -156,13 +159,64 @@ public class BMF {
*/
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;
// int[] buffer = new int[img.getWidth()*img.getHeight()];
// img.getRGB(buffer, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
img = Image.createRGBImage(buffer, img.getWidth(), img.getHeight(), true);
// for (int i=0; i<buffer.length; i++)
// {
// if (buffer[i] == 0xFF000000) buffer[i] = rgb;
// else buffer[i] = 0x00000000;
// }
try
{
// ByteArrayOutputStream out = new ByteArrayOutputStream(128*64);
// Gzip.gunzip(this.getClass().getResourceAsStream("/silly/bmf/nds12_0.silly.gz"), out);
// GZIPInputStream in = new GZIPInputStream(this.getClass().getResourceAsStream("/silly/bmf/nds12_0.silly.gz"));
InputStream in = this.getClass().getResourceAsStream("/silly/bmf/nds12_0.silly");
int[] buffer = new int[128*64];
// read header
byte[] size = new byte[4];
in.read(size, 0, 4);
int pointer = 0;
while(true)
{
byte[] temp = new byte[2];
int res = in.read(temp, 0, 2);
if (res == -1) break;
char i = (char)((temp[1] << 8) | temp[0]);
// Extract 5-bit ABGR;
char alpha = (char)((i >> 15) & 0x01);
char blue = (char)((i >> 10) & 0x1F);
char green = (char)((i >> 5) & 0x1F);
char red = (char)(i & 0x1F);
// Scale the 5-bit values to 8-bit
if (alpha == 1) alpha = 255;
else alpha = 0;
red = (char)((red << 3) | 0x07);
blue = (char)((green << 3) | 0x07);
green = (char)((blue << 3) | 0x07);
// Combine into 24-bit value AARRGGBB
buffer[pointer] = (alpha << 24) | (red << 16) | (green << 8) | blue;
pointer++;
}
// img = Image.createRGBImage(buffer, img.getWidth(), img.getHeight(), true);
img = Image.createRGBImage(buffer, 128, 64, true);
}
catch(Exception e)
{
e.printStackTrace();
Sagiri._instance.Set_Scene(new DeathError(e));
}
}
// TODO: handle multiline

View File

@ -1,21 +1,17 @@
package sillysagiri;
public final class Input {
public int state_keycode = KeyCode.NONE;
public int state_keycode = Sagiri.KEY_NONE;
public int state_keyphase = 0;
public int state_touchState = Sagiri.TOUCH_NONE;
public int touchX = 0;
public int touchY = 0;
public Input()
{
}
public final void Update()
{
if (state_keyphase == 0) state_keyphase = KeyCode.NONE;
if (state_keyphase != 0 && state_keyphase != KeyCode.NONE) state_keyphase++;
if (state_keyphase == 0) state_keyphase = Sagiri.KEY_NONE;
if (state_keyphase != 0 && state_keyphase != Sagiri.KEY_NONE) state_keyphase++;
state_touchState = Sagiri.TOUCH_NONE;
}

View File

@ -1,6 +1,5 @@
package sillysagiri.scene;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
@ -8,8 +7,6 @@ import javax.microedition.lcdui.game.Sprite;
import sillysagiri.BMF;
import sillysagiri.Easing;
import sillysagiri.Input;
import sillysagiri.KeyCode;
import sillysagiri.Scene;
import sillysagiri.Utils;
@ -29,7 +26,7 @@ public class Intro extends Scene {
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);
bmf_black.SetColor(0xFFFF0000);
img_logo = Image.createImage("/t_1.png");
}
catch(Exception e)
@ -131,6 +128,8 @@ public class Intro extends Scene {
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.7),
Graphics.VCENTER | Graphics.HCENTER);
g.drawImage(bmf_black.img, 0, 0, 20);
if (sagiri.input.IsKeyDownAny())
sagiri.Set_Scene(new MainMenu());
}