This commit is contained in:
Victor 2018-11-14 23:57:41 +02:00
commit 9a5ea0bf47
26 changed files with 4174 additions and 0 deletions

83
build.xml Normal file
View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<project name="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>

1251
nbproject/build-impl.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
build.xml.data.CRC32=ff7d85e0
build.xml.script.CRC32=a6631c98
build.xml.stylesheet.CRC32=9c6a911d
nbproject/build-impl.xml.data.CRC32=ff7d85e0
nbproject/build-impl.xml.script.CRC32=59b1617a
nbproject/build-impl.xml.stylesheet.CRC32=e46c2d22

View File

@ -0,0 +1,8 @@
#Tue, 15 Mar 2011 16:10:11 +0300
#Fri May 07 21:10:28 VOLST 2010
netbeans.user=C:\\Users\\aNNiMON\\AppData\\Roaming\\NetBeans\\dev
javadoc.preview=true
config.active=Release
deployment.counter=129
app-version.autoincrement=true
deployment.number=0.1.28

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

View File

@ -0,0 +1,168 @@
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=\ ,NoBluetooth,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.NoBluetooth.debug.level=debug
configs.NoBluetooth.filter.exclude.tests=false
configs.NoBluetooth.filter.excludes=res/btank.png
configs.NoBluetooth.filter.more.excludes=**/overview.html,**/package.html
configs.NoBluetooth.filter.use.standard=true
configs.NoBluetooth.javac.debug=false
configs.NoBluetooth.javac.deprecation=false
configs.NoBluetooth.javac.encoding=UTF-8
configs.NoBluetooth.javac.optimize=true
configs.NoBluetooth.obfuscation.custom=
configs.NoBluetooth.obfuscation.level=9
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.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.obfuscation.custom=
configs.Release.obfuscation.level=9
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=
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=${reference.PLib.jar}
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,org.pabloid.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=
obfuscation.level=0
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,JSR177-1.0,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/satsa-jcrmi.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/satsa-apdu.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_China_JP7_128x160_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
project.PLib=../PLib
reference.PLib.jar=${project.PLib}/dist/PLib.jar
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=manufacturer
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

23
nbproject/project.xml Normal file
View File

@ -0,0 +1,23 @@
<?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">
<reference>
<foreign-project>PLib</foreign-project>
<artifact-type>jar</artifact-type>
<script>${project.PLib}/build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
<properties>
<property name="config.active"/>
</properties>
</reference>
</references>
</configuration>
</project>

View File

