Add project files

This commit is contained in:
Victor 2018-11-15 00:02:33 +02:00
parent a7ba25d928
commit 32ece1a7c7
14 changed files with 1981 additions and 44 deletions

83
build.xml Normal file
View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="RayCanvas" default="jar" basedir=".">
<description>Builds, tests, and runs the project .</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
pre-init: called before initialization of project properties
post-init: called after initialization of project properties
pre-preprocess: called before text preprocessing of sources
post-preprocess: called after text preprocessing of sources
pre-compile: called before source compilation
post-compile: called after source compilation
pre-obfuscate: called before obfuscation
post-obfuscate: called after obfuscation
pre-preverify: called before preverification
post-preverify: called after preverification
pre-jar: called before jar building
post-jar: called after jar building
pre-build: called before final distribution building
post-build: called after final distribution building
pre-clean: called before cleaning build products
post-clean: called after cleaning build products
Example of pluging a my-special-task after the compilation could look like
<target name="post-compile">
<my-special-task>
<fileset dir="${build.classes.dir}"/>
</my-special-task>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Other way how to customize the build is by overriding existing main targets.
The target of interest are:
preprocess: preprocessing
extract-libs: extraction of libraries and resources
compile: compilation
create-jad: construction of jad and jar manifest source
obfuscate: obfuscation
preverify: preverification
jar: jar archive building
run: execution
debug: execution in debug mode
build: building of the final distribution
javadoc: javadoc generation
Example of overriding the target for project execution could look like
<target name="run" depends="init,jar">
<my-special-exec jadfile="${dist.dir}/${dist.jad}"/>
</target>
Be careful about correct dependencies when overriding original target.
Again, for list of available properties which you can use check the target
you are overriding in nbproject/build-impl.xml file.
A special target for-all-configs can be used to run some specific targets for
all project configurations in a sequence. File nbproject/build-impl.xml
already contains some "for-all" targets:
jar-all
javadoc-all
clean-all
Example of definition of target iterating over all project configurations:
<target name="jar-all">
<property name="target.to.call" value="jar"/>
<antcall target="for-all-configs"/>
</target>
-->
</project>

1247
nbproject/build-impl.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>

View File

@ -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

10
nbproject/project.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.kjava.j2meproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2me-project">
<name>RayCanvas</name>
<minimum-ant-version>1.6</minimum-ant-version>
</data>
</configuration>
</project>

View File

@ -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;

