Initial
83
build.xml
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<project name="Tank" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project .</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
pre-init: called before initialization of project properties
|
||||
post-init: called after initialization of project properties
|
||||
pre-preprocess: called before text preprocessing of sources
|
||||
post-preprocess: called after text preprocessing of sources
|
||||
pre-compile: called before source compilation
|
||||
post-compile: called after source compilation
|
||||
pre-obfuscate: called before obfuscation
|
||||
post-obfuscate: called after obfuscation
|
||||
pre-preverify: called before preverification
|
||||
post-preverify: called after preverification
|
||||
pre-jar: called before jar building
|
||||
post-jar: called after jar building
|
||||
pre-build: called before final distribution building
|
||||
post-build: called after final distribution building
|
||||
pre-clean: called before cleaning build products
|
||||
post-clean: called after cleaning build products
|
||||
|
||||
Example of pluging a my-special-task after the compilation could look like
|
||||
|
||||
<target name="post-compile">
|
||||
<my-special-task>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</my-special-task>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
Other way how to customize the build is by overriding existing main targets.
|
||||
The target of interest are:
|
||||
|
||||
preprocess: preprocessing
|
||||
extract-libs: extraction of libraries and resources
|
||||
compile: compilation
|
||||
create-jad: construction of jad and jar manifest source
|
||||
obfuscate: obfuscation
|
||||
preverify: preverification
|
||||
jar: jar archive building
|
||||
run: execution
|
||||
debug: execution in debug mode
|
||||
build: building of the final distribution
|
||||
javadoc: javadoc generation
|
||||
|
||||
Example of overriding the target for project execution could look like
|
||||
|
||||
<target name="run" depends="init,jar">
|
||||
<my-special-exec jadfile="${dist.dir}/${dist.jad}"/>
|
||||
</target>
|
||||
|
||||
Be careful about correct dependencies when overriding original target.
|
||||
Again, for list of available properties which you can use check the target
|
||||
you are overriding in nbproject/build-impl.xml file.
|
||||
|
||||
A special target for-all-configs can be used to run some specific targets for
|
||||
all project configurations in a sequence. File nbproject/build-impl.xml
|
||||
already contains some "for-all" targets:
|
||||
|
||||
jar-all
|
||||
javadoc-all
|
||||
clean-all
|
||||
|
||||
Example of definition of target iterating over all project configurations:
|
||||
|
||||
<target name="jar-all">
|
||||
<property name="target.to.call" value="jar"/>
|
||||
<antcall target="for-all-configs"/>
|
||||
</target>
|
||||
|
||||
-->
|
||||
</project>
|
1247
nbproject/build-impl.xml
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
build.xml.data.CRC32=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
|
8
nbproject/private/private.properties
Normal file
@ -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
|
5
nbproject/private/private.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
</project-private>
|
169
nbproject/project.properties
Normal file
@ -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
|
11
nbproject/project.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.kjava.j2meproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2me-project">
|
||||
<name>Tank</name>
|
||||
<minimum-ant-version>1.6</minimum-ant-version>
|
||||
</data>
|
||||
<references xmlns="http://www.netbeans.org/ns/ant-project-references/2"/>
|
||||
</configuration>
|
||||
</project>
|
11
src/changelog.txt
Normal file
@ -0,0 +1,11 @@
|
||||
Что сделано:
|
||||
|
||||
Оптимизация.
|
||||
Смена спрайта автомобиля.
|
||||
HSV обработка картинки автомобиля. В результате машин стало больше.
|
||||
Добавлена полицейская машина.
|
||||
Игра подготовлена к настройке вибрации и эффекта Motion-blur (сменив значение переменной).
|
||||
Дрожание экрана при столкновении с машиной.
|
||||
|
||||
|
||||
Что не сделано:
|
BIN
src/res/bomb.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
src/res/car.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
src/res/fuel.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
src/res/live.png
Normal file
After Width: | Height: | Size: 103 B |
BIN
src/res/man.png
Normal file
After Width: | Height: | Size: 162 B |
BIN
src/res/mis.png
Normal file
After Width: | Height: | Size: 97 B |
BIN
src/res/police.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
src/res/tank.png
Normal file
After Width: | Height: | Size: 166 B |
46
src/tank/Const.java
Normal file
@ -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 {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Шрифты">
|
||||
/**
|
||||
* Стандартный шрифт
|
||||
*/
|
||||
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);
|
||||
// </editor-fold>
|
||||
|
||||
public static final Random rnd = new Random();
|
||||
|
||||
/**
|
||||
* Включена ли глобально вибрация
|
||||
*/
|
||||
public static boolean isVibrate = true;//false;
|
||||
/**
|
||||
* Эффект размытия в движении
|
||||
*/
|
||||
public static boolean isMotionBlur = false;
|
||||
}
|
101
src/tank/HSVProcessor.java
Normal file
@ -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<num; i++) {
|
||||
out[i] = HSV(currentImage, i*step);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private Image HSV(Image img, float hh) {
|
||||
float[] hsb = new float[3];
|
||||
int w = img.getWidth();
|
||||
int h = img.getHeight();
|
||||
int[] pixel = new int[w * h];
|
||||
img.getRGB(pixel, 0, w, 0, 0, w, h);
|
||||
for (int io = 0; io < pixel.length; io++) {
|
||||
int qa = (pixel[io] >> 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<b) h = 60 * ((g-b)/(v-min))+360;
|
||||
else if(v==g) h = 60 * ((b-r)/(v-min))+120;
|
||||
else if(v==b) h = 60 * ((r-g)/(v-min))+240;
|
||||
//saturation
|
||||
if(v==0) s = 0;
|
||||
else s=((v - min)/v);//1-(min/max);
|
||||
if(s==0) h=-1;
|
||||
hsv[0] = h;
|
||||
hsv[1] = s;
|
||||
hsv[2] = v;
|
||||
return hsv;
|
||||
}
|
||||
}
|
87
src/tank/Menu.java
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.Sprite;
|
||||
|
||||
/**
|
||||
* @author pabloid
|
||||
*/
|
||||
public class Menu extends Canvas {
|
||||
|
||||
public static final Command COMMAND_SELECT = new Command("Select", Command.OK, 0);
|
||||
private int w, h;
|
||||
private int index, ph;
|
||||
private Image cursor;
|
||||
private CommandListener cl;
|
||||
private String[] choice;
|
||||
private String message, text;
|
||||
|
||||
public Menu(String[] arr) {
|
||||
setFullScreenMode(true);
|
||||
w = getWidth();
|
||||
h = getHeight();
|
||||
index = 0;
|
||||
ph = Const.def.getHeight()+2;
|
||||
message = text = "";
|
||||
choice = arr;
|
||||
try {
|
||||
Image tmp = Image.createImage("/res/tank.png");
|
||||
cursor = Image.createImage(tmp, 0, 0, tmp.getWidth(), tmp.getHeight(), Sprite.TRANS_ROT90);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void paint(Graphics g) {
|
||||
g.setColor(UI.MENU_BACKGROUND);
|
||||
g.fillRect(0, 0, w, h);
|
||||
g.setColor(UI.MENU_CURSOR_TEXT);
|
||||
g.drawImage(cursor, 8, 8 + index*ph, 20);
|
||||
for (int i = 0; i < choice.length; i++)
|
||||
g.drawString(choice[i], 32, 8 + ph*i, 20);
|
||||
g.setFont(Const.bl);
|
||||
UI.drawHL(g, message, 8, h-8, UI.MENU_MESSAGE_OUTLINE, UI.MENU_BACKGROUND, Graphics.BASELINE | Graphics.LEFT);
|
||||
g.setFont(Const.def);
|
||||
UI.drawHL(g, text, 8, h-10-ph, UI.MENU_STATUS_OUTLINE, UI.MENU_STATUS_TEXT, Graphics.BASELINE | Graphics.LEFT);
|
||||
}
|
||||
|
||||
protected void keyPressed(int key) {
|
||||
int ga = getGameAction(key);
|
||||
switch(ga) {
|
||||
case UP:
|
||||
if (--index < 0) index = choice.length - 1;
|
||||
break;
|
||||
case DOWN:
|
||||
if (++index == choice.length) index = 0;
|
||||
break;
|
||||
case FIRE:
|
||||
if (cl != null) cl.commandAction(COMMAND_SELECT, this);
|
||||
break;
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
protected void keyRepeated(int key) {
|
||||
keyPressed(key);
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setCommandListener(CommandListener cl) {
|
||||
this.cl = cl;
|
||||
}
|
||||
}
|
84
src/tank/Rms.java
Normal file
@ -0,0 +1,84 @@
|
||||
package tank;
|
||||
|
||||
/*
|
||||
* aNNiMON 2011
|
||||
* For more info visit http://annimon.com/
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import javax.microedition.rms.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Rms {
|
||||
|
||||
private static final String rmsName = "TankInCity";
|
||||
private static RecordStore rmsStore;
|
||||
|
||||
/**
|
||||
* Сохранение настроек
|
||||
*/
|
||||
public static void saveOptions() {
|
||||
if (rmsStore != null) {
|
||||
byte[] options = null;
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(baos);
|
||||
dos.writeInt(TankCanvas.maxScore);
|
||||
dos.writeInt(TankCanvas.fireSpeed);
|
||||
dos.writeInt(TankCanvas.controlSpeed);
|
||||
dos.writeInt(TankCanvas.level);
|
||||
dos.writeInt(TankCanvas.money);
|
||||
dos.writeInt(TankCanvas.maxFuel);
|
||||
dos.writeInt(TankCanvas.maxMis);
|
||||
dos.writeDouble(TankCanvas.mis);
|
||||
dos.writeInt(TankCanvas.bombs);
|
||||
dos.flush();
|
||||
options = baos.toByteArray();
|
||||
dos.close();
|
||||
rmsStore.setRecord(1, options, 0, options.length);
|
||||
} catch (InvalidRecordIDException ridex) {
|
||||
ridex.printStackTrace();
|
||||
try {
|
||||
rmsStore.addRecord(options, 0, options.length);
|
||||
} catch (RecordStoreException ex) {}
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
}
|
||||
if (rmsStore != null) {
|
||||
try {
|
||||
rmsStore.closeRecordStore();
|
||||
rmsStore = null;
|
||||
} catch (RecordStoreException ex) {ex.printStackTrace();}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Восстановить настройки
|
||||
*/
|
||||
public static void restoreOptions() {
|
||||
try {
|
||||
rmsStore = RecordStore.openRecordStore(rmsName, true);
|
||||
} catch (RecordStoreException ex) {
|
||||
rmsStore = null;
|
||||
}
|
||||
if (rmsStore != null) {
|
||||
try {
|
||||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(rmsStore.getRecord(1)));
|
||||
TankCanvas.maxScore = dis.readInt();
|
||||
TankCanvas.fireSpeed = dis.readInt();
|
||||
TankCanvas.controlSpeed = dis.readInt();
|
||||
TankCanvas.level = dis.readInt();
|
||||
TankCanvas.money = dis.readInt();
|
||||
TankCanvas.maxFuel = dis.readInt();
|
||||
TankCanvas.maxMis = dis.readInt();
|
||||
TankCanvas.mis = dis.readDouble();
|
||||
TankCanvas.bombs = dis.readInt();
|
||||
dis.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
206
src/tank/Tank.java
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package tank;
|
||||
|
||||
import javax.microedition.lcdui.*;
|
||||
import javax.microedition.midlet.*;
|
||||
|
||||
/**
|
||||
* TODO: сделать ночь
|
||||
* @author pabloid
|
||||
*/
|
||||
public class Tank extends MIDlet implements CommandListener {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Константы цен">
|
||||
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;
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Основные методы и инициализация">
|
||||
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();
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Обработка менюшек">
|
||||
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);
|
||||
}// </editor-fold>
|
||||
}
|
526
src/tank/TankCanvas.java
Normal file
@ -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; //кол-во машин на экране
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Данные для сохранения">
|
||||
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; //Скорость полёта снаряда
|
||||
// </editor-fold>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Публичные методы">
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Защищенные Canvas методы">
|
||||
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;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
66
src/tank/UI.java
Normal file
@ -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);
|
||||
}
|
||||
}
|