@ -0,0 +1,175 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pabloid.tank;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import org.pabloid.ui.ImageUtils;
/**
*
* @author pabloid
*/
public class ImageLoader
{
public static final int TRANSPARENT_COLOR = 0xff00ff;
private static final double[][] colors =
{
{
1, 0, 0
},
{
1, 0.5, 0
},
{
1, 1, 0
},
{
0.5, 1, 0
},
{
0, 1, 0
},
{
0, 1, 0.5
},
{
0, 1, 1
},
{
0, 0.5, 1
},
{
0, 0, 1
},
{
0.3, 0.3, 0.3
}
};
public static final int CAR_FRAMES = colors.length + 2;
public static final int ID_TANK = 0;
public static final int ID_BTANK = 1;
public static final int ID_LIVE = 2;
public static final int ID_BOMB = 3;
public static final int ID_BOOM = 4;
public static final int ID_CAR = 5;
public static final int ID_FUEL = 6;
public static final int ID_MAN = 7;
public static final int ID_MIS = 8;
public static final int ID_SWIBORG = 9;
public static final int ID_FAST_MIS = 10;
private Vector images = new Vector();
public ImageLoader() throws IOException
{
Image tmp = Image.createImage("/res/tank.png");
images.addElement(tmp);//0
int w = tmp.getWidth(), h = tmp.getHeight();
int[] rgb = new int[w * h];
tmp.getRGB(rgb, 0, w, 0, 0, w, h);
for (int i = 0; i < rgb.length; i++)
{
int a = rgb[i] & 0xff000000;
int r = (rgb[i] >> 8) & 0xff;
int other = rgb[i] & 0xffff;
rgb[i] = a | (r << 16) | other;
}
tmp = Image.createRGBImage(rgb, w, h, true);
images.addElement(tmp);//1
images.addElement(fromHalf(Image.createImage("/res/live.png")));//2
images.addElement(Image.createImage("/res/bomb.png"));//3
tmp = Image.createImage("/res/boom.png");
Image boom = Image.createImage(4 * 32, 32);
Graphics G = boom.getGraphics();
G.setColor(TRANSPARENT_COLOR);
G.fillRect(0, 0, boom.getWidth(), boom.getHeight());
for (int i = 0; i < 4; i++)
{
G.drawImage(tmp, i * 32 + 16, 16, Graphics.VCENTER | Graphics.HCENTER);
tmp = ImageUtils.resize(tmp, tmp.getWidth() / 2, tmp.getHeight() / 2);
tmp = Image.createImage(tmp, 0, 0, tmp.getWidth(), tmp.getWidth(), Sprite.TRANS_ROT90);
}
images.addElement(whiteToAlpha(boom));//4
Image car = Image.createImage("/res/car.png");
w = car.getWidth();
h = car.getHeight();
tmp = Image.createImage(w / 2 * CAR_FRAMES, h);
G = tmp.getGraphics();
G.setColor(TRANSPARENT_COLOR);
G.fillRect(0, 0, tmp.getWidth(), tmp.getHeight());
G.drawImage(car, tmp.getWidth(), 0, Graphics.TOP | Graphics.RIGHT);
car = Image.createImage(car, 0, 0, w / 2, h, 0);
w /= 2;
for (int i = 0; i < colors.length; i++)
G.drawImage(switchChannels(car, colors[i]), w * i, 0, 0);
images.addElement(whiteToAlpha(tmp));
images.addElement(Image.createImage("/res/fuel.png"));
images.addElement(Image.createImage("/res/man.png"));
images.addElement(Image.createImage("/res/mis.png"));
images.addElement(fromHalf(Image.createImage("/res/swiborg.png")));
tmp = Image.createImage(5, 5);
G = tmp.getGraphics();
G.setColor(TRANSPARENT_COLOR);
G.fillRect(0, 0, tmp.getWidth(), tmp.getHeight());
G.setColor(0xff0000);
G.fillArc(0, 0, 5, 5, 0, 360);
images.addElement(whiteToAlpha(tmp));
}
public Image get(int id)
{
return (Image) images.elementAt(id);
}
private Image whiteToAlpha(Image src)
{
int w = src.getWidth(), h = src.getHeight();
int[] rgb = new int[w * h];
src.getRGB(rgb, 0, w, 0, 0, w, h);
for (int i = 0; i < rgb.length; i++)
if ((rgb[i] & 0xffffff) == TRANSPARENT_COLOR)
rgb[i] = 0;
return Image.createRGBImage(rgb, w, h, true);
}
private Image switchChannels(Image src, double[] color)
{
int w = src.getWidth(), h = src.getHeight();
int[] rgb = new int[w * h];
src.getRGB(rgb, 0, w, 0, 0, w, h);
double cr = color[0];
double cg = color[1];
double cb = color[2];
for (int i = 0; i < rgb.length; i++)
{
int a = rgb[i] & 0xff000000;
int r = (rgb[i] >> 16) & 0xff;
r *= cr;
int g = (rgb[i] >> 8) & 0xff;
g *= cg;
int b = (rgb[i]) & 0xff;
b *= cb;
rgb[i] = a | (r << 16) | (g << 8) | b;
}
return Image.createRGBImage(rgb, w, h, true);
}
private Image fromHalf(Image image)
{
int w = image.getWidth();
int h = image.getHeight();
Image result = Image.createImage(w * 2, h);
Graphics g = result.getGraphics();
g.setColor(TRANSPARENT_COLOR);
g.fillRect(0, 0, w * 2, h);
g.drawImage(image, 0, 0, 0);
image = Image.createImage(image, 0, 0, w, h, Sprite.TRANS_MIRROR);
g.drawImage(image, w, 0, 0);
return whiteToAlpha(result);
}
}

