From: Anna Ivanova Date: Thu, 11 Aug 2016 05:26:23 +0000 (+0500) Subject: Initial commit. X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=7f13ef4cd626db2985daa1d17c9face94e0e7998;p=LongFlight.git Initial commit. --- 7f13ef4cd626db2985daa1d17c9face94e0e7998 diff --git a/Crypto/build.xml b/Crypto/build.xml new file mode 100644 index 0000000..3ed3d73 --- /dev/null +++ b/Crypto/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Crypto. + + + diff --git a/Crypto/nbproject/build-impl.xml b/Crypto/nbproject/build-impl.xml new file mode 100644 index 0000000..b6aec53 --- /dev/null +++ b/Crypto/nbproject/build-impl.xml @@ -0,0 +1,1413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Crypto/nbproject/genfiles.properties b/Crypto/nbproject/genfiles.properties new file mode 100644 index 0000000..652dcb1 --- /dev/null +++ b/Crypto/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7f90a431 +build.xml.script.CRC32=a2c5abf7 +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# 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. +nbproject/build-impl.xml.data.CRC32=7f90a431 +nbproject/build-impl.xml.script.CRC32=bbf0bcf8 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/Crypto/nbproject/private/config.properties b/Crypto/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/Crypto/nbproject/private/private.properties b/Crypto/nbproject/private/private.properties new file mode 100644 index 0000000..845c36f --- /dev/null +++ b/Crypto/nbproject/private/private.properties @@ -0,0 +1,6 @@ +compile.on.save=true +do.depend=false +do.jar=true +javac.debug=true +javadoc.preview=true +user.properties.file=C:\\Users\\Kalter\\AppData\\Roaming\\NetBeans\\8.0.1\\build.properties diff --git a/Crypto/nbproject/private/private.xml b/Crypto/nbproject/private/private.xml new file mode 100644 index 0000000..6807a2b --- /dev/null +++ b/Crypto/nbproject/private/private.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Crypto/nbproject/project.properties b/Crypto/nbproject/project.properties new file mode 100644 index 0000000..c43d30e --- /dev/null +++ b/Crypto/nbproject/project.properties @@ -0,0 +1,75 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=Crypto +application.vendor=Kalter +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Crypto.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=code.kalter.longflight.crypto.Crypto +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Crypto/nbproject/project.xml b/Crypto/nbproject/project.xml new file mode 100644 index 0000000..7af0877 --- /dev/null +++ b/Crypto/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Crypto + + + + + + + + + diff --git a/Crypto/src/code/kalter/longflight/crypto/CIStream.java b/Crypto/src/code/kalter/longflight/crypto/CIStream.java new file mode 100644 index 0000000..ded156e --- /dev/null +++ b/Crypto/src/code/kalter/longflight/crypto/CIStream.java @@ -0,0 +1,38 @@ +package code.kalter.longflight.crypto; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Шифровальный входной поток + * + * @author Kalter + */ +public class CIStream extends InputStream { + + private final InputStream istream; + private final Random random; + + public CIStream(InputStream istream, int key) { + this.istream = istream; + this.random = new Random(key); + } + + @Override + public int read() throws IOException { + int b = istream.read(); + b = (b << 4) | (b >> 4); + b ^= random.random(0xFF); + return b; + } + + @Override + public int available() throws IOException { + return istream.available(); + } + + @Override + public void close() throws IOException { + istream.close(); + } +} diff --git a/Crypto/src/code/kalter/longflight/crypto/Crypto.java b/Crypto/src/code/kalter/longflight/crypto/Crypto.java new file mode 100644 index 0000000..876384c --- /dev/null +++ b/Crypto/src/code/kalter/longflight/crypto/Crypto.java @@ -0,0 +1,33 @@ +package code.kalter.longflight.crypto; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Главный класс + * + * @author Kalter + */ +public class Crypto { + + public static void main(String[] args) throws IOException { + final String iname = args[0]; + final String oname = args[1]; + final int key = Integer.parseInt(args[2], 16); + try (InputStream fistream = new CIStream(new FileInputStream(iname), key); + OutputStream fostream = new FileOutputStream("_" + oname);) { + while (fistream.available() > 0) { + fostream.write(fistream.read()); + } + } catch (FileNotFoundException e) { + System.out.println("File not found"); + e.printStackTrace(); + } catch (IOException e) { + System.out.println("I/O error"); + } + } +} diff --git a/Crypto/src/code/kalter/longflight/crypto/Random.java b/Crypto/src/code/kalter/longflight/crypto/Random.java new file mode 100644 index 0000000..408bde0 --- /dev/null +++ b/Crypto/src/code/kalter/longflight/crypto/Random.java @@ -0,0 +1,26 @@ +package code.kalter.longflight.crypto; + +/** + * ГПСЧ + * + * @author Kalter + */ +public class Random { + + private int next; + + public Random(int next) { + this.next = next; + } + + public int random() { + next ^= (next << 13); + next ^= (next >>> 17); + next ^= (next << 5); + return Math.abs(next); + } + + public int random(int max) { + return random() % max; + } +} diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..2ba189e --- /dev/null +++ b/README.MD @@ -0,0 +1,3 @@ +Long Flight - game for Java ME + +All files *.png encrypted \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..efaedac --- /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..b42e8ce --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..6243a0e --- /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=df8d64c8 +build.xml.script.CRC32=06525edf +build.xml.stylesheet.CRC32=9c6a911d +nbproject/build-impl.xml.data.CRC32=df8d64c8 +nbproject/build-impl.xml.script.CRC32=f96173cd +nbproject/build-impl.xml.stylesheet.CRC32=051c3749 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..4672260 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,8 @@ +#Sun, 11 Jan 2015 18:45:51 +0600 +app-version.autoincrement=true +config.active= +deployment.counter=601 +deployment.number=0.6.0 +javadoc.preview=true +netbeans.user=C\:\\Users\\Kalter\\AppData\\Roaming\\NetBeans\\8.0.1 +platform.apis.defaults=MMAPI-1.2,JSR238-1.0,J2ME-WS-1.0,JSR293-2.0,JSR82-1.1,JSR211-1.0,JSR234-1.0,JSR280-1.0,JSR75-1.0,JSR258-1.0,JSR226-1.0,JSR281-1.0,JSR256-1.2,JSR184-1.1,JSR239-1.0,JSR180-1.1.0,JSR253-1.0,JSR229-1.1,JSR177-1.0,WMA-1.1,WMA-2.0,JSR257-1.0,JSR179-1.0 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..5af0ed1 --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..965e13f --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,106 @@ +abilities=ColorScreen,MIDP=2.1,ScreenHeight=320,JSR229=1.1,JSR226=1.0,JSR184=1.1,JSR82=1.1,JSR281=1.0,JSR180=1.1.0,JSR280=1.0,OBEX=1.0,SATSA=1.0,WMA=2.0,ScreenColorDepth=16,JSR238=1.0,JSR239=1.0,JSR258=1.0,JSR234=1.0,JSR179=1.0,JSR256=1.2,JSR257=1.0,JSR177=1.0,JSR211=1.0,CLDC=1.1.1,J2MEWS=1.0,ScreenWidth=240,JSR253=1.0,MMAPI=1.2,TouchScreen,JSR293=2.0,JSR172=1.0,JSR75=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=Long_Flight.jad +dist.jar=Long_Flight.jar +dist.javadoc.dir=${dist.dir}/doc +dist.root.dir=dist +extra.classpath= +file.reference.builtin.ks=${netbeans.user}/config/j2me/builtin.ks +filter.exclude.tests=false +filter.excludes= +filter.more.excludes=**/overview.html,**/package.html +filter.use.standard=true +jar.compress=false +javac.debug=true +javac.deprecation=false +javac.encoding=UTF-8 +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: Long Flight,/gfx/icon.png,code.kalter.longflight.LongFlight\n +manifest.others=MIDlet-Vendor: Kalter\nMIDlet-Version: 1.0\nMIDlet-Name: Long Flight\n +manifest.pushregistry= +name=Long Flight +no.dependencies=false +nokiaS80.application.icon= +obfuscated.classes.dir=${build.dir}/obfuscated +obfuscation.custom= +obfuscation.level=0 +obfuscator.destjar=${build.dir}/obfuscated.jar +obfuscator.srcjar=${build.dir}/before-obfuscation.jar +platform.active=Oracle_Java_TM__Platform_Micro_Edition_SDK_3_0_5 +platform.active.description=Oracle Java(TM) Platform Micro Edition SDK 3.0.5 +platform.apis=WMA-1.1,WMA-2.0,MMAPI-1.2,JSR238-1.0,JSR211-1.0,JSR82-1.1,JSR177-1.0,JSR179-1.0,JSR234-1.0,JSR257-1.0,JSR281-1.0,J2ME-WS-1.0,JSR239-1.0,JSR293-2.0,JSR256-1.2,JSR253-1.0,JSR258-1.0,JSR229-1.1,JSR180-1.1.0,JSR226-1.0,JSR280-1.0,JSR75-1.0,JSR184-1.1 +platform.bootclasspath=${platform.home}/lib/jsr281_1.0.jar:${platform.home}/lib/jsr177_1.0.jar:${platform.home}/lib/jsr082_1.1.jar:${platform.home}/lib/jsr253_1.0.jar:${platform.home}/lib/jsr234_1.0.jar:${platform.home}/lib/jsr226_1.0.jar:${platform.home}/lib/jsr75_1.0.jar:${platform.home}/lib/jsr211_1.0.jar:${platform.home}/lib/jsr239_1.0.jar:${platform.home}/lib/jsr179_1.0.jar:${platform.home}/lib/jsr238_1.0.jar:${platform.home}/lib/jsr205_2.0.jar:${platform.home}/lib/jsr180_1.1.jar:${platform.home}/lib/jsr258_1.0.jar:${platform.home}/lib/jsr120_1.1.jar:${platform.home}/lib/jsr229_1.1.jar:${platform.home}/lib/jsr257_1.0.jar:${platform.home}/lib/jsr135_1.2.jar:${platform.home}/lib/jsr256_1.2.jar:${platform.home}/lib/jsr293_1.0.jar:${platform.home}/lib/jsr172_1.0.jar:${platform.home}/lib/jsr280_1.0.jar:${platform.home}/lib/jsr184_1.1.jar:${platform.home}/lib/midp_2.0.jar:${platform.home}/lib/cldc_1.1.jar +platform.configuration=CLDC-1.1 +platform.device=DefaultCldcPhone1 +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 +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=E4379672 +semc.certificate.path= +semc.private.key.password= +semc.private.key.path= +sign.alias=minimal +sign.enabled=false +sign.keystore=${file.reference.builtin.ks} +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..7baa9cf --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,10 @@ + + + org.netbeans.modules.kjava.j2meproject + + + Long Flight + 1.6 + + + diff --git a/src/code/kalter/longflight/Animation.java b/src/code/kalter/longflight/Animation.java new file mode 100644 index 0000000..84f2a9c --- /dev/null +++ b/src/code/kalter/longflight/Animation.java @@ -0,0 +1,166 @@ +package code.kalter.longflight; + +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Реализация анимации: покадровая смена кадра из массива картинок за + * определённое время. Можно запустить как конечную анимацию, так и бесконечную + * + * @author KalterFive + */ +public class Animation { + + public static Animation createAnimation(String path, int width, + int deltaTime) throws IOException { + final Loader loader = Loader.getInstance(); + final Image image = loader.getImage(path); + return createAnimation(image, width, deltaTime); + } + + public static Animation createAnimation(String path, int width, int height, + int deltaTime) throws IOException { + final Loader loader = Loader.getInstance(); + final Image image = loader.getImage(path); + return createAnimation(image, width, height, deltaTime); + } + + public static Animation createAnimation(Image source, int width, + int deltaTime) { + final int height = source.getHeight(); + return createAnimation(source, width, height, deltaTime); + } + + public static Animation createAnimation(Image source, int width, int height, + int deltaTime) { + final Image[] still = new Image[source.getWidth() / width]; + for (int i = 0; i < still.length; i++) { + still[i] = Image.createImage(source, i * width, 0, + width, height, 0); + } + return createAnimation(still, width, height, deltaTime); + } + + public static Animation createAnimation(Image[] still, int deltaTime) { + int width = still[0].getWidth(); + int height = still[0].getHeight(); + for (int i = 1; i < still.length; i++) { + if (still[i].getWidth() > width) { + width = still[i].getWidth(); + } + if (still[i].getHeight() > height) { + height = still[i].getHeight(); + } + } + return createAnimation(still, width, height, deltaTime); + } + + public static Animation createAnimation(Image[] still, + int width, int height, int deltaTime) { + return new Animation(still, width, height, deltaTime); + } + + private final Image[] still; // кадры + private final int width; + private final int height; + //======================= + private long lastTime; // необходимо для засекания времени + private int deltaTime; // скорость смены кадров + //======================= + private int position; + private boolean animationLoop; + + private Animation(Image[] still, int width, int height, int deltaTime) { + this.still = still; + this.width = width; + this.height = height; + this.deltaTime = deltaTime; + lastTime = System.currentTimeMillis(); + position = 0; + animationLoop = true; + } + + public Image getStill(int index) { + if (index < 0) { + throw new IllegalArgumentException("index < 0"); + } + if (index >= still.length) { + throw new ArrayIndexOutOfBoundsException("i >= length"); + } + return still[index]; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public int getDeltaTime() { + return deltaTime; + } + + public void setDeltaTime(int deltaTime) { + if (deltaTime < 0) { + throw new IllegalArgumentException("delta time < 0"); + } + this.deltaTime = deltaTime; + } + + public int getPosition() { + return position; + } + + // использование нежелательно, но безопасно + public void setPosition(int position) { + if (position < 0) { + throw new IllegalArgumentException("index < 0"); + } + if (position >= still.length) { + throw new ArrayIndexOutOfBoundsException("i >= length"); + } + this.position = position; + } + + public void start() { + animationLoop = true; + position = 0; + } + + public void stop() { + animationLoop = false; + } + + public boolean getState() { + return animationLoop; + } + + public void nextToInfinity() { + final long time = System.currentTimeMillis() - lastTime; + if (time > deltaTime) { + lastTime = System.currentTimeMillis(); + if (++position >= still.length) { + start(); + } + } + } + + public void next() { + final long time = System.currentTimeMillis() - lastTime; + if (getState() && time > deltaTime) { + lastTime = System.currentTimeMillis(); + if (++position >= still.length) { + stop(); + } + } + } + + public void paint(Graphics graphics, int x, int y) { + if (animationLoop) { + graphics.drawImage(still[position], x, y, 0); + } + } +} diff --git a/src/code/kalter/longflight/Area.java b/src/code/kalter/longflight/Area.java new file mode 100644 index 0000000..2b0dcb5 --- /dev/null +++ b/src/code/kalter/longflight/Area.java @@ -0,0 +1,45 @@ +package code.kalter.longflight; + +/** + * Площадь прямоугольника + * + * @author KalterFive + */ +public class Area { + + private final int positionX; + private final int positionY; + private final int endPositionX; + private final int endPositionY; + + public Area(int positionX, int positionY, + int endPositionX, int endPositionY) { + this.positionX = positionX; + this.positionY = positionY; + this.endPositionX = endPositionX; + this.endPositionY = endPositionY; + } + + public boolean isEntry(int positionX, int positionY) { + return (positionX > this.positionX) + && (positionX < this.endPositionX) + && (positionY > this.positionY) + && (positionY < this.endPositionY); + } + + public int getPositionX() { + return positionX; + } + + public int getPositionY() { + return positionY; + } + + public int getEndPositionX() { + return endPositionX; + } + + public int getEndPositionY() { + return endPositionY; + } +} diff --git a/src/code/kalter/longflight/Arrays.java b/src/code/kalter/longflight/Arrays.java new file mode 100644 index 0000000..d73fd85 --- /dev/null +++ b/src/code/kalter/longflight/Arrays.java @@ -0,0 +1,25 @@ +package code.kalter.longflight; + +/** + * Некоторые полезные методы для работы с массивами + * + * @author KalterFive + */ +public class Arrays { + + public static void insertShiftRight(int[] array, int value, int position) { + for (int i = position; i < array.length; i++) { + swap(array, i, position); + } + array[position] = value; + } + + public static void swap(int[] array, int i, int j) { + int tmp = array[i]; + array[i] = array[j]; + array[j] = tmp; + } + + private Arrays() { + } +} diff --git a/src/code/kalter/longflight/ByteArrayInputStream.java b/src/code/kalter/longflight/ByteArrayInputStream.java new file mode 100644 index 0000000..4a38c16 --- /dev/null +++ b/src/code/kalter/longflight/ByteArrayInputStream.java @@ -0,0 +1,72 @@ +package code.kalter.longflight; + +/** + * Удобное чтение разных типов с байтового массива + * + * @author KalterFive + */ +public class ByteArrayInputStream { + + private final byte[] array; + private int position; + + public ByteArrayInputStream(byte[] array) { + this.array = array; + position = 0; + } + + public byte readByte() { + return array[position++]; + } + + public short readShort() { + // AND для того, чтобы читать байт без знака + final short a = (short) (readByte() & 0x00FF); + final short b = (short) (readByte() & 0x00FF); + return (short) ((a << 8) | b); + } + + public int readInteger() { + final int a = readShort(); + final int b = readShort(); + return (int) ((a << 16) | b); + } + + public long readLong() { + final long a = readInteger(); + final long b = readInteger(); + return (long) ((a << 32) | b); + } + + public byte[] toByteArray(int size) { + final byte[] array = new byte[size]; + for (int i = 0; i < size; i++) { + array[i] = readByte(); + } + return array; + } + + public short[] toShortArray(int size) { + final short[] array = new short[size]; + for (int i = 0; i < size; i++) { + array[i] = readShort(); + } + return array; + } + + public int[] toIntArray(int size) { + final int[] array = new int[size]; + for (int i = 0; i < size; i++) { + array[i] = readInteger(); + } + return array; + } + + public long[] toLongArray(int size) { + final long[] array = new long[size]; + for (int i = 0; i < size; i++) { + array[i] = readLong(); + } + return array; + } +} diff --git a/src/code/kalter/longflight/ByteArrayOutputStream.java b/src/code/kalter/longflight/ByteArrayOutputStream.java new file mode 100644 index 0000000..35dc765 --- /dev/null +++ b/src/code/kalter/longflight/ByteArrayOutputStream.java @@ -0,0 +1,64 @@ +package code.kalter.longflight; + +/** + * Удобная запись разных типов в байтовый массив + * + * @author KalterFive + */ +public class ByteArrayOutputStream { + + private final byte[] array; + private int position; + + public ByteArrayOutputStream(int size) { + array = new byte[size]; + position = 0; + } + + public void writeByte(byte b) { + array[position++] = b; + } + + public void writeShort(short s) { + writeByte((byte) (s >> 8)); + writeByte((byte) s); + } + + public void writeInt(int i) { + writeShort((short) (i >> 16)); + writeShort((short) i); + } + + public void writeLong(long l) { + writeInt((int) (l >> 32)); + writeInt((int) l); + } + + public void writeByteArray(byte[] array, int length) { + for (int i = 0; i < length; i++) { + writeByte(array[i]); + } + } + + public void writeShortArray(short[] array, int length) { + for (int i = 0; i < length; i++) { + writeShort(array[i]); + } + } + + public void writeIntArray(int[] array, int length) { + for (int i = 0; i < length; i++) { + writeInt(array[i]); + } + } + + public void writeLongArray(long[] array, int length) { + for (int i = 0; i < length; i++) { + writeLong(array[i]); + } + } + + public byte[] toArray() { + return array; + } +} diff --git a/src/code/kalter/longflight/Color.java b/src/code/kalter/longflight/Color.java new file mode 100644 index 0000000..9440fa6 --- /dev/null +++ b/src/code/kalter/longflight/Color.java @@ -0,0 +1,20 @@ +package code.kalter.longflight; + +/** + * @author KalterFive + */ +public class Color { + + public static final int BLACK = 0x000000; + public static final int BLUE = 0x0000FF; + public static final int GREEN = 0x00FF00; + public static final int RED = 0xFF0000; + public static final int WHITE = 0xFFFFFF; + + public static int maskRGB(int r, int g, int b) { + return (r << 16) | (g << 8) | b; + } + + private Color() { + } +} diff --git a/src/code/kalter/longflight/EventListener.java b/src/code/kalter/longflight/EventListener.java new file mode 100644 index 0000000..f7c4ce9 --- /dev/null +++ b/src/code/kalter/longflight/EventListener.java @@ -0,0 +1,13 @@ +package code.kalter.longflight; + +/** + * Простое событие: событие и условие, при котором оно возбуждается + * + * @author KalterFive + */ +public interface EventListener { + + boolean is(); + + void event(); +} diff --git a/src/code/kalter/longflight/FPS.java b/src/code/kalter/longflight/FPS.java new file mode 100644 index 0000000..60b58e0 --- /dev/null +++ b/src/code/kalter/longflight/FPS.java @@ -0,0 +1,46 @@ +package code.kalter.longflight; + +/** + * Ограничитель кадров + * + * @author KalterFive + */ +public class FPS { + + private static FPS instance; + + public static FPS getInstance(int max) { + if (instance == null) { + instance = new FPS(max); + } + return instance; + } + + private long fpsTime; + private long fpsDt; + private int max; // кол-во кадров в секунду + + private FPS(int max) { + this.max = max; + this.fpsTime = System.currentTimeMillis(); + this.fpsDt = 1; + } + + // обновляет необходимые данные и возвращает текущий fps + public long process() { + long dt; + if ((dt = System.currentTimeMillis() - fpsTime) != 0) { + fpsDt = dt; + } + fpsTime = System.currentTimeMillis(); + return 1000 / fpsDt; + } + + // останавливает программу, пока скорость смены кадров больше заданной + public void max() { + long dt = System.currentTimeMillis() - fpsTime; + while (dt < max) { + dt = System.currentTimeMillis() - fpsTime; + } + } +} diff --git a/src/code/kalter/longflight/Font.java b/src/code/kalter/longflight/Font.java new file mode 100644 index 0000000..fe2655d --- /dev/null +++ b/src/code/kalter/longflight/Font.java @@ -0,0 +1,127 @@ +package code.kalter.longflight; + +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Костыль - и этим всё сказанно + * + * @author KalterFive + */ +public class Font { + + private static Font instance; + + public static Font getInstance() throws IOException { + if (instance == null) { + instance = new Font(); + } + return instance; + } + + private final Image[] ascii; + + private Font() throws IOException { + Image font = Loader.getInstance().getImage("/gfx/font.png"); + ascii = new Image[0x7F]; + int x = 0; + for (int i = 0x41; i <= 0x5A; i++, x += 5) { + ascii[i] = Image.createImage(font, x, 0, 5, 9, 0); + } + for (int i = 0x61; i <= 0x7A; i++, x += 5) { + ascii[i] = Image.createImage(font, x, 0, 5, 9, 0); + } + for (int i = 0x30; i <= 0x39; i++, x += 5) { + ascii[i] = Image.createImage(font, x, 0, 5, 9, 0); + } + ascii[0x21] = Image.createImage(font, x, 0, 5, 9, 0); + ascii[0x22] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x27] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x2C] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x2D] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x2E] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x3A] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x28] = Image.createImage(font, x += 5, 0, 5, 9, 0); + ascii[0x29] = Image.createImage(font, x += 5, 0, 4, 9, 0); + } + + public int getWidth(String text) { + return text.length() * 6; + } + + public void paint(Graphics graphics, String text, int x, int y) { + for (int i = 0, px = x; i < text.length(); i++) { + final char c = text.charAt(i); + switch (c) { + case '\r': + x = px; + break; + + case '\n': + y += 10; + break; + + case ' ': + x += 6; + break; + + default: + graphics.drawImage(ascii[c], x, y, 0); + x += 6; + break; + } + } + } + + public void paint(Graphics graphics, String text, + int x, int y, int width) { + String[] word = split(text); + int px = x; + for (int i = 0; i < word.length; i++) { + paint(graphics, word[i], px, y); + int length = (getWidth(word[i])) + 6; + if ((px += length) + length > width) { + px = x; + y += 10; + } + } + } + + public int getHeight(String text, int width) { + String[] word = split(text); + int result = 0; + for (int i = 0, x = 0; i < word.length; i++) { + int length = (getWidth(word[i])) + 6; + if ((x += length) + length > width) { + x = 0; + result += 10; + } + } + return result; + } + + private String[] split(String text) { + String[] result; + int length = 1; + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == ' ') { + length++; + } + } + result = new String[length]; + StringBuffer word = new StringBuffer(); + int j = 0; + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if (c == ' ') { + result[j++] = word.toString(); + word = new StringBuffer(); + } else { + word.append(c); + } + } + result[j] = word.toString(); + return result; + } +} diff --git a/src/code/kalter/longflight/Loader.java b/src/code/kalter/longflight/Loader.java new file mode 100644 index 0000000..25f5c3a --- /dev/null +++ b/src/code/kalter/longflight/Loader.java @@ -0,0 +1,71 @@ +package code.kalter.longflight; + +import code.kalter.longflight.crypto.CIStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Vector; +import javax.microedition.lcdui.Image; +import javax.microedition.media.Manager; +import javax.microedition.media.MediaException; +import javax.microedition.media.Player; + +/** + * Дабы избежать повторных загрузок из разных мест программы, а так же + * обеспечить загрузку с расшифкой создан это класс + * + * @author KalterFive + */ +public class Loader { + + private static final int KEY = 5; // шифровальный XOR ключ + + private static Loader instance; + + public static Loader getInstance() { + if (instance == null) { + instance = new Loader(); + } + return instance; + } + + private final Vector dump; // все успешно загруженные ресурсы + + private Loader() { + dump = new Vector(); + } + + public Object getObject(String path) { + Object result = null; + for (int i = 0; i < dump.size(); i++) { + ObjectItem item = (ObjectItem) dump.elementAt(i); + if (item.get(path) != null) { + result = item.get(path); + break; + } + } + return result; + } + + public Image getImage(String path) throws IOException { + Image result = (Image) getObject(path); + if (result == null) { + final InputStream istream = getClass().getResourceAsStream(path); + final InputStream cistream = new CIStream(istream, KEY); + result = Image.createImage(cistream); + cistream.close(); + dump.addElement(new ObjectItem(result, path)); + } + return result; + } + + public Player getPlayer(String path, String type) throws + IOException, MediaException { + Player result = (Player) getObject(path); + if (result == null) { + final InputStream iStream = getClass().getResourceAsStream(path); + result = Manager.createPlayer(iStream, type); + dump.addElement(new ObjectItem(result, path)); + } + return result; + } +} diff --git a/src/code/kalter/longflight/LongFlight.java b/src/code/kalter/longflight/LongFlight.java new file mode 100644 index 0000000..79a43d1 --- /dev/null +++ b/src/code/kalter/longflight/LongFlight.java @@ -0,0 +1,140 @@ +package code.kalter.longflight; + +import code.kalter.longflight.screen.About; +import code.kalter.longflight.screen.Crash; +import code.kalter.longflight.screen.EnableSound; +import code.kalter.longflight.screen.Game; +import code.kalter.longflight.screen.HighScore; +import code.kalter.longflight.screen.Loading; +import code.kalter.longflight.screen.Menu; +import code.kalter.longflight.screen.Pause; +import code.kalter.longflight.screen.Screen; +import code.kalter.longflight.screen.SelectShip; +import code.kalter.longflight.screen.Splash; +import java.io.IOException; +import javax.microedition.lcdui.Display; +import javax.microedition.media.MediaException; +import javax.microedition.midlet.MIDlet; + +/** + * Главный класс + * + * @author KalterFive + */ +public final class LongFlight extends MIDlet { + + public static LongFlight link; + + // screens + public static final int SPLASH = 0; + public static final int GAME = 1; + public static final int MENU = 2; + public static final int SELECT_SHIP = 3; + public static final int ABOUT = 4; + public static final int HIGH_SCORE = 5; + public static final int LOADING = 6; + public static final int PAUSE = 7; + public static final int ENABLE_SOUND = 8; + public static final int CRASH = 9; + + private Sound music; + private Screen[] screen; + private int screenID; + private int previosScreenID; + + public LongFlight() { + screenID = SPLASH; + link = this; + try { + screen = new Screen[]{ + new Splash(), + new Game(), + new Menu(), + new SelectShip(), + new About(), + new HighScore(), + new Loading(), + new Pause(), + new EnableSound(), + new Crash() + }; + } catch (Exception e) { + catchException(e); + } + } + + // override + public void startApp() { + Display.getDisplay(this).setCurrent(screen[ENABLE_SOUND]); + screen[ENABLE_SOUND].start(); + } + + // override + public void pauseApp() { + // TODO + } + + // override + public void destroyApp(boolean unconditional) { + try { + if (music != null) { + music.stop(); + } + } catch (MediaException e) { + catchException(e); + } + notifyDestroyed(); + } + + public void catchException(Exception e) { + if (screen != null) { + screen[screenID].stop(); + } + System.out.println(e.getMessage()); + e.printStackTrace(); + destroyApp(true); + } + + public void setScreen(int screenID) { + previosScreenID = this.screenID; + screen[this.screenID].stop(); + screen[screenID].start(); + this.screenID = screenID; + Display.getDisplay(this).setCurrent(screen[screenID]); + } + + // принудительно, то есть без остановки текущего + public void $setScreen(int screenID) { + previosScreenID = this.screenID; + screen[this.screenID = screenID].start(); + Display.getDisplay(this).setCurrent(screen[screenID]); + } + + public int getPreviosScreenID() { + return previosScreenID; + } + + // для облегчения жизни + public void sleep(long millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException interruptedException) { + catchException(interruptedException); + } + } + + public void playMusic() { + try { + music = new Sound() {{ + add("/song/monster.mid", "audio/midi"); + add("/song/mobscene.mid", "audio/midi"); + add("/song/iha.mid", "audio/midi"); + play(); + }}; + } catch (IOException e) { + catchException(e); + } catch (MediaException e) { + catchException(e); + } + } +} diff --git a/src/code/kalter/longflight/ObjectItem.java b/src/code/kalter/longflight/ObjectItem.java new file mode 100644 index 0000000..a452dad --- /dev/null +++ b/src/code/kalter/longflight/ObjectItem.java @@ -0,0 +1,26 @@ +package code.kalter.longflight; + +import java.io.IOException; + +/** + * Объект и путь к нему + * + * @author KalterFive + */ +public class ObjectItem { + + private final Object image; + private final String path; + + public ObjectItem(Object object, String path) throws IOException { + this.path = path; + this.image = object; + } + + public Object get(String path) { + if (this.path.equals(path)) { + return image; + } + return null; + } +} diff --git a/src/code/kalter/longflight/Pointer.java b/src/code/kalter/longflight/Pointer.java new file mode 100644 index 0000000..a343039 --- /dev/null +++ b/src/code/kalter/longflight/Pointer.java @@ -0,0 +1,59 @@ +package code.kalter.longflight; + +/** + * Координаты, нажатые и отпущенные на экране + * + * @author KalterFive + */ +public class Pointer { + + // нажатые координаты + private int xPressed; + private int yPressed; + + // отпущенные координаты + private int xReleased; + private int yReleased; + + public void setPressed(int xPressed, int yPressed) { + setXPressed(xPressed); + setYPressed(yPressed); + } + + public void setXPressed(int xPressed) { + this.xPressed = xPressed; + } + + public void setYPressed(int yPressed) { + this.yPressed = yPressed; + } + + public void setReleased(int xReleased, int yReleased) { + setXReleased(xReleased); + setYReleased(yReleased); + } + + public void setXReleased(int xReleased) { + this.xReleased = xReleased; + } + + public void setYReleased(int yReleased) { + this.yReleased = yReleased; + } + + public int getXPressed() { + return xPressed; + } + + public int getYPressed() { + return yPressed; + } + + public int getXReleased() { + return xReleased; + } + + public int getYReleased() { + return yReleased; + } +} diff --git a/src/code/kalter/longflight/Quote.java b/src/code/kalter/longflight/Quote.java new file mode 100644 index 0000000..e57a969 --- /dev/null +++ b/src/code/kalter/longflight/Quote.java @@ -0,0 +1,25 @@ +package code.kalter.longflight; + +/** + * Цитата и её автор + * + * @author KalterFive + */ +public class Quote { + + private final String quote; + private final String author; + + public Quote(String quote, String author) { + this.author = author; + this.quote = quote; + } + + public String getQuote() { + return quote; + } + + public String getAuthor() { + return "(c) " + author; + } +} diff --git a/src/code/kalter/longflight/Sound.java b/src/code/kalter/longflight/Sound.java new file mode 100644 index 0000000..9dbd3d3 --- /dev/null +++ b/src/code/kalter/longflight/Sound.java @@ -0,0 +1,85 @@ +package code.kalter.longflight; + +import java.io.IOException; +import java.util.Vector; +import javax.microedition.media.MediaException; +import javax.microedition.media.Player; +import javax.microedition.media.PlayerListener; + +/** + * Фоновая музыка: поочерёдное воспроизведение с цикличностью. Для создания + * необходимо применить трюк Double-Brace, где сначала нужно загрузить ресурсы, + * а после запустить + * + * @author KalterFive + */ +public class Sound { + + // вызывается для смены текущей мелодии + private final PlayerListener playerListener; + + { + playerListener = new PlayerListener() { + // override + public void playerUpdate(Player player, String event, + Object eventData) { + if (event.equals(PlayerListener.END_OF_MEDIA)) { + try { + player.stop(); + player.deallocate(); + play(); + } catch (MediaException e) { + LongFlight.link.catchException(e); + } + } + } + }; + } + + private final Vector dump; + private int active; + + public Sound() throws MediaException { + active = -1; + dump = new Vector(); + } + + // останавливает каждый плеер, освобождает ресурсы и закрывает + public void stop() throws MediaException { + for (int i = 0; i < dump.size(); i++) { + final Player player = (Player) dump.elementAt(i); + if (i == active) { + player.stop(); + player.deallocate(); + } + player.close(); + } + } + + /* + * Берёт из вектора следующий плеер, реализует, упреждает выборку, ставит + * воспроизведение на начало и включает + */ + protected void play() throws MediaException { + if (++active >= dump.size()) { + active = 0; + } + final Player player = (Player) dump.elementAt(active); + player.realize(); + player.prefetch(); + player.setMediaTime(0); + player.start(); + } + + // добавляет загруженный плеер в вектор - ничего более + protected void add(Player player) throws MediaException { + player.addPlayerListener(playerListener); + dump.addElement(player); + } + + protected void add(String path, String type) throws IOException, + MediaException { + final Loader loader = Loader.getInstance(); + add(loader.getPlayer(path, type)); + } +} diff --git a/src/code/kalter/longflight/Sprite.java b/src/code/kalter/longflight/Sprite.java new file mode 100644 index 0000000..bd05c7c --- /dev/null +++ b/src/code/kalter/longflight/Sprite.java @@ -0,0 +1,109 @@ +package code.kalter.longflight; + +import java.io.IOException; +import java.util.Vector; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Спрайт - основной графический элемент + * + * @author KalterFive + */ +public class Sprite { + + protected final Image image; + private int positionX; + private int positionY; + + // события + private Vector eventListener; + + public Sprite(Image image, int positionX, int positionY) { + this.image = image; + this.positionX = positionX; + this.positionY = positionY; + eventListener = new Vector(1); + } + + public Sprite(String path, int positionX, int positionY) + throws IOException { + this(Image.createImage(path), positionX, positionY); + } + + public void paint(Graphics graph) { + graph.drawImage(image, positionX, positionY, 0); + } + + public void addEvent(EventListener event) { + eventListener.addElement(event); + } + + // попытаться возбудить события + public void exciteEvent() { + for (int i = 0; i < eventListener.size(); i++) { + EventListener event = (EventListener) eventListener.elementAt(i); + if ((event != null) && (event.is())) { + event.event(); + } + } + } + + public EventListener getEvent(int number) + throws ArrayIndexOutOfBoundsException { + return (EventListener) eventListener.elementAt(number); + } + + // удалить событие без сдвига (то есть оnullить его) + public void removeEvent(int number) + throws ArrayIndexOutOfBoundsException { + eventListener.setElementAt(null, number); + } + + public boolean isEntrySet(int positionX, int positionY) { + return (positionX >= this.positionX) + && (positionX <= this.positionX + getWidth()) + && (positionY >= this.positionY) + && (positionY <= this.positionY + getHeight()); + } + + public void moveDown(int speed) { + positionY += speed; + } + + public void moveRight(int speed) { + positionX += speed; + } + + public void moveUp(int speed) { + moveDown(-speed); + } + + public void moveLeft(int speed) { + moveRight(-speed); + } + + public int getX() { + return positionX; + } + + public int getY() { + return positionY; + } + + public int getWidth() { + return image.getWidth(); + } + + public int getHeight() { + return image.getHeight(); + } + + protected void setX(int x) { + this.positionX = x; + } + + protected void setY(int y) { + this.positionY = y; + } +} diff --git a/src/code/kalter/longflight/StringReader.java b/src/code/kalter/longflight/StringReader.java new file mode 100644 index 0000000..4b8793c --- /dev/null +++ b/src/code/kalter/longflight/StringReader.java @@ -0,0 +1,70 @@ +package code.kalter.longflight; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Для удобного чтения строк и других типов из файла. Является не более, чем + * обёрткой для Inputstream + * + * @author KalterFive + */ +public class StringReader { + + private final InputStream inputStream; + + public StringReader(InputStream inputStream) { + this.inputStream = inputStream; + } + + public String nextString() throws IOException { + StringBuffer stringBuffer = new StringBuffer(); + int c = inputStream.read(); + while (c != '\r' && c != -1) { + stringBuffer.append((char) c); + c = inputStream.read(); + } + inputStream.read(); + return stringBuffer.toString(); + } + + // читает true or false + public boolean nextBool() throws IOException { + String line = nextString(); + if (line.equals("true")) { + return true; + } else if (line.equals("false")) { + return false; + } else { + throw new IllegalArgumentException(line); + } + } + + public byte nextByte() throws IOException { + return Byte.parseByte(nextString()); + } + + public short nextShort() throws IOException { + return Short.parseShort(nextString()); + } + + public int nextInt() throws IOException { + return Integer.parseInt(nextString()); + } + + public long nextLong() throws IOException { + return Long.parseLong(nextString()); + } + + public float nextFloat() throws IOException { + return Float.parseFloat(nextString()); + } + + public double nextDouble() throws IOException { + return Double.parseDouble(nextString()); + } + + public void close() throws IOException { + inputStream.close(); + } +} diff --git a/src/code/kalter/longflight/Time.java b/src/code/kalter/longflight/Time.java new file mode 100644 index 0000000..bed35f7 --- /dev/null +++ b/src/code/kalter/longflight/Time.java @@ -0,0 +1,52 @@ +package code.kalter.longflight; + +import java.util.Calendar; +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +/** + * Класс, определяющий текущее время (используется для вывода даты на экране) + * + * @author KalterFive + */ +public class Time extends TimerTask { + + private static Time instance; + + public static Time getInstance(int step) { + if (instance == null) { + instance = new Time(step); + } + return instance; + } + + private final Timer updating; + private String time; + + // step - шаг обновления даты + private Time(int step) { + time = "Long Flight"; + updating = new Timer(); + updating.schedule(this, 0, step); + } + + // override + public void run() { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date(System.currentTimeMillis())); + int minute = calendar.get(Calendar.MINUTE); + int hour = calendar.get(Calendar.HOUR); + int ampm = calendar.get(Calendar.AM_PM); + int day = calendar.get(Calendar.DAY_OF_MONTH); + int month = calendar.get(Calendar.MONTH) + 1; + int year = calendar.get(Calendar.YEAR) + 1000; + time = hour + ":" + minute + " " + (ampm == 1 ? "AM" : "PM") + " " + + day + "." + month + "." + year; + } + + // override + public String toString() { + return time; + } +} diff --git a/src/code/kalter/longflight/crypto/CIStream.java b/src/code/kalter/longflight/crypto/CIStream.java new file mode 100644 index 0000000..894f5d2 --- /dev/null +++ b/src/code/kalter/longflight/crypto/CIStream.java @@ -0,0 +1,37 @@ +package code.kalter.longflight.crypto; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Шифровальный входной поток (обёртка для InputStream). Дешифровка: + * xor -> xchgb + * + * @author KalterFive + */ +public class CIStream extends InputStream { + + private final InputStream istream; + private final Random random; + + // key - ключ для ГПСЧ + public CIStream(InputStream istream, int key) { + this.istream = istream; + this.random = new Random(key); + } + + public int read() throws IOException { + int b = istream.read(); + b ^= random.random(0xFF); + b = (b << 4) | (b >> 4); + return b; + } + + public int available() throws IOException { + return istream.available(); + } + + public void close() throws IOException { + istream.close(); + } +} diff --git a/src/code/kalter/longflight/crypto/Random.java b/src/code/kalter/longflight/crypto/Random.java new file mode 100644 index 0000000..63555f6 --- /dev/null +++ b/src/code/kalter/longflight/crypto/Random.java @@ -0,0 +1,31 @@ +package code.kalter.longflight.crypto; + +/** + * Простой Генератор Псевдослучайных Чисел + * + * @author KalterFive + */ +public class Random { + + private int next; + + public Random(int next) { + this.next = next; + } + + public Random() { + this((int) System.currentTimeMillis()); + } + + public int random() { + next ^= (next << 13); + next ^= (next >>> 17); + next ^= (next << 5); + return Math.abs(next); + } + + // random от [0] до [max - 1] + public int random(int max) { + return random() % max; + } +} diff --git a/src/code/kalter/longflight/game/Bullet.java b/src/code/kalter/longflight/game/Bullet.java new file mode 100644 index 0000000..18fdda8 --- /dev/null +++ b/src/code/kalter/longflight/game/Bullet.java @@ -0,0 +1,98 @@ +package code.kalter.longflight.game; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.game.bullet.Collisionable; +import code.kalter.longflight.game.bullet.Gun; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Пули! + * + * @author KalterFive + */ +public class Bullet implements Gun { + + private final int SIZE = 128; + private final int screenH; + + private final Image[] gfx; + + private final int[] positionX; + private final int[] positionY; + private final int[] type; + + private Collisionable[] object; + + public Bullet(int screenH) throws IOException { + this.screenH = screenH; + positionX = new int[SIZE]; + positionY = new int[SIZE]; + type = new int[SIZE]; + Loader imageLoader = Loader.getInstance(); + gfx = new Image[]{ + imageLoader.getImage("/gfx/bullet/0.png"), + imageLoader.getImage("/gfx/bullet/1.png") + }; + } + + // магия - все пули исчезают + public void setNull() { + for (int i = 0; i < SIZE; i++) { + type[i] = NULL; + } + } + + public void setCollisionable(Collisionable[] object) { + this.object = object; + } + + public void update() { + for (int i = 0; i < SIZE; i++) { + if (type[i] == NULL) { + continue; + } + collision(i); + positionY[i] += (type[i] * 2 - 1) * 5; + if ((positionY[i] < -10) || (positionY[i] > screenH)) { + type[i] = NULL; + } + } + } + + public void paint(Graphics graphics) { + for (int i = 0; i < SIZE; i++) { + if (type[i] == NULL) { + continue; + } + graphics.drawImage(gfx[type[i]], positionX[i], positionY[i], 0); + } + } + + // override + public void fire(int type, int positionX, int positionY) { + for (int i = 0; i < SIZE; i++) { + if (this.type[i] != NULL) { + continue; + } + this.type[i] = type; + this.positionX[i] = positionX; + this.positionY[i] = positionY; + break; + } + } + + private void collision(int i) { + for (int j = 0; j < object.length; j++) { + if (type[i] == object[j].getType()) { + continue; + } + if (object[j].isCollisionOfBullet(positionX[i], positionY[i])) { + object[j].boomOfBullet(); + type[i] = NULL; + break; + } + } + } +} diff --git a/src/code/kalter/longflight/game/ColorEffect.java b/src/code/kalter/longflight/game/ColorEffect.java new file mode 100644 index 0000000..ea92234 --- /dev/null +++ b/src/code/kalter/longflight/game/ColorEffect.java @@ -0,0 +1,41 @@ +package code.kalter.longflight.game; + +import javax.microedition.lcdui.Graphics; + +/** + * Цветовой эффект при попадании пули в игрока + * + * @author KalterFive + */ +public class ColorEffect { + + private final int screenW; + private final int screenH; + + private final int color; + //========================== + private final int number; // количество кадров для рисования цветного экрана + private int count; // счётчик + //========================== + private boolean is; + + public ColorEffect(int color, int number, int screenW, int screenH) { + this.color = color; + this.number = number; + this.screenW = screenW; + this.screenH = screenH; + } + + public void activate() { + is = true; + count = 0; + } + + public void paint(Graphics graphics) { + if (is) { + graphics.setColor(color); + graphics.fillRect(0, 0, screenW, screenH); + is = ++count < number; + } + } +} diff --git a/src/code/kalter/longflight/game/Enemy.java b/src/code/kalter/longflight/game/Enemy.java new file mode 100644 index 0000000..3e879c1 --- /dev/null +++ b/src/code/kalter/longflight/game/Enemy.java @@ -0,0 +1,232 @@ +package code.kalter.longflight.game; + +import code.kalter.longflight.game.bullet.Collisionable; +import code.kalter.longflight.game.bullet.Gun; +import code.kalter.longflight.game.explosion.Detonator; +import code.kalter.longflight.game.ship.Ship; +import code.kalter.longflight.game.ship.ShipEnemy; +import java.io.IOException; +import java.util.Random; +import java.util.Timer; +import java.util.TimerTask; +import javax.microedition.lcdui.Graphics; + +/** + * Враги и всё связанное с ними + * + * @author KalterFive + */ +public class Enemy implements Collisionable { + + private static final int COUNT = 28; + + // специальное обозначение для несуществующего врага + private static final int NULL = 666; + + private final int screenW; + private final int screenH; + + private final Gamer gamer; + private final Detonator detonator; + private final ShipEnemy ship; + private final Gun gun; + private final Random random; + private Timer createEnemy; + + // enemy... + private final int[] x; + private final int[] y; + private final int[] type; + private final int[] life; + private final long[] lastFire; + + private int score; + private int numKill; + private int boom; // индекс врага, в которого попала пуля + + public Enemy(int screenW, int screenH, Gun gun, + Detonator detonator, Gamer gamer) throws IOException { + this.screenW = screenW; + this.screenH = screenH; + this.gun = gun; + this.detonator = detonator; + this.gamer = gamer; + ship = ShipEnemy.getInstance(); + random = new Random(); + x = new int[COUNT]; + y = new int[COUNT]; + type = new int[COUNT]; + life = new int[COUNT]; + lastFire = new long[COUNT]; + } + + // очистка всех врагов + public void setNull() { + for (int i = 0; i < COUNT; i++) { + type[i] = NULL; + } + numKill = score = 0; + } + + public void update() { + for (int i = 0; i < COUNT; i++) { + if (type[i] == NULL) { + continue; + } + switch (type[i]) { + case Ship.LAX: + aiLax(i); + break; + + case Ship.POWERFUL: + aiPowerful(i); + break; + + case Ship.UNIVERSAL: + aiUniversal(i); + break; + + case Ship.STRONG: + aiStrong(i); + break; + } + } + } + + public void paint(Graphics graphics) { + for (int i = 0; i < COUNT; i++) { + if (type[i] == NULL) { + continue; + } + graphics.drawImage(ship.getImage(type[i]), x[i], y[i], 0); + } + } + + // override + public boolean isCollisionOfBullet(int bx, int by) { + for (int i = 0; i < COUNT; i++) { + if (type[i] == NULL) { + continue; + } + if ((bx > x[i]) && (bx < x[i] + Ship.SIZE) + && (by > y[i]) && (by < y[i] + Ship.SIZE)) { + boom = i; + return true; + } + } + return false; + } + + // override + public void boomOfBullet() { + if (--life[boom] <= 0) { + numKill++; + score += (((type[boom] + 1) * 2) - 1); + type[boom] = NULL; + detonator.activate(x[boom], y[boom]); + } + } + + // override + public int getType() { + return Gun.ENEMY; + } + + public void activateCreator() { + createEnemy = new Timer(); + createEnemy.schedule(new TimerTask() { + // override + public void run() { + for (int i = 0; i < COUNT; i++) { + if (type[i] != NULL) { + continue; + } + int type = random.nextInt(numKill / 30 + 1); + Enemy.this.type[i] = type >= Ship.COUNT ? Ship.COUNT - 1 : type < 0 ? 0 : type; + life[i] = ship.getLife(Enemy.this.type[i]); + lastFire[i] = System.currentTimeMillis(); + x[i] = random.nextInt(screenW - Ship.SIZE); + y[i] = -Ship.SIZE; + break; + } + } + }, 2500, 2500); + } + + public void deactivateCreator() { + createEnemy.cancel(); + } + + public int getScore() { + return score; + } + + private void aiLax(int i) { + y[i] += ship.getSpeed(type[i]); + if (y[i] > screenH) { + type[i] = NULL; + } + if (y[i] > gamer.getY()) { + return; + } + fire(i); + if (x[i] > gamer.getX()) { + x[i] -= ship.getSpeed(type[i]) / 2; + } + if (x[i] < gamer.getX()) { + x[i] += ship.getSpeed(type[i]) / 2; + } + } + + private void aiPowerful(int i) { + y[i] += ship.getSpeed(type[i]); + if (y[i] > screenH) { + type[i] = NULL; + } + if (y[i] > gamer.getY()) { + return; + } + fire(i); + } + + private void aiUniversal(int i) { + if (y[i] < screenH / 3) { + y[i] += ship.getSpeed(type[i]); + } + fire(i); + if (x[i] > gamer.getX()) { + x[i] -= ship.getSpeed(type[i]) / 2; + } + if (x[i] < gamer.getX()) { + x[i] += ship.getSpeed(type[i]) / 2; + } + } + + private void aiStrong(int i) { + y[i] += ship.getSpeed(type[i]); + if (y[i] > screenH) { + type[i] = NULL; + } + if (y[i] > gamer.getY()) { + return; + } + if (x[i] > gamer.getX()) { + x[i] -= ship.getSpeed(type[i]); + } + if (x[i] < gamer.getX()) { + x[i] += ship.getSpeed(type[i]); + } + final int deltaX = Math.abs(x[i] - gamer.getX()); + if (deltaX < Ship.SIZE * 2) { + fire(i); + } + } + + private void fire(int i) { + if (System.currentTimeMillis() - lastFire[i] > ship.getDeltaFire(type[i])) { + gun.fire(Gun.ENEMY, x[i] + 4, y[i] + 38); + gun.fire(Gun.ENEMY, x[i] + 30, y[i] + 38); + lastFire[i] = System.currentTimeMillis(); + } + } +} diff --git a/src/code/kalter/longflight/game/Gamer.java b/src/code/kalter/longflight/game/Gamer.java new file mode 100644 index 0000000..1fbc72a --- /dev/null +++ b/src/code/kalter/longflight/game/Gamer.java @@ -0,0 +1,206 @@ +package code.kalter.longflight.game; + +import code.kalter.longflight.ByteArrayInputStream; +import code.kalter.longflight.Color; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.game.bullet.Collisionable; +import code.kalter.longflight.game.bullet.Gun; +import code.kalter.longflight.game.explosion.Detonator; +import code.kalter.longflight.game.ship.Ship; +import code.kalter.longflight.game.ship.ShipGamer; +import code.kalter.longflight.rms.RMS; +import code.kalter.longflight.screen.Game; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; +import javax.microedition.rms.RecordStoreException; + +/** + * Игрок, и всё связанное с ним + * + * @author KalterFive + */ +public class Gamer implements Collisionable { + + private final int screenW; + private final int screenH; + + private final Image nozzle; + + private final ColorEffect colorEffect; + private final Detonator detonator; + private final ShipGamer ship; + private final Gun gun; + private boolean alive; + private int overheat; + private int type; + private int life; + private int speedX; + private int speedY; + private int positionX; + private int positionY; + + private long lastFireTime; + + public Gamer(int screenW, int screenH, Gun gun, Detonator detonator) + throws IOException { + this.screenW = screenW; + this.screenH = screenH; + this.gun = gun; + this.detonator = detonator; + this.colorEffect = new ColorEffect(Color.WHITE, 2, screenW, screenH); + ship = ShipGamer.getInstance(); + Loader imageLoader = Loader.getInstance(); + nozzle = imageLoader.getImage("/gfx/ship/nozzle.png"); + } + + // ставим игрока на своё место + public void setNull() { + alive = true; + lastFireTime = System.currentTimeMillis(); + speedX = speedY = 0; + overheat = 0; + positionX = (screenW - Ship.SIZE) / 2; + positionY = screenH - 80; + try { + RMS rms = new RMS("longflight", true); + ByteArrayInputStream byteReader = rms.get(1); + type = byteReader.readByte(); + rms.close(); + } catch (RecordStoreException e) { + LongFlight.link.catchException(e); + } + life = ship.getLife(type); + } + + public void paint(Graphics graphics) { + if (alive) { + graphics.drawImage(ship.getImage(type), positionX, positionY, 0); + } + if (speedY < 0) { + graphics.drawImage(nozzle, positionX + 16, positionY + 36, 0); + } + colorEffect.paint(graphics); + } + + public void update() { + // охлаждение + overheat -= overheat > 0 ? 1 : 0; + + // перемещение + positionX += speedX / ship.getTime(type); + positionY += speedY / ship.getTime(type); + + // ограничение перемещения + // position x + if (positionX < 0) { + positionX = 0; + } else if (positionX > screenW - Ship.SIZE) { + positionX = screenW - Ship.SIZE; + } + // position y + if (positionY < 18) { + positionY = 18; + } else if (positionY > screenH - Ship.SIZE - 22) { + positionY = screenH - Ship.SIZE - 22; + } + + // ускорение стремится к нулю + speedX = speedX < 0 ? ++speedX : speedX > 0 ? --speedX : speedX; + speedY = speedY < 0 ? ++speedY : speedY > 0 ? --speedY : speedY; + } + + // override + public boolean isCollisionOfBullet(int bx, int by) { + return alive && bx > positionX && bx < positionX + Ship.SIZE && by > positionY && by < positionY + Ship.SIZE; + } + + // override + public void boomOfBullet() { + if (alive) { + colorEffect.activate(); + if (--life < 0) { + alive = false; + Game.link.stop(); + detonator.activate(positionX, positionY); + } + } + } + + // override + public int getType() { + return Gun.GAMER; + } + + public void moveLeft() { + speedX -= ship.getAcceleration(type); + if (speedX < (-ship.getVelocityMax(type))) { + speedX = (-ship.getVelocityMax(type)); + } + } + + public void moveRight() { + speedX += ship.getAcceleration(type); + if (speedX > ship.getVelocityMax(type)) { + speedX = ship.getVelocityMax(type); + } + } + + public void moveUp() { + speedY -= ship.getAcceleration(type); + if (speedY < (-ship.getVelocityMax(type))) { + speedY = (-ship.getVelocityMax(type)); + } + } + + public void moveDown() { + speedY += ship.getAcceleration(type); + if (speedY > ship.getVelocityMax(type)) { + speedY = ship.getVelocityMax(type); + } + } + + public void fire() { + overheat += overheat < 160 ? ship.getSpeedOverheat(type) : 0; + if (!isGetFire()) { + return; + } + gun.fire(Gun.GAMER, getX() + 4, getY()); + gun.fire(Gun.GAMER, getX() + 30, getY()); + } + + public int getX() { + return positionX; + } + + public int getY() { + return positionY; + } + + public int getSpeedX() { + return speedX; + } + + public int getSpeedY() { + return speedY; + } + + private boolean isGetFire() { + boolean result = false; + if (System.currentTimeMillis() - lastFireTime > ship.getDeltaFire(type)) { + lastFireTime = System.currentTimeMillis(); + result = true; + } + return result && overheat < 160; + } + + public int getLife() { + return life * 4; + } + + public int getOverheat() { + int result = overheat / 3; + return result > 48 ? 48 : result; + } +} diff --git a/src/code/kalter/longflight/game/bullet/Collisionable.java b/src/code/kalter/longflight/game/bullet/Collisionable.java new file mode 100644 index 0000000..b7d695b --- /dev/null +++ b/src/code/kalter/longflight/game/bullet/Collisionable.java @@ -0,0 +1,20 @@ +package code.kalter.longflight.game.bullet; + +/** + * Для проверки столновений пуль с объектами + * + * @author KalterFive + */ +public interface Collisionable { + + int UP = 0; + int DOWN = 1; + int LEFT = 2; + int RIGHT = 3; + + boolean isCollisionOfBullet(int x, int y); + + int getType(); + + void boomOfBullet(); +} diff --git a/src/code/kalter/longflight/game/bullet/Gun.java b/src/code/kalter/longflight/game/bullet/Gun.java new file mode 100644 index 0000000..4d4625a --- /dev/null +++ b/src/code/kalter/longflight/game/bullet/Gun.java @@ -0,0 +1,15 @@ +package code.kalter.longflight.game.bullet; + +/** + * Интерфейс для Bullet для стрельбы врагов + * + * @author KalterFive + */ +public interface Gun { + + int GAMER = 0; + int ENEMY = 1; + int NULL = 666; + + void fire(int t, int x, int y); +} diff --git a/src/code/kalter/longflight/game/explosion/Detonator.java b/src/code/kalter/longflight/game/explosion/Detonator.java new file mode 100644 index 0000000..10e23b2 --- /dev/null +++ b/src/code/kalter/longflight/game/explosion/Detonator.java @@ -0,0 +1,11 @@ +package code.kalter.longflight.game.explosion; + +/** + * Взрыватель! + * + * @author KalterFive + */ +public interface Detonator { + + void activate(int x, int y); +} diff --git a/src/code/kalter/longflight/game/explosion/Explosion.java b/src/code/kalter/longflight/game/explosion/Explosion.java new file mode 100644 index 0000000..7d82a2f --- /dev/null +++ b/src/code/kalter/longflight/game/explosion/Explosion.java @@ -0,0 +1,70 @@ +package code.kalter.longflight.game.explosion; + +import code.kalter.longflight.Animation; +import code.kalter.longflight.Loader; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Не приблежаться, рванёт! + * + * @author KalterFive + */ +public class Explosion implements Detonator { + + public static Explosion createExplosion(String path) throws IOException { + final Loader loader = Loader.getInstance(); + final Image image = loader.getImage(path); + return createExplosion(image); + } + + public static Explosion createExplosion(Image image) { + return new Explosion(image); + } + + private static final int MAX = 5; + private final Animation[] boom; + private final int[] positionX; + private final int[] positionY; + + // каждый кадр должен быть квадратным + private Explosion(Image explosion) { + boom = new Animation[MAX]; + positionX = new int[MAX]; + positionY = new int[MAX]; + for (int i = 0; i < MAX; i++) { + boom[i] = Animation.createAnimation(explosion, + explosion.getHeight(), 80); + } + } + + public void deactivateAll() { + for (int i = 0; i < boom.length; i++) { + boom[i].stop(); + } + } + + public void activate(int x, int y) { + for (int i = 0; i < boom.length; i++) { + if (!boom[i].getState()) { + boom[i].start(); + this.positionX[i] = x; + this.positionY[i] = y; + break; + } + } + } + + public void paint(Graphics graphics) { + for (int i = 0; i < boom.length; i++) { + boom[i].paint(graphics, positionX[i], positionY[i]); + } + } + + public void update() { + for (int i = 0; i < boom.length; i++) { + boom[i].next(); + } + } +} diff --git a/src/code/kalter/longflight/game/ship/Ship.java b/src/code/kalter/longflight/game/ship/Ship.java new file mode 100644 index 0000000..f01dbd6 --- /dev/null +++ b/src/code/kalter/longflight/game/ship/Ship.java @@ -0,0 +1,17 @@ +package code.kalter.longflight.game.ship; + +/** + * Основные константы: типы, количество типов, размер w|h квадратного (!) + * кораблика + * + * @author KalterFive + */ +public interface Ship { + + int COUNT = 4; + int SIZE = 40; + int LAX = 0; + int POWERFUL = 1; + int UNIVERSAL = 2; + int STRONG = 3; +} diff --git a/src/code/kalter/longflight/game/ship/ShipEnemy.java b/src/code/kalter/longflight/game/ship/ShipEnemy.java new file mode 100644 index 0000000..529cc54 --- /dev/null +++ b/src/code/kalter/longflight/game/ship/ShipEnemy.java @@ -0,0 +1,87 @@ +package code.kalter.longflight.game.ship; + +import code.kalter.longflight.Loader; +import java.io.IOException; +import javax.microedition.lcdui.Image; +import javax.microedition.lcdui.game.Sprite; + +/** + * Свойства всех корабликов врага + * + * @author KalterFive + */ +public class ShipEnemy implements Ship { + + private static ShipEnemy instance; + + public static ShipEnemy getInstance() throws IOException { + if (instance == null) { + instance = new ShipEnemy(); + } + return instance; + } + + private final int[] deltaFire; + private final int[] life; + private final int[] speed; + private final Image[] image; + + private ShipEnemy() throws IOException { + deltaFire = new int[4]; + life = new int[4]; + speed = new int[4]; + image = new Image[4]; + + Loader imageLoader = Loader.getInstance(); + + //TYPE: LAX + deltaFire[LAX] = 2000; + life[LAX] = 3; + speed[LAX] = 2; + image[LAX] = imageLoader.getImage("/gfx/ship/" + LAX + ".png"); + image[LAX] = Image.createImage(image[LAX], 0, 0, 40, 40, + Sprite.TRANS_MIRROR_ROT180); + + //TYPE: POWERFUL + deltaFire[POWERFUL] = 3000; + life[POWERFUL] = 6; + speed[POWERFUL] = 1; + image[POWERFUL] = imageLoader.getImage("/gfx/ship/" + POWERFUL + + ".png"); + image[POWERFUL] = Image.createImage(image[POWERFUL], 0, 0, 40, 40, + Sprite.TRANS_MIRROR_ROT180); + + //TYPE: UNIVERSAL + deltaFire[UNIVERSAL] = 3000; + life[UNIVERSAL] = 3; + speed[UNIVERSAL] = 2; + image[UNIVERSAL] = imageLoader.getImage("/gfx/ship/" + UNIVERSAL + + ".png"); + image[UNIVERSAL] = Image.createImage(image[UNIVERSAL], 0, 0, 40, 40, + Sprite.TRANS_MIRROR_ROT180); + + //TYPE: STRONG + deltaFire[STRONG] = 1500; + life[STRONG] = 6; + speed[STRONG] = 1; + image[STRONG] = imageLoader.getImage("/gfx/ship/" + STRONG + ".png"); + image[STRONG] = Image.createImage(image[STRONG], 0, 0, 40, 40, + Sprite.TRANS_MIRROR_ROT180); + } + + public int getDeltaFire(int type) { + return deltaFire[type]; + } + + public int getLife(int type) { + return life[type]; + } + + public int getSpeed(int type) { + return speed[type]; + } + + public Image getImage(int type) { + return image[type]; + } +} diff --git a/src/code/kalter/longflight/game/ship/ShipGamer.java b/src/code/kalter/longflight/game/ship/ShipGamer.java new file mode 100644 index 0000000..bcfc92d --- /dev/null +++ b/src/code/kalter/longflight/game/ship/ShipGamer.java @@ -0,0 +1,109 @@ +package code.kalter.longflight.game.ship; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import java.io.IOException; +import javax.microedition.lcdui.Image; + +/** + * Все свойства корабликов игрока + * + * @author KalterFive + */ +public class ShipGamer implements Ship { + + private static ShipGamer instance; + + public static ShipGamer getInstance() throws IOException { + if (instance == null) { + instance = new ShipGamer(); + } + return instance; + } + + private final int[] life; + private final int[] time; + private final int[] acceleration; + private final int[] velocityMax; + private final int[] deltaFire; + private final int[] speedOverheat; + private final Image[] image; + + public ShipGamer() throws IOException { + life = new int[COUNT]; + time = new int[COUNT]; + acceleration = new int[COUNT]; + velocityMax = new int[COUNT]; + deltaFire = new int[COUNT]; + speedOverheat = new int[COUNT]; + image = new Image[COUNT]; + + Loader imageLoader = Loader.getInstance(); + + //TYPE: LAX + life[LAX] = 3; + time[LAX] = 2; + acceleration[LAX] = 2; + velocityMax[LAX] = 6; + deltaFire[LAX] = 250; + speedOverheat[LAX] = 4; + image[LAX] = imageLoader.getImage("/gfx/ship/" + LAX + ".png"); + + //TYPE: POWERFUL + life[POWERFUL] = 10; + time[POWERFUL] = 2; + acceleration[POWERFUL] = 2; + velocityMax[POWERFUL] = 4; + deltaFire[POWERFUL] = 300; + speedOverheat[POWERFUL] = 4; + image[POWERFUL] = imageLoader.getImage("/gfx/ship/" + POWERFUL + + ".png"); + + //TYPE: UNIVERSAL + life[UNIVERSAL] = 5; + time[UNIVERSAL] = 2; + acceleration[UNIVERSAL] = 2; + velocityMax[UNIVERSAL] = 8; + deltaFire[UNIVERSAL] = 200; + speedOverheat[UNIVERSAL] = 4; + image[UNIVERSAL] = imageLoader.getImage("/gfx/ship/" + UNIVERSAL + + ".png"); + + //TYPE: STRONG + life[STRONG] = 6; + time[STRONG] = 4; + acceleration[STRONG] = 4; + velocityMax[STRONG] = 24; + deltaFire[STRONG] = 200; + speedOverheat[STRONG] = 4; + image[STRONG] = imageLoader.getImage("/gfx/ship/" + STRONG + ".png"); + } + + public int getLife(int type) { + return life[type]; + } + + public int getTime(int type) { + return time[type]; + } + + public int getAcceleration(int type) { + return acceleration[type]; + } + + public int getVelocityMax(int type) { + return velocityMax[type]; + } + + public int getDeltaFire(int type) { + return deltaFire[type]; + } + + public int getSpeedOverheat(int type) { + return speedOverheat[type]; + } + + public Image getImage(int type) { + return image[type]; + } +} diff --git a/src/code/kalter/longflight/rms/RMS.java b/src/code/kalter/longflight/rms/RMS.java new file mode 100644 index 0000000..c64d97a --- /dev/null +++ b/src/code/kalter/longflight/rms/RMS.java @@ -0,0 +1,50 @@ +package code.kalter.longflight.rms; + +import code.kalter.longflight.ByteArrayInputStream; +import code.kalter.longflight.ByteArrayOutputStream; +import javax.microedition.rms.InvalidRecordIDException; +import javax.microedition.rms.RecordStore; +import javax.microedition.rms.RecordStoreException; + +/** + * Удобная работа с RMS + * + * @author KalterFive + */ +public class RMS { + + public final RecordStore recordStore; + + public RMS(String name, boolean createIfRecordStoreNotFound) + throws RecordStoreException { + recordStore = RecordStore.openRecordStore(name, + createIfRecordStoreNotFound); + } + + public ByteArrayInputStream get(int id) throws RecordStoreException, + RecordNotFoundException { + if (recordStore.getNumRecords() < id) { + throw new RecordNotFoundException(); + } + return new ByteArrayInputStream(recordStore.getRecord(id)); + } + + /* + * Если запись с номером не будет найдена, то массив байтов запишется в + * новую запись, после последней + */ + public void put(int id, ByteArrayOutputStream bytes) + throws RecordStoreException { + final byte[] array = bytes.toArray(); + final int length = array.length; + try { + recordStore.setRecord(id, array, 0, length); + } catch (InvalidRecordIDException e) { + recordStore.addRecord(array, 0, length); + } + } + + public void close() throws RecordStoreException { + recordStore.closeRecordStore(); + } +} diff --git a/src/code/kalter/longflight/rms/RecordNotFoundException.java b/src/code/kalter/longflight/rms/RecordNotFoundException.java new file mode 100644 index 0000000..e0cc709 --- /dev/null +++ b/src/code/kalter/longflight/rms/RecordNotFoundException.java @@ -0,0 +1,11 @@ +package code.kalter.longflight.rms; + +import javax.microedition.rms.RecordStoreException; + +/** + * Формируется в случае, если в хранилище ну будет найдена искомая запись + * + * @author KalterFive + */ +public class RecordNotFoundException extends RecordStoreException { +} diff --git a/src/code/kalter/longflight/screen/About.java b/src/code/kalter/longflight/screen/About.java new file mode 100644 index 0000000..92ef50f --- /dev/null +++ b/src/code/kalter/longflight/screen/About.java @@ -0,0 +1,139 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import javax.microedition.lcdui.Image; + +/** + * Экран информации об игре + * + * @author Kalter + */ +public class About extends Screen { + + private final Sprite window; + private final Sprite leftSoft; + private final Sprite rightSoft; + private final Image downPanel; + + public About() throws IOException { + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/about/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + window.addEvent(new EventListener() { + // override + public boolean is() { + return window.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + setScreenMenu(); + } + }); + + // left soft + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + setScreenMenu(); + } + }); + + // right soft + Image rightSoftImage = loader.getImage("/gfx/awt/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + setScreenMenu(); + } + }); + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + } + + // override + public void start() { + setDate(39, screenH - 9); + super.start(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case FIRE: + keyCode = RIGHT_SOFT; + break; + } + switch (keyCode) { + case RIGHT_SOFT: + case LEFT_SOFT: + setScreenMenu(); + break; + } + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + leftSoft.exciteEvent(); + rightSoft.exciteEvent(); + window.exciteEvent(); + } + + private void setScreenMenu() { + LongFlight.link.setScreen(LongFlight.MENU); + } + + private void update() { + space.update(); + } + + private void paint() { + space.paint(graphics); + window.paint(graphics); + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(downPanel, i, screenH - 18, 0); + } + leftSoft.paint(graphics); + rightSoft.paint(graphics); + paintDate(); + flushGraphics(); + } +} diff --git a/src/code/kalter/longflight/screen/Crash.java b/src/code/kalter/longflight/screen/Crash.java new file mode 100644 index 0000000..0129813 --- /dev/null +++ b/src/code/kalter/longflight/screen/Crash.java @@ -0,0 +1,127 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import javax.microedition.lcdui.Image; + +/** + * Экран информации о уничтожении + * + * @author Kalter + */ +public class Crash extends Screen { + + private final Sprite window; + private final Sprite leftSoft; + private final Sprite rightSoft; + private final Image downPanel; + + public Crash() throws IOException { + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/crash/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + // здесь для окошка не обрабатываются события + + // right soft + Image rightSoftImage = loader.getImage("/gfx/awt/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + keyPressed(LEFT_SOFT); + } + }); + + //left soft + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + keyPressed(LEFT_SOFT); + } + }); + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + } + + // override + public void start() { + setDate(39, screenH - 9); + super.start(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case FIRE: + keyCode = LEFT_SOFT; + break; + } + switch (keyCode) { + case LEFT_SOFT: + case RIGHT_SOFT: + LongFlight.link.setScreen(LongFlight.MENU); + break; + } + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + window.exciteEvent(); + rightSoft.exciteEvent(); + leftSoft.exciteEvent(); + } + + private void update() { + space.update(); + Game.link.updateElements(); + } + + private void paint() { + space.paint(graphics); + Game.link.paintElements(graphics); + window.paint(graphics); + for (int i = 0; i < screenW; i += downPanel.getWidth()) { + graphics.drawImage(downPanel, i, screenH - downPanel.getHeight(), 0); + } + leftSoft.paint(graphics); + rightSoft.paint(graphics); + paintDate(); + flushGraphics(); + } +} diff --git a/src/code/kalter/longflight/screen/EnableSound.java b/src/code/kalter/longflight/screen/EnableSound.java new file mode 100644 index 0000000..b8b3773 --- /dev/null +++ b/src/code/kalter/longflight/screen/EnableSound.java @@ -0,0 +1,213 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import javax.microedition.lcdui.Image; + +/** + * Включение / не включение звука + * + * @author KalterFive + */ +public class EnableSound extends Screen { + + private static final int COUNT = 2; // of choise + + private static final int YES = 0; + private static final int NO = 1; + + private int position; + private final Sprite window; + private final Sprite leftSoft; + private final Sprite[] choise; + private final Sprite[] selectChoise; + private final Image downPanel; + + public EnableSound() throws IOException { + position = 0; + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/enable_sound/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + + // left panel + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + leftSoftPressed(); + } + }); + + // choises + Image choiseCrop = loader.getImage("/gfx/enable_sound/choise.png"); + choise = new Sprite[COUNT]; + selectChoise = new Sprite[COUNT]; + for (int i = 0; i < COUNT; i++) { + // choise + Image c = Image.createImage(choiseCrop, 0, i * 22, 102, 22, 0); + int choiseX = (screenW - 102) / 2; + int choiseY = window.getY() + 51 + i * 24; + choise[i] = new Sprite(c, choiseX, choiseY); + + // selectchoise + Image sc = Image.createImage(choiseCrop, 102, i * 22, 102, 22, 0); + int selectChoiseX = choise[i].getX(); + int selectChoiseY = choise[i].getY(); + selectChoise[i] = new Sprite(sc, selectChoiseX, selectChoiseY); + } + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + + // adding event listener for choise about of "yes" + choise[YES].addEvent(new EventListener() { + // override + public boolean is() { + return choise[YES].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + yes(); + } + }); + selectChoise[YES].addEvent(choise[YES].getEvent(0)); + + // adding event listener for choise about of "no" + choise[NO].addEvent(new EventListener() { + // override + public boolean is() { + return choise[NO].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + no(); + } + }); + selectChoise[NO].addEvent(choise[NO].getEvent(0)); + } + + // override + public void start() { + setDate(39, screenH - 9); + super.start(); + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + leftSoft.exciteEvent(); + choise[YES].exciteEvent(); + choise[NO].exciteEvent(); + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case UP: + upPressed(); + break; + + case DOWN: + downPressed(); + break; + + case FIRE: + firePressed(); + break; + } + switch (keyCode) { + case LEFT_SOFT: + leftSoftPressed(); + break; + } + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + LongFlight.link.setScreen(LongFlight.SPLASH); + } + + private void paint() { + space.paint(graphics); + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(downPanel, i, screenH - 18, 0); + } + paintDate(); + leftSoft.paint(graphics); + window.paint(graphics); + for (int i = 0; i < COUNT; i++) { + if (position == i) { + selectChoise[i].paint(graphics); + } else { + choise[i].paint(graphics); + } + } + flushGraphics(); + } + + private void update() { + space.update(); + } + + private void leftSoftPressed() { + firePressed(); + } + + private void upPressed() { + if (--position < 0) { + position = 0; + } + } + + private void downPressed() { + if (++position >= COUNT) { + position = COUNT - 1; + } + } + + private void firePressed() { + switch (position) { + case YES: + yes(); + break; + + case NO: + no(); + break; + } + } + + private void yes() { + choise[YES].removeEvent(0); + LongFlight.link.playMusic(); + stop(); + } + + private void no() { + stop(); + } +} diff --git a/src/code/kalter/longflight/screen/Game.java b/src/code/kalter/longflight/screen/Game.java new file mode 100644 index 0000000..905440c --- /dev/null +++ b/src/code/kalter/longflight/screen/Game.java @@ -0,0 +1,345 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.Arrays; +import code.kalter.longflight.ByteArrayOutputStream; +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import code.kalter.longflight.game.Bullet; +import code.kalter.longflight.game.Enemy; +import code.kalter.longflight.game.Gamer; +import code.kalter.longflight.game.bullet.Collisionable; +import code.kalter.longflight.game.explosion.Explosion; +import code.kalter.longflight.rms.RMS; +import code.kalter.longflight.rms.RecordNotFoundException; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; +import javax.microedition.rms.RecordStoreException; + +/** + * Игровой экран. Остаётся активным во время паузы и информации о уничтожении. В + * меню паузы происходит отрисовка элементов (см. метод + * paintElements), а в меню информации о уничтожении происходит и + * отрисовка (см. метод updateElements), и обновление, но без + * создания новых врагов + * + * @author KalterFive + */ +public class Game extends Screen { + + public static Game link; + + // keys + private boolean up; + private boolean down; + private boolean left; + private boolean right; + private boolean fire; + private boolean pointerPressed; + + private final Gamer gamer; + private final Bullet bullet; + private final Enemy enemy; + private final Explosion explosion; + + private final Sprite rightSoft; + private final Sprite lifeStatus; + private final Sprite overheatStatus; + private final Image downPanel; + private final Image upPanel; + + private boolean isPause; // для проверки на переход в меню паузы + + public Game() throws IOException { + explosion = Explosion.createExplosion("/gfx/boom.png"); + bullet = new Bullet(screenH); + gamer = new Gamer(screenW, screenH, bullet, explosion); + enemy = new Enemy(screenW, screenH, bullet, explosion, gamer); + bullet.setCollisionable(new Collisionable[]{gamer, enemy}); + + Loader loader = Loader.getInstance(); + + // right soft + Image rightSoftImage = loader.getImage("/gfx/game/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + rightSoftPressed(); + } + }); + + // life status + Image lifeStatusImage = loader.getImage("/gfx/game/life.png"); + int lifeStatusX = 2; + int lifeStatusY = screenH - 20; + lifeStatus = new Sprite(lifeStatusImage, lifeStatusX, lifeStatusY); + + // overheat status + Image overheatStatusImage = loader.getImage("/gfx/game/overheat.png"); + int overheatStatusX = screenW - overheatStatusImage.getWidth() - 2; + int overheatStatusY = screenH - 20; + overheatStatus = new Sprite(overheatStatusImage, + overheatStatusX, overheatStatusY); + + // up & down panel + downPanel = loader.getImage("/gfx/game/down_panel.png"); + upPanel = loader.getImage("/gfx/game/up_panel.png"); + + link = this; + } + + // override + public void start() { + try { + up = down = right = left = fire = pointerPressed = false; + enemy.activateCreator(); + if (isPause) { + isPause = false; + return; + } + explosion.deactivateAll(); + gamer.setNull(); + bullet.setNull(); + enemy.setNull(); + setDate(2, screenH - 9); + } catch (Exception e) { + LongFlight.link.catchException(e); + } finally { + isPause = false; + super.start(); + } + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + paint(); + checkKey(); + update(); + LongFlight.link.sleep(20); + fps.max(); + } + if (isPause) { + return; + } + LongFlight.link.$setScreen(LongFlight.CRASH); + } + + // override + public void keyPressed(int keyCode) { + switch (keyCode) { + case RIGHT_SOFT: + setPauseScreen(); + break; + } + switch (getGameAction(keyCode)) { + case UP: + up = true; + break; + + case DOWN: + down = true; + break; + + case LEFT: + left = true; + break; + + case RIGHT: + right = true; + break; + + case FIRE: + fire = true; + break; + } + } + + // override + public void keyReleased(int keyCode) { + switch (getGameAction(keyCode)) { + case UP: + up = false; + break; + + case DOWN: + down = false; + break; + + case LEFT: + left = false; + break; + + case RIGHT: + right = false; + break; + + case FIRE: + fire = false; + break; + } + } + + // override + public void pointerReleased(int x, int y) { + pointerPressed = false; + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + rightSoft.exciteEvent(); + pointerPressed = true; + } + + // override + public void stop() { + enemy.deactivateCreator(); + super.stop(); + } + + public Explosion getExplosion() { + return explosion; + } + + public void setNullPause() { + isPause = false; + } + + public void save() { + final int score = enemy.getScore(); + try { + final RMS rms = new RMS("longflight", true); + try { + final int[] record = rms.get(2).toIntArray(5); + for (int i = 0; i < 5; i++) { + if (score > record[i]) { + Arrays.insertShiftRight(record, score, i); + break; + } + } + saveRecord(rms, record); + } catch (RecordNotFoundException e) { + saveRecord(rms, new int[]{score, 0, 0, 0, 0}); + } + rms.close(); + } catch (RecordStoreException e) { + LongFlight.link.catchException(e); + } + } + + private void rightSoftPressed() { + setPauseScreen(); + } + + private void checkKey() { + if (pointerPressed) { + if (isPointerUp()) { + gamer.moveUp(); + } + if (isPointerDown()) { + gamer.moveDown(); + } + if (isPointerLeft()) { + gamer.moveLeft(); + } + if (isPointerRight()) { + gamer.moveRight(); + } + if (isPointerFire()) { + gamer.fire(); + } + } + if (up) { + gamer.moveUp(); + } + if (down) { + gamer.moveDown(); + } + if (left) { + gamer.moveLeft(); + } + if (right) { + gamer.moveRight(); + } + if (fire) { + gamer.fire(); + } + } + + private void update() { + updateElements(); + space.update(); + } + + private void paint() { + space.paint(graphics); + paintElements(graphics); + paintGui(); + flushGraphics(); + } + + public void updateElements() { + gamer.update(); + bullet.update(); + enemy.update(); + explosion.update(); + } + + public void paintElements(Graphics graphics) { + enemy.paint(graphics); + gamer.paint(graphics); + bullet.paint(graphics); + explosion.paint(graphics); + } + + private void paintGui() { + // up & down panel + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(upPanel, i, 0, 0); + graphics.drawImage(downPanel, i, screenH - 27, 0); + } + overheatStatus.paint(graphics); + lifeStatus.paint(graphics); + rightSoft.paint(graphics); + paintDate(); + + // score + font.paint(graphics, "Score: " + enemy.getScore(), 2, 2); + + // life + graphics.setColor(0xBF0B10); + graphics.fillRect(4, screenH - 19, gamer.getLife(), 2); + graphics.setColor(0x001A27); + graphics.fillRect(4 + gamer.getLife(), screenH - 19, 1, 2); + + // overheat + graphics.setColor(0xBFCA10); + graphics.fillRect(screenW - 52, screenH - 19, gamer.getOverheat(), 2); + graphics.setColor(0x001A27); + graphics.fillRect(screenW - 52 + gamer.getOverheat(), screenH - 19, + 1, 2); + } + + private void setPauseScreen() { + isPause = true; + LongFlight.link.setScreen(LongFlight.PAUSE); + } + + private void saveRecord(RMS rms, int[] record) throws RecordStoreException { + final ByteArrayOutputStream byteWriter = new ByteArrayOutputStream(20); + byteWriter.writeIntArray(record, 5); + rms.put(2, byteWriter); + } +} diff --git a/src/code/kalter/longflight/screen/HighScore.java b/src/code/kalter/longflight/screen/HighScore.java new file mode 100644 index 0000000..2cf419d --- /dev/null +++ b/src/code/kalter/longflight/screen/HighScore.java @@ -0,0 +1,160 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.ByteArrayInputStream; +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import code.kalter.longflight.rms.RMS; +import code.kalter.longflight.rms.RecordNotFoundException; +import java.io.IOException; +import javax.microedition.lcdui.Image; +import javax.microedition.rms.RecordStoreException; + +/** + * Экран отображения лучших рекордов + * + * @author KalterFive + */ +public class HighScore extends Screen { + + private String score; + private final Sprite window; + private final Sprite leftSoft; + private final Sprite rightSoft; + private final Image downPanel; + + public HighScore() throws IOException { + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/hscore/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + window.addEvent(new EventListener() { + // override + public boolean is() { + return window.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + setScreenMenu(); + } + }); + + // left soft + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + setScreenMenu(); + } + }); + + // right soft + Image rightSoftImage = loader.getImage("/gfx/awt/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + setScreenMenu(); + } + }); + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + } + + // override + public void start() { + score = ""; + try { + RMS rms = new RMS("longflight", true); + ByteArrayInputStream byteReader = rms.get(2); + rms.close(); + for (int i = 0; i < 5; i++) { + score += (i + 1) + ". " + byteReader.readInteger() + "\r\n"; + } + } catch (RecordNotFoundException e) { + for (int i = 0; i < 5; i++) { + score += (i + 1) + ". 0\r\n"; + } + } catch (RecordStoreException e) { + LongFlight.link.catchException(e); + } + setDate(39, screenH - 9); + super.start(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case FIRE: + keyCode = LEFT_SOFT; + break; + } + switch (keyCode) { + case LEFT_SOFT: + case RIGHT_SOFT: + setScreenMenu(); + break; + } + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + rightSoft.exciteEvent(); + leftSoft.exciteEvent(); + window.exciteEvent(); + } + + private void setScreenMenu() { + LongFlight.link.setScreen(LongFlight.MENU); + } + + private void update() { + space.update(); + } + + private void paint() { + space.paint(graphics); + window.paint(graphics); + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(downPanel, i, screenH - 18, 0); + } + leftSoft.paint(graphics); + rightSoft.paint(graphics); + font.paint(graphics, score, window.getX() + 10, window.getY() + 37); + paintDate(); + flushGraphics(); + } +} diff --git a/src/code/kalter/longflight/screen/Loading.java b/src/code/kalter/longflight/screen/Loading.java new file mode 100644 index 0000000..5309b6b --- /dev/null +++ b/src/code/kalter/longflight/screen/Loading.java @@ -0,0 +1,99 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Quote; +import code.kalter.longflight.Sprite; +import code.kalter.longflight.StringReader; +import java.io.IOException; +import java.io.InputStream; +import java.util.Random; +import javax.microedition.lcdui.Image; + +/** + * Фейковая загрузка + * + * @author KalterFive + */ +public class Loading extends Screen { + + private static final long SLEEP = 8000; + + private final int COUNT; // of quots + private final Quote[] quote; + + private final Sprite loading; + private int quoteID; + + private long lastTime; + + public Loading() throws IOException { + final InputStream file = getClass().getResourceAsStream("/quote.txt"); + final StringReader reader = new StringReader(file); + COUNT = reader.nextInt(); + quote = new Quote[COUNT]; + for (int i = 0; i < COUNT; i++) { + String q = reader.nextString(); // quote + String a = reader.nextString(); // author + quote[i] = new Quote(q, a); + } + reader.close(); + + Loader loader = Loader.getInstance(); + + // loading + Image loadingImage = loader.getImage("/gfx/loading/loading.png"); + int loadingX = screenW - loadingImage.getWidth(); + int loadingY = 15; + loading = new Sprite(loadingImage, loadingX, loadingY); + } + + // override + public void start() { + lastTime = System.currentTimeMillis(); + quoteID = new Random().nextInt(COUNT); + super.start(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + LongFlight.link.setScreen(LongFlight.GAME); + } + + private void update() { + if (System.currentTimeMillis() - lastTime > SLEEP) { + stop(); + } + } + + private void paint() { + // gfx + graphics.setColor(0x002C40); + graphics.fillRect(0, 0, screenW, screenH); + graphics.setColor(0x004C6F); + graphics.fillRect(0, 22, screenW, 2); + loading.paint(graphics); + + // quote + String quoteText = quote[quoteID].getQuote(); + int quoteX = 10; + int quoteY = 30; + int quoteHeight = screenW - 10; + font.paint(graphics, quoteText, quoteX, quoteY, quoteHeight); + + // author + String author = quote[quoteID].getAuthor(); + int authorX = 10; + int authorY = 18 + quoteY + font.getHeight(quoteText, quoteHeight); + int authorHeight = screenW - 10; + font.paint(graphics, author, authorX, authorY, authorHeight); + flushGraphics(); + } +} diff --git a/src/code/kalter/longflight/screen/Menu.java b/src/code/kalter/longflight/screen/Menu.java new file mode 100644 index 0000000..1cd9121 --- /dev/null +++ b/src/code/kalter/longflight/screen/Menu.java @@ -0,0 +1,293 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import javax.microedition.lcdui.Image; + +/** + * Экран главного меню + * + * @author KalterFive + */ +public class Menu extends Screen { + + private static final int COUNT_CHOISE = 3; + + private static final int FIGHT = 0; + private static final int HSCORE = 1; + private static final int ABOUT = 2; + + private final Sprite[] choise; + private final Sprite[] selectChoise; + private final Sprite window; + private final Sprite leftSoft; + private final Sprite rightSoft; + private final Image downPanel; + + private int position; + + public Menu() throws IOException { + position = 0; + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/menu/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + //===========================================================[Пасхалка] + window.addEvent(new EventListener() { + // override + public boolean is() { + return (getXReleased() > getXPressed()) + && (window.isEntrySet(getXPressed(), getYPressed())) + && (window.isEntrySet(getXReleased(), getYReleased())) + && (Math.abs(getXPressed() - getXReleased()) + > window.getWidth() / 2); + } + + // override + public void event() { + space.activateEgg(); + } + }); + + // left panel + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + leftSoftPressed(); + } + }); + + // right panel + Image rightSoftImage = loader.getImage("/gfx/awt/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + rightSoftPressed(); + } + }); + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + + // choises + Image choiseCrop = loader.getImage("/gfx/menu/choise.png"); + choise = new Sprite[COUNT_CHOISE]; + selectChoise = new Sprite[COUNT_CHOISE]; + for (int i = 0; i < COUNT_CHOISE; i++) { + // choise + Image c = Image.createImage(choiseCrop, 0, i * 22, 102, 22, 0); + int choiseX = (screenW - 102) / 2; + int choiseY = window.getY() + 34 + i * 24; + choise[i] = new Sprite(c, choiseX, choiseY); + + // selectchoise + Image sc = Image.createImage(choiseCrop, 102, i * 22, 102, 22, 0); + int selectChoiseX = choise[i].getX(); + int selectChoiseY = choise[i].getY(); + selectChoise[i] = new Sprite(sc, selectChoiseX, selectChoiseY); + } + + // adding event listener for choise about of "fight" + choise[FIGHT].addEvent(new EventListener() { + // override + public boolean is() { + return choise[FIGHT].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + position = FIGHT; + firePressed(); + } + }); + selectChoise[FIGHT].addEvent(choise[FIGHT].getEvent(0)); + + // adding event listener for choise about of "high score" + choise[HSCORE].addEvent(new EventListener() { + // override + public boolean is() { + return choise[HSCORE].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + position = HSCORE; + firePressed(); + } + }); + selectChoise[HSCORE].addEvent(choise[HSCORE].getEvent(0)); + + // adding event listener for choise about of "about" + choise[ABOUT].addEvent(new EventListener() { + // override + public boolean is() { + return choise[ABOUT].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + position = ABOUT; + firePressed(); + } + }); + selectChoise[ABOUT].addEvent(choise[ABOUT].getEvent(0)); + } + + // override + public void start() { + final int previosScreenID = LongFlight.link.getPreviosScreenID(); + if (previosScreenID == LongFlight.CRASH + || previosScreenID == LongFlight.PAUSE) { + Game.link.save(); + } + setDate(39, screenH - 9); + super.start(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case UP: + upPressed(); + break; + + case DOWN: + downPressed(); + break; + + case FIRE: + firePressed(); + break; + } + switch (keyCode) { + case RIGHT_SOFT: + rightSoftPressed(); + break; + + case LEFT_SOFT: + leftSoftPressed(); + break; + } + } + + // override + public void keyReleased(int keyCode) { + switch (keyCode) { + //=======================================================[Пасхалка] + case KEY_NUM0: + space.activateEgg(); + break; + } + } + + // override + public void pointerReleased(int x, int y) { + super.pointerReleased(x, y); + window.exciteEvent(); + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + rightSoft.exciteEvent(); + leftSoft.exciteEvent(); + choise[FIGHT].exciteEvent(); + choise[HSCORE].exciteEvent(); + choise[ABOUT].exciteEvent(); + } + + private void upPressed() { + position--; + if (position < 0) { + position = 0; + } + } + + private void downPressed() { + position++; + if (position >= COUNT_CHOISE) { + position = COUNT_CHOISE - 1; + } + } + + private void firePressed() { + leftSoftPressed(); + } + + private void rightSoftPressed() { + LongFlight.link.destroyApp(true); + } + + private void leftSoftPressed() { + switch (position) { + case FIGHT: + LongFlight.link.setScreen(LongFlight.SELECT_SHIP); + break; + + case HSCORE: + LongFlight.link.setScreen(LongFlight.HIGH_SCORE); + break; + + case ABOUT: + LongFlight.link.setScreen(LongFlight.ABOUT); + break; + } + } + + private void update() { + space.update(); + } + + private void paint() { + space.paint(graphics); + window.paint(graphics); + for (int i = 0; i < COUNT_CHOISE; i++) { + if (i == position) { + selectChoise[i].paint(graphics); + } else { + choise[i].paint(graphics); + } + } + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(downPanel, i, screenH - 18, 0); + } + leftSoft.paint(graphics); + rightSoft.paint(graphics); + paintDate(); + flushGraphics(); + } +} diff --git a/src/code/kalter/longflight/screen/Pause.java b/src/code/kalter/longflight/screen/Pause.java new file mode 100644 index 0000000..7a5e536 --- /dev/null +++ b/src/code/kalter/longflight/screen/Pause.java @@ -0,0 +1,243 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import javax.microedition.lcdui.Image; + +/** + * Специальный экран, предназначенный для временной задержки действующего экрана + * и одновременным контактом с пользователем. Жёстко привязан к игровому экрану + * + * @author KalterFive + */ +public class Pause extends Screen { + + private static final int COUNT = 2; //choise + + private static final int FIGHT = 0; + private static final int MENU = 1; + + private final Sprite[] choise; + private final Sprite[] selectChoise; + private final Sprite window; + private final Sprite leftSoft; + private final Sprite rightSoft; + private final Image downPanel; + + private int position; + + public Pause() throws IOException { + position = 0; + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/pause/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + + // right soft + Image rightSoftImage = loader.getImage("/gfx/awt/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + rightSoftPressed(); + } + }); + + // left soft + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + leftSoftPressed(); + } + }); + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + + // choises + Image choiseCrop = loader.getImage("/gfx/pause/choise.png"); + choise = new Sprite[COUNT]; + selectChoise = new Sprite[COUNT]; + for (int i = 0; i < COUNT; i++) { + // choise + Image c = Image.createImage(choiseCrop, 0, i * 22, 102, 22, 0); + int choiseX = (screenW - 102) / 2; + int choiseY = window.getY() + 34 + i * 24; + choise[i] = new Sprite(c, choiseX, choiseY); + + // selectchoise + Image sc = Image.createImage(choiseCrop, 102, i * 22, 102, 22, 0); + int selectChoiseX = choise[i].getX(); + int selectChoiseY = choise[i].getY(); + selectChoise[i] = new Sprite(sc, selectChoiseX, selectChoiseY); + } + + // adding event listener for choise about of "fight" + choise[FIGHT].addEvent(new EventListener() { + // override + public boolean is() { + return choise[FIGHT].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + position = FIGHT; + firePressed(); + } + }); + + // adding event listener for choise about of "menu" + choise[MENU].addEvent(new EventListener() { + // override + public boolean is() { + return choise[MENU].isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + position = MENU; + firePressed(); + } + }); + } + + //override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + } + + // override + public void start() { + setDate(39, screenH - 9); + super.start(); + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case UP: + upPressed(); + break; + + case DOWN: + downPressed(); + break; + + case FIRE: + firePressed(); + break; + } + switch (keyCode) { + case LEFT_SOFT: + leftSoftPressed(); + break; + + case RIGHT_SOFT: + rightSoftPressed(); + break; + } + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + leftSoft.exciteEvent(); + rightSoft.exciteEvent(); + choise[FIGHT].exciteEvent(); + choise[MENU].exciteEvent(); + } + + private void upPressed() { + if (--position < 0) { + position = 0; + } + } + + private void downPressed() { + if (++position >= COUNT) { + position = COUNT - 1; + } + } + + private void leftSoftPressed() { + firePressed(); + } + + private void rightSoftPressed() { + position = FIGHT; + firePressed(); + } + + private void firePressed() { + switch (position) { + case FIGHT: + LongFlight.link.setScreen(LongFlight.GAME); + break; + + case MENU: + Game.link.setNullPause(); + LongFlight.link.setScreen(LongFlight.MENU); + break; + } + } + + private void update() { + space.update(); + } + + private void paint() { + space.paint(graphics); + Game.link.paintElements(graphics); + window.paint(graphics); + paintChoise(); + paintDownPanel(); + leftSoft.paint(graphics); + rightSoft.paint(graphics); + paintDate(); + flushGraphics(); + } + + private void paintChoise() { + for (int i = 0; i < COUNT; i++) { + if (i == position) { + selectChoise[i].paint(graphics); + } else { + choise[i].paint(graphics); + } + } + } + + private void paintDownPanel() { + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(downPanel, i, screenH - 18, 0); + } + } +} diff --git a/src/code/kalter/longflight/screen/Screen.java b/src/code/kalter/longflight/screen/Screen.java new file mode 100644 index 0000000..012f043 --- /dev/null +++ b/src/code/kalter/longflight/screen/Screen.java @@ -0,0 +1,143 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.Area; +import code.kalter.longflight.FPS; +import code.kalter.longflight.Font; +import code.kalter.longflight.Pointer; +import code.kalter.longflight.Time; +import code.kalter.longflight.space.Space; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.game.GameCanvas; + +/** + * Абстрактный класс для всех экранов + * + * @author KalterFive + */ +public abstract class Screen extends GameCanvas implements Runnable { + + // софт-кнопки + public final int LEFT_SOFT = -6; + public final int RIGHT_SOFT = -7; + + // некоторые свойства, характерные каждому экрану + protected final Graphics graphics; + protected final FPS fps; + protected final Space space; + protected final Font font; + protected final int screenW; + protected final int screenH; + + // нажатие и области нажатия + private final Pointer pointer; + private final Area upArea; + private final Area downArea; + private final Area leftArea; + private final Area rightArea; + private final Area fireArea; + + // текущее время и его координаты + private final Time time; + private int timeXPosition; + private int timeYPosition; + + private Thread thread; + protected boolean gameLoop; + + public Screen() throws IOException { + super(false); + setFullScreenMode(true); + graphics = getGraphics(); + screenW = getWidth(); + screenH = getHeight(); + fps = FPS.getInstance(30); + space = Space.getInstance(screenW, screenH); + font = Font.getInstance(); + time = Time.getInstance(60000); + pointer = new Pointer(); + upArea = new Area(screenW / 3, 0, screenW - screenW / 3, screenH / 3); + downArea = new Area(screenW / 3, screenH - screenH / 3, + screenW - screenW / 3, screenH); + leftArea = new Area(0, 0, screenW / 3, screenH); + rightArea = new Area(screenW - screenW / 3, 0, screenW, screenH); + fireArea = new Area(screenW / 3, screenH / 3, + screenW - screenW / 3, screenH - screenH / 3); + } + + public void start() { + showNotify(); + space.paint(graphics); + gameLoop = true; + thread = new Thread(this); + thread.start(); + } + + public void stop() { + hideNotify(); + gameLoop = false; + } + + // override + public void pointerPressed(int x, int y) { + pointer.setPressed(x, y); + } + + // override + public void pointerReleased(int x, int y) { + pointer.setReleased(x, y); + } + + public final boolean getGameLoop() { + return gameLoop; + } + + public int getXPressed() { + return pointer.getXPressed(); + } + + public int getYPressed() { + return pointer.getYPressed(); + } + + public int getXReleased() { + return pointer.getXReleased(); + } + + public int getYReleased() { + return pointer.getYReleased(); + } + + public boolean isPointerUp() { + return isPointerArea(upArea); + } + + public boolean isPointerDown() { + return isPointerArea(downArea); + } + + public boolean isPointerLeft() { + return isPointerArea(leftArea); + } + + public boolean isPointerRight() { + return isPointerArea(rightArea); + } + + public boolean isPointerFire() { + return isPointerArea(fireArea); + } + + public boolean isPointerArea(Area area) { + return area.isEntry(pointer.getXPressed(), pointer.getYPressed()); + } + + protected final void setDate(int x, int y) { + this.timeXPosition = x; + this.timeYPosition = y; + } + + protected final void paintDate() { + font.paint(graphics, time.toString(), timeXPosition, timeYPosition); + } +} diff --git a/src/code/kalter/longflight/screen/SelectShip.java b/src/code/kalter/longflight/screen/SelectShip.java new file mode 100644 index 0000000..5af5185 --- /dev/null +++ b/src/code/kalter/longflight/screen/SelectShip.java @@ -0,0 +1,292 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.ByteArrayOutputStream; +import code.kalter.longflight.EventListener; +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import code.kalter.longflight.game.ship.Ship; +import code.kalter.longflight.game.ship.ShipGamer; +import code.kalter.longflight.rms.RMS; +import java.io.IOException; +import javax.microedition.lcdui.Image; +import javax.microedition.rms.RecordStoreException; + +/** + * Выбор кораблика + * + * @author KalterFive + */ +public class SelectShip extends Screen { + + private int position; + private final Sprite window; + private final Sprite frame; + private final Sprite leftSoft; + private final Sprite rightSoft; + private final Sprite[] leftButton; + private final Sprite[] rightButton; + private final Sprite[] ship; + private final Image downPanel; + + public SelectShip() throws IOException { + Loader loader = Loader.getInstance(); + + // window + Image windowImage = loader.getImage("/gfx/select_ship/window.png"); + int windowX = (screenW - windowImage.getWidth()) / 2; + int windowY = (screenH - windowImage.getHeight()) / 2; + window = new Sprite(windowImage, windowX, windowY); + window.addEvent(new EventListener() { + // override + public boolean is() { + return window.isEntrySet(getXPressed(), getYPressed()) + && getXPressed() == getXReleased() + && getYPressed() == getYReleased(); + } + + // override + public void event() { + firePressed(); + } + }); + window.addEvent(new EventListener() { + // override + public boolean is() { + return window.isEntrySet(getXPressed(), getYPressed()) + && window.isEntrySet(getXReleased(), getYReleased()) + && Math.abs(getXReleased() - getXPressed()) > 50 + && Math.abs(getYReleased() - getYPressed()) < 50; + } + + // override + public void event() { + if (getXPressed() < getXReleased()) { + leftPressed(); + } + if (getXPressed() > getXReleased()) { + rightPressed(); + } + } + }); + + // left soft + Image leftSoftImage = loader.getImage("/gfx/awt/left_soft.png"); + int leftSoftX = 0; + int leftSoftY = screenH - leftSoftImage.getHeight(); + leftSoft = new Sprite(leftSoftImage, leftSoftX, leftSoftY); + leftSoft.addEvent(new EventListener() { + // override + public boolean is() { + return leftSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + leftSoftPressed(); + } + }); + + // right soft + Image rightSoftImage = loader.getImage("/gfx/awt/right_soft.png"); + int rightSoftX = screenW - rightSoftImage.getWidth(); + int rightSoftY = screenH - rightSoftImage.getHeight(); + rightSoft = new Sprite(rightSoftImage, rightSoftX, rightSoftY); + rightSoft.addEvent(new EventListener() { + // override + public boolean is() { + return rightSoft.isEntrySet(getXPressed(), getYPressed()); + } + + // override + public void event() { + rightSoftPressed(); + } + }); + + // down panel + downPanel = loader.getImage("/gfx/awt/down_panel.png"); + + // frame + Image frameImage = loader.getImage("/gfx/select_ship/frame.png"); + int frameX = window.getX() + + (window.getWidth() - frameImage.getWidth()) / 2; + int frameY = window.getY() + 14 + + (window.getHeight() - frameImage.getHeight()) / 2; + frame = new Sprite(frameImage, frameX, frameY); + + // ships + ship = new Sprite[4]; + for (int i = 0; i < Ship.COUNT; i++) { + Image shipImage = ShipGamer.getInstance().getImage(i); + int shipX = frame.getX() + + (frame.getWidth() - shipImage.getWidth()) / 2; + int shipY = frame.getY() + + (frame.getHeight() - shipImage.getHeight()) / 2; + ship[i] = new Sprite(shipImage, shipX, shipY); + } + + // left / right buttons + Image button = loader.getImage("/gfx/select_ship/lr_button.png"); + leftButton = new Sprite[2]; + rightButton = new Sprite[2]; + + // left button + Image leftButtonImage = Image.createImage(button, 0, 0, 6, 11, 0); + int leftButtonX = window.getX() + 15; + int leftButtonY = frame.getY() + (frame.getHeight() - 11) / 2; + leftButton[0] = new Sprite(leftButtonImage, leftButtonX, leftButtonY); + + // select left button + Image selectLeftButtonImage = Image.createImage(button, 0, 11, + 6, 11, 0); + int selectLeftButtonX = leftButton[0].getX(); + int selectLeftButtonY = leftButton[0].getY(); + leftButton[1] = new Sprite(selectLeftButtonImage, + selectLeftButtonX, selectLeftButtonY); + + // right button + Image rightButtonImage = Image.createImage(button, 6, 0, 6, 11, 0); + int rightButtonX = window.getX() + window.getWidth() - 21; + int rightButtonY = frame.getY() + (frame.getHeight() - 11) / 2; + rightButton[0] = new Sprite(rightButtonImage, + rightButtonX, rightButtonY); + + // select right button + Image selectRightButtonImage = Image.createImage(button, 6, 11, + 6, 11, 0); + int selectRightButtonX = rightButton[0].getX(); + int selectRightButtonY = rightButton[0].getY(); + rightButton[1] = new Sprite(selectRightButtonImage, + selectRightButtonX, selectRightButtonY); + } + + // override + public void start() { + position = 0; + setDate(39, screenH - 9); + super.start(); + } + + // override + public void stop() { + super.stop(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + update(); + paint(); + LongFlight.link.sleep(20); + fps.max(); + } + } + + // override + public void keyPressed(int keyCode) { + switch (getGameAction(keyCode)) { + case LEFT: + leftPressed(); + break; + + case RIGHT: + rightPressed(); + break; + + case FIRE: + firePressed(); + break; + } + switch (keyCode) { + case RIGHT_SOFT: + rightSoftPressed(); + break; + + case LEFT_SOFT: + leftSoftPressed(); + break; + } + } + + // override + public void pointerPressed(int x, int y) { + super.pointerPressed(x, y); + rightSoft.exciteEvent(); + leftSoft.exciteEvent(); + } + + // override + public void pointerReleased(int x, int y) { + super.pointerReleased(x, y); + window.exciteEvent(); + } + + private void leftPressed() { + if (--position < 0) { + position = Ship.COUNT - 1; + } + } + + private void rightPressed() { + if (++position >= Ship.COUNT) { + position = 0; + } + } + + private void firePressed() { + leftSoftPressed(); + } + + private void rightSoftPressed() { + LongFlight.link.setScreen(LongFlight.MENU); + } + + private void leftSoftPressed() { + saveAndGoToFire(); + } + + private void update() { + space.update(); + } + + private void paint() { + space.paint(graphics); + window.paint(graphics); + frame.paint(graphics); + ship[position].paint(graphics); + int keyStates = getKeyStates(); + int li = 0; + if ((keyStates & LEFT_PRESSED) != 0) { + li = 1; + } + leftButton[li].paint(graphics); + int ri = 0; + if ((keyStates & RIGHT_PRESSED) != 0) { + ri = 1; + } + rightButton[ri].paint(graphics); + for (int i = 0; i < screenW; i += 128) { + graphics.drawImage(downPanel, i, screenH - 18, 0); + } + leftSoft.paint(graphics); + rightSoft.paint(graphics); + paintDate(); + flushGraphics(); + } + + private void saveAndGoToFire() { + try { + RMS rms = new RMS("longflight", true); + ByteArrayOutputStream data = new ByteArrayOutputStream(1); + data.writeByte((byte) position); + rms.put(1, data); + rms.close(); + } catch (RecordStoreException rse) { + LongFlight.link.catchException(rse); + } + space.deactivateEgg(); + LongFlight.link.setScreen(LongFlight.LOADING); + } +} diff --git a/src/code/kalter/longflight/screen/Splash.java b/src/code/kalter/longflight/screen/Splash.java new file mode 100644 index 0000000..4fb7ee2 --- /dev/null +++ b/src/code/kalter/longflight/screen/Splash.java @@ -0,0 +1,80 @@ +package code.kalter.longflight.screen; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import java.util.Random; +import javax.microedition.lcdui.Image; + +/** + * Сплэш + * + * @author KalterFive + */ +public class Splash extends Screen { + + private final Random random; + private final Sprite splash0; + private final Sprite splash1; + private long lastTime; + + public Splash() throws IOException { + random = new Random(); + Loader loader = Loader.getInstance(); + + // splash 0 + Image splash0Image = loader.getImage("/gfx/splash/0.png"); + int splash0X = (screenW - splash0Image.getWidth()) / 2; + int splash0Y = (screenH - splash0Image.getHeight()) / 2; + splash0 = new Sprite(splash0Image, splash0X, splash0Y); + + // splash 1 + Image splash1Image = loader.getImage("/gfx/splash/1.png"); + int splash1X = (screenW - splash1Image.getWidth()) / 2; + int splash1Y = (screenH - splash1Image.getHeight()) / 2; + splash1 = new Sprite(splash1Image, splash1X, splash1Y); + } + + // override + public void start() { + lastTime = System.currentTimeMillis(); + super.start(); + } + + // override + public void run() { + while (getGameLoop()) { + fps.process(); + space.update(); + space.paint(graphics); + long delta = System.currentTimeMillis() - lastTime; + + // painting splash 0 + if (delta < 4000) { + splash0.paint(graphics); + } + + // painting splash 1 + if (delta > 5000) { + splash1.paint(graphics); + } + + // painting white fucking effect + if ((delta > 4000) && (delta < 5000) || (delta > 9000)) { + int c = random.nextInt(2) * 255; + graphics.setColor((c << 16) | (c << 8) | c); + graphics.fillRect(0, 0, screenW, screenH); + } + + // set screen menu and stop painting splash + if (delta > 10000) { + LongFlight.link.setScreen(LongFlight.MENU); + } + + flushGraphics(); + LongFlight.link.sleep(20); + fps.max(); + } + } +} diff --git a/src/code/kalter/longflight/space/Egg.java b/src/code/kalter/longflight/space/Egg.java new file mode 100644 index 0000000..e2ced2a --- /dev/null +++ b/src/code/kalter/longflight/space/Egg.java @@ -0,0 +1,51 @@ +package code.kalter.longflight.space; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.Sprite; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Пасхалка + * + * @author KalterFive + */ +class Egg extends Sprite { + + private boolean alive; + private final int maxH; + + public Egg(String path, int screenW, int maxH) throws IOException { + this(Loader.getInstance().getImage(path), screenW, maxH); + } + + public Egg(Image image, int screenW, int maxH) { + super(image, (screenW - image.getWidth()) / 2, -image.getHeight()); + this.maxH = maxH; + } + + public void paint(Graphics graph) { + if (alive) { + super.paint(graph); + } + } + + public void upd() { + if (alive) { + moveDown(1); + if (getY() > maxH) { + deactivate(); + } + } + } + + public void activate() { + alive = true; + } + + public void deactivate() { + alive = false; + setY(-image.getHeight()); + } +} diff --git a/src/code/kalter/longflight/space/Planet.java b/src/code/kalter/longflight/space/Planet.java new file mode 100644 index 0000000..acb7583 --- /dev/null +++ b/src/code/kalter/longflight/space/Planet.java @@ -0,0 +1,72 @@ +package code.kalter.longflight.space; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import java.io.IOException; +import java.util.Random; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Генерация случайных планет + * + * @author KalterFive + */ +class Planet { + + private final int screenW; + private final int screenH; + private final int COUNT = 5; + + private final Random random; + private final Image[] planetGraphics; // все планеты + //======================= + private long lastTime; // для засекания времени + private long delay; // задержка для генерации планеты + //======================= + private int positionX; + private int positionY; + private int index; + + public Planet(int screenW, int screenH) throws IOException { + this.screenW = screenW; + this.screenH = screenH; + random = new Random(); + positionX = random.nextInt(screenW - 60); + positionY = -100; + index = random.nextInt(COUNT); + planetGraphics = new Image[COUNT]; + Loader iml = Loader.getInstance(); + for (int i = 0; i < COUNT; i++) { + planetGraphics[i] = iml.getImage("/gfx/space/planet/" + i + ".png"); + } + delay = random.nextInt(25000) + 10000; + lastTime = System.currentTimeMillis(); + } + + public void paint(Graphics graph) { + long delta = System.currentTimeMillis() - lastTime; + if (delta < delay) { + return; + } + graph.drawImage(planetGraphics[index], positionX, positionY, 0); + } + + public void upd() { + long delta = System.currentTimeMillis() - lastTime; + if (delta < delay) { + return; + } + if (positionY++ > screenH) { + newPlanet(); + } + } + + private void newPlanet() { + for (int i = index; i == index; index = random.nextInt(COUNT)); + delay = random.nextInt(25000) + 10000; + lastTime = System.currentTimeMillis(); + positionX = random.nextInt(screenW - 60); + positionY = -planetGraphics[index].getHeight(); + } +} diff --git a/src/code/kalter/longflight/space/Space.java b/src/code/kalter/longflight/space/Space.java new file mode 100644 index 0000000..58df58e --- /dev/null +++ b/src/code/kalter/longflight/space/Space.java @@ -0,0 +1,56 @@ +package code.kalter.longflight.space; + +import java.io.IOException; +import javax.microedition.lcdui.Graphics; + +/** + * Космос: звёзды, планеты и фон + * + * @author KalterFive + */ +public class Space { + + private static Space instance; + + public static Space getInstance(int screenW, int screenH) + throws IOException { + if (instance == null) { + instance = new Space(screenW, screenH); + } + return instance; + } + + private final Egg egg; + private final Tile tile; + private final Planet planet; + private final Star star; + + private Space(int screenW, int screenH) throws IOException { + egg = new Egg("/gfx/ship/5.png", screenW, screenH); + tile = new Tile("/gfx/space/background.png", screenW, screenH); + planet = new Planet(screenW, screenH); + star = new Star(screenW, screenH); + } + + public void paint(Graphics graphics) { + tile.paint(graphics); + planet.paint(graphics); + star.paint(graphics); + egg.paint(graphics); + } + + public void update() { + planet.upd(); + tile.upd(); + star.upd(); + egg.upd(); + } + + public void activateEgg() { + egg.activate(); + } + + public void deactivateEgg() { + egg.deactivate(); + } +} diff --git a/src/code/kalter/longflight/space/Star.java b/src/code/kalter/longflight/space/Star.java new file mode 100644 index 0000000..94100a3 --- /dev/null +++ b/src/code/kalter/longflight/space/Star.java @@ -0,0 +1,49 @@ +package code.kalter.longflight.space; + +import code.kalter.longflight.Color; +import java.util.Random; +import javax.microedition.lcdui.Graphics; + +/** + * Звёзды... + * + * @author KalterFive + */ +class Star { + + private final int screenH; + private final int COUNT; + private final int[] positionX; + private final int[] positionY; + private final int[] color; + + public Star(int screenW, int screenH) { + this.screenH = screenH; + Random random = new Random(); + COUNT = (screenH + screenW) / 3; + positionX = new int[COUNT]; + positionY = new int[COUNT]; + color = new int[COUNT]; + for (int i = 0; i < COUNT; i++) { + positionX[i] = random.nextInt(screenH); + positionY[i] = random.nextInt(screenW); + int a = random.nextInt(256); + color[i] = Color.maskRGB(a, a, a); + } + } + + public void paint(Graphics graphics) { + for (int i = 0; i < COUNT; i++) { + graphics.setColor(color[i]); + graphics.fillRect(positionX[i], positionY[i], 1, 1); + } + } + + public void upd() { + for (int i = 0; i < COUNT; i++) { + if ((positionY[i] += ((color[i] & 0x0000FF) / 50)) > screenH) { + positionY[i] = 0; + } + } + } +} diff --git a/src/code/kalter/longflight/space/Tile.java b/src/code/kalter/longflight/space/Tile.java new file mode 100644 index 0000000..99ab830 --- /dev/null +++ b/src/code/kalter/longflight/space/Tile.java @@ -0,0 +1,49 @@ +package code.kalter.longflight.space; + +import code.kalter.longflight.Loader; +import code.kalter.longflight.LongFlight; +import java.io.IOException; +import javax.microedition.lcdui.Graphics; +import javax.microedition.lcdui.Image; + +/** + * Тайловый фон + * + * @author KalterFive + */ +class Tile { + + private final Image tile; + private final int screenW; + private final int screenH; + private final int widthOfTile; + private final int heightOfTile; + private int positionY; + + public Tile(Image tile, int screenW, int screenH) { + this.tile = tile; + this.screenW = screenW; + this.screenH = screenH; + this.widthOfTile = tile.getWidth(); + this.heightOfTile = tile.getHeight(); + this.positionY = -128; + } + + public Tile(String path, int screenW, int screenH) throws IOException { + this(Loader.getInstance().getImage(path), screenW, screenH); + } + + public void paint(Graphics graph) { + for (int x = 0; x < screenW; x += widthOfTile) { + for (int y = positionY; y < screenH; y += heightOfTile) { + graph.drawImage(tile, x, y, 0); + } + } + } + + public void upd() { + if ((positionY++) > 0) { + positionY = -128; + } + } +} diff --git a/src/gfx/about/window.png b/src/gfx/about/window.png new file mode 100644 index 0000000..930c5b8 Binary files /dev/null and b/src/gfx/about/window.png differ diff --git a/src/gfx/awt/down_panel.png b/src/gfx/awt/down_panel.png new file mode 100644 index 0000000..13bbb3e --- /dev/null +++ b/src/gfx/awt/down_panel.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄŒÖ_6ånš¢R)Jér-¦‰½.¬ ñÜdTw禺úëL½`l'–-KÄCç¡»´áºüÞÉѳØç¬ë6xñ›\¨Aòײ|¬äk°%4ÎÆ"L›Å\TÐ/T/R(DàÎÈù‘½´ñVz`‘–kâÙC \ No newline at end of file diff --git a/src/gfx/awt/left_soft.png b/src/gfx/awt/left_soft.png new file mode 100644 index 0000000..138ef22 --- /dev/null +++ b/src/gfx/awt/left_soft.png @@ -0,0 +1,2 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÖÖ_6®/š¢RÝ·Ógr-¦Ý,®ýŽ˜ô)ÒDïXú·C@ƒ*™P¤ãQÞÊfýȯcXØa£òª + àí¿®«¾ù^ï5¦eúl,¸ÕgÔ£L»–þ¤’ãcÓè—E¸ú\3Þ ©Zúü |CgôGƒZ ¡³åAT‹ iúëI²q­’ª[Ñßìß­¡å%#µËŸRÞÐh©:¡⠈.SiÆÎ¥Äa[ \ No newline at end of file diff --git a/src/gfx/awt/right_soft.png b/src/gfx/awt/right_soft.png new file mode 100644 index 0000000..f76b196 Binary files /dev/null and b/src/gfx/awt/right_soft.png differ diff --git a/src/gfx/boom.png b/src/gfx/boom.png new file mode 100644 index 0000000..9c384e1 Binary files /dev/null and b/src/gfx/boom.png differ diff --git a/src/gfx/bullet/0.png b/src/gfx/bullet/0.png new file mode 100644 index 0000000..42cea64 --- /dev/null +++ b/src/gfx/bullet/0.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄäÖ_6¤nš¢R†Ur-¦Þ½.¬ )4/ͨšF@Ò#Ð `‹›1Ѩâ†ÆÊW|æàƒsêŠ-‹=ôâÞ2ˆÏ£¯ diff --git a/src/gfx/bullet/1.png b/src/gfx/bullet/1.png new file mode 100644 index 0000000..43b2d92 --- /dev/null +++ b/src/gfx/bullet/1.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄäÖ_6¤nš¢R†Ur-¦½.¬ ñ4¦¼¤{œæ“ Áޙ2uÀAqP} .—¾L±\?¬ôãþº~–$'ôvŠÖXqcíÈÞVë \ No newline at end of file diff --git a/src/gfx/crash/window.png b/src/gfx/crash/window.png new file mode 100644 index 0000000..df9a8f9 Binary files /dev/null and b/src/gfx/crash/window.png differ diff --git a/src/gfx/enable_sound/choise.png b/src/gfx/enable_sound/choise.png new file mode 100644 index 0000000..5af5060 Binary files /dev/null and b/src/gfx/enable_sound/choise.png differ diff --git a/src/gfx/enable_sound/window.png b/src/gfx/enable_sound/window.png new file mode 100644 index 0000000..ae07e42 Binary files /dev/null and b/src/gfx/enable_sound/window.png differ diff --git a/src/gfx/font.png b/src/gfx/font.png new file mode 100644 index 0000000..55258e6 Binary files /dev/null and b/src/gfx/font.png differ diff --git a/src/gfx/game/down_panel.png b/src/gfx/game/down_panel.png new file mode 100644 index 0000000..d55c0e2 Binary files /dev/null and b/src/gfx/game/down_panel.png differ diff --git a/src/gfx/game/life.png b/src/gfx/game/life.png new file mode 100644 index 0000000..81daada --- /dev/null +++ b/src/gfx/game/life.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÇÖ_6”n?š¢RH€ýšr-¦¾½.¬ ñ4/O;™‚ .2Îƛ§ÇøQª ±kæ@jOw’x¿—¬â-‹© ’Î<è#¯ \ No newline at end of file diff --git a/src/gfx/game/overheat.png b/src/gfx/game/overheat.png new file mode 100644 index 0000000..1e87607 --- /dev/null +++ b/src/gfx/game/overheat.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÇÖ_6”n?š¢RH€ýšr-¦¾½.¬ ñ4/O;™‚ .2Îƛ§Ç1ÑYêè8Ðu(Ÿ’Õ@_8ÔË£X´¬â-‹© ’Î<è#¯ \ No newline at end of file diff --git a/src/gfx/game/right_soft.png b/src/gfx/game/right_soft.png new file mode 100644 index 0000000..7a5ac0a --- /dev/null +++ b/src/gfx/game/right_soft.png @@ -0,0 +1,2 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ĶÖ_6®/š¢R VÔr-¦Ý,®ýŽ˜ô)ÒDïXú·C@ƒ*™P¤ãQÞÊfýÈßcXØa"ò +¤æ­¿*ÄØʞ\áÄÖü‚`ÍZkí«•vX^L 7TE•6år)qÆÓºuû”6sû#,’ ´¯VÅ#¬ãƒx힎DÊÊÝ@j÷¢R*¯®t¿f˜/E_Á—«Ÿ˜ˆ.Sý~j¯y>¼ \ No newline at end of file diff --git a/src/gfx/game/up_panel.png b/src/gfx/game/up_panel.png new file mode 100644 index 0000000..e5a9a29 --- /dev/null +++ b/src/gfx/game/up_panel.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄŒÖ_6ånš¢R)Jér-¦™½.¬ ñÜdTw禺úëL½`l'–-KÄCç¡»´áºüÞÉÑdèçnҞb-›?ô6‚ÖÍ%§­"¿Ìc‚¨<¯DÁÿ3á1ÿ–sp?™Swm'»Í!ôåÆVz`VÛBw8£i \ No newline at end of file diff --git a/src/gfx/hscore/window.png b/src/gfx/hscore/window.png new file mode 100644 index 0000000..cd1612c Binary files /dev/null and b/src/gfx/hscore/window.png differ diff --git a/src/gfx/icon.png b/src/gfx/icon.png new file mode 100644 index 0000000..5e63de5 Binary files /dev/null and b/src/gfx/icon.png differ diff --git a/src/gfx/loading/loading.png b/src/gfx/loading/loading.png new file mode 100644 index 0000000..860069c --- /dev/null +++ b/src/gfx/loading/loading.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÇÖ_6Tþ/š¢Rdf¡lr-¦ì,®ýŽ˜ô)‚£®Ú»4æ²@v‡Ý|.ŒÍ&P»íR#ËÏÒon#ŒöÏæ åÿ>¹E‚ÎÚϯèŒÐó°15ü*Œ]¿‚ÿg°?„'[Éê5xÏ#‰î‘ñÂ.„A(«  \ No newline at end of file diff --git a/src/gfx/menu/choise.png b/src/gfx/menu/choise.png new file mode 100644 index 0000000..599d5f8 Binary files /dev/null and b/src/gfx/menu/choise.png differ diff --git a/src/gfx/menu/window.png b/src/gfx/menu/window.png new file mode 100644 index 0000000..f2b7b4e Binary files /dev/null and b/src/gfx/menu/window.png differ diff --git a/src/gfx/pause/choise.png b/src/gfx/pause/choise.png new file mode 100644 index 0000000..05657a1 Binary files /dev/null and b/src/gfx/pause/choise.png differ diff --git a/src/gfx/pause/window.png b/src/gfx/pause/window.png new file mode 100644 index 0000000..d6649e7 --- /dev/null +++ b/src/gfx/pause/window.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÃÖ_6±nš¢RMin*r-¶”½.¬ ñÜô\°Ç&òóJÁ›:%1`§†âÄvå‹îCCÇܣʩ(Z”Î÷…ÙG‡~Á=+iŽjáÏ2Ù4ߓ/ð€Ê™¢.Û±2ÎöE[=!™1äóJÍÜ&8öµ,¹5îÞðpÁ€ÓŒn³Ÿ5ZYÓtØÀ±"I\y`dìþ½W°9ÂÏ$;n‡²óË·ƒò›ë*´jýÍ(Vd}•æz£›L*‡ò¿Ù¼Ü“pV¢ox­‘j:?}÷‚M(\cêÕ¤x%¤Ñä8‚+T-þ÷ô|'—¨,οkQ­›¬v.ÐÀ‹”&Y'PïLN•‡j¡aõ¼2sùA'²mʶx‰ÛŠ®³½-sH¨“³Ö‘ÆNÞ}SøV㊆˜*i½lDK,Ó÷f ÌH…±8Nan;!ñÏI³óŒ=ð§0q K•Îg¶ó]Eé¨Õ¿ÛD~M­lˆ!Ât´áâ. ®:Ì;kèÞ»T;ÎãSöe:eöc RA6`Ì(ƒK3 '½Û \ No newline at end of file diff --git a/src/gfx/select_ship/frame.png b/src/gfx/select_ship/frame.png new file mode 100644 index 0000000..5442326 Binary files /dev/null and b/src/gfx/select_ship/frame.png differ diff --git a/src/gfx/select_ship/lr_button.png b/src/gfx/select_ship/lr_button.png new file mode 100644 index 0000000..41fba6b Binary files /dev/null and b/src/gfx/select_ship/lr_button.png differ diff --git a/src/gfx/select_ship/window.png b/src/gfx/select_ship/window.png new file mode 100644 index 0000000..7c1c105 Binary files /dev/null and b/src/gfx/select_ship/window.png differ diff --git a/src/gfx/ship/0.png b/src/gfx/ship/0.png new file mode 100644 index 0000000..3d82c3e Binary files /dev/null and b/src/gfx/ship/0.png differ diff --git a/src/gfx/ship/1.png b/src/gfx/ship/1.png new file mode 100644 index 0000000..10937e7 Binary files /dev/null and b/src/gfx/ship/1.png differ diff --git a/src/gfx/ship/2.png b/src/gfx/ship/2.png new file mode 100644 index 0000000..daab9d9 Binary files /dev/null and b/src/gfx/ship/2.png differ diff --git a/src/gfx/ship/3.png b/src/gfx/ship/3.png new file mode 100644 index 0000000..2165ed7 Binary files /dev/null and b/src/gfx/ship/3.png differ diff --git a/src/gfx/ship/5.png b/src/gfx/ship/5.png new file mode 100644 index 0000000..eaaa593 Binary files /dev/null and b/src/gfx/ship/5.png differ diff --git a/src/gfx/ship/nozzle.png b/src/gfx/ship/nozzle.png new file mode 100644 index 0000000..74c9b51 --- /dev/null +++ b/src/gfx/ship/nozzle.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÖ_6´nš¢RCÖ¸4r-¦½.¬ ñ4¦»NóGÏk첿?Ör.xÇØÉ©Ö)Яæí[–$õi<ŒN ”œ¥”+V‹èã‡ø%<ÃóõÙÔOØ/UŠ[¼X2-–Æ \ No newline at end of file diff --git a/src/gfx/space/background.png b/src/gfx/space/background.png new file mode 100644 index 0000000..068f758 Binary files /dev/null and b/src/gfx/space/background.png differ diff --git a/src/gfx/space/planet/0.png b/src/gfx/space/planet/0.png new file mode 100644 index 0000000..c4e22d7 Binary files /dev/null and b/src/gfx/space/planet/0.png differ diff --git a/src/gfx/space/planet/1.png b/src/gfx/space/planet/1.png new file mode 100644 index 0000000..621f67d Binary files /dev/null and b/src/gfx/space/planet/1.png differ diff --git a/src/gfx/space/planet/2.png b/src/gfx/space/planet/2.png new file mode 100644 index 0000000..4c40134 Binary files /dev/null and b/src/gfx/space/planet/2.png differ diff --git a/src/gfx/space/planet/3.png b/src/gfx/space/planet/3.png new file mode 100644 index 0000000..3e9d9a4 Binary files /dev/null and b/src/gfx/space/planet/3.png differ diff --git a/src/gfx/space/planet/4.png b/src/gfx/space/planet/4.png new file mode 100644 index 0000000..d6ae53e Binary files /dev/null and b/src/gfx/space/planet/4.png differ diff --git a/src/gfx/splash/0.png b/src/gfx/splash/0.png new file mode 100644 index 0000000..3103366 --- /dev/null +++ b/src/gfx/splash/0.png @@ -0,0 +1 @@ +ÂE½ãÀ‚å®â ”‹nwUQ?ÄÖ_6•þ/š¢Rç‰]ír-¦ì,®ýŽ\)ž3úÓæ²@ÕT¼Œ^%•$Éù£ýá\Ý〰iKøfù!Tú²tÅ ‰D)Ï&†‡‡ù/Ї—66Üͤª¥#먐ªí>Ì=}«ÒWnñktçÂ_)EûqKìWž[>þ¦²œ³ÕÈ \ No newline at end of file diff --git a/src/gfx/splash/1.png b/src/gfx/splash/1.png new file mode 100644 index 0000000..24b42a0 Binary files /dev/null and b/src/gfx/splash/1.png differ diff --git a/src/quote.txt b/src/quote.txt new file mode 100644 index 0000000..a979271 --- /dev/null +++ b/src/quote.txt @@ -0,0 +1,15 @@ +7 +Happy new war! +... +Reactor.Core.destroy() +4 +The rocket took off perfectly. The only pity is landed on the wrong planet. +Wernher von Braun +Kalter +Five +Stuart needs "space" and "time", as if this were physics and not a human relationship. +Kathryn Stockett +That's one small step for a man, one giant leap for mankind. +Neil Armstrong +Every human has a finite number of heartbeats. I don't intent to waste any of mine. +Neil Armstrong diff --git a/src/song/iha.mid b/src/song/iha.mid new file mode 100644 index 0000000..e00ea47 Binary files /dev/null and b/src/song/iha.mid differ diff --git a/src/song/mobscene.mid b/src/song/mobscene.mid new file mode 100644 index 0000000..cd6956c Binary files /dev/null and b/src/song/mobscene.mid differ diff --git a/src/song/monster.mid b/src/song/monster.mid new file mode 100644 index 0000000..f87b2dd Binary files /dev/null and b/src/song/monster.mid differ