diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..0fc924a
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+ Builds, tests, and runs the project .
+
+
+
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
new file mode 100644
index 0000000..6b13589
--- /dev/null
+++ b/nbproject/build-impl.xml
@@ -0,0 +1,1247 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Classpath to J2ME Ant extension library (libs.j2me_ant_ext.classpath property) is not set. For example: location of mobility/modules/org-netbeans-mobility-antext.jar file in the IDE installation directory.
+ Platform home (platform.home property) is not set. Value of this property should be ${platform.active.description} emulator home directory location.
+ Platform boot classpath (platform.bootclasspath property) is not set. Value of this property should be ${platform.active.description} emulator boot classpath containing all J2ME classes provided by emulator.
+ Must set src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set preprocessed.dir
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set build.classes.dir
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set obfuscated.classes.dir
+
+
+
+ Must set obfuscated.classes.dir
+ Must set obfuscator.srcjar
+ Must set obfuscator.destjar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set preverify.classes.dir
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ MicroEdition-Configuration: ${platform.configuration}
+
+ MicroEdition-Configuration: ${platform.configuration}
+
+
+
+ MicroEdition-Profile: ${platform.profile}
+
+ MicroEdition-Profile: ${platform.profile}
+
+
+
+ Must set dist.jad
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.jad}
+ ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.manifest}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Starting emulator with port number ${active.debug.port}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Starting emulator with port number ${active.debug.port}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set dist.javadoc.dir
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ${all.configurations}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Property deployment.${deployment.method}.scriptfile not set. The property should point to an Ant script providing ${deployment.method} deployment.
+
+
+
+
+
+
+
+ Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set.
+
+
+
+
+
+
+
+
+ Active project configuration: @{cfg}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Property build.root.dir is not set. By default its value should be \"build\".
+ Property dist.root.dir is not set. By default its value should be \"dist\".
+
+
+
+
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
new file mode 100644
index 0000000..8a3593d
--- /dev/null
+++ b/nbproject/genfiles.properties
@@ -0,0 +1,8 @@
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+build.xml.data.CRC32=50493141
+build.xml.script.CRC32=17c5769f
+build.xml.stylesheet.CRC32=9c6a911d
+nbproject/build-impl.xml.data.CRC32=50493141
+nbproject/build-impl.xml.script.CRC32=870b7a65
+nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22
diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties
new file mode 100644
index 0000000..2445f1a
--- /dev/null
+++ b/nbproject/private/private.properties
@@ -0,0 +1,7 @@
+#Fri, 06 Jan 2012 19:36:48 +0200
+app-version.autoincrement=true
+config.active=
+deployment.counter=101
+deployment.number=0.1.0
+javadoc.preview=true
+netbeans.user=C:\\Users\\aNNiMON\\.netbeans\\7.1
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
new file mode 100644
index 0000000..c1f155a
--- /dev/null
+++ b/nbproject/private/private.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644
index 0000000..dd8a3dd
--- /dev/null
+++ b/nbproject/project.properties
@@ -0,0 +1,142 @@
+abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,NOKIAUI=1.0,JSR226=1.0,capuchin=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,eSWT=1.1,J2MEWS=1.0,VSCL=2.1,WMA=2.0,JSR172=1.0,JSR256=1.1,SEMC_EXT_JP8=1.0,ColorScreen,NokiaUI=1.0,OBEX=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,MascotV3=1.0,JSR75=1.0,IAPInfo=1.0,SATSAPKI=1.0,JSR184=1.1,ScreenHeight=321,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0,
+all.configurations=\
+application.args=
+application.description=
+application.description.detail=
+application.name=
+application.vendor=Vendor
+build.classes.dir=${build.dir}/compiled
+build.classes.excludes=**/*.java,**/*.form,**/*.class,**/.nbintdb,**/*.mvd,**/*.wsclient,**/*.vmd
+build.dir=build/${config.active}
+build.root.dir=build
+debug.level=debug
+debugger.timeout=
+deployment.copy.target=deploy
+deployment.instance=default
+deployment.jarurl=${dist.jar}
+deployment.method=NONE
+deployment.override.jarurl=false
+dist.dir=dist/${config.active}
+dist.jad=RayCanvas.jad
+dist.jar=RayCanvas.jar
+dist.javadoc.dir=${dist.dir}/doc
+dist.root.dir=dist
+extra.classpath=
+filter.exclude.tests=false
+filter.excludes=
+filter.more.excludes=**/overview.html,**/package.html
+filter.use.standard=true
+jar.compress=true
+javac.debug=true
+javac.deprecation=false
+javac.encoding=windows-1251
+javac.optimize=false
+javac.source=1.3
+javac.target=1.3
+javadoc.author=false
+javadoc.encoding=
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+libs.classpath=
+main.class=
+main.class.class=applet
+manifest.apipermissions=
+manifest.file=manifest.mf
+manifest.is.liblet=false
+manifest.jad=
+manifest.manifest=
+manifest.midlets=MIDlet-1: RayCanvas,/res/2.png,Main\n
+manifest.others=MIDlet-Vendor: aNNiMON\nMIDlet-Name: RayCanvas\nMIDlet-Version: 1.0\n
+manifest.pushregistry=
+name=RayCanvas
+no.dependencies=false
+nokiaS80.application.icon=
+nsicom.application.monitorhost=
+nsicom.application.runremote=
+nsicom.application.runverbose=
+nsicom.remoteapp.location=\\My Documents\\NetBeans Applications
+nsicom.remotevm.location=\\Windows\\creme\\bin\\CrEme.exe
+obfuscated.classes.dir=${build.dir}/obfuscated
+obfuscation.custom=@E:\\SETUPS\\Disk\\Programming\\Java\\annimon.pro
+obfuscation.level=1
+obfuscator.destjar=${build.dir}/obfuscated.jar
+obfuscator.srcjar=${build.dir}/before-obfuscation.jar
+platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_
+platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator)
+platform.apis=WMA-2.0,JSR211-1.0,JSR82-1.1,JSR177-1.0,JSR234-1.0,SATSA-APDU-1.0,capuchin-1.0,J2ME-WS-1.0,J2ME-XMLRPC-1.0,SATSA-JCRMI-1.0,SATSA-CRYPTO-1.0,JSR239-1.0,MascotV3-1.0,JSR238-1.0,MMAPI-1.1,JSR256-1.1,NokiaUI-1.0,IAPInfo-1.0,JSR229-1.1.0,SATSA-PKI-1.0,JSR180-1.0.1,JSR226-1.0,SEMC_EXT_JP8-1.0,VSCL-2.0,VSCL-2.1,eSWT-1.1,JSR75-1.0,JSR184-1.1,JSR179-1.0.1
+platform.bootclasspath=${platform.home}/lib/eswt.jar:${platform.home}/lib/mascotv3.jar:${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr256.jar:${platform.home}/lib/satsa-crypto.jar:${platform.home}/lib/jsr229.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/j2me-xmlrpc.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/vscl21.jar:${platform.home}/lib/satsa-jcrmi.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/satsa-apdu.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/nokiaext.jar:${platform.home}/lib/capuchin.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/satsa-pki.jar:${platform.home}/lib/jsr179.jar:${platform.home}/lib/jsr180.jar:${platform.home}/lib/iapinfo.jar:${platform.home}/lib/vscl.jar:${platform.home}/lib/mmapi.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/semc_ext_jp8.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar
+platform.configuration=CLDC-1.1
+platform.device=SonyEricsson_JP8_240x320_Emu
+platform.fat.jar=true
+platform.profile=MIDP-2.0
+platform.trigger=CLDC
+platform.type=UEI-1.0.1
+preprocessed.dir=${build.dir}/preprocessed
+preverify.classes.dir=${build.dir}/preverified
+preverify.sources.dir=${build.dir}/preverifysrc
+resources.dir=resources
+ricoh.application.email=
+ricoh.application.fax=
+ricoh.application.icon=
+ricoh.application.target-jar=
+ricoh.application.telephone=
+ricoh.application.uid=98793259
+ricoh.application.version=
+ricoh.dalp.application-desc.auto-run=false
+ricoh.dalp.application-desc.energy-save=
+ricoh.dalp.application-desc.exec-auth=
+ricoh.dalp.application-desc.visible=true
+ricoh.dalp.argument=
+ricoh.dalp.codebase=
+ricoh.dalp.display-mode.color=true
+ricoh.dalp.display-mode.is-4line-support=false
+ricoh.dalp.display-mode.is-hvga-support=true
+ricoh.dalp.display-mode.is-vga-support=false
+ricoh.dalp.display-mode.is-wvga-support=false
+ricoh.dalp.information.abbreviation=
+ricoh.dalp.information.icon.basepath=
+ricoh.dalp.information.icon.location=
+ricoh.dalp.information.is-icon-used=true
+ricoh.dalp.install.destination=hdd
+ricoh.dalp.install.mode.auto=true
+ricoh.dalp.install.work-dir=hdd
+ricoh.dalp.is-managed=true
+ricoh.dalp.resources.dsdk.version=2.0
+ricoh.dalp.resources.jar.basepath=
+ricoh.dalp.resources.jar.version=
+ricoh.dalp.version=
+ricoh.icon.invert=false
+ricoh.platform.target.version=
+run.cmd.options=
+run.jvmargs=
+run.method=STANDARD
+run.security.domain=trusted
+run.use.security.domain=false
+savaje.application.icon=
+savaje.application.icon.focused=
+savaje.application.icon.small=
+savaje.application.uid=TBD
+savaje.bundle.base=
+savaje.bundle.debug=false
+savaje.bundle.debug.port=
+semc.application.caps=
+semc.application.icon=
+semc.application.icon.count=
+semc.application.icon.splash=
+semc.application.icon.splash.installonly=false
+semc.application.uid=E0889518
+semc.certificate.path=
+semc.private.key.password=
+semc.private.key.path=
+sign.alias=
+sign.enabled=false
+sign.keystore=
+src.dir=src
+use.emptyapis=true
+use.preprocessor=true
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644
index 0000000..34abe72
--- /dev/null
+++ b/nbproject/project.xml
@@ -0,0 +1,10 @@
+
+
+ org.netbeans.modules.kjava.j2meproject
+
+
+ RayCanvas
+ 1.6
+
+
+
diff --git a/src/About.java b/src/About.java
index a674186..2f718f1 100644
--- a/src/About.java
+++ b/src/About.java
@@ -180,7 +180,7 @@ public class About extends EWindow {
}
private String[] splitString(String str, String delim) {
- if (str.equals("") || delim == null || delim.length() == 0) return new String[]{str};
+ if (str.length() == 0 || delim == null || delim.length() == 0) return new String[]{str};
String[] s;
Vector v = new Vector();
int pos = 0;
diff --git a/src/Fps.java b/src/Fps.java
new file mode 100644
index 0000000..38b33df
--- /dev/null
+++ b/src/Fps.java
@@ -0,0 +1,30 @@
+
+import javax.microedition.lcdui.Graphics;
+
+/*
+ * aNNiMON 2012
+ * For more info visit http://annimon.com/
+ */
+
+/**
+ *
+ * @author aNNiMON
+ */
+public class Fps {
+
+ static long FPS, FPS_Count, FPS_Start;
+ static String getFPS() {
+ FPS_Count ++;
+ if (System.currentTimeMillis() - FPS_Start >= 1000) {
+ FPS = FPS_Count;
+ FPS_Count = 0;
+ FPS_Start = System.currentTimeMillis();
+ }
+ return Long.toString(FPS);
+ }
+
+ static void drawFps(Graphics g) {
+ g.setColor(0xFF);
+ g.drawString(Fps.getFPS(), 0, 0, 20);
+ }
+}
diff --git a/src/Grid.java b/src/Grid.java
index 8f8d42e..7a47e44 100644
--- a/src/Grid.java
+++ b/src/Grid.java
@@ -7,7 +7,7 @@ import java.util.Vector;
*
* @author Carol Hamer
*/
-public class Grid {
+public final class Grid {
/**
* Random number generator to create a random maze.
@@ -30,6 +30,8 @@ public class Grid {
// maze generation methods
/**
* Create a new maze.
+ * @param width
+ * @param height
*/
public Grid(int width, int height) {
this.width = width;
@@ -37,7 +39,7 @@ public class Grid {
}
public Grid(int max) {
- this.width = getRandomInt(max)+10;
+ this.width = //getRandomInt(max)+10;
this.height = getRandomInt(max)+10;
}
@@ -59,6 +61,7 @@ public class Grid {
mySquares[mySquares.length-2][mySquares[0].length-2] = 5;
mySquares[mySquares.length-2][mySquares[0].length-3] = 5;
mySquares[mySquares.length-1][mySquares[0].length-3] = 5;
+ width--; height--;
}
/**
@@ -200,10 +203,6 @@ public class Grid {
* @return a random non-negative int less than the bound upper.
*/
public int getRandomInt(int upper) {
- int retVal = myRandom.nextInt() % upper;
- if (retVal < 0) {
- retVal += upper;
- }
- return (retVal);
+ return myRandom.nextInt(upper);
}
}
diff --git a/src/Main.java b/src/Main.java
index 3c3063e..f9f62d0 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -54,8 +54,9 @@ public class Main extends MIDlet implements PlayerListener {
private void yesSound() {
try {
int yy;
- do yy = Math.abs(rnd.nextInt()%5);
- while(currentmusic == yy);
+ do {
+ yy = Math.abs(rnd.nextInt()%5);
+ } while(currentmusic == yy);
currentmusic = yy;
InputStream is = getClass().getResourceAsStream("/res/"+String.valueOf(yy));
diff --git a/src/Menu.java b/src/Menu.java
index 061d90b..f01f80c 100644
--- a/src/Menu.java
+++ b/src/Menu.java
@@ -18,18 +18,17 @@ public class Menu extends EWindow {
private Random rnd;
private long ty;
- private RayCanvas ray;
public Menu() {
super("RayCanvas");
m1 = new String[] {
- "Начать",
+ "Начать в DBCanvas",
+ "Начать в GameCanvas",
"Об игре",
"Музыка ",
"Выход",
};
rnd = new Random();
- ray = new RayCanvas();
ESkin e = new ESkin(rnd.nextInt()%0xFFFFFF);
fh = EConst.mainFont.getHeight()+2;
yy = cu = 0;
@@ -63,7 +62,7 @@ public class Menu extends EWindow {
}
public void keyEvent(int key, byte state) {
- if(state!=RELEASED) {
+ if(state != RELEASED) {
int ga = getGameAction(key);
if (ga==UP && cu>0) {cu--; yy=fh;}
else if (ga==DOWN && cu10) size = 10;
}
@@ -307,9 +324,23 @@ public class RayCanvas extends Canvas {// implements Runnable {
private void drawStats(Graphics g) {
g.setColor(0xFF6159);
- g.drawString(" ", w/2, h/2, 33);
- g.drawString(": "+Rms.games, w/2, h/2+2, 17);
- g.drawString(": "+(Rms.vict+1), w/2, h/2+fh+2, 17);
- g.drawString("% : "+((Rms.vict+1)*100/Rms.games), w/2, h/2+fh*2+2, 17);
+ g.drawString("Вы выиграли", w/2, h/2, 33);
+ g.drawString("Игр: "+Rms.games, w/2, h/2+2, 17);
+ g.drawString("Побед: "+(Rms.vict+1), w/2, h/2+fh+2, 17);
+ g.drawString("% побед: "+((Rms.vict+1)*100/Rms.games), w/2, h/2+fh*2+2, 17);
+ }
+
+ public void run() {
+ while (true) {
+ try {
+ repaint();
+ // Sleep to prevent starvation
+ try {
+ Thread.sleep(20);
+ } catch (Exception e) {}
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
}
diff --git a/src/RayGameCanvas.java b/src/RayGameCanvas.java
new file mode 100644
index 0000000..c4b04cf
--- /dev/null
+++ b/src/RayGameCanvas.java
@@ -0,0 +1,375 @@
+
+import java.io.IOException;
+import javax.microedition.lcdui.*;
+import javax.microedition.lcdui.game.GameCanvas;
+
+public class RayGameCanvas extends GameCanvas implements Runnable {
+
+ private Keyboard keyb;
+ private Grid grid;
+ private byte gluk;
+ private Image pr;
+ //Motion Blur
+ private int[] motionArray;
+ private int[][] colors = new int[][] {
+ {0xcccc44, 0x444444, 0x333333, 0x222222, 0x111111},//gluk0
+ {0xcccc44, 0xaaaaaa, 0x888888, 0x555555, 0xcccccc},//gluk1
+ {0xcccc44, 0xcc4444, 0x44cc44, 0x4444cc, 0xcccccc},//gluk2
+ {0xcccc44, 0xaa54a4, 0x803488, 0x5a5055, 0xc2087c} //gluk3
+ };
+ private int[] glukstep;
+ private byte[] glukmode;
+ private double posX, posY; //x and y start position
+ private double dirX, dirY; //initial direction vector
+ private double planeX, planeY; //the 2d raycaster version of camera plane
+ private int w,h, fh;
+ private long lastTime;
+ private boolean showUI, end;
+ private int size = 4;
+
+ public RayGameCanvas() {
+ super(true);
+ setFullScreenMode(true);
+ w = getWidth();
+ h = getHeight();
+ motionArray = new int[w * (h/2)];
+ for (int io = 0; io < motionArray.length; io++) {
+ motionArray[io] = 0x30000000;
+ }
+ fh = Font.getDefaultFont().getHeight()+2;
+ glukstep = new int[colors.length];
+ glukmode = new byte[colors.length];
+ restart(true);
+ showUI = false;
+ dirX = -1;
+ lastTime = 0;
+ dirY = planeX = 0;
+ planeY = 0.56;
+ gluk = 1;
+
+ keyb = new Keyboard();
+ try {
+ pr = Image.createImage("/res/2.png");
+ } catch (IOException ex) {}
+ Thread t = new Thread(this);
+ t.start();
+ }
+
+ public void paint(Graphics g) {
+ long thisTime = System.currentTimeMillis(); //
+ double dTime = (thisTime - lastTime)/1000d;// ,
+ lastTime = thisTime;
+
+ if(glukmode[0]==1 && gluk==3){// && gluk==2) {
+ g.drawRGB(motionArray, 0, w, 0, 0, w, h/2, true);
+ g.drawRGB(motionArray, 0, w, 0, h/2, w, h/2, true);
+ }else{
+ if(glukmode[0]==3 && gluk==1)
+ g.setColor(0xFFFFFF);
+ else g.setColor(0);
+ g.fillRect(0, 0, w, h);
+ }
+
+ int yy = grid.width/3;
+ if (posX < yy) gluk = glukmode[1];
+ else if(posX > yy && posX < yy*2) gluk = glukmode[2];
+ else if (posX > yy*2 && posX < grid.width) gluk = glukmode[3];
+ else if ((posX > (yy+yy/2)) && posY < (grid.height/2)) gluk = glukmode[0];
+
+ for (int x = 0; x < w; x+=glukstep[gluk]) {
+ //calculate ray position and direction
+ double cameraX = 2 * x / (double) w - 1; //x-coordinate in camera space
+ double rayPosX = posX;
+ double rayPosY = posY;
+ double rayDirX = dirX + planeX * cameraX;
+ double rayDirY = dirY + planeY * cameraX;
+ //which box of the map we're in
+ int mapX = (int) rayPosX;
+ int mapY = (int) rayPosY;
+
+ //length of ray from current position to next x or y-side
+ double sideDistX;
+ double sideDistY;
+
+ //length of ray from one x or y-side to next x or y-side
+ double deltaDistX = Math.sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
+ double deltaDistY = Math.sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
+ double perpWallDist;
+
+ //what direction to step in x or y-direction (either +1 or -1)
+ int stepX;
+ int stepY;
+
+ int hit = 0; //was there a wall hit?
+ int side = 0; //was a NS or a EW wall hit?
+ //calculate step and initial sideDist
+ if (rayDirX < 0) {
+ stepX = -1;
+ sideDistX = (rayPosX - mapX) * deltaDistX;
+ } else {
+ stepX = 1;
+ sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
+ }
+ if (rayDirY < 0) {
+ stepY = -1;
+ sideDistY = (rayPosY - mapY) * deltaDistY;
+ } else {
+ stepY = 1;
+ sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
+ }
+ //perform DDA
+ while (hit == 0) {
+ //jump to next map square, OR in x-direction, OR in y-direction
+ if (sideDistX < sideDistY) {
+ sideDistX += deltaDistX;
+ mapX += stepX;
+ side = 0;
+ } else {
+ sideDistY += deltaDistY;
+ mapY += stepY;
+ side = 1;
+ }
+ //Check if ray has hit a wall
+ try {
+ if (getCell(mapX, mapY) > 0) hit = 1;
+ } catch (Exception e) {
+ hit = 1;
+ }
+ }
+ //Calculate distance projected on camera direction (oblique distance will give fisheye effect!)
+ if (side == 0) {
+ perpWallDist = Math.abs((mapX - rayPosX + (1 - stepX) / 2) / rayDirX);
+ } else {
+ perpWallDist = Math.abs((mapY - rayPosY + (1 - stepY) / 2) / rayDirY);
+ }
+
+ //Calculate height of line to draw on screen
+ int lineHeight = Math.abs((int) (h / perpWallDist));
+
+ //calculate lowest and highest pixel to fill in current stripe
+ int drawStart = -lineHeight / 2 + h / 2;
+ if (drawStart < 0) drawStart = 0;
+ int drawEnd = lineHeight / 2 + h / 2;
+ if (drawEnd >= h) drawEnd = h - 1;
+
+ //choose wall color
+
+ int color = 0;
+ try {
+ color = colors[gluk][getCell(mapX, mapY)];
+ //give x and y sides different brightness
+ if (side == 1) color /= 2;
+ } catch (Exception e) {
+ color = 0xcccc44;
+ }
+
+ //draw the pixels of the stripe as a vertical line
+ //verLine(x, drawStart, drawEnd, color);
+ g.setColor(color);
+ g.drawLine(x, drawStart, x, drawEnd);
+ }
+
+ //speed modifiers
+ double moveSpeed = dTime * 5.0; //the constant value is in squares/second
+ double rotSpeed = dTime * 3.0; //the constant value is in radians/second
+
+ //move forward if no wall in front of you
+ if (keyb.getKeyState(UP)) {
+ if (getCell((int) (posX + dirX * moveSpeed), (int) posY) == 0) {
+ posX += dirX * moveSpeed;
+ }
+ if (getCell((int) posX, (int) (posY + dirY * moveSpeed)) == 0) {
+ posY += dirY * moveSpeed;
+ }
+ }else
+ if (keyb.getKeyState(DOWN)) {//move backwards if no wall behind you
+ if (getCell((int) (posX - dirX * moveSpeed), (int) posY) == 0) {
+ posX -= dirX * moveSpeed;
+ }
+ if (getCell((int) posX, (int) (posY - dirY * moveSpeed)) == 0) {
+ posY -= dirY * moveSpeed;
+ }
+ }
+ boolean isRight = keyb.getKeyState(RIGHT);
+ boolean isLeft = keyb.getKeyState(LEFT);
+ if(glukmode[0]==3 && gluk==3) {
+ if(isRight) {isRight = false; isLeft = true;}
+ else if(isLeft) {isLeft = false; isRight = true;}
+ }
+ //rotate to the right
+ if (isRight) {
+ //both camera direction and camera plane must be rotated
+ double oldDirX = dirX;
+ final double cos = Math.cos(-rotSpeed);
+ final double sin = Math.sin(-rotSpeed);
+ dirX = dirX * cos - dirY * sin;
+ dirY = oldDirX * sin + dirY * cos;
+ double oldPlaneX = planeX;
+ planeX = planeX * cos - planeY * sin;
+ planeY = oldPlaneX * sin + planeY * cos;
+ }else
+ if (isLeft) {//rotate to the left
+ //both camera direction and camera plane must be rotated
+ double oldDirX = dirX;
+ final double sin = Math.sin(rotSpeed);
+ final double cos = Math.cos(rotSpeed);
+ dirX = dirX * cos - dirY * sin;
+ dirY = oldDirX * sin + dirY * cos;
+ double oldPlaneX = planeX;
+ planeX = planeX * cos - planeY * sin;
+ planeY = oldPlaneX * sin + planeY * cos;
+ }
+
+ g.drawImage(pr, w / 2, h / 2, 3);
+ if (showUI) showLabirinth(g, (int)posX, (int)posY);
+ if (end) drawStats(g);
+ Fps.drawFps(g);
+ }
+
+ private void showLabirinth(Graphics g, int x, int y) {
+ g.setColor(0x00FF);
+ for(int i=0; i10) size = 10;
+ }
+
+ protected void pointerPressed(int x, int y) {
+ int w3 = w/3;
+ int h3 = h/3;
+ if(yw3 && x<(w-w3))) keyPressed(UP);
+ else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyPressed(DOWN);
+
+ if(xh3 && y<(h-h3))) keyPressed(LEFT);
+ else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyPressed(RIGHT);
+
+ if(x(w-w3) && y(h-h3)) keyPressed(-6);
+ else if(x>(w-w3) && y>(h-h3)) keyPressed(-7);
+ else if( (x>w3 && x<(w-w3)) && (y>h3 && y<(h-h3)) ) keyPressed(FIRE);
+ }
+
+ protected void pointerReleased(int x, int y) {
+ int w3 = w/3;
+ int h3 = h/3;
+ if(yw3 && x<(w-w3))) keyReleased(UP);
+ else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyReleased(DOWN);
+
+ if(xh3 && y<(h-h3))) keyReleased(LEFT);
+ else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyReleased(RIGHT);
+ }
+
+ private void drawStats(Graphics g) {
+ g.setColor(0xFF6159);
+ g.drawString(" ", w/2, h/2, 33);
+ g.drawString(": "+Rms.games, w/2, h/2+2, 17);
+ g.drawString(": "+(Rms.vict+1), w/2, h/2+fh+2, 17);
+ g.drawString("% : "+((Rms.vict+1)*100/Rms.games), w/2, h/2+fh*2+2, 17);
+ }
+
+ /*protected void keyPressed(int key) {
+ if(key == KEY_STAR) showUI = !showUI;
+ else if (key == -6) restart(false);
+ else if (key == -7 || (end && getGameAction(key)==FIRE)) restart(true);
+ else if (key == KEY_NUM0) Main.midlet.dsp.setCurrent(Main.midlet.mn);
+ else if(showUI && key == KEY_NUM1) uiSize(-1);
+ else if(showUI && key == KEY_NUM3) uiSize(1);
+ else keyb.onPressed(key, getGameAction(key));
+ }
+
+ protected void keyReleased(int key) {
+ keyb.onReleased(key, getGameAction(key));
+ }*/
+
+ /** Processes keys
+ */
+ protected void process() {
+ int keys = getKeyStates();
+
+ if ((keys & GameCanvas.LEFT_PRESSED) != 0) {
+ keyb.onPressed(-1, Canvas.LEFT);
+ } else {
+ keyb.onReleased(-1, Canvas.LEFT);
+ }
+
+ if ((keys & GameCanvas.RIGHT_PRESSED) != 0) {
+ keyb.onPressed(-1, Canvas.RIGHT);
+ } else {
+ keyb.onReleased(-1, Canvas.RIGHT);
+ }
+
+ if ((keys & GameCanvas.UP_PRESSED) != 0) {
+ keyb.onPressed(-1, Canvas.UP);
+ } else {
+ keyb.onReleased(-1, Canvas.UP);
+ }
+
+ if ((keys & GameCanvas.DOWN_PRESSED) != 0) {
+ keyb.onPressed(-1, Canvas.DOWN);
+ } else {
+ keyb.onReleased(-1, Canvas.DOWN);
+ }
+ }
+
+ public void run() {
+ while (true) {
+ try {
+ // Call the process method (computes keys)
+ process();
+
+ // Draw everything
+ paint(getGraphics());
+ flushGraphics();
+
+ // Sleep to prevent starvation
+ try {
+ Thread.sleep(20);
+ } catch (Exception e) {
+ }
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ }
+ }
+ }
+}