View File

@ -0,0 +1,93 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pabloid.tank;
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import org.pabloid.ui.ImageUtils;
/**
*
* @author pabloid
*/
class Loading extends Canvas implements Runnable
{
private final int max;
private String msg = "";
private final double coef;
private Image img;
private final int h;
private final int w;
private double index;
private Thread thread;
Loading(int max)
{
setFullScreenMode(true);
coef = (double) (getWidth() - 10) / (double) max;
this.max = max;
this.w = getWidth();
this.h = getHeight();
try
{
img = Image.createImage("/res/tank.png");
}
catch (IOException t)
{
t.printStackTrace();
}
index = 0;
}
protected void paint(Graphics g)
{
ImageUtils.gradient(g, 0, 0, w, h, 0xccffff, 0xffffcc, true);
g.drawImage(img, w / 2, h / 3, Graphics.HCENTER | Graphics.VCENTER);
g.setColor(0x008000);
g.drawRect(3, 2 * h / 3, w - 6, 19);
ImageUtils.gradient(g, 5, 2 * h / 3 + 2, (int) (coef * index) - 3, 16, 0x008000, 0x00ff00, true);
}
void start()
{
if (thread == null)
thread = new Thread(this);
else
thread.interrupt();
thread.start();
}
void stop()
{
if (thread != null)
thread.interrupt();
}
void next()
{
index++;
if (index >= max)
index = 0;
repaint();
serviceRepaints();
}
public void run()
{
while (true)
{
next();
try
{
Thread.sleep(100);
}
catch (InterruptedException t)
{
}
}
}
}

View File

@ -0,0 +1,69 @@
package org.pabloid.tank;
import javax.microedition.lcdui.Image;
class Missile
{
private double x;
private double y;
private double sx;
private double sy;
private int type;
private Image image;
public int multiCount=0;
Missile(Image img, int x, double y, double speed, int type)
{
this.x = x;
this.y = y;
if (speed < 1)
speed = 1;
this.sy = -speed;
this.sx = 0;
image = img;
this.type = type;
}
Missile(Image img, int x, double y, double speed, int type, int angle)
{
this.x = x;
this.y = y;
if (speed < 1)
speed = 1;
this.sy = -speed * Math.sin(Math.toRadians(angle));
this.sx = speed * Math.cos(Math.toRadians(angle));
image = img;
this.type = type;
}
public int getType()
{
return type;
}
public Image getImage()
{
return image;
}
public int getX()
{
return (int) x;
}
public int getY()
{
return (int) y;
}
void move()
{
y += sy;
x += sx;
}
boolean isOut()
{
return (y < -8 || y > TankCanvas.h || x < -8 || x > TankCanvas.w);
}
}

View File

