Game Plane Warrior ini merupakan game yang berjalan pada perangkat selular yang berbasis java, khususnya Java 2 Micro Edition(J2ME) yang mampu memberikan hiburan bagi yang memainkannya. Game ini juga melatih ketepatan dalam menembak sasaran yang ada di depan mata. Deskripsi dari game ini yaitu sebuah dunia khayalan yang di serang oleh sekelompok makhluk planet(alien). Makhluk planet disini diibaratkan sebagai pesawat alien atau pesawat musuh. Alien ini menyerang dunia khayalan yang diibaratkan sebagai bumi untuk menguasai dunia khayalan tersebut. Makhluk bumi atau pesawat pemain tidak tinggal diam, mereka juga menyiapkan pasukan untuk menyerang pasukan musuh yaitu pesawat alien agar dunia khayalan(bumi) tidak dikuasai oleh makhluk-makhluk planet tersebut. Game ini merupakan perpaduan antara game action dan petualangan yang sifatnya menghibur.
Game ini terdiri dari 3 level dan setiap level memiliki tingkat kesulitan yang berbeda-beda. Berikut adalah gambaran permainan pada setiap level dalam game ini.
· Level 1
Pada level ini berlatar pemandangan di bumi, tepatnya di atas langit. Disini berlatar warna biru muda dengan disertai dengan awan-awan yang bertebaran. Maksud dari latar ini yaitu saat pesawat pemain (pesawat bumi) masih berada dalam bumi atau dunia khayal, lalu datang pesawat alien atau pesawat musuh. Pada level ini pemain diharuskan untuk menghabisi pesawat musuh sebanyak 20 pesawat apabila ingin melanjutkan permainan ke level berikutnya dengan banyaknya darah atau nyawa yang telah disediakan. Dan apabila pesawat pemain bertabrakan dengan pesawat musuh akan mengurangi darah pesawat pemain sebanyak 10% dari 100% darah yang telah disediakan. Dan bila darah tersebut telah habis, maka pemain dinyatakan kalah dan tidak dapat melanjutkan permainan ke level berikutnya. Di level ini pesawat pemain diberikan senjata berupa tembakan 1x sedangkan untuk pesawat musuh tidak diberikan. Pada awal permainan pemain diberikan bonus score 100.
· Level 2
Pada level ini berlatarkan pemandangan saat perjalanan pesawat bumi dan pesawat alien sedang bertarung. Disini diibaratkan berwarna biru tua dengan di taburi dengan bintang-bintang yang berkilauan, dan sudah hampir memasuki daerah luar angkasa atau markas dari pesawat alien. Namun pada level ini yang membedakan dengan level 1 pada pesawat musuh disertai dengan tembakan 1x. Pada level 2 terdapat 2 macam pesawat musuh, yang pertama pesawat musuh yang bergerak lambat ada 20 pesawat dan yang satunya pesawat musuh dengan gerakan yang agak cepat ada 10 pesawat. Dan apabila pesawat pemain bertabrakan dengan pesawat musuh atau pesawat pemain terkena tembakan pesawat musuh maka akan mengurangi darah pesawat pemain sebanyak 10% dari 100% darah yang telah disediakan. Apabila darah tersebut telah habis, maka pemain dinyatakan kalah.
· Level 3
Pada level terakhir ini yang berlatarkan sebuah pemandangan luar angkasa dengan bintang yang bertaburan. Disini diibaratkan luar angkasa berwarna hitam dengan bertaburan bintang-bintang yang berkilauan. Pada level ini pemain dihadapkan pada raja musuh (alien). Pesawat raja alien ini sangat kuat, pemain harus menembakan beberapa kali tembakan supaya raja tersebut mati. Dan harus tepat sasaran. Untuk pesawat raja di level ini disertai dengan tembakan juga seperti pesawat pemain. Jika tembakan tersebut mengenai pesawat pemain maka akan mengurangi darah pesawat pemain. Sama seperti level 1 dan 2, apabila pesawat pemain mengenai pesawat raja ataupun pesawat pemain terkena tembakan pesawat raja maka akan mengurangi darah pesawat pemain sebanyak 10% dari 100% darah yang telah disediakan. Apabila darah yang telah tersedia telah habis, maka pemain dinyatakan kalah. Dan bila ingin memenangkan permainan ini, pemain diharuskan untuk menghabisi raja alien tersebut hingga mati.
Di dalam game ini pemain harus memainkan setiap level satu persatu mulai dari level 1 hingga level ke 3. Apabila pemain mati pada level tertentu, maka ia tidak perlu mengulang dari level 1, akan tetapi pemain dapat melanjutkan permainan dari level yang terakhir di mainkan.
Aturan dalam memainkan game ini ialah sebanyak mungkin kita menghancurkan pesawat musuh dengan menembak/membidik pesawat musuh dengan tepat, karena dalam game ini pesawat yang digunakan pemain dilengkapi dengan tembakan dan radar (pada level 2) untuk memudahkan dalam menembak pesawat musuh dan pesawat yang digunakan oleh pemain juga dapat menghindari tembakan/sasaran yang diarahkan oleh musuh dengan menggunakan tombol-tombol yang ada dalam ponsel. Dalam game ini Pesawat yang digunakan pemain untuk bergerak ke atas, ke bawah, ke kanan, dan kekiri. Saat pertama bermain, pemain diberikan bonus nilai sebanyak 100 poin. Pada level 1 pemain dihadapkan oleh sekumpulan pesawat musuh ada 20 pesawat musuh, dan pemain harus menghabiskan atau menembak pesawat-pesawat tersebut apabila ingin meneruskan ke level selanjutnya. Tembakan tersebut harus tepat sasaran. Pada level ini pesawat pemain hanya mengeluarkan tembakan 1x dan untuk pesawat musuh tidak disediakan tembakan. Pada level 2 pemain dihadapkan oleh sekumpulan pesawat musuh yang lebih banyak dari pada level 1 yaitu ada 30 pesawat musuh, diantaranya 20 pesawat dengan gerakan yang lambat dan 10 pesawat musuh dengan gerakan yang agak cepat caranya sama seperti level 1 menembakan semua musuh tetapi pada level 2 ini pesawat musuh disertai dengan tembakan untuk menembak. Dan untuk level 3 pemain dihadapkan pada raja dari pesawat musuh. Pemain diharuskan menghabisi raja tersebut apabila ingin memenangkan permainan ini. Pada awal permainan pemain diberikan nyawa sebanyak 100%. Apabila nyawa tersebut habis pada saat pemain memainkan game ini pada level 1 pemain tidak perlu mengulangnya pada level 1, begitu juga pada level 2 dan 3.
source code untuk About.java :
package source;
import javax.microedition.lcdui.*;
class About
extends Form
implements CommandListener
{
private final PlaneWarrior midlet;
private final Command kembali;
String pesan;
Image gundar;
About(PlaneWarrior midlet)
{
super("About");
this.midlet = midlet;
pesan = "Jenis Game : Action & shooting..\n" +
"Berbasis : Java 2 Micro Edition (J2ME)..\n" +
"Game ini dibuat oleh Sri Noviyanti\n"+
"50407815\n\n";
try {
gundar = Image.createImage("/res/gundar.png");
} catch (java.io.IOException e) {
e.printStackTrace();
}
append(new ImageItem("gunadarma", gundar, ImageItem.LAYOUT_DEFAULT, null));
append(new StringItem(null, pesan));
kembali = new Command("Kembali", Command.BACK, 0);
addCommand(kembali);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d){
midlet.tampilan_utama();
}
}
source code untuk Best_of_the_best.java :
package source;
import javax.microedition.lcdui.*;
public class Best_of_the_best
extends Form
implements CommandListener {
private PlaneWarrior midlet;
private Display display;
private Command cmBack;
private StringItem si;
int skor;
String nama;
String rec;
public Best_of_the_best(PlaneWarrior midlet, Display display) {
super("Best of the best");
this.midlet = midlet;
this.display = display;
saverecord();
cmBack = new Command("Back", Command.BACK, 1);
setCommandListener(this);
addCommand(cmBack);
}
public void saverecord(){
skor=midlet.skor;
nama=midlet.nama;
boolean publish = false;
Save save = new Save("db_data");
save.open();
save.saveRecordStream(skor, nama, publish, 0);
append(new StringItem(null, save.readRecordStreamSortInt()));
save.close();
}
public void commandAction(Command c, Displayable s) {
if (c == cmBack)
this.deleteAll();
midlet.tampilan_utama();
}
};
source code untuk Level1.java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package source;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.*;
/**
* @author ichong
*/
public class Level1 extends GameCanvas implements Runnable{
/**
* constructor
*/
PlaneWarrior midlet;
Display display;
private boolean main;
private boolean gameover = false;
public boolean menang;
private Pesawat pesawat;
//private Musuh musuh;
private Sprite[] musuh = new Sprite[20];
private Sprite[] tembakan = new Sprite[50];
private Image pesmus, tem;
private TiledLayer back;
private TiledLayer tiled;
private TiledLayer finish;
public LayerManager dunia;
private int speed = 10;
public int Skor;
public boolean[] tembak = new boolean[50];
int a,b;
private int peluru;
private int darahjagoan=10;
public String reason;
private int count = 50;
private Timer tm;
private TestTimerTask tt;
private Command cmExit, cmInstruction;
int maptiled[][]={
// 1 2 3 4 5 6 7 8
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 6, 7, 8, 0, 0, 0},
{0, 0, 9, 10, 11, 0, 0, 0},
{0, 0, 12, 13, 14, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 6, 7, 8, 0},
{0, 0, 0, 0, 9, 10, 11, 0},
{0, 0, 0, 0, 12, 13, 14, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 6, 7, 8, 0, 0},
{0, 0, 0, 9, 10, 11, 0, 0},
{0, 0, 0, 12, 13, 14, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 6, 7, 8, 0},
{0, 0, 0, 0, 9, 10, 11, 0},
{0, 0, 0, 0, 12, 13, 14, 0},
};
int mapfinish[][]={
// 1 2 3 4 5 6 7 8
{1, 1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
};
public Level1(PlaneWarrior midlet, Display display) throws IOException{
super(true);
pesawat = createZoakh();
tiled = createLayer(maptiled);
finish = createLayer(mapfinish);
try {
//sprite Image
pesmus=Image.createImage("/res/plane.png");
tem=Image.createImage("/res/tembak.png");
} catch(Exception e){}
for(int i=0;i<20;i++){
musuh[i] = new Sprite(pesmus, 25, 25);
musuh[i].setFrame(1);
}
for(int i=0;i<50;i++){
tembakan[i] = new Sprite(tem, 10, 10);
tembakan[i].setFrame(0);
}
dunia = new LayerManager();
dunia.append(pesawat);
for(int i=0;i<20;i++){
dunia.append(musuh[i]);
}
for(int i=0;i<50;i++){
dunia.append(tembakan[i]);
}
dunia.append(tiled);
dunia.append(finish);
tm = new Timer();
tt = new TestTimerTask();
tm.scheduleAtFixedRate(tt, new Date(), 1000);
}
private Pesawat createZoakh() throws IOException{
Image image = Image.createImage("/res/plane.png");
return new Pesawat(image, 25, 25);
}
private TiledLayer createLayer(int map[][]) throws IOException{
Image image = Image.createImage("/res/back.png");
TiledLayer tiledLayer = new TiledLayer(8, 30, image, 30, 30);
for (int row = 0; row < 30; row++) {
for(int column = 0;column<8; column++){
tiledLayer.setCell(column, row, map[row][column]);
}
}
return tiledLayer;
}
public void start(){
main = true;
Thread t = new Thread(this);
t.start();
tiled.setPosition((getWidth()/2-120), -900+getHeight());
finish.setPosition((getWidth()/2-120), -900);
pesawat.setPosition(getWidth()/2, getHeight()-30);
musuh[0].setPosition(10, -10);
musuh[1].setPosition(getWidth()-35, -70);
musuh[2].setPosition(getWidth()/2, -100);
musuh[3].setPosition(25, -150);
musuh[4].setPosition(getWidth()-40,-230);
musuh[5].setPosition(10,-250);
musuh[6].setPosition(25, -320);
musuh[7].setPosition(getWidth()/2+5, -330);
musuh[8].setPosition(getWidth()/2-15, -350);
musuh[9].setPosition(getWidth()/2, -400);
musuh[10].setPosition(getWidth()-50, -480);
musuh[11].setPosition(getWidth()/2-50,-550);
musuh[12].setPosition(getWidth()/2+30,-580);
musuh[13].setPosition(getWidth()/2-5, -670);
musuh[14].setPosition(50, -720);
musuh[15].setPosition(30, -780);
musuh[16].setPosition(getWidth()-40, -800);
musuh[17].setPosition(getWidth()/2-10, -830);
musuh[18].setPosition(getWidth()/2-50,-840);
musuh[19].setPosition(getWidth()/2+30,-870);
for(int i=0;i<50;i++){
tembakan[i].setPosition(-50, -50);
}
Skor = 0;
darahjagoan = 10;
}
public void stop(){
main = false;
}
public void run(){
//playlagu();
Graphics g = getGraphics();
while(main){
while(!gameover){
a++;
if(a%5==0){
tiled.move(0, 1);
a=0;
}
b++;
if(b%3==0){
for(int i=0;i<20;i++){
musuh[i].move(0, 1);
}
finish.move(0, 1);
b=0;
}
input();
nembak();
tick();
render(g);
try{
Thread.sleep(speed);
}catch(InterruptedException e){
stop();
}
}
if(gameover==true){
//synchronized(this){
g.setColor(255, 255, 255);
g.fillRect(getWidth()/2-50, getHeight()/2-10, 100,30 );
g.setColor(255,0,0);
if(menang==true)
g.drawString("YOU WIN", getWidth()/2-30, getHeight()/2-5, Graphics.TOP|Graphics.LEFT);
else{
g.drawString("YOU LOSE " , getWidth()/2-30, getHeight()/2-15, Graphics.TOP|Graphics.LEFT);
g.drawString(reason, getWidth()/2-40, getHeight()/2-5, Graphics.TOP|Graphics.LEFT);
}
g.drawString("Nilai anda = " + Skor, getWidth()/2-40, getHeight()/2+5, Graphics.TOP|Graphics.LEFT);
flushGraphics();
}
}
}
private void selesai(){
}
public void tick(){
for(int i=0;i<20;i++){
//musuh tertembak
for(int j=0;j<50;j++){
if(tembakan[j].collidesWith(musuh[i], true)){
musuh[i].setVisible(false);
Skor+=100;
tembakan[j].setPosition(-50, -50);
}
}
//kena musuh
if(pesawat.collidesWith(musuh[i], true)){
darahjagoan--;
musuh[i].setVisible(false);
if(darahjagoan<=0){
gameover=true;
menang = false;
}
}
}
if(pesawat.collidesWith(finish, true)){
gameover=true;
menang = true;
}
}
private void keluar(){
}
private void input() {
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0){
if(pesawat.getX()-1>0)
pesawat.Kiri();
}
else if ((keyStates & RIGHT_PRESSED) != 0){
if(pesawat.getX()+260)
pesawat.Atas();
}
else if ((keyStates & DOWN_PRESSED) != 0){
if(pesawat.getY()+26<-10){
tembakan[i].setPosition(-50, -50);
tembak[i]=false;
}
}
}
}
private void render(Graphics g){
int w = getWidth();
int h = getHeight();
g.setColor(34,176,235);
g.fillRect(0, 0, w, h);
dunia.paint(g, 0, 0);
g.setColor(255,255,255);
g.fillRect(5, 5, 50, 20);
g.fillRect(5, 30, 50, 10);
g.setColor(255,0,0);
g.drawString("warrior", 10, 5, Graphics.TOP|Graphics.LEFT);
g.drawString("" + Skor, w-50, 5, Graphics.TOP|Graphics.LEFT);
g.setColor(255,0,0);
g.fillRect(5, 30, darahjagoan*5, 10);
flushGraphics();
}
public class TestTimerTask extends TimerTask{
public final void run(){
}
}
}
source code untuk Level2.java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package source;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.*;
/**
* @author ichong
*/
public class Level2 extends GameCanvas implements Runnable{
/**
* constructor
*/
PlaneWarrior midlet;
Display display;
private boolean main;
private boolean gameover = false;
public boolean menang;
private Pesawat pesawat;
private Sprite[] musuh = new Sprite[20];
private Sprite[] musuh2 = new Sprite[10];
private Sprite[] tembakan = new Sprite[50];
private Sprite[] tembakan2 = new Sprite[50];
private Image pesmus, tem;
private TiledLayer back;
private TiledLayer tiled;
private TiledLayer finish;
private TiledLayer star;
public LayerManager dunia;
private int speed = 0;
public int Skor;
private int level;
public boolean[] tembak = new boolean[50];
public boolean[] tembak2 = new boolean[50];
int a,b,c;
private int peluru, peluru2;
private int darahjagoan=10;
public String reason;
private int count = 50;
private Timer tm;
private TestTimerTask tt;
private Command cmExit, cmInstruction;
int maptiled[][]={
// 1 2 3 4 5 6 7 8
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 6, 7, 8, 0, 0, 0},
{0, 0, 9, 10, 11, 0, 0, 0},
{0, 0, 12, 13, 14, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 0, 6, 7, 8, 0},
{0, 0, 0, 0, 9, 10, 11, 0},
{0, 0, 0, 0, 12, 13, 14, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 6, 7, 8, 0, 0},
{0, 0, 0, 9, 10, 11, 0, 0},
{0, 0, 0, 12, 13, 14, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 6, 7, 8, 0},
{0, 0, 0, 0, 9, 10, 11, 0},
{0, 0, 0, 0, 12, 13, 14, 0},
};
int mapstar[][]={
// 1 2 3 4 5 6 7 8
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
{4, 5, 5, 4, 4, 5, 5, 5},
{4, 5, 5, 4, 4, 5, 5, 5},
{5, 4, 4, 5, 5, 4, 4, 4},
};
int mapfinish[][]={
// 1 2 3 4 5 6 7 8
{2, 2, 2, 2, 2, 2, 2, 2},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
};
public Level2(PlaneWarrior midlet, Display display) throws IOException{
super(true);
pesawat = createZoakh();
tiled = createLayer(maptiled);
finish = createLayer(mapfinish);
star = createLayer(mapstar);
try {
//sprite Image
pesmus=Image.createImage("/res/plane.png");
tem=Image.createImage("/res/tembak.png");
} catch(Exception e){}
for(int i=0;i<20;i++){
musuh[i] = new Sprite(pesmus, 25, 25);
musuh[i].setFrame(1);
musuh[i].setVisible(false);
}
for(int i=0;i<10;i++){
musuh2[i] = new Sprite(pesmus, 25, 25);
musuh2[i].setFrame(2);
musuh2[i].setVisible(false);
}
for(int i=0;i<50;i++){
tembakan[i] = new Sprite(tem, 10, 10);
tembakan[i].setFrame(0);
}
for(int i=0;i<50;i++){
tembakan2[i] = new Sprite(tem, 10, 10);
tembakan2[i].setFrame(1);
}
dunia = new LayerManager();
dunia.append(pesawat);
for(int i=0;i<20;i++){
dunia.append(musuh[i]);
}
for(int i=0;i<10;i++){
dunia.append(musuh2[i]);
}
for(int i=0;i<50;i++){
dunia.append(tembakan[i]);
}
for(int i=0;i<50;i++){
dunia.append(tembakan2[i]);
}
dunia.append(tiled);
//dunia.append(star);
dunia.append(finish);
tm = new Timer();
tt = new TestTimerTask();
tm.scheduleAtFixedRate(tt, new Date(), 1000);
}
private Pesawat createZoakh() throws IOException{
Image image = Image.createImage("/res/plane.png");
return new Pesawat(image, 25, 25);
}
private TiledLayer createLayer(int map[][]) throws IOException{
Image image = Image.createImage("/res/back.png");
TiledLayer tiledLayer = new TiledLayer(8, 30, image, 30, 30);
for (int row = 0; row < 30; row++) {
for(int column = 0;column<8; column++){
tiledLayer.setCell(column, row, map[row][column]);
}
}
return tiledLayer;
}
public void start(){
main = true;
Thread t = new Thread(this);
t.start();
tiled.setPosition((getWidth()/2-120), -900+getHeight());
star.setPosition((getWidth()/2-120), -900+getHeight());
finish.setPosition((getWidth()/2-120), -900);
pesawat.setPosition(getWidth()/2, getHeight()-30);
musuh[0].setPosition(10, -40);
musuh[1].setPosition(getWidth()-35, -70);
musuh[2].setPosition(getWidth()/2, -100);
musuh[3].setPosition(25, -150);
musuh[4].setPosition(getWidth()-40,-230);
musuh[5].setPosition(10,-250);
musuh[6].setPosition(25, -320);
musuh[7].setPosition(getWidth()/2+5, -330);
musuh[8].setPosition(getWidth()/2-15, -350);
musuh[9].setPosition(getWidth()/2, -400);
musuh[10].setPosition(getWidth()-50, -480);
musuh[11].setPosition(getWidth()/2-50,-550);
musuh[12].setPosition(getWidth()/2+30,-580);
musuh[13].setPosition(getWidth()/2-5, -670);
musuh[14].setPosition(50, -720);
musuh[15].setPosition(30, -780);
musuh[16].setPosition(getWidth()-40, -800);
musuh[17].setPosition(getWidth()/2-10, -830);
musuh[18].setPosition(getWidth()/2-50,-840);
musuh[19].setPosition(getWidth()/2+30,-870);
musuh2[0].setPosition(30, -200);
musuh2[1].setPosition(getWidth()-50, -250);
musuh2[2].setPosition(getWidth()/2-30, -350);
musuh2[3].setPosition(10, -450);
musuh2[4].setPosition(getWidth()-60,-600);
musuh2[5].setPosition(50,-700);
musuh2[6].setPosition(40, -800);
musuh2[7].setPosition(getWidth()/2-50, -900);
musuh2[8].setPosition(getWidth()/2+15, -1100);
musuh2[9].setPosition(getWidth()/2+5, -1200);
for(int i=0;i<50;i++){
tembakan[i].setPosition(-50, -50);
}
for(int i=0;i<50;i++){
tembakan2[i].setPosition(-50, getHeight()+30);
}
Skor = 0;
darahjagoan = 10;
}
public void stop(){
main = false;
}
public void run(){
//playlagu();
Graphics g = getGraphics();
while(main){
while(!gameover){
a++;
if(a%5==0){
tiled.move(0, 1);
star.move(0, 1);
a=0;
}
b++;
if(b%3==0){
for(int i=0;i<20;i++){
musuh[i].move(0, 1);
if(musuh[i].getY()==-30){
musuh[i].setVisible(true);
}
if(musuh[i].getY()==30){
tembakan2[peluru2].setPosition(musuh[i].getX()+5, musuh[i].getY()+15);
tembak2[peluru2] = true;
peluru2++;
if(peluru2==49)
peluru2=0;
}
}
finish.move(0, 1);
b=0;
}
c++;
if(b%2==0){
for(int i=0;i<10;i++){
musuh2[i].move(0, 1);
if(musuh2[i].getY()==-30){
musuh2[i].setVisible(true);
}
if(musuh2[i].getY()==50){
tembakan2[peluru2].setPosition(musuh2[i].getX()+5, musuh2[i].getY()+15);
tembak2[peluru2] = true;
peluru2++;
if(peluru2==49)
peluru2=0;
}
}
c=0;
}
input();
nembak();
nembak2();
tick();
render(g);
try{
Thread.sleep(speed);
}catch(InterruptedException e){
stop();
}
}
if(gameover==true){
//synchronized(this){
g.setColor(255, 255, 255);
g.fillRect(getWidth()/2-50, getHeight()/2-10, 100,30 );
g.setColor(255,0,0);
if(menang==true)
g.drawString("YOU WIN", getWidth()/2-30, getHeight()/2-5, Graphics.TOP|Graphics.LEFT);
else{
g.drawString("YOU LOSE " , getWidth()/2-30, getHeight()/2-15, Graphics.TOP|Graphics.LEFT);
g.drawString(reason, getWidth()/2-40, getHeight()/2-5, Graphics.TOP|Graphics.LEFT);
}
g.drawString("Nilai anda = " + Skor, getWidth()/2-40, getHeight()/2+5, Graphics.TOP|Graphics.LEFT);
flushGraphics();
}
}
}
private void selesai(){
}
public void tick(){
for(int i=0;i<20;i++){
//musuh tertembak
for(int j=0;j<50;j++){
if(tembakan[j].collidesWith(musuh[i], true)){
musuh[i].setVisible(false);
Skor+=100;
tembakan[j].setPosition(-50, -50);
}
}
//kena musuh
if(pesawat.collidesWith(musuh[i], true)){
darahjagoan--;
musuh[i].setVisible(false);
if(darahjagoan<=0){
gameover=true;
menang = false;
}
}
}
for(int i=0;i<10;i++){
//musuh2 tertembak
for(int j=0;j<50;j++){
if(tembakan[j].collidesWith(musuh2[i], true)){
musuh2[i].setVisible(false);
Skor+=200;
tembakan[j].setPosition(-50, -50);
}
}
//kena musuh2
if(pesawat.collidesWith(musuh2[i], true)){
darahjagoan--;
musuh2[i].setVisible(false);
if(darahjagoan<=0){
gameover=true;
menang = false;
}
}
}
//kena pesawat musuh
if(pesawat.collidesWith(finish, true)){
gameover=true;
menang = true;
}
//tertembak
for(int j=0;j<50;j++){
if(tembakan2[j].collidesWith(pesawat, true)){
darahjagoan--;
tembakan2[j].setPosition(-50, getHeight()+30);
}
}
}
private void keluar(){
}
private void input() {
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0){
if(pesawat.getX()-1>0)
pesawat.Kiri();
}
else if ((keyStates & RIGHT_PRESSED) != 0){
if(pesawat.getX()+260)
pesawat.Atas();
}
else if ((keyStates & DOWN_PRESSED) != 0){
if(pesawat.getY()+26<0){
tembakan[i].setPosition(-50, -50);
tembak[i]=false;
}
}
}
}
private void nembak2(){
for(int i=0;i<50;i++){
if(tembak2[i]==true){
tembakan2[i].move(0, 1);
if(tembakan2[i].getY()>getHeight()){
tembakan2[i].setPosition(-50, getHeight()+50);
tembak2[i]=false;
}
}
}
}
private void render(Graphics g){
int w = getWidth();
int h = getHeight();
g.setColor(15,51,154);
g.fillRect(0, 0, w, h);
dunia.paint(g, 0, 0);
g.setColor(255,255,255);
g.fillRect(5, 5, 50, 20);
g.fillRect(5, 30, 50, 10);
g.setColor(255,0,0);
g.drawString("warrior", 10, 5, Graphics.TOP|Graphics.LEFT);
g.drawString("" + Skor, w-50, 5, Graphics.TOP|Graphics.LEFT);
g.setColor(255,0,0);
g.fillRect(5, 30, darahjagoan*5, 10);
flushGraphics();
}
public class TestTimerTask extends TimerTask{
public final void run(){
}
}
}
source code Level3.java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package source;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.*;
/**
* @author ichong
*/
public class Level3 extends GameCanvas implements Runnable{
/**
* constructor
*/
PlaneWarrior midlet;
Display display;
private boolean main;
private boolean gameover = false;
private boolean kanan;
public boolean menang;
private Pesawat pesawat;
private Sprite musuh;
private Sprite[] tembakan = new Sprite[50];
private Sprite[] tembakan2 = new Sprite[50];
private Image pesmus, tem, tem2;
private TiledLayer back;
private TiledLayer tiled;
public LayerManager dunia;
private int speed = 10;
public int Skor;
private int level;
public boolean[] tembak = new boolean[50];
public boolean[] tembak2 = new boolean[50];
int a,b,c;
private int peluru, peluru2;
private int darahjagoan=10, darahmusuh = 10;
public String reason;
private int count = 50;
private Timer tm;
private TestTimerTask tt;
private Command cmExit, cmInstruction;
int maptiled[][]={
// 1 2 3 4 5 6 7 8
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 6, 7, 8, 0, 0, 0},
{0, 0, 9, 10, 11, 0, 0, 0},
{0, 0, 12, 13, 14, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 0, 6, 7, 8, 0},
{0, 0, 0, 0, 9, 10, 11, 0},
{0, 0, 0, 0, 12, 13, 14, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 6, 7, 8, 0, 0, 0, 0},
{0, 9, 10, 11, 0, 0, 0, 0},
{0, 12, 13, 14, 0, 0, 0, 0},
{0, 0, 0, 6, 7, 8, 0, 0},
{0, 0, 0, 9, 10, 11, 0, 0},
{0, 0, 0, 12, 13, 14, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 6, 7, 8, 0},
{0, 0, 0, 0, 9, 10, 11, 0},
{0, 0, 0, 0, 12, 13, 14, 0},
};
public Level3(PlaneWarrior midlet, Display display) throws IOException{
super(true);
pesawat = createZoakh();
tiled = createLayer(maptiled);
try {
//sprite Image
pesmus=Image.createImage("/res/pesawatraja.png");
tem=Image.createImage("/res/tembak.png");
tem2=Image.createImage("/res/plane.png");
} catch(Exception e){}
musuh = new Sprite(pesmus, 50, 50);
musuh.setFrame(0);
for(int i=0;i<50;i++){
tembakan[i] = new Sprite(tem, 10, 10);
tembakan[i].setFrame(0);
}
for(int i=0;i<50;i++){
tembakan2[i] = new Sprite(tem2, 25,25);
tembakan2[i].setFrame(4);
tembakan2[i].setVisible(false);
}
dunia = new LayerManager();
dunia.append(pesawat);
dunia.append(musuh);
for(int i=0;i<50;i++){
dunia.append(tembakan[i]);
}
for(int i=0;i<50;i++){
dunia.append(tembakan2[i]);
}
dunia.append(tiled);
//dunia.append(star);
tm = new Timer();
tt = new TestTimerTask();
tm.scheduleAtFixedRate(tt, new Date(), 1000);
}
private Pesawat createZoakh() throws IOException{
Image image = Image.createImage("/res/plane.png");
return new Pesawat(image, 25, 25);
}
private TiledLayer createLayer(int map[][]) throws IOException{
Image image = Image.createImage("/res/back.png");
TiledLayer tiledLayer = new TiledLayer(8, 30, image, 30, 30);
for (int row = 0; row < 30; row++) {
for(int column = 0;column<8; column++){
tiledLayer.setCell(column, row, map[row][column]);
}
}
return tiledLayer;
}
public void start(){
main = true;
Thread t = new Thread(this);
t.start();
tiled.setPosition((getWidth()/2-120), -900+getHeight());
pesawat.setPosition(getWidth()/2, getHeight()-30);
musuh.setPosition(getWidth()/2, 10);
for(int i=0;i<50;i++){
tembakan[i].setPosition(-50, -50);
}
for(int i=0;i<50;i++){
tembakan2[i].setPosition(-50, getHeight()+30);
}
Skor = 0;
darahjagoan = 10;
darahmusuh = 10;
}
public void stop(){
main = false;
}
public void run(){
//playlagu();
Graphics g = getGraphics();
while(main){
while(!gameover){
a++;
if(a%5==0){
tiled.move(0, 1);
if(tiled.getX()==getHeight())
tiled.setPosition((getWidth()/2-120), -900+getHeight());
a=0;
}
gerakanraja();
input();
nembak();
nembak2();
tick();
render(g);
try{
Thread.sleep(speed);
}catch(InterruptedException e){
stop();
}
}
if(gameover==true){
g.setColor(255, 255, 255);
g.fillRect(getWidth()/2-50, getHeight()/2-10, 100,30 );
g.setColor(255,0,0);
if(menang==true)
g.drawString("YOU WIN", getWidth()/2-30, getHeight()/2-5, Graphics.TOP|Graphics.LEFT);
else{
g.drawString("YOU LOSE " , getWidth()/2-30, getHeight()/2-15, Graphics.TOP|Graphics.LEFT);
g.drawString(reason, getWidth()/2-40, getHeight()/2-5, Graphics.TOP|Graphics.LEFT);
}
g.drawString("Nilai anda = " + Skor, getWidth()/2-40, getHeight()/2+5, Graphics.TOP|Graphics.LEFT);
flushGraphics();
}
}
}
private void gerakanraja(){
if(musuh.getX()<-25)
kanan=true;
if(musuh.getX()>getWidth()-25)
kanan=false;
if(kanan==true)
musuh.move(1, 0);
else
musuh.move(-1, 0);
b++;
if(b%70==0){
tembakan2[peluru2].setPosition(musuh.getX()+10, musuh.getY()+25);
tembakan2[peluru2].setVisible(true);
tembak2[peluru2] = true;
peluru2++;
if(peluru2==49)
peluru2=0;
}
}
private void selesai(){
}
public void tick(){
//musuh tertembak
for(int j=0;j<50;j++){
if(tembakan[j].collidesWith(musuh, true)){
darahmusuh--;
Skor+=100;
tembakan[j].setPosition(-50, -50);
if(darahmusuh<=0){
gameover=true;
menang = true;
}
}
}
//kena musuh
if(pesawat.collidesWith(musuh, true)){
darahjagoan--;
musuh.setVisible(false);
if(darahjagoan<=0){
gameover=true;
menang = false;
}
}
//tertembak
for(int j=0;j<50;j++){
if(tembakan2[j].collidesWith(pesawat, true)){
darahjagoan--;
tembakan2[j].setPosition(-50, getHeight()+30);
}
}
}
private void keluar(){
}
private void input() {
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0){
if(pesawat.getX()-1>0)
pesawat.Kiri();
}
else if ((keyStates & RIGHT_PRESSED) != 0){
if(pesawat.getX()+260)
pesawat.Atas();
}
else if ((keyStates & DOWN_PRESSED) != 0){
if(pesawat.getY()+26<0){
tembakan[i].setPosition(-50, -50);
tembak[i]=false;
}
}
}
}
private void nembak2(){
for(int i=0;i<50;i++){
if(tembak2[i]==true){
tembakan2[i].move(0, 1);
if(tembakan2[i].getY()>getHeight()){
tembakan2[i].setPosition(-50, getHeight()+50);
tembakan2[i].setVisible(false);
tembak2[i]=false;
}
}
}
}
private void render(Graphics g){
int w = getWidth();
int h = getHeight();
g.setColor(0,0,0);
g.fillRect(0, 0, w, h);
dunia.paint(g, 0, 0);
g.setColor(255,255,255);
g.fillRect(5, 5, 50, 20);
g.fillRect(5, 30, 50, 10);
g.fillRect(w-55, 5, 50, 20);
g.fillRect(w-55, 30, 50, 10);
g.setColor(255,0,0);
g.drawString("warrior", 10, 5, Graphics.TOP|Graphics.LEFT);
g.drawString("king", w-50, 5, Graphics.TOP|Graphics.LEFT);
//g.drawString("" + Skor, w-50, 5, Graphics.TOP|Graphics.LEFT);
g.setColor(255,0,0);
g.fillRect(5, 30, darahjagoan*5, 10);
g.fillRect(w-55, 30, darahmusuh*5, 10);
flushGraphics();
}
public class TestTimerTask extends TimerTask{
public final void run(){
}
}
}
source code untuk Pesawat.java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package source;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
/**
* @author ichong
*/
public class Pesawat extends Sprite{
private int langkah;
private int arah;
private int gerakan = 1;
public boolean mentok;
public int gerakansebelumnya;
private static final int laju = 1;
/**
* constructor
*/
public Pesawat(Image image, int frameWidth, int frameHeight) {
super(image, frameWidth, frameHeight);
defineReferencePixel(frameWidth / 2, frameHeight / 2);
}
private static final int[][] framelook = {
{ 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}
};
public void Atas(){
arah = 0;
this.move(0,- laju);
gerakansebelumnya = 1;
}
public void Bawah(){
arah = 1;
this.move(0, +laju);
gerakansebelumnya = 2;
}
public void Kanan(){
arah = 2;
this.move(+laju, 0);
gerakansebelumnya = 3;
}
public void Kiri(){
arah = 3;
this.move(-laju, 0);
gerakansebelumnya = 4;
}
public void undo(){
switch(arah){
case 0 :
this.move(0,+ laju);
break;
case 1:
this.move(0,- laju);
break;
case 2:
this.move(-laju, 0);
break;
case 3:
this.move(+laju, 0);
break;
}
}
}
source code untuk Petunjuk.java :
package source;
import javax.microedition.lcdui.*;
class Petunjuknya
extends Form
implements CommandListener
{
private final PlaneWarrior midlet;
private final Command kembali;
String pesan1, pesan2;
int tipe;
Petunjuknya(PlaneWarrior midlet, int Tipe)
{
super("Petunjuknya");
this.midlet = midlet;
this.tipe = Tipe;
pesan();
pesan1 = "- Tembak aja musuhnya...\n" +
" Tombol ** Petunjuk\n" +
" UP/2 ** Bergerak ke atas\n" +
" DOWN/8 ** Bergerak ke bawah\n" +
" RGHT/6 ** Bergerak ke kanan\n" +
" LEFT/4 ** Bergerak ke kiri\n"+
" SHOOT/5 ** Menembak\n"+
"** Bila pesawat bertabrakan dengan pesawat musuh akan mengurangi nyawa **\n\n"+
"...Selamat Mencoba yaa...\n\n" +
"...LET'S PLAY....\n";
append(new StringItem(null, pesan1));
append(new StringItem(null, pesan2));
kembali = new Command("Kembali", Command.BACK, 0);
addCommand(kembali);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d){
switch(tipe){
case 0 :
midlet.tampilan_utama();
break;
case 1 :
midlet.lanjut(1);
break;
case 2 :
midlet.lanjut(2);
break;
case 3 :
midlet.lanjut(3);
break;
case 4 :
midlet.lanjut(4);
break;
}
}
void pesan(){
switch(tipe){
case 0 :
pesan2 = "instruksi di menu utama";
break;
case 1 :
pesan2 = "instruksi di level 1";
break;
case 2 :
pesan2 = "instruksi di level 2";
break;
case 3 :
pesan2 = "instruksi di level 3";
break;
case 4 :
pesan2 = "instruksi di level 4";
break;
}
}
}
source code untuk PlaneWarrior.java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package source;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.IOException;
/**
* @author ichong
*/
public class PlaneWarrior extends MIDlet implements CommandListener, PlayerListener{
private Level1 canvas1;
private Level2 canvas2;
private Level3 canvas3;
public String nama;
private TextBox textBox;
private boolean level2=false, level3=false, level4=false;
Display display;
private static Player player;
private VolumeControl vc;
public int level = 1;
public int levelterakhir;
public int skor;
private List menu_utama;
private List menu_new;
private List lanjut;
public int instruksi;
Command cmBack, exit, ins1, ins2, ins3, ins4, con1, con2, con3, cmSubmit;
public boolean main = false;
Best_of_the_best read;
public PlaneWarrior(){
if(canvas1==null){
try{
canvas1 = new Level1(this, display);
exit = new Command("Exit", Command.EXIT, 1);
ins1 = new Command("Petunjuknya", Command.SCREEN, 2);
con1 = new Command("Lanjutkan Permainan", Command.SCREEN, 3);
canvas1.addCommand(exit);
canvas1.addCommand(ins1);
canvas1.addCommand(con1);
canvas1.setCommandListener(this);
}catch(IOException ioe){
System.out.println(ioe);
}
}
if(canvas2==null){
try{
canvas2 = new Level2(this, display);
exit = new Command("Exit", Command.EXIT, 1);
ins2 = new Command("Petunjuknya", Command.SCREEN, 2);
con2 = new Command("Lanjutkan Permainan", Command.SCREEN, 3);
canvas2.addCommand(exit);
canvas2.addCommand(ins2);
canvas2.addCommand(con2);
canvas2.setCommandListener(this);
}catch(IOException ioe){
System.out.println(ioe);
}
}
if(canvas3==null){
try{
canvas3 = new Level3(this, display);
exit = new Command("Exit", Command.EXIT, 1);
ins3 = new Command("Petunjuknya", Command.SCREEN, 2);
con3 = new Command("Lanjutkan Permainan", Command.SCREEN, 3);
canvas3.addCommand(exit);
canvas3.addCommand(ins3);
canvas3.addCommand(con3);
canvas3.setCommandListener(this);
}catch(IOException ioe){
System.out.println(ioe);
}
}
}
public void startApp() {
list();
playintro();
display = Display.getDisplay(this);
read = new Best_of_the_best(this, display);
//savelevel();
loadlevel();
Display.getDisplay(this).setCurrent(new welcome(this));
//this.mulai_permainan3();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
if (canvas1 != null)
canvas1.stop();
}
public void list(){
cmBack = new Command("Kembali", Command.BACK, 1);
cmSubmit = new Command("OK dah!!", Command.OK, 1);
menu_utama = new List("MENU UTAMA", List.IMPLICIT);
menu_utama.append("Permainan Baru", null);
menu_utama.append("Lanjutkan Permainan", null);
menu_utama.append("Best of the best", null);
menu_utama.append("Petunjuknya", null);
menu_utama.append("About", null);
menu_utama.append("Keluar",null);
menu_utama.setCommandListener(this);
textBox = new TextBox("Masukkan Nama Kamu yaa : ", "", 100, TextField.ANY);
textBox.addCommand(cmSubmit);
textBox.addCommand(cmBack);
textBox.setCommandListener(this);
lanjut = new List("Lanjutkan Permainan", List.IMPLICIT);
lanjut.append("level 1", null);
lanjut.addCommand(cmBack);
lanjut.setCommandListener(this);
}
void ubahcommandcanvas(){
canvas1.removeCommand(ins1);
canvas1.setCommandListener(this);
}
void tampilan_utama(){
Display.getDisplay(this).setCurrent(menu_utama);
}
void Instruksi(int tipe){
Display.getDisplay(this).setCurrent(new Petunjuknya(this, tipe));
}
void lanjut(int tipe){
switch(tipe){
case 1 :
canvas1.setFullScreenMode(true);
display.setCurrent(canvas1);
break;
case 2 :
canvas2.setFullScreenMode(true);
display.setCurrent(canvas2);
break;
case 3 :
canvas3.setFullScreenMode(true);
display.setCurrent(canvas3);
break;
}
}
void mulai_permainan1(){
main = true;
//playlagu();
playback();
canvas1.start();
canvas1.setFullScreenMode(true);
display.setCurrent(canvas1);
}
void mulai_permainan2(){
main = true;
//playlagu();
playback();
canvas2.start();
canvas2.setFullScreenMode(true);
display.setCurrent(canvas2);
}
void mulai_permainan3(){
main = true;
//playlagu();
playback();
canvas3.start();
canvas3.setFullScreenMode(true);
display.setCurrent(canvas3);
}
public void commandAction (Command command, Displayable displayable){
if(displayable == menu_utama){
if(command == List.SELECT_COMMAND){
switch(menu_utama.getSelectedIndex()){
case 0 :
//permainan baru
Save save2 = new Save("jelek");
save2.open();
save2.delete();
save2.close();
display.setCurrent(textBox);
break;
case 1 :
//lanjutkan permainan
display.setCurrent(lanjut);
break;
case 2 :
//best of the best
display.setCurrent(read);
break;
case 3 :
//petunjuknya
instruksi = 0;
Instruksi(0);
break;
case 4 :
//about
Display.getDisplay(this).setCurrent(new About(this));
break;
case 5 :
//keluar
exitMIDlet();
break;
}
}
}else if(displayable == textBox){
if(command == cmSubmit){
level = 1;
skor = 0;
nama = textBox.getString();
if(level2){
lanjut.delete(1);
level2=false;
}
if(level3){
lanjut.delete(2);
level3=false;
}
Display.getDisplay(this).setCurrent(new loading(this, 1));
}else if(command == cmBack){
display.setCurrent(menu_utama);
}
}else if(displayable == lanjut){
if(command == List.SELECT_COMMAND){
switch(lanjut.getSelectedIndex()){
case 0 :
level = 1;
Display.getDisplay(this).setCurrent(new loading(this, 1));
break;
case 1 :
level = 2;
mulai_permainan2();
break;
case 2 :
level = 3;
mulai_permainan3();
break;
}
}else if(command == cmBack){
display.setCurrent(menu_utama);
}
}
if (command.getCommandType() == Command.EXIT) {
main = false;
playintro();
//stoplagu();
display.setCurrent(menu_utama);
}else if (command == ins1) {
Instruksi(1);
}else if (command == ins2) {
Instruksi(2);
}else if (command == ins3) {
Instruksi(3);
}else if (command == ins4) {
Instruksi(4);
}else if (command == con1){
if(canvas1.menang==true){
this.skor = skor + canvas1.Skor;
read.saverecord();
if(!level2){
lanjut.append("level 2", null);
level2=true;
}
Display.getDisplay(this).setCurrent(new loading(this, 2));
}else{
lanjut(1);
}
}else if (command == con2){
if(canvas2.menang==true){
this.skor = skor + canvas2.Skor;
read.saverecord();
if(!level3){
lanjut.append("level 3", null);
level3=true;
}
Display.getDisplay(this).setCurrent(new loading(this, 3));
}else{
lanjut(2);
}
}else if (command == con3){
if(canvas3.menang==true){
this.skor = canvas3.Skor;
read.saverecord();
Display.getDisplay(this).setCurrent(new loading(this, 5));
}else{
lanjut(4);
}
}
}
private void playintro(){
try{
player.stop();
if(player!=null){
player.close();
}
}catch(Exception e){
}
try {
playMedia("/res/intro.mid");
} catch (Exception e) {
e.printStackTrace();
}
}
private void playback(){
try{
player.stop();
if(player!=null){
player.close();
}
}catch(Exception e){
}
try {
playMedia("/res/backsound.mid");
} catch (Exception e) {
e.printStackTrace();
}
}
private void playMedia(String file)
throws Exception {
player = Manager.createPlayer(getClass().getResourceAsStream(file), "audio/midi");
player.addPlayerListener(this);
player.setLoopCount(-1);
player.prefetch();
player.realize();
vc = (VolumeControl)player.getControl("VolumeControl");
if (vc != null) vc.setLevel(50);
player.start();
}
public void playerUpdate(Player player, String event, Object eventData) {
if(event.equals(PlayerListener.STARTED) &&
new Long(0L).equals((Long)eventData)) {
} else if(event.equals(PlayerListener.CLOSED)) {
}
}
public void loadlevel(){
Save save2 = new Save("jelek");
save2.open();
save2.close();
String Level;
nama = save2.readNama();
Level = save2.readLevel();
if(Level == "level2"){
lanjut.append("level2", null);
level2=true;
}else if(Level == "level3"){
lanjut.append("level2", null);
level2=true;
lanjut.append("level3", null);
level2=true;
}
System.out.println("neh die " + Level + nama);
System.out.println(nama);
//save.close();
}
public void savelevel(){
Save save2 = new Save("jelek");
save2.open();
String Level = "level1";
switch(level){
case 1 :
Level = "level1";
break;
case 2 :
Level = "level2";
break;
case 3 :
Level = "level3";
break;
case 4 :
Level = "level4";
break;
}
save2.delete();
save2.saveRecordStream(level, nama, true, 0);
save2.saveRecordStream(level, nama, true, 0);
System.out.println(nama);
save2.close();
}
public void exitMIDlet(){
savelevel();
try{
player.stop();
if(player!=null){
player.close();
}
}catch(Exception e){
}
destroyApp(true);
notifyDestroyed();
}
}
source code untuk Save.java :
package source;
import javax.microedition.rms.*;
import java.io.*;
class Save {
private RecordStore store;
private String storage;
private int amount = 0;
Save(String storage, int amount) {
store = null;
this.amount = amount;
this.storage = storage;
}
Save(String storage){
this.storage = storage;
}
RecordStore getStore() {
return store;
}
boolean open() {
try {
store = RecordStore.openRecordStore(storage, true);
} catch (RecordStoreException rse) {
}
if (store == null)
return false;
return true;
}
void close() {
try {
if (store != null)
store.closeRecordStore();
} catch (RecordStoreException rse) {
}
}
void delete() {
try {
store.deleteRecordStore(storage);
} catch (Exception e) {
}
}
void saveRecord(int recID, String str) {
byte[] rec = str.getBytes();
try {
if (recID == 0)
store.addRecord(rec, 0, rec.length);
else
store.setRecord(recID, rec, 0, rec.length);
} catch (RecordStoreException rse) {
System.out.println("gagal");
}
}
String readRecord(int recID) {
try {
byte[] recData = new byte[amount];
int len;
len = store.getRecord(recID, recData, 0);
return new String(recData, 0, len);
} catch (RecordStoreException rse) {
return "null";
}
}
void saveRecordStream(int skor, String nama, boolean bPublish, int recID) {
try {
ByteArrayOutputStream strmBytes = new ByteArrayOutputStream();
DataOutputStream strmDataType = new DataOutputStream(strmBytes);
byte[] record;
strmDataType.writeInt(skor);
strmDataType.writeUTF(nama);
strmDataType.writeBoolean(bPublish);
strmDataType.flush();
record = strmBytes.toByteArray();
try {
if (recID == 0)
store.addRecord(record, 0, record.length);
else
store.setRecord(recID, record, 0, record.length);
} catch (RecordStoreException rse) {
}
strmBytes.reset();
strmBytes.close();
strmDataType.close();
} catch (Exception e) {
System.out.println("gagal");
}
}
String readRecordStreamSortInt() {
try {
String rec = "";
byte[] recData = new byte[50];
ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);
DataInputStream strmDataType = new DataInputStream(strmBytes);
if (store.getNumRecords() > 0){
SortInt sort = new SortInt();
int i = 1;
RecordEnumeration re = store.enumerateRecords(null, sort, false);
while (re.hasNextElement()){
store.getRecord(re.nextRecordId(), recData, 0);
rec = rec + strmDataType.readInt() + " | " + strmDataType.readUTF() + "\n";
strmBytes.reset();
}
sort.sortIntClose();
re.destroy();
}
strmBytes.close();
strmDataType.close();
return rec;
}catch (Exception e){
return null;
}
}
String readNama() {
try {
String rec = "";
byte[] recData = new byte[50];
ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);
DataInputStream strmDataType = new DataInputStream(strmBytes);
if (store.getNumRecords() > 0){
SortInt sort = new SortInt();
int i = 1;
RecordEnumeration re = store.enumerateRecords(null, sort, false);
while (re.hasNextElement()){
store.getRecord(re.nextRecordId(), recData, 0);
rec = rec + strmDataType.readUTF();
strmBytes.reset();
}
sort.sortIntClose();
re.destroy();
}
strmBytes.close();
strmDataType.close();
return rec;
}catch (Exception e){
return null;
}
}
String readLevel() {
try {
String rec = "";
byte[] recData = new byte[50];
ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);
DataInputStream strmDataType = new DataInputStream(strmBytes);
if (store.getNumRecords() > 0){
SortInt sort = new SortInt();
int i = 1;
RecordEnumeration re = store.enumerateRecords(null, sort, false);
while (re.hasNextElement()){
store.getRecord(re.nextRecordId(), recData, 0);
rec = rec + strmDataType.readInt();
strmBytes.reset();
}
sort.sortIntClose();
re.destroy();
}
strmBytes.close();
strmDataType.close();
return rec;
}catch (Exception e){
return null;
}
}
};
source code untuk SortInt.java :
package source;
import java.io.*;
import javax.microedition.rms.*;
class SortInt implements RecordComparator {
private byte[] recData = new byte[10];
private ByteArrayInputStream strmBytes = null;
private DataInputStream strmDataType = null;
public void sortIntClose() {
try{
if (strmBytes != null)
strmBytes.close();
if (strmDataType != null)
strmDataType.close();
}catch (Exception e){
}
}
public int compare(byte[] record1, byte[] record2){
int x1, x2;
try{
int maxsize = Math.max(record1.length, record2.length);
if (maxsize > recData.length)
recData = new byte[maxsize];
strmBytes = new ByteArrayInputStream(record1);
strmDataType = new DataInputStream(strmBytes);
x1 = strmDataType.readInt();
strmBytes = new ByteArrayInputStream(record2);
strmDataType = new DataInputStream(strmBytes);
x2 = strmDataType.readInt();
if (x1 == x2)
return RecordComparator.EQUIVALENT;
else if (x1 > x2)
return RecordComparator.PRECEDES;
else
return RecordComparator.FOLLOWS;
} catch (Exception e) {
return RecordComparator.EQUIVALENT;
}
}
}
source code untuk loading.java :
package source;
import javax.microedition.lcdui.*;
class loading extends Canvas implements Runnable{
private final PlaneWarrior midlet;
private Image gambar,gambar2;
private volatile boolean dismissed = false;
int level;
loading(PlaneWarrior midlet, int Level){
level = Level;
this.midlet = midlet;
setFullScreenMode(true);
try {
gambar = Image.createImage("/res/pesawatraja.png");
}catch(java.io.IOException e){
}
new Thread(this).start();
}
public void run(){
synchronized(this){
try{
wait(5000L);
}
catch (InterruptedException e){
}
skip();
}
}
public void paint(Graphics g){
int lebar = getWidth();
int tinggi = getHeight();
g.setColor(0,0,0);
g.fillRect(0, 0, lebar, tinggi);
g.drawImage(gambar,getWidth()/2-25,getHeight()/2-40,Graphics.TOP | Graphics.LEFT);
g.setColor(255,255,255);
if(level<5)
g.drawString("loading level " + level, getWidth()/2-30, getHeight()/2+40, Graphics.TOP | Graphics.LEFT);
else
g.drawString("the end", getWidth()/2-30, getHeight()/2+40, Graphics.TOP | Graphics.LEFT);
}
public synchronized void keyPressed(int keyCode){
skip();
}
private void skip(){
if (!dismissed){
dismissed = true;
switch(level){
case 1 :
midlet.mulai_permainan1();
break;
case 2:
midlet.mulai_permainan2();
break;
case 3:
midlet.mulai_permainan3();
break;
case 5 :
midlet.tampilan_utama();
break;
}
}
}
}
source code untuk welcome.java :
package source;
import javax.microedition.lcdui.*;
class welcome extends Canvas implements Runnable{
private final PlaneWarrior midlet;
private Image gambar, gambar2;
private volatile boolean dismissed = false;
welcome(PlaneWarrior midlet){
this.midlet = midlet;
setFullScreenMode(true);
try {
gambar = Image.createImage("/res/pesawatraja.png");
gambar2 = Image.createImage("/res/planewarrior.png");
}catch(java.io.IOException e){
}
new Thread(this).start();
}
public void run(){
synchronized(this){
try{
wait(5000L);
}
catch (InterruptedException e){
}
skip();
}
}
public void paint(Graphics g){
int lebar = getWidth();
int tinggi = getHeight();
g.setColor(0,0,0);
g.fillRect(0, 0, lebar, tinggi);
g.drawImage(gambar,getWidth()/2-25,getHeight()/2-40,Graphics.TOP | Graphics.LEFT);
g.drawImage(gambar2,getWidth()/2-40,getHeight()/2+20,Graphics.TOP | Graphics.LEFT);
}
public synchronized void keyPressed(int keyCode){
skip();
}
private void skip(){
if (!dismissed){
dismissed = true;
midlet.tampilan_utama();
}
}
}
Implementasi/Layout :
Tampilan Utama :
Tampilan Awal Game :
Tampilan Permainan Baru :
Tampilan About :
Tidak ada komentar:
Posting Komentar