Compare commits
6 Commits
fb8d6515c4
...
48cfca9f63
Author | SHA1 | Date | |
---|---|---|---|
48cfca9f63 | |||
df0183d2f5 | |||
f9f1a85eff | |||
4d3863ac70 | |||
3a7c10a53c | |||
59c57aec1a |
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"lib/**/*.jar",
|
"lib/**/*.jar",
|
||||||
|
],
|
||||||
|
"java.project.sourcePaths": [
|
||||||
|
"src"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -2,16 +2,25 @@ 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() {}
|
||||||
@ -19,6 +28,21 @@ 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
@ -1,9 +1,10 @@
|
|||||||
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<Integer, Integer> hash_keyState = new Hashtable<>();
|
public Hashtable hash_keyState = new Hashtable(20);
|
||||||
|
|
||||||
public int state_anyKey = 0;
|
public int state_anyKey = 0;
|
||||||
public int state_touchState = Sagiri.TOUCH_NONE;
|
public int state_touchState = Sagiri.TOUCH_NONE;
|
||||||
@ -18,11 +19,15 @@ public final class Input {
|
|||||||
|
|
||||||
public final void Update()
|
public final void Update()
|
||||||
{
|
{
|
||||||
for (Integer key : hash_keyState.keySet())
|
Enumeration i = hash_keyState.keys();
|
||||||
|
while(i.hasMoreElements())
|
||||||
{
|
{
|
||||||
int value = hash_keyState.get(key);
|
Integer key = (Integer)i.nextElement();
|
||||||
if (value == -1) hash_keyState.remove(key);
|
Integer value = (Integer)hash_keyState.get(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++;
|
||||||
@ -31,12 +36,13 @@ public final class Input {
|
|||||||
|
|
||||||
public final void HandleKeyDown(int keycode)
|
public final void HandleKeyDown(int keycode)
|
||||||
{
|
{
|
||||||
Integer value = hash_keyState.get(keycode);
|
Integer key = new Integer(keycode);
|
||||||
|
Integer value = (Integer)hash_keyState.get(key);
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
hash_keyState.put(keycode, new Integer(Math.max(value, 1)));
|
hash_keyState.put(key, new Integer(Math.max(value.intValue(), 1)));
|
||||||
else
|
else
|
||||||
hash_keyState.put(keycode, 1);
|
hash_keyState.put(key, new Integer(1));
|
||||||
|
|
||||||
state_anyKey = Math.max(state_anyKey, 1);
|
state_anyKey = Math.max(state_anyKey, 1);
|
||||||
state_lastKey = keycode;
|
state_lastKey = keycode;
|
||||||
@ -44,7 +50,9 @@ public final class Input {
|
|||||||
|
|
||||||
public final void HandleKeyUp(int keycode)
|
public final void HandleKeyUp(int keycode)
|
||||||
{
|
{
|
||||||
hash_keyState.put(keycode, -1);
|
Integer key = new Integer(keycode);
|
||||||
|
|
||||||
|
hash_keyState.put(key, new Integer(-1));
|
||||||
state_anyKey = -1;
|
state_anyKey = -1;
|
||||||
state_lastKey = keycode;
|
state_lastKey = keycode;
|
||||||
}
|
}
|
||||||
@ -58,7 +66,8 @@ public final class Input {
|
|||||||
|
|
||||||
public final boolean IsKeyHeld(int keycode)
|
public final boolean IsKeyHeld(int keycode)
|
||||||
{
|
{
|
||||||
Integer value = hash_keyState.get(keycode);
|
Integer key = new Integer(keycode);
|
||||||
|
Integer value = (Integer)hash_keyState.get(key);
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
return value.intValue() > 0;
|
return value.intValue() > 0;
|
||||||
@ -68,14 +77,15 @@ public final class Input {
|
|||||||
|
|
||||||
public final boolean IsKeyHeld(int[] keycode)
|
public final boolean IsKeyHeld(int[] keycode)
|
||||||
{
|
{
|
||||||
for (int i : keycode)
|
for (int i=0; i<keycode.length; i++)
|
||||||
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 value = hash_keyState.get(keycode);
|
Integer key = new Integer(keycode);
|
||||||
|
Integer value = (Integer)hash_keyState.get(key);
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
return value.intValue() == 0;
|
return value.intValue() == 0;
|
||||||
@ -85,14 +95,15 @@ public final class Input {
|
|||||||
|
|
||||||
public final boolean IsKeyDown(int[] keycode)
|
public final boolean IsKeyDown(int[] keycode)
|
||||||
{
|
{
|
||||||
for (int i : keycode)
|
for (int i=0; i<keycode.length; i++)
|
||||||
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 value = hash_keyState.get(keycode);
|
Integer key = new Integer(keycode);
|
||||||
|
Integer value = (Integer)hash_keyState.get(key);
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
return value.intValue() == -1;
|
return value.intValue() == -1;
|
||||||
@ -102,7 +113,7 @@ public final class Input {
|
|||||||
|
|
||||||
public final boolean IsKeyReleased(int[] keycode)
|
public final boolean IsKeyReleased(int[] keycode)
|
||||||
{
|
{
|
||||||
for (int i : keycode)
|
for (int i=0; i<keycode.length; i++)
|
||||||
if (IsKeyReleased(keycode[i])) return true;
|
if (IsKeyReleased(keycode[i])) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -111,5 +122,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 int getKeyStatus(int keycode) { return hash_keyState.get(keycode); }
|
public final Integer getKeyStatus(int keycode) { return (Integer)hash_keyState.get(new Integer(keycode)); }
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
@ -13,24 +15,34 @@ public class Sagiri
|
|||||||
|
|
||||||
public int fps = 20;
|
public int fps = 20;
|
||||||
|
|
||||||
private Scene _scene_current;
|
private Scene _scene_current = null;
|
||||||
private long _time_begin;
|
public long time_begin = 0;
|
||||||
private long _time_delta;
|
public long time_delta = 0;
|
||||||
|
|
||||||
public Sagiri()
|
public Sagiri()
|
||||||
{
|
{
|
||||||
_instance = this;
|
_instance = this;
|
||||||
input = new Input();
|
input = new Input();
|
||||||
_scene_current = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update(Graphics g)
|
||||||
{
|
{
|
||||||
_time_begin = System.currentTimeMillis();
|
|
||||||
|
|
||||||
input.Update();
|
input.Update();
|
||||||
if (_scene_current != null) _scene_current.Update();
|
if (_scene_current != null)
|
||||||
|
_scene_current.Update(time_delta, g);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long GetFrameTime() { return _time_delta; }
|
public Scene Get_Scene() { return _scene_current; }
|
||||||
|
public void Set_Scene(Scene scene)
|
||||||
|
{
|
||||||
|
if (_scene_current != null)
|
||||||
|
{
|
||||||
|
_scene_current.Destroy();
|
||||||
|
_scene_current = null;
|
||||||
|
System.gc();
|
||||||
|
}
|
||||||
|
_scene_current = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final long GetFrameTime() { return time_delta; }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ 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();
|
public abstract void Update(long dt, Graphics g);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,4 +26,16 @@ 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,53 +10,50 @@ import sillysagiri.Scene;
|
|||||||
import sillysagiri.Utils;
|
import sillysagiri.Utils;
|
||||||
|
|
||||||
public class Intro extends Scene {
|
public class Intro extends Scene {
|
||||||
private int counter = 0;
|
private long counter = 0;
|
||||||
private int state = 0;
|
private int state = 0;
|
||||||
|
|
||||||
private Image img_logo;
|
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
|
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()
|
public void Update(long dt, Graphics g)
|
||||||
{
|
{
|
||||||
// TODO: use time based counter instead
|
counter += dt;
|
||||||
counter++;
|
|
||||||
if (counter > 100) counter = 0;
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
if (counter > 25)
|
|
||||||
{
|
|
||||||
// img_logo = Image.createImage("/pEZ.png");
|
|
||||||
counter = 0;
|
|
||||||
state = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(Graphics g)
|
|
||||||
{
|
|
||||||
Utils.Clear_Screen(g, 73, 0, 0);
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
|
if (counter > 1800)
|
||||||
|
{
|
||||||
|
counter = 0;
|
||||||
|
state = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils.Clear_Screen(g, 73, 0, 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.CubicEaseOut((float)counter/25);
|
float r = Easing.CubicEaseInOut((float)counter/1800);
|
||||||
int pos = (int)(((Utils.GetScreenWidth()/2)+halfW) * r) - halfW;
|
int pos = (int)Math.ceil(((Utils.GetScreenWidth()/2)+halfW) * r) - halfW;
|
||||||
|
|
||||||
g.drawRegion(
|
g.drawRegion(
|
||||||
img_logo,
|
img_logo,
|
||||||
@ -69,24 +66,53 @@ 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:
|
||||||
{
|
{
|
||||||
g.drawImage(
|
if (counter > 500)
|
||||||
img_logo,
|
{
|
||||||
Utils.GetScreenWidth()/2,
|
counter = 0;
|
||||||
Utils.GetScreenHeight()/2,
|
state = 2;
|
||||||
Graphics.VCENTER | Graphics.HCENTER
|
|
||||||
);
|
|
||||||
|
|
||||||
break;
|
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;
|
||||||
default: return;
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Utils.Clear_Screen(g, 146, 36, 0);
|
||||||
|
g.drawImage(
|
||||||
|
img_logo,
|
||||||
|
Utils.GetScreenWidth()/2, Utils.GetScreenHeight()/2-35,
|
||||||
|
Graphics.HCENTER | Graphics.VCENTER);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user