@ -0,0 +1,118 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pabloid.tank;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import org.pabloid.ui.ImageUtils;
/**
* @author pabloid
*/
public class Scale extends Canvas
{
public static Command COMMAND_SELECT = new Command("Select", Command.OK, 0);
private int index = 0, ph = Font.getDefaultFont().getHeight();
CommandListener cl;
String message = "", text = "";
private final int width;
private int max;
private double coef;
private double add = 1;
public void setText(String text)
{
this.text = text;
}
public void setMax(int max)
{
this.max = max;
coef = (double) (width - 3) / max;
index = 0;
}
public void setMessage(String message)
{
this.message = message;
}
public void setCommandListener(CommandListener cl)
{
this.cl = cl;
}
public Scale(int max)
{
setFullScreenMode(true);
this.width = getWidth();
this.max = max;
coef = (double) (width - 3) / max;
}
/**
* paint
* @param g
*/
public void paint(Graphics g)
{
ImageUtils.gradient(g, 0, 0, getWidth(), getHeight(), 0xffffcc, 0xccffff, true);
g.setColor(0x006600);
g.drawRect(1, 4 + ph, width - 3, 19);
ImageUtils.gradient(g, 3, 6 + ph, (int) (coef * index) - 3, 16, 0x00ff00, 0x008000, true);
TankCanvas.drawHL(g, "" + index, 3, 3, 0xff0000, 0xffff00, Graphics.TOP | Graphics.LEFT);
g.setFont(Font.getFont(0, Font.STYLE_BOLD, Font.SIZE_LARGE));
TankCanvas.drawHL(g, message, 8, getHeight() - 8, 0x990000, 0xffff99, Graphics.BASELINE | Graphics.LEFT);
g.setFont(Font.getDefaultFont());
TankCanvas.drawHL(g, text, 8, getHeight() - 12 - ph, 0x9900, 0x99ffff, Graphics.BASELINE | Graphics.LEFT);
}
/**
* Called when a key is pressed.
* @param key
*/
protected void keyPressed(int key)
{
int ga = getGameAction(key);
if ((ga == LEFT) || (key == '4'))
if (--index < 0)
index = 0;
if ((ga == RIGHT) || (key == '6'))
if (++index >= max)
index = max;
if ((ga == FIRE) || (key == '5'))
if (cl != null)
cl.commandAction(COMMAND_SELECT, this);
if (key == '0')
index = 0;
repaint();
}
protected void keyRepeated(int key)
{
int ga = getGameAction(key);
if ((ga == LEFT) || (key == '4'))
if ((index -= (int) add) < 0)
index = 0;
if ((ga == RIGHT) || (key == '6'))
if ((index += (int) add) >= max)
index = max;
add += 0.2;
repaint();
}
protected void keyReleased(int k)
{
add = 1;
}
public int getSelectedValue()
{
return index;
}
}

View File

