GameMidlet01


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class gerakEfa extends MIDlet {
private Display display;
public void startApp() {
display = Display.getDisplay(this);
MyCanvas gameCanvas = new MyCanvas();
gameCanvas.start();
display.setCurrent(gameCanvas);
}
public Display getDisplay() {
return display;
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
exit();
}
public void exit() {
System.gc();
destroyApp(false);
notifyDestroyed();
}
}

 

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class MyCanvas extends GameCanvas implements Runnable {
private boolean running;
private long delay;
private int currentX, currentY;
private int screenWidth;
private int screenHeight;
private String text = “A”;

public MyCanvas() {
super(true);
screenWidth = getWidth();
screenHeight = getHeight();
currentX = screenWidth / 2;
currentY = screenHeight / 2;
delay = 20;
}

public void start() {
running = true;
Thread thread = new Thread(this);
thread.start();
}

public void stop() { running = false; }

// The Game Loop
public void run() {
Graphics g = getGraphics();

while (running == true) {
getInput();
drawScreen(g);
try { Thread.sleep(delay); } catch (InterruptedException ie) {}
}
}

private void getInput() {
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0) {
currentX = Math.max(20, currentX – 1);
text = “L”;
}
if ((keyStates & RIGHT_PRESSED) != 0) {
currentX = Math.min(screenWidth-30, currentX + 1);
text = “R”;
}
if ((keyStates & UP_PRESSED) != 0) {
currentY = Math.max(20, currentY – 1);
text = “U”;
}
if ((keyStates & DOWN_PRESSED) != 0) {
currentY = Math.min(screenHeight-30, currentY + 1);
text = “D”;
}
}
private void drawScreen(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x0000ff);

if (text ==”A”)
{
g.setColor(0,0,255);
g.fillArc(currentX, currentY,10,10,0,360);

g.setColor(0,200,255);
g.fillArc(currentX+2, currentY+2,6,6,0,360);

g.setColor(0,0,255);
g.fillArc(currentX+10, currentY,10,10,0,360);

g.setColor(0,200,255);
g.fillArc(currentX+12, currentY+2,6,6,0,360);

g.setColor(0,0,255);
g.fillArc(currentX-10, currentY,10,10,0,360);

g.setColor(0,200,255);
g.fillArc(currentX-8, currentY+2,6,6,0,360);

g.setColor(0,0,255);
g.fillArc(currentX, currentY-10,10,10,0,360);

g.setColor(0,200,255);
g.fillArc(currentX+2, currentY-8,6,6,0,360);
}

if (text ==”U”)
{
//kotak
g.setColor(0,0,255);
g.drawLine(currentX, currentY,currentX+10, currentY);
g.drawLine(currentX+10, currentY,currentX+10,currentY+10);
g.drawLine(currentX+10, currentY+10,currentX,currentY+10);
g.drawLine(currentX, currentY+10,currentX,currentY);
//kotak kecil
g.setColor(255,0,255);
g.drawLine(currentX+2, currentY+2,currentX+8, currentY+2);
g.drawLine(currentX+8, currentY+2,currentX+8,currentY+8);
g.drawLine(currentX+8, currentY+8,currentX+2,currentY+8);
g.drawLine(currentX+2, currentY+8,currentX+2,currentY+2);
//segitiga kanan
g.setColor(0,0,255);
g.drawLine(currentX+12, currentY,currentX+22, currentY+5);
g.drawLine(currentX+22, currentY+5,currentX+12,currentY+10);
g.drawLine(currentX+12, currentY+10,currentX+12,currentY);
//segitiga kiri
g.setColor(0,0,255);
g.drawLine(currentX-2, currentY,currentX-12, currentY+5);
g.drawLine(currentX-12, currentY+5,currentX-2,currentY+10);
g.drawLine(currentX-2, currentY+10,currentX-2,currentY);
//segitiga atas
g.setColor(0,0,255);
g.drawLine(currentX, currentY-2,currentX+10, currentY-2);
g.drawLine(currentX+10, currentY-2,currentX+5,currentY-12);
g.drawLine(currentX+5, currentY-12,currentX,currentY-2);
//segitiga atas kecil
g.setColor(255,0,255);
g.drawLine(currentX+2, currentY-14,currentX+8, currentY-14);
g.drawLine(currentX+8, currentY-14,currentX+5,currentY-20);
g.drawLine(currentX+5, currentY-20,currentX+2,currentY-14);

g.setColor(255, 0, 0); // red
// garis
g.drawLine(currentX+5, currentY-20,currentX+5,0);

}