30
src/Fps.java Normal file
View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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 && cu<m1.length-1) {cu++; yy=-fh;}
@ -73,10 +72,11 @@ public class Menu extends EWindow {
}
private void getM1Code(int nfct) {
if(nfct==0) Main.midlet.dsp.setCurrent(ray);
else if(nfct==1) Main.midlet.dsp.setCurrent(new About(m1[nfct]));
else if(nfct==2) Main.midlet.changeSoundState(!Main.music);
else if(nfct==3) Main.midlet.destroyApp(true);
if(nfct==0) Main.midlet.dsp.setCurrent(new RayDBCanvas());
else if(nfct==1) Main.midlet.dsp.setCurrent(new RayGameCanvas());
else if(nfct==2) Main.midlet.dsp.setCurrent(new About(m1[nfct]));
else if(nfct==3) Main.midlet.changeSoundState(!Main.music);
else if(nfct==4) Main.midlet.destroyApp(true);
}
protected void pointerPressed(int x, int y) {

View File

@ -2,13 +2,14 @@
import java.io.IOException;
import javax.microedition.lcdui.*;
public class RayCanvas extends Canvas {// implements Runnable {
public class RayDBCanvas extends Canvas 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
@ -24,17 +25,25 @@ public class RayCanvas extends Canvas {// implements Runnable {
private long lastTime;
private boolean showUI, end;
private int size = 4;
/** Картинка и графика для двойной буферизации */
private Image I;
private Graphics G;
public RayCanvas() {
public RayDBCanvas() {
setFullScreenMode(true);
w = getWidth();
h = getHeight();
I = Image.createImage(w, h);
G = I.getGraphics();
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;
@ -46,6 +55,8 @@ public class RayCanvas extends Canvas {// implements Runnable {
try {
pr = Image.createImage("/res/2.png");
} catch (IOException ex) {}
Thread t = new Thread(this);
t.start();
}
protected void keyPressed(int key) {
@ -63,16 +74,19 @@ public class RayCanvas extends Canvas {// implements Runnable {
}
public void paint(Graphics g) {
long thisTime = System.currentTimeMillis(); // òåêóùåå âðåìÿ
double dTime = (thisTime - lastTime)/1000d;// âðåìÿ, ïðîøåäøåå ñ ïðîøëîãî êàäðà
draw(G);
g.drawImage(I, 0, 0, 20);
Fps.drawFps(g);
}
private void draw(Graphics g) {
long thisTime = System.currentTimeMillis(); // текущее время
double dTime = (thisTime - lastTime)/1000d;// время, прошедшее с прошлого кадра
lastTime = thisTime;
if(glukmode[0]==1 && gluk==3){// && gluk==2) {
int[] pixelArray = new int[w * h];
for (int io = 0; io < pixelArray.length; io++) {
pixelArray[io] = 0x30000000;
}
g.drawRGB(pixelArray, 0, w, 0, 0, w, h, true);
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);
@ -210,26 +224,29 @@ public class RayCanvas extends Canvas {// implements Runnable {
if (isRight) {
//both camera direction and camera plane must be rotated
double oldDirX = dirX;
dirX = dirX * Math.cos(-rotSpeed) - dirY * Math.sin(-rotSpeed);
dirY = oldDirX * Math.sin(-rotSpeed) + dirY * Math.cos(-rotSpeed);
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 * Math.cos(-rotSpeed) - planeY * Math.sin(-rotSpeed);
planeY = oldPlaneX * Math.sin(-rotSpeed) + planeY * Math.cos(-rotSpeed);
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;
dirX = dirX * Math.cos(rotSpeed) - dirY * Math.sin(rotSpeed);
dirY = oldDirX * Math.sin(rotSpeed) + dirY * Math.cos(rotSpeed);
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 * Math.cos(rotSpeed) - planeY * Math.sin(rotSpeed);
planeY = oldPlaneX * Math.sin(rotSpeed) + planeY * Math.cos(rotSpeed);
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 (showUI) showLabirinth(g, (int)posX, (int)posY);
if (end) drawStats(g);
repaint();
}
private void showLabirinth(Graphics g, int x, int y) {
@ -274,7 +291,7 @@ public class RayCanvas extends Canvas {// implements Runnable {
}
private void uiSize(int num) {
size+=num;
size += num;
if(size<2) size = 2;
else if(size>10) 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();
}
}
}
}

375
src/RayGameCanvas.java Normal file
View File

@ -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; i<grid.width; i++) {
for(int j=0; j<grid.height; j++) {
if(grid.mySquares[i][j]==0)
g.fillRect(i*size, j*size, size, size);
}
}
g.setColor(0xFF0000);
g.fillRect(x*size, y*size, size, size);
}
private int getCell(int x, int y) {
try {
int yy = Math.abs(1-grid.mySquares[x][y]);
if(yy==4) end = true;
return yy;
}catch(Exception ex) {
return 0;
}
}
private void restart(boolean newsize) {
if(end) Rms.vict++;
if(newsize) grid = new Grid(25);
grid.newMaze();
end = false;
Rms.games++;
posX = 1;
posY = 1.1;
for(int i=0; i<glukmode.length; i++) {
glukstep[i] = 1;
glukmode[i] = (byte) grid.getRandomInt(4);
colors[1][i] = grid.getRandomInt(0xbbbbbb)+0x333333;
colors[2][i] = grid.getRandomInt(0xbbbbbb)+0x333333;
colors[3][i] = grid.getRandomInt(0xbbbbbb)+0x333333;
}
glukstep[glukmode[2]] = 2;
if(glukmode[0]==2) glukstep[glukmode[3]] = 3;
}
private void uiSize(int num) {
size += num;
if(size<2) size = 2;
else if(size>10) size = 10;
}
protected void pointerPressed(int x, int y) {
int w3 = w/3;
int h3 = h/3;
if(y<h3 && (x>w3 && x<(w-w3))) keyPressed(UP);
else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyPressed(DOWN);
if(x<w3 && (y>h3 && y<(h-h3))) keyPressed(LEFT);
else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyPressed(RIGHT);
if(x<w3 && y<h3) keyPressed(KEY_STAR);
else if(x>(w-w3) && y<h3) keyPressed(KEY_NUM0);
else if(x<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(y<h3 && (x>w3 && x<(w-w3))) keyReleased(UP);
else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyReleased(DOWN);
if(x<w3 && (y>h3 && 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();
}
}
}
}