@ -0,0 +1,118 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pabloid.tank;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import org.pabloid.io.RecordStoreInputStream;
import org.pabloid.io.RecordStoreOutputStream;
import org.pabloid.ui.PList;
/**
*
* @author pabloid
*/
public class Settings extends PList implements CommandListener
{
public static final String dbName = "Tank.settings";
public int numElements;
private boolean[] elements;
private Image imTick = null, imCross = null;
private void readSettings()
{
try
{
RecordStoreInputStream ris = new RecordStoreInputStream(dbName);
DataInputStream dis = new DataInputStream(ris);
elements = new boolean[numElements];
for (int i = 0; i < numElements; i++)
elements[i] = dis.readBoolean();
dis.close();
}
catch (Exception e)
{
elements = new boolean[numElements];
for (int i = 0; i < numElements; i++)
elements[i] = true;
saveSettings();
//#ifdef DefaultConfiguration
e.printStackTrace();
//#endif
}
catch (Throwable t)
{
t.printStackTrace();
}
}
public void saveSettings()
{
try
{
RecordStoreOutputStream ros = new RecordStoreOutputStream(dbName);
DataOutputStream dos = new DataOutputStream(ros);
for (int i = 0; i < numElements; i++)
dos.writeBoolean(elements[i]);
dos.close();
}
catch (Throwable t)
{
t.printStackTrace();
}
}
public Settings(String items[])
{
super(items);
try
{
numElements = items.length;
setTitle("Настройки");
append("Назад");
setCommandListener(this);
readSettings();
imTick = Image.createImage("/res/tick.png");
imCross = Image.createImage("/res/cross.png");
for (int index = 0; index < numElements; index++)
set(index, getString(index), elements[index] ? imTick : imCross);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
public void commandAction(Command c, Displayable d)
{
int index = getSelectedIndex();
if (index >= numElements)
{
saveSettings();
Tank.instance.d.setCurrent(Tank.instance.main);
return;
}
else
{
elements[index] = !elements[index];
set(index, getString(index), elements[index] ? imTick : imCross);
}
}
public boolean getSetting(int index)
{
return elements[index];
}
public void setSetting(int index, boolean value)
{
elements[index] = value;
set(index, getString(index), value ? imTick : imCross);
}
}

View File

@ -0,0 +1,523 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.pabloid.tank;
import java.io.IOException;
import java.util.Hashtable;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.L2CAPConnection;
import javax.bluetooth.L2CAPConnectionNotifier;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import org.pabloid.io.IOUtils;
import org.pabloid.io.ResourceReader;
import org.pabloid.ui.PList;
/**
* @author pabloid
*/
public class Tank extends MIDlet implements
//#ifndef NoBluetooth
CommandListener, DiscoveryListener, Runnable
//#else
//# CommandListener
//#endif
{
public Display d;
public static Tank instance;
public PList main;
public PList shop;
private boolean bServer = true;
public static final int values[] =
{
2000, 1750, 1500, 1250, 1000, 5000, 1000, 10000, 100500, 500, 1500, 30000, 20000
};
public Settings settings;
public TankCanvas c;
private Form help;
PList confirm, reset;
Command cmdBack;
private String url;
private Scale scale = new Scale(1);
private Loading loading;
//#ifndef NoBluetooth
PList devices;
PList multiplayerMenu;
private Hashtable htDevices = new Hashtable();
public static L2CAPConnection con;
public static final String SERVICE_UUID = "1020304050d0708093a1b121d1e1f100";
public static final UUID L2CAP_UUID = new UUID(0x100);
private DiscoveryAgent agent;
private LocalDevice local;
private boolean bBluetooth = true;
private Thread server;
//#endif
public Tank()
{
instance = this;
d = Display.getDisplay(this);
loading = new Loading(18);
d.setCurrent(loading);
main = new PList(new String[]
{
"Заезд", "Магазин",
//#ifndef NoBluetooth
"Мультиплеер",
//#else
//# null,
//#endif
"Настройки", "Помощь", "Обнулить прогресс", "Выход"
});
loading.next();
shop = new PList(new String[]
{
"Зарядка(" + values[0] + ")", "Ракеты(" + values[1] + ")", "Скорость ракет(" + values[2] + ")",
"Управление(" + values[3] + ")", "Топливо(" + values[4] + ")", "Бомба(" + values[5] + ")",
"Щит(" + values[6] + ")", "Сброс скорости(" + values[7] + ")", "Шар Свиборга(" + values[8] + ")",
"Быстрая ракета(" + values[9] + ")", "Разрывная ракета(" + values[10] + ")", "Ракет одновременно(" + values[11] + ")",
"Мега-ракета(" + values[12] + ")",
"Назад"
});
loading.next();
reset = new PList(new String[]
{
"Зарядка", "Ракеты", "Скорость ракет",
"Управление", "Топливо",
"Щит", "Ракет одновременно", "Все",
"Назад"
});
reset.setTitle("Сбросить");
reset.setCommandListener(this);
loading.next();
settings = new Settings(new String[]
{
"Режим ночи", "Вибрация"
});
loading.next();
help = new Form("Помощь");
loading.next();
c = new TankCanvas();
loading.next();
confirm = new PList(new String[]
{
"Нет", "Да"
});
loading.next();
cmdBack = new Command("Назад", Command.BACK, 0);
loading.next();
//#ifndef NoBluetooth
devices = new PList("Bluetooth устройства", 0);
multiplayerMenu = new PList("Bluetooth мультиплеер", 0);
//#endif
main.setCommandListener(this);
loading.next();
main.setTitle("Рекорд: " + c.maxScore);
loading.next();
main.repaint();
loading.next();
shop.setCommandListener(this);
loading.next();
confirm.setCommandListener(this);
loading.next();
scale.setCommandListener(this);
loading.next();
//#ifndef NoBluetooth
devices.setCommandListener(this);
devices.addCommand(cmdBack);
multiplayerMenu.setCommandListener(this);
multiplayerMenu.append("Клиент");
multiplayerMenu.append("Сервер");
multiplayerMenu.addCommand(cmdBack);
//#endif
try
{
ResourceReader r = new ResourceReader("/res/about.txt", "UTF-8");
help.append(IOUtils.asString(r));
r.close();
}
catch (Throwable t)
{
t.printStackTrace();
}
loading.next();
help.setCommandListener(this);
loading.next();
help.addCommand(new Command("ОК", Command.OK, 0));
loading.next();
d.setCurrent(main);
}
public void startApp()
{
}
public void pauseApp()
{
System.gc();
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void commandAction(Command cmd, Displayable disp)
{
try
{
if (disp == help)
{
d.setCurrent(main);
return;
}
//#ifndef NoBluetooth
else if (bBluetooth && disp == multiplayerMenu && cmd == PList.SELECT_COMMAND)
{
int index = multiplayerMenu.getSelectedIndex();
switch (index)
{
case 0:
devices.deleteAll();
d.setCurrent(devices);
if (agent == null)
getLocalDevice();
agent.startInquiry(DiscoveryAgent.GIAC, this);
devices.setTitle("Поиск устройств...");
break;
case 1:
c.reset();
d.setCurrent(c);
c.start();
if (server == null)
{
server = new Thread(this);
server.start();
}
break;
}
}
else if (disp == devices && cmd == PList.SELECT_COMMAND)
{
loading.start();
d.setCurrent(loading);
String name = devices.getString(devices.getSelectedIndex());
RemoteDevice remote = (RemoteDevice) htDevices.get(name);
agent.searchServices(null, new UUID[]
{
L2CAP_UUID, new UUID(SERVICE_UUID, false)
}, remote, this);
}
else if (disp == devices && cmd == cmdBack)
d.setCurrent(multiplayerMenu);
else if (disp == multiplayerMenu && cmd == cmdBack)
d.setCurrent(main);
//#endif
else if (cmd == PList.SELECT_COMMAND && disp == confirm)
{
if (confirm.getSelectedIndex() == 1)
{
switch (reset.getSelectedIndex())
{
case 0:
c.fireSpeed = 1000;
break;
case 1:
c.maxMis = 2;
break;
case 2:
c.mis = 1;
break;
case 3:
c.controlSpeed = 1;
break;
case 4:
c.maxFuel = 100;
break;
case 5:
c.shield = 0;
break;
case 6:
c.nMissilesAtTime = 1;
break;
case 7:
c.resetGame();
break;
}
c.save();
}
d.setCurrent(main);
}
else if (cmd == PList.SELECT_COMMAND && disp == main)
switch (main.getSelectedIndex())
{
case 0:
c.reset();
c.start();
d.setCurrent(c);
break;
case 1:
d.setCurrent(shop);
shop.setTitle("Денег: " + c.money);
shop.repaint();
break;
case 2:
//#ifndef NoBluetooth
if (!bBluetooth)
{
multiplayerMenu.deleteAll();
multiplayerMenu.append("Bluetooth не доступен");
}
d.setCurrent(multiplayerMenu);
//#endif
break;
case 3:
d.setCurrent(settings);
break;
case 4:
d.setCurrent(help);
break;
case 5:
d.setCurrent(reset);
break;
case 6:
destroyApp(true);
break;
}
else if (cmd == PList.SELECT_COMMAND && disp == shop)
{
int index = shop.getSelectedIndex();
if (index >= shop.size() - 1)
{
d.setCurrent(main);
main.repaint();
shop.setTitle("");
}
else if (c.money < values[index])
shop.setTitle("Недостаточно денег");
else
{
scale.setText(shop.getString(index));
scale.setMax(c.money / values[index]);
d.setCurrent(scale);
}
new TitleRefreshThread().start();
}
else if (cmd == Scale.COMMAND_SELECT && disp == scale)
{
int index = shop.getSelectedIndex();
c.money -= scale.getSelectedValue() * values[index];
switch (index)
{
case 0:
for (int i = 0; i < scale.getSelectedValue(); i++)
{
c.fireSpeed -= c.fireSpeed / 20;
if (c.fireSpeed < c.calcMinFiretime())
{
c.fireSpeed = c.calcMinFiretime();
c.money += values[0];
shop.setTitle("Максимум");
}
}
break;
case 1:
c.maxMis += scale.getSelectedValue();
break;
case 2:
for (int i = 0; i < scale.getSelectedValue(); i++)
{
c.mis += 0.2;
if (c.mis > c.imMissile.getHeight())
{
c.mis = c.imMissile.getHeight();
c.money += values[2];
shop.setTitle("Максимум");
}
}
break;
case 3:
for (int i = 0; i < scale.getSelectedValue(); i++)
{
c.controlSpeed++;
if (c.controlSpeed > c.imTank.getHeight())
{
c.controlSpeed = c.imMissile.getHeight();
c.money += values[3];
shop.setTitle("Максимум");
}
}
break;
case 4:
for (int i = 0; i < scale.getSelectedValue(); i++)
c.maxFuel += (int) Math.ceil(5000.0 / c.maxFuel);
break;
case 5:
c.bombs += scale.getSelectedValue();
break;
case 6:
c.shield += scale.getSelectedValue();
break;
case 7:
c.speedReset += scale.getSelectedValue();
break;
case 8:
c.swiborg += scale.getSelectedValue();
break;
case 9:
c.nFastMissiles += scale.getSelectedValue();
break;
case 10:
c.nExplosiveMissiles += scale.getSelectedValue();
break;
case 11:
c.nMissilesAtTime += scale.getSelectedValue();
if (c.nMissilesAtTime > 180)
{
c.money += (c.nMissilesAtTime - 180) * values[11];
c.nMissilesAtTime = 180;
shop.setTitle("Максимум");
}
break;
case 12:
c.nMultiExplosiveMissiles += scale.getSelectedValue();
break;
}
c.save();
d.setCurrent(shop);
if (!shop.getTitle().startsWith("Денег:"))
new TitleRefreshThread().start();
else
shop.setTitle("Денег: " + c.money);
}
else if (disp == reset && cmd == PList.SELECT_COMMAND)
if (reset.getSelectedIndex() == reset.size() - 1)
d.setCurrent(main);
else
{
String s = reset.getString(reset.getSelectedIndex());
confirm.setTitle("Обнулить \"" + s + "\"");
confirm.setSelectedIndex(0, true);
d.setCurrent(confirm);
}
}
catch (Throwable t)
{
t.printStackTrace();
}
}
//#ifndef NoBluetooth
public boolean isServer()
{
return bServer;
}
public void run()
{
try
{
if (local == null)
getLocalDevice();
bServer = true;
local = LocalDevice.getLocalDevice();
int mode = local.getDiscoverable();
local.setDiscoverable(DiscoveryAgent.GIAC);
L2CAPConnectionNotifier serv = (L2CAPConnectionNotifier) Connector.open("btl2cap://localhost:" + SERVICE_UUID);
con = serv.acceptAndOpen();
local.setDiscoverable(mode);
serv.close();
}
catch (Throwable t)
{
t.printStackTrace();
}
server = null;
}
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
{
try
{
htDevices.put(btDevice.getFriendlyName(false), btDevice);
devices.append(btDevice.getFriendlyName(false));
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public void servicesDiscovered(int transID, ServiceRecord[] servRecord)
{
ServiceRecord record = servRecord[0];
url = record.getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
}
public void serviceSearchCompleted(int transID, int respCode)
{
bServer = false;
try
{
con = (L2CAPConnection) Connector.open(url);
}
catch (Throwable t)
{
t.printStackTrace();
}
c.reset();
c.start();
loading.stop();
d.setCurrent(c);
}
public void inquiryCompleted(int discType)
{
devices.setTitle("Bluetooth-устройства");
}
private void getLocalDevice()
{
try
{
local = LocalDevice.getLocalDevice();
agent = local.getDiscoveryAgent();
bBluetooth = true;
}
catch (Throwable t)
{
bBluetooth = false;
}
}
//#endif
private class TitleRefreshThread extends Thread
{
public void run()
{
try
{
sleep(2000);
}
catch (Throwable t)
{
t.printStackTrace();
}
shop.setTitle("Денег: " + c.money);
}
}
}

File diff suppressed because it is too large Load Diff

41
src/res/about.txt Normal file
View File

@ -0,0 +1,41 @@
Цель игры - набрать как можно больше очков, уничтожая машины и сбивая мотоциклистов.
Полученные очки можно в магазине обменять на улучшения танка.
При столкновении с машиной снимается жизнь.
Полицейская машина будет стараться специально врезаться в танк.
Если кончается топливо, снимается жизнь, а топливо восстанавливается.
Если число жизней станет равно 0, то игра заканчивается.
В Bluetooth режиме большинство параметров у обоих танков складываются.
Для соединения телефон с бОльшим экраном должен в меню "Мультиплеер" выбрать режим сервера.
Его союзник выбирает "Клиент" и после поиска нужный телефон.
Магазин:
- Зарядка: скорость зарядки. Не может быть меньше определенного предела.
- Ракеты: количество ракет, которые могут быть одновременно быть на экране.
- Скорость ракет: скорость, с которой летят ракеты. Не может быть больше длины ракеты, равной 12.
- Управление: скорость перемещения танка по дороге. Не может быть больше 36. Не cоветую ставить больше 5, иначе очень трудно прицелиться.
- Топливо: увеличивает размер топливного бака, соответственно танк проедет больше.
- Бомба: при активации уничтожает весь транспорт на короткое время.
- Щит: при активации танк становится неуязвим для машин.
- Сброс скорости: при активации скорость движения на дороге снижается до начальной.
- Шар Свиборга: при активации, Свиборг своим брутальным и бессердечным взглядом превращает весь транспорт в дерьмо.
Можно активировать только одного Свиборга на 30 секунд, ибо Свиборг существует только один.
- Быстрые ракеты: летят в 2 раза быстрее обычных, но не наносят вреда полиции.
- Разрывные ракеты: при попадании в цель разлетаются на части, которые тоже могут разрушать машины.
- Ракет одновременно: сколько танк может выпустить обычных ракет за залп..
- Мега-ракеты: действуют как разрывныя, но выпущенные после разрыва ракеты так же способны разлетаться, и.т.д.
Управление:
Вверх, Вниз, Влево, Вправо - управление движением
2, 4, 6, 8 - управление движением
5 - выстрел
Держать * - выход
# - активировать бомбу
0 - включить/выключить щит
9 - сброс скорости
7 - включить Свиборга
1 - переключить режим стрельбы
Автор - P@bloid
Сделано для конкурса на http://annimon.com/

BIN
src/res/bomb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

BIN
src/res/boom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

BIN
src/res/car.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
src/res/cross.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

BIN
src/res/fuel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 B

BIN
src/res/live.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

BIN
src/res/man.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

BIN
src/res/mis.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

BIN
src/res/swiborg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B

BIN
src/res/tank.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

BIN
src/res/tick.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B