if (text ==”D”)
{
//kotak
g.setColor(0,0,255);
g.drawLine(currentX, currentY,currentX+10, currentY);
g.drawLine(currentX+10, currentY,currentX+10,currentY+10);
g.drawLine(currentX+10, currentY+10,currentX,currentY+10);
g.drawLine(currentX, currentY+10,currentX,currentY);
//kotak kecil
g.setColor(255,0,255);
g.drawLine(currentX+2, currentY+2,currentX+8, currentY+2);
g.drawLine(currentX+8, currentY+2,currentX+8,currentY+8);
g.drawLine(currentX+8, currentY+8,currentX+2,currentY+8);
g.drawLine(currentX+2, currentY+8,currentX+2,currentY+2);
//segitiga kanan
g.setColor(0,0,255);
g.drawLine(currentX+12, currentY,currentX+22, currentY+5);
g.drawLine(currentX+22, currentY+5,currentX+12,currentY+10);
g.drawLine(currentX+12, currentY+10,currentX+12,currentY);
//segitiga kiri
g.setColor(0,0,255);
g.drawLine(currentX-2, currentY,currentX-12, currentY+5);
g.drawLine(currentX-12, currentY+5,currentX-2,currentY+10);
g.drawLine(currentX-2, currentY+10,currentX-2,currentY);
//segitiga bawah
g.setColor(0,0,255);
g.drawLine(currentX, currentY+12,currentX+10, currentY+12);
g.drawLine(currentX+10, currentY+12,currentX+5,currentY+22);
g.drawLine(currentX+5, currentY+22,currentX,currentY+12);
//segitiga bawah kecil
g.setColor(255,0,255);
g.drawLine(currentX+2, currentY+24,currentX+8,currentY+24);
g.drawLine(currentX+8, currentY+24,currentX+5,currentY+30);
g.drawLine(currentX+5, currentY+30,currentX+2,currentY+24);

g.setColor(255, 0, 0); // red
// garis
g.drawLine(currentX+5, currentY+30,currentX+5,screenHeight);

}

if (text ==”L”)
{
//kotak
g.setColor(0,0,255);
g.drawLine(currentX, currentY,currentX+10, currentY);
g.drawLine(currentX+10, currentY,currentX+10,currentY+10);
g.drawLine(currentX+10, currentY+10,currentX,currentY+10);
g.drawLine(currentX, currentY+10,currentX,currentY);
//kotak kecil
g.setColor(255,0,255);
g.drawLine(currentX+2, currentY+2,currentX+8, currentY+2);
g.drawLine(currentX+8, currentY+2,currentX+8,currentY+8);
g.drawLine(currentX+8, currentY+8,currentX+2,currentY+8);
g.drawLine(currentX+2, currentY+8,currentX+2,currentY+2);
//segitiga atas
g.setColor(0,0,255);
g.drawLine(currentX, currentY-2,currentX+10, currentY-2);
g.drawLine(currentX+10, currentY-2,currentX+5,currentY-12);
g.drawLine(currentX+5, currentY-12,currentX,currentY-2);
//segitiga bawah
g.setColor(0,0,255);
g.drawLine(currentX, currentY+12,currentX+10, currentY+12);
g.drawLine(currentX+10, currentY+12,currentX+5,currentY+22);
g.drawLine(currentX+5, currentY+22,currentX,currentY+12);
//segitiga kiri
g.setColor(0,0,255);
g.drawLine(currentX-2, currentY,currentX-12, currentY+5);
g.drawLine(currentX-12, currentY+5,currentX-2,currentY+10);
g.drawLine(currentX-2, currentY+10,currentX-2,currentY);
//    segitiga kiri kecil
g.setColor(255,0,255);
g.drawLine(currentX-14, currentY+2,currentX-14,currentY+8);
g.drawLine(currentX-14, currentY+8,currentX-20,currentY+5);
g.drawLine(currentX-20, currentY+5,currentX-14,currentY+2);

g.setColor(255, 0, 0); // red
// garis
g.drawLine(currentX-20, currentY+5,0,currentY+5);

}

if (text ==”R”)
{
//kotak
g.setColor(0,0,255);
g.drawLine(currentX, currentY,currentX+10, currentY);
g.drawLine(currentX+10, currentY,currentX+10,currentY+10);
g.drawLine(currentX+10, currentY+10,currentX,currentY+10);
g.drawLine(currentX, currentY+10,currentX,currentY);
//kotak kecil
g.setColor(255,0,255);
g.drawLine(currentX+2, currentY+2,currentX+8, currentY+2);
g.drawLine(currentX+8, currentY+2,currentX+8,currentY+8);
g.drawLine(currentX+8, currentY+8,currentX+2,currentY+8);
g.drawLine(currentX+2, currentY+8,currentX+2,currentY+2);
//segitiga atas
g.setColor(0,0,255);
g.drawLine(currentX, currentY-2,currentX+10, currentY-2);
g.drawLine(currentX+10, currentY-2,currentX+5,currentY-12);
g.drawLine(currentX+5, currentY-12,currentX,currentY-2);
//segitiga bawah
g.setColor(0,0,255);
g.drawLine(currentX, currentY+12,currentX+10, currentY+12);
g.drawLine(currentX+10, currentY+12,currentX+5,currentY+22);
g.drawLine(currentX+5, currentY+22,currentX,currentY+12);

//segitiga kanan
g.setColor(0,0,255);
g.drawLine(currentX+12, currentY,currentX+22, currentY+5);
g.drawLine(currentX+22, currentY+5,currentX+12,currentY+10);
g.drawLine(currentX+12, currentY+10,currentX+12,currentY);

//    segitiga kanan kecil
g.setColor(255,0,255);
g.drawLine(currentX+22, currentY+2,currentX+30,currentY+5);
g.drawLine(currentX+30, currentY+5,currentX+22,currentY+8);
g.drawLine(currentX+22, currentY+8,currentX+22,currentY+2);

g.setColor(255, 0, 0); // red
// garis
g.drawLine(currentX+30, currentY+5,screenWidth , currentY+5);

}

//        g.drawString(text, currentX, currentY,
//        Graphics.TOP|Graphics.LEFT);
flushGraphics();
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s