Compare commits

..

No commits in common. "48cfca9f634229d4b2965f8db8f2d08ba0181029" and "fb8d6515c4cbb3b74a6060bb4013060d377683e5" have entirely different histories.

8 changed files with 1117 additions and 1209 deletions

View File

@ -1,8 +1,5 @@
{ {
"java.project.referencedLibraries": [ "java.project.referencedLibraries": [
"lib/**/*.jar", "lib/**/*.jar",
],
"java.project.sourcePaths": [
"src"
] ]
} }

View File

@ -2,25 +2,16 @@ package dothack;
import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDlet;
import sillysagiri.Sagiri;
public class DotHack extends MIDlet implements Runnable { public class DotHack extends MIDlet implements Runnable {
public DotHackC game; public DotHackC game;
public Sagiri sagiri;
private Display _display; private Display _display;
public Thread thread;
public void startApp() { public void startApp() {
Global.app = this; Global.app = this;
sagiri = new Sagiri();
game = new DotHackC(this); game = new DotHackC(this);
_display = Display.getDisplay(this); _display = Display.getDisplay(this);
_display.setCurrent(game); _display.setCurrent(game);
thread = new Thread(this);
thread.setPriority(Thread.MAX_PRIORITY);
thread.start();
} }
public void pauseApp() {} public void pauseApp() {}
@ -28,21 +19,6 @@ public class DotHack extends MIDlet implements Runnable {
public void destroyApp(boolean paramBoolean) {} public void destroyApp(boolean paramBoolean) {}
public void run() { public void run() {
while (true) {
try
{
sagiri.time_begin = System.currentTimeMillis();
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
}
}
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,9 @@
package sillysagiri; package sillysagiri;
import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
public final class Input { public final class Input {
public Hashtable hash_keyState = new Hashtable(20); public Hashtable<Integer, Integer> hash_keyState = new Hashtable<>();
public int state_anyKey = 0; public int state_anyKey = 0;
public int state_touchState = Sagiri.TOUCH_NONE; public int state_touchState = Sagiri.TOUCH_NONE;
@ -19,15 +18,11 @@ public final class Input {
public final void Update() public final void Update()
{ {
Enumeration i = hash_keyState.keys(); for (Integer key : hash_keyState.keySet())
while(i.hasMoreElements())
{ {
Integer key = (Integer)i.nextElement(); int value = hash_keyState.get(key);
Integer value = (Integer)hash_keyState.get(key); if (value == -1) hash_keyState.remove(key);
else hash_keyState.put(key, value+1);
if (value.intValue() == -1) hash_keyState.remove(key);
else hash_keyState.put(key, new Integer(value.intValue()+1));
} }
if (state_anyKey != 0) state_anyKey++; if (state_anyKey != 0) state_anyKey++;
@ -36,13 +31,12 @@ public final class Input {
public final void HandleKeyDown(int keycode) public final void HandleKeyDown(int keycode)
{ {
Integer key = new Integer(keycode); Integer value = hash_keyState.get(keycode);
Integer value = (Integer)hash_keyState.get(key);
if (value != null) if (value != null)
hash_keyState.put(key, new Integer(Math.max(value.intValue(), 1))); hash_keyState.put(keycode, new Integer(Math.max(value, 1)));
else else
hash_keyState.put(key, new Integer(1)); hash_keyState.put(keycode, 1);
state_anyKey = Math.max(state_anyKey, 1); state_anyKey = Math.max(state_anyKey, 1);
state_lastKey = keycode; state_lastKey = keycode;
@ -50,9 +44,7 @@ public final class Input {
public final void HandleKeyUp(int keycode) public final void HandleKeyUp(int keycode)
{ {
Integer key = new Integer(keycode); hash_keyState.put(keycode, -1);
hash_keyState.put(key, new Integer(-1));
state_anyKey = -1; state_anyKey = -1;
state_lastKey = keycode; state_lastKey = keycode;
} }
@ -66,8 +58,7 @@ public final class Input {
public final boolean IsKeyHeld(int keycode) public final boolean IsKeyHeld(int keycode)
{ {
Integer key = new Integer(keycode); Integer value = hash_keyState.get(keycode);
Integer value = (Integer)hash_keyState.get(key);
if (value != null) if (value != null)
return value.intValue() > 0; return value.intValue() > 0;
@ -77,15 +68,14 @@ public final class Input {
public final boolean IsKeyHeld(int[] keycode) public final boolean IsKeyHeld(int[] keycode)
{ {
for (int i=0; i<keycode.length; i++) for (int i : keycode)
if (IsKeyHeld(keycode[i])) return true; if (IsKeyHeld(keycode[i])) return true;
return false; return false;
} }
public final boolean IsKeyDown(int keycode) public final boolean IsKeyDown(int keycode)
{ {
Integer key = new Integer(keycode); Integer value = hash_keyState.get(keycode);
Integer value = (Integer)hash_keyState.get(key);
if (value != null) if (value != null)
return value.intValue() == 0; return value.intValue() == 0;
@ -95,15 +85,14 @@ public final class Input {
public final boolean IsKeyDown(int[] keycode) public final boolean IsKeyDown(int[] keycode)
{ {
for (int i=0; i<keycode.length; i++) for (int i : keycode)
if (IsKeyDown(keycode[i])) return true; if (IsKeyDown(keycode[i])) return true;
return false; return false;
} }
public final boolean IsKeyReleased(int keycode) public final boolean IsKeyReleased(int keycode)
{ {
Integer key = new Integer(keycode); Integer value = hash_keyState.get(keycode);
Integer value = (Integer)hash_keyState.get(key);
if (value != null) if (value != null)
return value.intValue() == -1; return value.intValue() == -1;
@ -113,7 +102,7 @@ public final class Input {
public final boolean IsKeyReleased(int[] keycode) public final boolean IsKeyReleased(int[] keycode)
{ {
for (int i=0; i<keycode.length; i++) for (int i : keycode)
if (IsKeyReleased(keycode[i])) return true; if (IsKeyReleased(keycode[i])) return true;
return false; return false;
} }
@ -122,5 +111,5 @@ public final class Input {
public final boolean IsKeyDownAny() { return state_anyKey == 1; } public final boolean IsKeyDownAny() { return state_anyKey == 1; }
public final boolean IsKeyReleasedAny() { return state_anyKey == -1; } public final boolean IsKeyReleasedAny() { return state_anyKey == -1; }
public final Integer getKeyStatus(int keycode) { return (Integer)hash_keyState.get(new Integer(keycode)); } public final int getKeyStatus(int keycode) { return hash_keyState.get(keycode); }
} }

View File

@ -1,7 +1,5 @@
package sillysagiri; package sillysagiri;
import javax.microedition.lcdui.Graphics;
public class Sagiri public class Sagiri
{ {
public final static int TOUCH_NONE = 0; public final static int TOUCH_NONE = 0;
@ -15,34 +13,24 @@ public class Sagiri
public int fps = 20; public int fps = 20;
private Scene _scene_current = null; private Scene _scene_current;
public long time_begin = 0; private long _time_begin;
public long time_delta = 0; private long _time_delta;
public Sagiri() public Sagiri()
{ {
_instance = this; _instance = this;
input = new Input(); input = new Input();
}
public void Update(Graphics g)
{
input.Update();
if (_scene_current != null)
_scene_current.Update(time_delta, g);
}
public Scene Get_Scene() { return _scene_current; }
public void Set_Scene(Scene scene)
{
if (_scene_current != null)
{
_scene_current.Destroy();
_scene_current = null; _scene_current = null;
System.gc();
}
_scene_current = scene;
} }
public final long GetFrameTime() { return time_delta; } public void Update()
{
_time_begin = System.currentTimeMillis();
input.Update();
if (_scene_current != null) _scene_current.Update();
}
public final long GetFrameTime() { return _time_delta; }
} }

View File

@ -8,7 +8,8 @@ public abstract class Scene {
} }
// override this // override this
public abstract void Draw(Graphics g);
public abstract void Destroy(); public abstract void Destroy();
public abstract void Update(long dt, Graphics g); public abstract void Update();
} }

View File

@ -26,16 +26,4 @@ public final class Utils {
{ {
return Global.app.game.getHeight(); return Global.app.game.getHeight();
} }
public static int clamp(int value, int min, int max) {
return Math.max(min, Math.min(value, max));
}
public static float clamp(float value, float min, float max) {
return Math.max(min, Math.min(value, max));
}
public static double clamp(double value, double min, double max) {
return Math.max(min, Math.min(value, max));
}
} }

View File

@ -10,50 +10,53 @@ import sillysagiri.Scene;
import sillysagiri.Utils; import sillysagiri.Utils;
public class Intro extends Scene { public class Intro extends Scene {
private long counter = 0; private int counter = 0;
private int state = 0; private int state = 0;
private Image img_logo = null; private Image img_logo;
private Image img_ez = null;
private Image img_theworld = null;
private Image img_vol1 = null;
private Image img_project = null;
public Intro() throws IOException public Intro() throws IOException
{ {
img_logo = Image.createImage("/t_1.png"); img_logo = Image.createImage("/t_1.png");
img_ez = Image.createImage("/pEZ.png");
} }
public void Destroy() public void Destroy()
{ {
img_logo = null; img_logo = null;
img_ez = null;
img_theworld = null;
img_vol1 = null;
img_project = null;
} }
public void Update(long dt, Graphics g) public void Update()
{ {
counter += dt; // TODO: use time based counter instead
counter++;
if (counter > 100) counter = 0;
switch (state) { switch (state) {
case 0: case 0:
{ {
if (counter > 1800) if (counter > 25)
{ {
// img_logo = Image.createImage("/pEZ.png");
counter = 0; counter = 0;
state = 1; state = 1;
}
}
break; break;
default: break;
}
} }
public void Draw(Graphics g)
{
Utils.Clear_Screen(g, 73, 0, 0); Utils.Clear_Screen(g, 73, 0, 0);
switch (state) {
case 0:
{
int halfW = img_logo.getWidth()/2; int halfW = img_logo.getWidth()/2;
int halfH = img_logo.getHeight()/2; int halfH = img_logo.getHeight()/2;
float r = Easing.CubicEaseInOut((float)counter/1800); float r = Easing.CubicEaseOut((float)counter/25);
int pos = (int)Math.ceil(((Utils.GetScreenWidth()/2)+halfW) * r) - halfW; int pos = (int)(((Utils.GetScreenWidth()/2)+halfW) * r) - halfW;
g.drawRegion( g.drawRegion(
img_logo, img_logo,
@ -66,53 +69,24 @@ public class Intro extends Scene {
0, halfH, img_logo.getWidth(), img_logo.getHeight()-halfH, Sprite.TRANS_NONE, 0, halfH, img_logo.getWidth(), img_logo.getHeight()-halfH, Sprite.TRANS_NONE,
Utils.GetScreenWidth() - pos, Utils.GetScreenHeight()/2, Utils.GetScreenWidth() - pos, Utils.GetScreenHeight()/2,
Graphics.TOP | Graphics.HCENTER); Graphics.TOP | Graphics.HCENTER);
}
break; break;
}
case 1: case 1:
{ {
if (counter > 500)
{
counter = 0;
state = 2;
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) {}
}
}
break;
case 2:
{
Utils.Clear_Screen(g, 146, 36, 0);
g.drawImage( g.drawImage(
img_logo, img_logo,
Utils.GetScreenWidth()/2, Utils.GetScreenHeight()/2-35, Utils.GetScreenWidth()/2,
Graphics.HCENTER | Graphics.VCENTER); Utils.GetScreenHeight()/2,
Graphics.VCENTER | Graphics.HCENTER
);
g.drawImage(
img_theworld,
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);
if (counter >= 1000) counter = 0;
if (counter < 600)
g.drawImage(
img_ez,
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.75),
Graphics.VCENTER | Graphics.HCENTER);
}
break; break;
}
default: break; default: return;
} }
} }
} }