commit 20004acd6affb9ad808c1c0d5a052c89be42e055 Author: Victor Date: Thu Nov 15 00:08:28 2018 +0200 Initial diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..92f624e --- /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..0e03cfa --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Classpath to J2ME Ant extension library (libs.j2me_ant_ext.classpath property) is not set. For example: location of mobility/modules/org-netbeans-mobility-antext.jar file in the IDE installation directory. + Platform home (platform.home property) is not set. Value of this property should be ${platform.active.description} emulator home directory location. + Platform boot classpath (platform.bootclasspath property) is not set. Value of this property should be ${platform.active.description} emulator boot classpath containing all J2ME classes provided by emulator. + Must set src.dir + Must set build.dir + Must set dist.dir + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preprocessed.dir + + + + + + + + + + + + + + + + + + Must set build.classes.dir + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must set obfuscated.classes.dir + + + + Must set obfuscated.classes.dir + Must set obfuscator.srcjar + Must set obfuscator.destjar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preverify.classes.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroEdition-Configuration: ${platform.configuration} + + MicroEdition-Configuration: ${platform.configuration} + + + + MicroEdition-Profile: ${platform.profile} + + MicroEdition-Profile: ${platform.profile} + + + + Must set dist.jad + + + + + + + + + + + + + + + + + + + + + + + + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.jad} + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.manifest} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Must set dist.javadoc.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${all.configurations} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property deployment.${deployment.method}.scriptfile not set. The property should point to an Ant script providing ${deployment.method} deployment. + + + + + + + + Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set. + + + + + + + + + Active project configuration: @{cfg} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property build.root.dir is not set. By default its value should be \"build\". + Property dist.root.dir is not set. By default its value should be \"dist\". + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..6e9bb9b --- /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=2878d7b0 +build.xml.script.CRC32=a6631c98 +build.xml.stylesheet.CRC32=9c6a911d +nbproject/build-impl.xml.data.CRC32=2878d7b0 +nbproject/build-impl.xml.script.CRC32=1f347715 +nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..cd031fe --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,8 @@ +#Sun, 01 Jul 2012 14:50:07 +0300 +#Fri May 07 21:10:28 VOLST 2010 +netbeans.user=C\:\\Users\\aNNiMON\\AppData\\Roaming\\NetBeans\\dev +javadoc.preview=true +config.active= +deployment.counter=77 +app-version.autoincrement=true +deployment.number=0.0.76 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..8505fc1 --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..c653230 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,169 @@ +abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,JSR226=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,J2MEWS=1.0,WMA=2.0,JSR172=1.0,OBEX=1.0,ColorScreen,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,JSR75=1.0,JSR184=1.1,SATSAPKI=1.0,ScreenHeight=320,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0, +all.configurations=\ ,Release +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 +configs.Release.abilities=MMAPI=1.1,JSR82=1.1,JSR280=1.0,JSR226=1.0,MIDP=2.1,JSR229=1.1,SATSA=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0,RELEASE=,J2MEWS=1.0,WMA=2.0,JSR172=1.0,JSR256=1.0,ColorScreen,OBEX=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,JSR75=1.0,JSR184=1.1,ScreenHeight=320,ScreenColorDepth=16,JSR180=1.1.0 +configs.Release.debug.level=debug +configs.Release.extra.classpath= +configs.Release.filter.exclude.tests=true +configs.Release.filter.excludes= +configs.Release.filter.more.excludes=**/overview.html,**/package.html +configs.Release.filter.use.standard=true +configs.Release.javac.debug=true +configs.Release.javac.deprecation=false +configs.Release.javac.encoding=UTF-8 +configs.Release.javac.optimize=true +configs.Release.javac.source=1.3 +configs.Release.javac.target=1.3 +configs.Release.libs.classpath= +configs.Release.obfuscation.custom= +configs.Release.obfuscation.level=9 +configs.Release.platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_ +configs.Release.platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator) +configs.Release.platform.apis=JSR234-1.0,J2ME-WS-1.0,JSR239-1.0,JSR238-1.0,MMAPI-1.1,JSR226-1.0,JSR75-1.0,JSR184-1.1,WMA-2.0,JSR211-1.0,JSR82-1.1 +configs.Release.platform.bootclasspath=${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/mmapi.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar +configs.Release.platform.configuration=CLDC-1.1 +configs.Release.platform.device=SonyEricsson_JP8_240x320_Emu +configs.Release.platform.fat.jar=true +configs.Release.platform.profile=MIDP-2.0 +configs.Release.platform.trigger=CLDC +configs.Release.platform.type=UEI-1.0.1 +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=Tank.jad +dist.jar=Tank.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=changelog.txt +filter.more.excludes=**/overview.html,**/package.html +filter.use.standard=true +jar.compress=true +javac.debug=true +javac.deprecation=false +javac.encoding=UTF-8 +javac.optimize=true +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: Tank,/res/tank.png,tank.Tank\n +manifest.others=MIDlet-Vendor: P@bloid\nMIDlet-Name: Tank\nMIDlet-Icon: /res/tank.png\nMIDlet-Version: ${deployment.number}\n +manifest.pushregistry= +name=Tank +no.dependencies=false +nokiaS80.application.icon= +nsicom.application.monitorhost= +nsicom.application.runremote= +nsicom.application.runverbose= +nsicom.remoteapp.location=\\My Documents\\NetBeans Applications +nsicom.remotevm.location=\\Windows\\creme\\bin\\CrEme.exe +obfuscated.classes.dir=${build.dir}/obfuscated +obfuscation.custom=-keep public class * extends javax.microedition.midlet.MIDlet \n-obfuscationdictionary E:\\SETUPS\\Disk\\Programming\\Java\\compact.txt\n-dontusemixedcaseclassnames\n-repackageclasses '' +obfuscation.level=1 +obfuscator.destjar=${build.dir}/obfuscated.jar +obfuscator.srcjar=${build.dir}/before-obfuscation.jar +platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_ +platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator) +platform.apis=WMA-2.0,JSR238-1.0,JSR211-1.0,JSR82-1.1,JSR234-1.0,J2ME-WS-1.0,JSR239-1.0,JSR226-1.0,JSR75-1.0,JSR184-1.1 +platform.bootclasspath=${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar +platform.configuration=CLDC-1.1 +platform.device=SonyEricsson_JP8_240x320_Emu +platform.fat.jar=true +platform.profile=MIDP-2.0 +platform.trigger=CLDC +platform.type=UEI-1.0.1 +preprocessed.dir=${build.dir}/preprocessed +preverify.classes.dir=${build.dir}/preverified +preverify.sources.dir=${build.dir}/preverifysrc +resources.dir=resources +ricoh.application.email= +ricoh.application.fax= +ricoh.application.icon= +ricoh.application.target-jar= +ricoh.application.telephone= +ricoh.application.uid=38103365 +ricoh.application.version= +ricoh.dalp.application-desc.auto-run=false +ricoh.dalp.application-desc.energy-save= +ricoh.dalp.application-desc.exec-auth= +ricoh.dalp.application-desc.visible=true +ricoh.dalp.argument= +ricoh.dalp.codebase= +ricoh.dalp.display-mode.color=true +ricoh.dalp.display-mode.is-4line-support=false +ricoh.dalp.display-mode.is-hvga-support=true +ricoh.dalp.display-mode.is-vga-support=false +ricoh.dalp.display-mode.is-wvga-support=false +ricoh.dalp.information.abbreviation= +ricoh.dalp.information.icon.basepath= +ricoh.dalp.information.icon.location= +ricoh.dalp.information.is-icon-used=true +ricoh.dalp.install.destination=hdd +ricoh.dalp.install.mode.auto=true +ricoh.dalp.install.work-dir=hdd +ricoh.dalp.is-managed=true +ricoh.dalp.resources.dsdk.version=2.0 +ricoh.dalp.resources.jar.basepath= +ricoh.dalp.resources.jar.version= +ricoh.dalp.version= +ricoh.icon.invert=false +ricoh.platform.target.version= +run.cmd.options= +run.jvmargs= +run.method=STANDARD +run.security.domain=trusted +run.use.security.domain=false +savaje.application.icon= +savaje.application.icon.focused= +savaje.application.icon.small= +savaje.application.uid=TBD +savaje.bundle.base= +savaje.bundle.debug=false +savaje.bundle.debug.port= +semc.application.caps= +semc.application.icon= +semc.application.icon.count= +semc.application.icon.splash= +semc.application.icon.splash.installonly=false +semc.application.uid=E0691280 +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..1668d7d --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,11 @@ + + + org.netbeans.modules.kjava.j2meproject + + + Tank + 1.6 + + + + diff --git a/src/changelog.txt b/src/changelog.txt new file mode 100644 index 0000000..74f53f7 --- /dev/null +++ b/src/changelog.txt @@ -0,0 +1,11 @@ + : + +. + . +HSV . . + . + Motion-blur ( ). + . + + + : diff --git a/src/res/bomb.png b/src/res/bomb.png new file mode 100644 index 0000000..5aeebc6 Binary files /dev/null and b/src/res/bomb.png differ diff --git a/src/res/car.png b/src/res/car.png new file mode 100644 index 0000000..ead19ef Binary files /dev/null and b/src/res/car.png differ diff --git a/src/res/fuel.png b/src/res/fuel.png new file mode 100644 index 0000000..7290359 Binary files /dev/null and b/src/res/fuel.png differ diff --git a/src/res/live.png b/src/res/live.png new file mode 100644 index 0000000..7838e56 Binary files /dev/null and b/src/res/live.png differ diff --git a/src/res/man.png b/src/res/man.png new file mode 100644 index 0000000..e79055c Binary files /dev/null and b/src/res/man.png differ diff --git a/src/res/mis.png b/src/res/mis.png new file mode 100644 index 0000000..6d519f7 Binary files /dev/null and b/src/res/mis.png differ diff --git a/src/res/police.png b/src/res/police.png new file mode 100644 index 0000000..a8860d2 Binary files /dev/null and b/src/res/police.png differ diff --git a/src/res/tank.png b/src/res/tank.png new file mode 100644 index 0000000..d6905d7 Binary files /dev/null and b/src/res/tank.png differ diff --git a/src/tank/Const.java b/src/tank/Const.java new file mode 100644 index 0000000..1b8ae42 --- /dev/null +++ b/src/tank/Const.java @@ -0,0 +1,46 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package tank; + +import java.util.Random; +import javax.microedition.lcdui.Font; + +/** + * Класс для хранения постоянных объектов + * @author aNNiMON + */ +public class Const { + + // + /** + * Стандартный шрифт + */ + public static final Font def = Font.getDefaultFont(); + /** + * Высота стандартного шрифта + */ + public static final int defheight = def.getHeight();//Font.getDefaultFont(); + /** + * Жирный большой шрифт + */ + public static final Font bl = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE); + /** + * Маленький обычный шрифт + */ + public static final Font ps = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); + // + + public static final Random rnd = new Random(); + + /** + * Включена ли глобально вибрация + */ + public static boolean isVibrate = true;//false; + /** + * Эффект размытия в движении + */ + public static boolean isMotionBlur = false; +} diff --git a/src/tank/HSVProcessor.java b/src/tank/HSVProcessor.java new file mode 100644 index 0000000..52e8cfd --- /dev/null +++ b/src/tank/HSVProcessor.java @@ -0,0 +1,101 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package tank; + +import javax.microedition.lcdui.Image; + +/** + * + * @author aNNiMON + */ +public class HSVProcessor { + + private Image currentImage; + + public HSVProcessor(Image img) { + currentImage = img; + } + + public void setImage(Image img) { + currentImage = img; + } + + public Image[] getHSVImages(int num) { + int step = 360/(num+1); + Image[] out = new Image[num]; + out[0] = currentImage; + for(int i=1; i> 24) & 0xff; + int qr = (pixel[io] >> 16) & 0xff; + int qg = (pixel[io] >> 8) & 0xff; + int qb = pixel[io] & 0xff; + hsb = RGBtoHSV(qr, qg, qb, hsb); + hsb[0] += hh; + while(hsb[0]>360) hsb[0]-=360; + pixel[io] = (qa << 24) | HSVtoRGB(hsb[0], hsb[1], hsb[2]); + } + return Image.createRGBImage(pixel, w, h, true); + } + + private int HSVtoRGB(float h, float s, float v) { + float qr = 0, qg = 0, qb = 0; + int r = 0, g = 0, b = 0; + if(s==0.0 && h==-1.0) return ((int)v << 16) | ((int)v << 8) | (int)v; + int Hi = (int) ((h / 60) % 6); + float f = (float) (h / 60 - (float)Math.floor(h/60)); + float p = (float) ((float)v*(1.0f - (float)s)); + float q = (float) ((float)v*(1.0f - (float)f*(float)s)); + float t = (float) ((float)v*(1.0f - (s*(1.0-f)))); + switch(Hi) { + case 0: qr = v; qg = t; qb = p; break; + case 1: qr = q; qg = v; qb = p; break; + case 2: qr = p; qg = v; qb = t; break; + case 3: qr = p; qg = q; qb = v; break; + case 4: qr = t; qg = p; qb = v; break; + case 5: qr = v; qg = p; qb = q; break; + } + r = (int) (255 * qr); g = (int) (255 * qg); b = (int) (255 * qb); + return (r << 16) | (g << 8) | b; + } + + private float[] RGBtoHSV(int qr, int qg, int qb, float[] hsv) { + float h = 0, s, v; + if (hsv == null) { + hsv = new float[3]; + } + float r = (float) qr/255; float g = (float) qg/255; float b = (float) qb/255; + v = (r > g) ? r : g; + if (b > v) v = b; + float min = (r < g) ? r : g; + if (b < min) min = b; + // hue + if(v==min) h=0; + else if(v==r && g>=b) h = 60 * ((g-b)/(v-min)); + else if(v==r && g + private static final int FIRE_SPEED_PRICE = 2000, + MAX_MISSILES_PRICE = 1750, + MISSILES_SPEED_PRICE = 1500, + CONTROLLABILITY_PRICE = 1250, + MAX_FUEL_PRICE = 1000, + BOMB_PRICE = 5000; + // + + // + public static Tank midlet; + public Display dsp; + public Menu menu; + private Menu shop, confirm; + private TankCanvas c; + private boolean bReset; + + public Tank() { + midlet = Tank.this; + dsp = Display.getDisplay(Tank.this); + shop = new Menu(new String[] { + "+Частота стрельбы(2000)", + "+Ракеты(1750)", + "+Скорость ракет(1500)", + "+Управление(1250)", + "+Топливо(1000)", + "+Бомба(5000)", + "Назад" + }); + menu = new Menu(new String[] { + "Заезд", "Магазин", "Помощь", "Обнулить прогресс", "Выход" + }); + confirm = new Menu(new String[] { + "Нет", "Да" + }); + } + + public void startApp() { + c = new TankCanvas(); + Rms.restoreOptions(); + dsp.setCurrent(menu); + menu.setCommandListener(this); + menu.setText("Рекорд: " + TankCanvas.maxScore); + menu.setMessage("Танк, автор P@bloid"); + menu.repaint(); + shop.setCommandListener(this); + confirm.setCommandListener(this); + } + + public void pauseApp() { + System.gc(); + } + + public void destroyApp(boolean unconditional) { + Rms.saveOptions(); + notifyDestroyed(); + } + // + + // + public void commandAction(Command cmd, Displayable disp) { + try { + if (disp == shop) operateShop(); + else if(disp == menu) operateMenu(); + else if(disp == confirm && bReset) { + bReset = false; + if (confirm.getSelectedIndex() == 1) + c.resetGame(); + dsp.setCurrent(menu); + confirm.setMessage(""); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + //Главное меню + private void operateMenu() throws Exception { + switch (menu.getSelectedIndex()) { + case 0: + if(c.gameOver) c.reset(); + dsp.setCurrent(c); + break; + case 1: + dsp.setCurrent(shop); + shop.repaint(); + shop.setMessage("Денег: " + TankCanvas.money); + break; + case 2: + dsp.setCurrent(shop); + shop.repaint(); + shop.setMessage("Денег: " + TankCanvas.money); + break; + case 3: + dsp.setCurrent(confirm); + confirm.setMessage("Обнулить результаты?"); + bReset = true; + break; + case 4: + destroyApp(true); + break; + } + } + + private void operateShop() throws Exception { + switch (shop.getSelectedIndex()) { + + case 0: + if (TankCanvas.money < FIRE_SPEED_PRICE) { + shop.setText("Недостаточно денег"); + break; + } + TankCanvas.money -= FIRE_SPEED_PRICE; + TankCanvas.fireSpeed -= (TankCanvas.fireSpeed / 20); + shop.setText("+Частота стрельбы"); + if (TankCanvas.fireSpeed < 10) { + TankCanvas.fireSpeed = 10; + TankCanvas.money += FIRE_SPEED_PRICE; + shop.setText("Максимум"); + } + break; + + case 1: + if (TankCanvas.money < MAX_MISSILES_PRICE) { + shop.setText("Недостаточно денег"); + break; + } + TankCanvas.money -= MAX_MISSILES_PRICE; + TankCanvas.maxMis++; + shop.setText("+Ракеты"); + break; + + case 2: + if (TankCanvas.money < MISSILES_SPEED_PRICE) { + shop.setText("Недостаточно денег"); + break; + } + TankCanvas.money -= MISSILES_SPEED_PRICE; + TankCanvas.mis += 0.2d; + shop.setText("+Скорость ракет"); + if (TankCanvas.mis > c.imMis.getHeight()) { + TankCanvas.mis = c.imMis.getHeight(); + TankCanvas.money += MISSILES_SPEED_PRICE; + shop.setText("Максимум"); + } + break; + + case 3: + if (TankCanvas.money < CONTROLLABILITY_PRICE) { + shop.setText("Недостаточно денег"); + break; + } + TankCanvas.money -= CONTROLLABILITY_PRICE; + TankCanvas.controlSpeed++; + shop.setText("+Управление"); + if (TankCanvas.controlSpeed > c.imTank.getHeight()) { + TankCanvas.controlSpeed = c.imMis.getHeight(); + TankCanvas.money += CONTROLLABILITY_PRICE; + shop.setText("Максимум"); + } + break; + + case 4: + if (TankCanvas.money < MAX_FUEL_PRICE) { + shop.setText("Недостаточно денег"); + break; + } + TankCanvas.money -= MAX_FUEL_PRICE; + TankCanvas.maxFuel += (int) Math.ceil(5000 / TankCanvas.maxFuel); + shop.setText("+Топливо"); + break; + + case 5: + if (TankCanvas.money < BOMB_PRICE) { + shop.setText("Недостаточно денег"); + break; + } + TankCanvas.money -= BOMB_PRICE; + TankCanvas.bombs++; + shop.setText("+Бомбы"); + break; + + default: + dsp.setCurrent(menu); + menu.repaint(); + shop.setText(""); + break; + } + shop.setMessage("Денег: " + TankCanvas.money); + }// +} diff --git a/src/tank/TankCanvas.java b/src/tank/TankCanvas.java new file mode 100644 index 0000000..edd9a0e --- /dev/null +++ b/src/tank/TankCanvas.java @@ -0,0 +1,526 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package tank; + +import javax.microedition.lcdui.*; +import javax.microedition.lcdui.game.*; +import java.util.*; + +/** + * @author pabloid + */ +public class TankCanvas extends Canvas implements Runnable { + + private static final int K_RIGHT = 0; + private static final int K_UP = 1; + private static final int K_LEFT = 2; + private static final int K_DOWN = 3; + private static final int K_FIRE = 4; + private static final int K_POUND = 5; + private static final int SPCAR_SPRITE_WIDTH = 18; //ширина спрайта машины + private static final int SPCAR_SPRITE_HEIGHT = 39; //высота спрайта машины + private static final int NUM_OF_CAR_SPRITES = 1; + private static final int NUM_OF_COLOUR_CAR = 16; + private static final int MAX_JITTER_COUNT = 18; //кол-во кадров дрожания экрана + private static final int MAX = 15; //кол-во машин на экране + + // + public static int + maxScore, //Рекорд + money; //Деньги + public static int + fireSpeed = 1000, //Скорострельность (сколько мс. требуется для перезарядки) + controlSpeed = 1, //Скорость управления + level = 1, //Ни на что не влияет + maxFuel = 100, //Вместимость бензобака + maxMis = 2, //Макс. количество ракет на экране + bombs = 0; //Что-то делает) + public static double mis = 1; //Скорость полёта снаряда + // + + public boolean bRun, //запущен главный поток + gameOver; //окончена ли игра (надпись на экране) + public Image imTank, imMis; + private Image[] imCars; + private HSVProcessor hp; + private Image imMan, imCar, polCar, imLive, imFuel, imBomb; + private Image buf; + private Graphics G; + private int w, h, w2, h2, w6, ww6; + private Sprite spTank; + private Sprite[] spMan, spCar; + private boolean[] keys; + private double ry, ry2; + private double[] cy, my; + //--------------------------------- + private boolean bCheat, //чит на 20000$ + jit; //дрожание экрана при столкновении + private int jitcount; + private final int RW, RH; //Размер дорожной разметки + private double speed; + + private Vector vMis = new Vector(); + private long lastFire, ticks; + private int fuel, lives, score, maxCars; + private double ly, fy, by; + private int lx, fx, bx; + + public TankCanvas() { + setFullScreenMode(true); + w = getWidth(); + h = getHeight(); + w2 = w/2; + h2 = h/2; + w6 = w/6; + ww6 = w-w6; + buf = Image.createImage(w, h); + G = buf.getGraphics(); + + //init + spMan = new Sprite[MAX]; + spCar = new Sprite[MAX]; + cy = new double[MAX]; + my = new double[MAX]; + keys = new boolean[] { + false, false, false, false, false, false + }; + jit = gameOver = bCheat = false; + ticks = lastFire = 0; + jitcount = score = 0; + speed = maxCars = 1; + lives = 2; + fuel = 100; + + RW = w/40; + RH = h/10; + ry = -RH; + ry2 = ry + h2; + resetLive(); + resetFuel(); + try { + imTank = Image.createImage("/res/tank.png"); + imMan = Image.createImage("/res/man.png"); + polCar = Image.createImage("/res/police.png"); + imCar = Image.createImage("/res/car.png"); + hp = new HSVProcessor(imCar); + imCars = hp.getHSVImages(NUM_OF_COLOUR_CAR); + + imMis = Image.createImage("/res/mis.png"); + imLive = Image.createImage("/res/live.png"); + imFuel = Image.createImage("/res/fuel.png"); + imBomb = Image.createImage("/res/bomb.png"); + spTank = new Sprite(imTank); + reset(); + spTank.defineReferencePixel(8, 8); + spTank.setRefPixelPosition(w2, h-50); + new Thread(this).start(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + + // + public final void reset() { + for (int i = 0; i < MAX; i++) { + spMan[i] = new Sprite(imMan, 6, 10); + spCar[i] = new Sprite(imCars[random(0, NUM_OF_COLOUR_CAR)], SPCAR_SPRITE_WIDTH, SPCAR_SPRITE_HEIGHT);//14, 23); + spMan[i].defineReferencePixel(3, 5); + spCar[i].defineReferencePixel(SPCAR_SPRITE_WIDTH/2, SPCAR_SPRITE_HEIGHT/2); + resetCar(i); + resetMan(i); + } + //Создаём полицейскую машину + int ii = random(0, NUM_OF_COLOUR_CAR/2); + spCar[ii].setImage(polCar, SPCAR_SPRITE_WIDTH, SPCAR_SPRITE_HEIGHT); + spCar[ii].defineReferencePixel(SPCAR_SPRITE_WIDTH/2, SPCAR_SPRITE_HEIGHT/2); + resetCar(ii); + + gameOver = false; + bRun = true; + score = 0; + maxCars = 1; + speed = 1; + lives = 2; + fuel = maxFuel; + vMis.removeAllElements(); + spTank.setRefPixelPosition(w2, h - 50); + } + + public void resetGame() throws Throwable { + reset(); + bombs = maxScore = money = 0; + mis = 1; + controlSpeed = level = 1; + maxMis = 2; + maxFuel = 100; + fireSpeed = 1000; + Tank.midlet.menu.setText("Рекорд: " + maxScore); + } + + public void run() { + while (true) { + while (bRun) { + try { + tick(); + ticks++; + if ((ticks % 25) == 0) { + fuel--; + score += (int) Math.floor(speed); + } + if ((ticks % 1500) == 0) { + if (maxCars != MAX) maxCars++; + speed += 0.5; + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + synchronized (this) { + try { + wait(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + } + // + + // + protected void paint(Graphics g) { + int x = 0; + int y = 0; + if(jit) {//дрожание экрана при столкновении + int spd = (int)(speed); + x = random(-spd, spd); + y = random(-spd, spd); + if(Const.isVibrate) Tank.midlet.dsp.vibrate(spd+1); + jitcount++; + if(jitcount>=MAX_JITTER_COUNT) jit=false; + g.setColor(UI.GRASS_COLOR); + g.fillRect(0, 0, w, h); + } + g.drawImage(buf, x, y, 20); + } + + protected void keyPressed(int key) { + if (key == KEY_NUM1 || key == KEY_NUM0) { + if (bCheat) money += 20000; + else bCheat = true; + } + + if (bRun) { + int ga = getGameAction(key); + if (ga == LEFT) keys[K_LEFT] = true; + else if(ga == UP) keys[K_UP] = true; + else if (ga == DOWN) keys[K_DOWN] = true; + else if (ga == RIGHT) keys[K_RIGHT] = true; + else if (ga == FIRE) keys[K_FIRE] = true; + else if (key == KEY_POUND) keys[K_POUND] = true; + else if (key == KEY_STAR || key == -6 || key ==-7) { + //gameOver(); + Tank.midlet.dsp.setCurrent(Tank.midlet.menu); + } + } else { + switch (key) { + case KEY_NUM1: + reset(); + showNotify(); + break; + case KEY_NUM2: + Tank.midlet.dsp.setCurrent(Tank.midlet.menu); + break; + } + } + } + + protected void keyReleased(int key) { + bCheat = false; + int ga = getGameAction(key); + if (ga == LEFT) keys[K_LEFT] = false; + else if(ga == UP) keys[K_UP] = false; + else if (ga == DOWN) keys[K_DOWN] = false; + else if (ga == RIGHT) keys[K_RIGHT] = false; + else if (ga == FIRE) keys[K_FIRE] = false; + else if (key == KEY_POUND) keys[K_POUND] = false; + } + + protected void showNotify() { + bRun = true; + synchronized (this) { + try { + notifyAll(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + + protected void hideNotify() { + bRun = false; + } + // + + private void moveRoad() { + ry += speed; + if (ry > h) ry = -RH; + ly += speed; + if (ly > h) resetLive(); + fy += speed; + if (fy > h) resetFuel(); + by += speed; + if (by > h) resetBomb(); + ry2 += speed; + if (ry2 > h) ry2 = -RH; + for (int i = 0; i < maxCars; i++) { + if (spCar[i].getFrame() < NUM_OF_CAR_SPRITES) { + if (spCar[i].getRefPixelX() < w2) { + cy[i] += speed * 2.0; + } else { + cy[i] += speed / 2.0; + } + } else { + cy[i] += speed; + } + spCar[i].setRefPixelPosition(spCar[i].getRefPixelX(), (int) cy[i]); + if (cy[i] > h + 10) resetCar(i); + if (spMan[i].getFrame() == 0) { + if (spMan[i].getRefPixelX() < w2) { + my[i] += speed * 1.5; + } else { + my[i] += speed / 1.5; + } + } else { + my[i] += speed; + } + spMan[i].setRefPixelPosition(spMan[i].getRefPixelX(), (int) my[i]); + if (my[i] > h + 10) resetMan(i); + } + } + + private void moveMis(int i) { + Missile m = (Missile) vMis.elementAt(i); + m.y -= mis; + if (m.y < -8) vMis.removeElementAt(i); + } + + private void tick() throws Throwable { + //--------------------------------------------- + if(Const.isMotionBlur) { + int ww = w-2*w6; + int[] pixelArray = new int[ww * h]; + for (int io = 0; io < pixelArray.length; io++) { + pixelArray[io] = 0x30000000 | UI.ROAD_COLOR; + } + G.drawRGB(pixelArray, 0, ww, w6, 0, ww, h, true); + }else{ + G.setColor(UI.ROAD_COLOR); + G.fillRect(0, 0, w, h); + } + G.setColor(UI.GRASS_COLOR); + G.fillRect(0, 0, w6, h); + G.fillRect(ww6, 0, w6, h); + G.setFont(Const.ps); + //--------------------------------------------- + moveRoad(); + if (keys[K_UP] && (spTank.getRefPixelY() > 8)) { + spTank.move(0, -controlSpeed); + }else if (keys[K_DOWN] && (spTank.getRefPixelY() < h - 8)) { + spTank.move(0, controlSpeed); + } + if (keys[K_RIGHT] && (spTank.getRefPixelX() < ww6 - 8)) { + spTank.move(controlSpeed, 0); + }else if (keys[K_LEFT] && (spTank.getRefPixelX() > w6 + 8)) { + spTank.move(-controlSpeed, 0); + } + if (keys[K_FIRE] && vMis.size() < maxMis && System.currentTimeMillis() - lastFire > fireSpeed) { + Missile m = new Missile(spTank.getRefPixelX() - 1, spTank.getY() - 8); + vMis.addElement(m); + lastFire = System.currentTimeMillis(); + } + if (keys[K_POUND] && bombs != 0) { + bombs--; + for (int i = 0; i < maxCars; i++) { + if (spCar[i].getFrame() < NUM_OF_CAR_SPRITES) { + spCar[i].setFrame(spCar[i].getFrame() + NUM_OF_CAR_SPRITES); + } + spMan[i].setFrame(1); + } + keys[K_POUND] = false; + } + for (int i = 0; i < maxCars; i++) { + for (int j = 0; j < maxCars; j++) { + if (i != j) { + if (spMan[j].getFrame() == 0 && spCar[i].collidesWith(spMan[j], false)) { + spMan[j].setFrame(1); + } + if (spCar[i].collidesWith(spCar[j], false)) { + if (spCar[j].getFrame() < NUM_OF_CAR_SPRITES) { + spCar[j].setFrame(spCar[j].getFrame() + NUM_OF_CAR_SPRITES); + } + if (spCar[i].getFrame() < NUM_OF_CAR_SPRITES) { + spCar[i].setFrame(spCar[i].getFrame() + NUM_OF_CAR_SPRITES); + } + } + if (spMan[i].collidesWith(spMan[j], false)) { + if (spMan[j].getFrame() == 0) { + spMan[j].setFrame(1); + } + if (spMan[i].getFrame() == 0) { + spMan[i].setFrame(1); + } + } + } + } + if (spTank.collidesWith(spMan[i], false) && spMan[i].getFrame() == 0) { + spMan[i].setFrame(1); + score += 5; + } + if (spTank.collidesWith(spCar[i], false) && spCar[i].getFrame() < NUM_OF_CAR_SPRITES) { + spCar[i].setFrame(NUM_OF_CAR_SPRITES + spCar[i].getFrame()); + if(spCar[i].getRefPixelX() < w2) { + jitcount=0; + }else{ + jitcount = MAX_JITTER_COUNT/4; + } + jit = true; + lives--; + } + for (int j = 0; j < vMis.size(); j++) { + Missile m = (Missile) vMis.elementAt(j); + + if (spCar[i].collidesWith(imMis, m.x, (int) m.y, false) && spCar[i].getFrame() < NUM_OF_CAR_SPRITES) { + if (spCar[i].getRefPixelX() < w2) { + score += 15; + } + score += 15; + spCar[i].setFrame(NUM_OF_CAR_SPRITES + spCar[i].getFrame()); + vMis.removeElementAt(j); + } + } + } + if (spTank.collidesWith(imFuel, fx, (int) fy, false)) { + score += 50; + addFuel(); + resetFuel(); + } + if (spTank.collidesWith(imLive, lx, (int) ly, false)) { + score += 75; + lives++; + resetLive(); + } + if (spTank.collidesWith(imBomb, bx, (int) by, false)) { + score += 150; + bombs++; + resetBomb(); + } + //----------------------------------------------- + G.setColor(UI.MENU_BACKGROUND); + G.fillRect((w - RW) / 2, (int) ry, RW, RH); + G.fillRect((w - RW) / 2, (int) ry2, RW, RH); + G.drawImage(imFuel, fx, (int) fy, 20); + G.drawImage(imLive, lx, (int) ly, 20); + for (int i = 0; i < maxCars; i++) { + spMan[i].paint(G); + spCar[i].paint(G); + } + for (int i = 0; i < vMis.size(); i++) { + Missile m = (Missile) vMis.elementAt(i); + moveMis(i); + G.drawImage(imMis, m.x, (int) m.y, 20); + } + G.setColor(UI.MENU_BACKGROUND); + int fh = (h - 10) * fuel / maxFuel; + int ffh = G.getFont().getHeight(); + G.fillRect(w - 15, h - 5 - fh, 10, fh); + G.drawImage(imFuel, w - 13, h - 3 - fh, 20); + UI.drawHL(G, "" + score, 2, 2, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, 20); + G.drawImage(imLive, 2, 6 + ffh, 20); + UI.drawHL(G, "" + lives, 12, 4 + ffh, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, 20); + G.setColor(UI.MENU_BACKGROUND); + G.fillRect(1, 3 + ffh * 2, imFuel.getWidth() + 2, imFuel.getHeight() + 2); + G.drawImage(imFuel, 2, 4 + ffh * 2, 20); + UI.drawHL(G, "" + fuel, 12, 4 + ffh * 2, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, 20); + G.drawImage(imBomb, 2, 4 + ffh * 3, 20); + UI.drawHL(G, "" + bombs, 12, 4 + ffh * 3, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, 20); + spTank.paint(G); + if (fuel <= 0 || lives <= 0) { + gameOver(); + } + //-------------------------------------------------- + repaint(); + Thread.sleep(10); + } + + private void gameOver() { + gameOver = true; + bRun = false; + money += maxScore == 0 ? score : score*score / maxScore; + if (maxScore < score) maxScore = score; + G.setFont(Const.bl); + UI.drawHL(G, "ИГРА ОКОНЧЕНА", w2, h / 4, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, Graphics.BASELINE | Graphics.HCENTER); + G.setFont(Const.def); + UI.drawHL(G, "Очки: " + score, w2, h2, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, Graphics.BASELINE | Graphics.HCENTER); + UI.drawHL(G, "Рекорд: " + maxScore, w2, h2 + 3, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, Graphics.TOP | Graphics.HCENTER); + UI.drawHL(G, "1 - Рестарт", w2, h2 + 5 + Const.defheight, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, Graphics.TOP | Graphics.HCENTER); + UI.drawHL(G, "2 - Меню ", w2, h2 + 5 + Const.defheight * 2, UI.STATUS_OUTLINE_COLOR, UI.STATUS_TEXT_COLOR, Graphics.TOP | Graphics.HCENTER); + Tank.midlet.menu.setText("Рекорд: " + maxScore); + } + + private void resetLive() { + lx = random(w6, ww6-8); + ly = random(-5000, -3000); + } + + private void resetBomb() { + bx = random(w6, ww6-8); + by = random(-25000, -15000); + } + + private void resetFuel() { + fx = random(w6, ww6-8); + fy = random(-maxFuel*10, -maxFuel*7); + } + + private void addFuel() { + fuel += 50; + if (fuel > maxFuel) fuel = maxFuel; + } + + private void resetCar(int i) { + cy[i] = -50; + spCar[i].setFrame(random(0, NUM_OF_CAR_SPRITES)); + spCar[i].setRefPixelPosition(random(w6, ww6-14), -50); + if (spCar[i].getRefPixelX() < w2) spCar[i].setTransform(Sprite.TRANS_ROT180); + else spCar[i].setTransform(Sprite.TRANS_NONE); + } + + private void resetMan(int i) { + my[i] = -25; + spMan[i].setFrame(0); + spMan[i].setRefPixelPosition(random(w6, ww6-14), -25); + if (spMan[i].getRefPixelX() < w2) spMan[i].setTransform(Sprite.TRANS_ROT180); + else spMan[i].setTransform(Sprite.TRANS_NONE); + } + + private int random(int a, int b) { + int r = Math.abs(Const.rnd.nextInt()); + int d = b - a; + r %= d; + r += a; + return r; + } + + class Missile { + + double y; + int x; + + public Missile(int x, double y) { + this.x = x; + this.y = y; + } + } +} diff --git a/src/tank/UI.java b/src/tank/UI.java new file mode 100644 index 0000000..14ff81b --- /dev/null +++ b/src/tank/UI.java @@ -0,0 +1,66 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package tank; + +import javax.microedition.lcdui.Graphics; + +/** + * + * @author aNNiMON + */ +public class UI { + + /** + * Задний фон меню, текст сообщений, дорожная разметка + */ + public static final int MENU_BACKGROUND = 0xffff99; + /** + * Цвет выделенного курсором текста + */ + public static final int MENU_CURSOR_TEXT = 0x006600; + /** + * Обводка текста сообщений + */ + public static final int MENU_MESSAGE_OUTLINE = 0x990000; + /** + * Обводка текста статуса + */ + public static final int MENU_STATUS_OUTLINE = 0x009900; + /** + * Цвет текст статуса + */ + public static final int MENU_STATUS_TEXT = 0x99ffff; + /** + * Цвет дороги + */ + public static final int ROAD_COLOR = 0xcccccc; + /** + * Цвет травы + */ + public static final int GRASS_COLOR = 0x008000; + /** + * Статус инфо, цвет обводки + */ + public static final int STATUS_OUTLINE_COLOR = 0xff0000; + /** + * Статус инфо, цвет текста + */ + public static final int STATUS_TEXT_COLOR = 0xffff00; + + + + public static void drawHL(Graphics g, String text, int x, int y, int bg, int fg, int a) { + int color = g.getColor(); + g.setColor(bg); + g.drawString(text, x - 1, y - 1, a); + g.drawString(text, x + 1, y - 1, a); + g.drawString(text, x - 1, y + 1, a); + g.drawString(text, x + 1, y + 1, a); + g.setColor(fg); + g.drawString(text, x, y, a); + g.setColor(color); + } +}