- Beranda
- Komunitas
- Tech
- Programmer Forum
J2ME / Game Programming


TS
qwe2113
J2ME / Game Programming
sebelum ane kasih code sourcenya... ada baiknya lihat Java syntax di wikipedia.
beberapa situs WEB Tutorial untuk membuat game Canvas J2ME:
http://sonusdream.blogspot.com/
http://delhidaredevilzgalary.blogspot.com
http://j2megame.uw.hu/
koderko-->cari di google dengan kata berikut.
nah sekarang ane mau kasih source code sederhana games j2me:
source code di ambil dari:
http://delhidaredevilzgalary.blogspo...2mecanvas.html
berikut source codenya:
import java.io.IOException;
import java.lang.Thread;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.Sprite;
public class GameMidlet extends MIDlet {
private SampleCanvas gameCanvas;
private Thread t=null;
private Display d;
public void startApp() {
try {
this.gameCanvas = new SampleCanvas();
} catch (IOException ex) {
ex.printStackTrace();
}
d = Display.getDisplay(this);
d.setCurrent(gameCanvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class SampleCanvas extends Canvas implements Runnable {
int x, y; // Location of cross hairs
String event = ""; // Last key event type
int keyCode; // Last keyCode pressed
int w, h; // width and height of the canvas
Image img;
Sprite sprite;
boolean flag;
Thread t1;
SampleCanvas() throws IOException {
img=Image.createImage("/sprite.png");
sprite=new Sprite(img);
w = getWidth();
h = getHeight();
}
protected void keyPressed(int key) {
keyCode = key;
event = "Pressed";
if(t1==null)
Check();
}
protected void Check()
{
flag=true;
t1=new Thread(this);
t1.start();
}
void handleActions(int keyCode) {
int action = getGameAction(keyCode);
switch (action) {
case LEFT:
x -= 1;
break;
case RIGHT:
x += 1;
break;
case UP:
y -= 1;
break;
case DOWN:
y += 1;
break;
}
}
protected void paint(Graphics g) {
g.setColor(255,255, 255);
g.fillRect(0, 0, w, h);
sprite.setRefPixelPosition(0,0) ;
sprite.setPosition(x, y);
sprite.paint(g) ;
}
public void run() {
while(flag)
{
handleActions(keyCode);
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
bisa di modif sesuka hati asal tau cara modifnya..
nah untuk membuatnya bisa pakek J2ME SDK MOBILE,
Untuk cara decompilenya gunakan aplikasi xplore 377, MJDecompiler, dan aplikasi yang bisa meng-decompile file class menjadi file java.
beberapa situs WEB Tutorial untuk membuat game Canvas J2ME:
http://sonusdream.blogspot.com/
http://delhidaredevilzgalary.blogspot.com
http://j2megame.uw.hu/
koderko-->cari di google dengan kata berikut.
nah sekarang ane mau kasih source code sederhana games j2me:
source code di ambil dari:
http://delhidaredevilzgalary.blogspo...2mecanvas.html
berikut source codenya:
import java.io.IOException;
import java.lang.Thread;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.Sprite;
public class GameMidlet extends MIDlet {
private SampleCanvas gameCanvas;
private Thread t=null;
private Display d;
public void startApp() {
try {
this.gameCanvas = new SampleCanvas();
} catch (IOException ex) {
ex.printStackTrace();
}
d = Display.getDisplay(this);
d.setCurrent(gameCanvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class SampleCanvas extends Canvas implements Runnable {
int x, y; // Location of cross hairs
String event = ""; // Last key event type
int keyCode; // Last keyCode pressed
int w, h; // width and height of the canvas
Image img;
Sprite sprite;
boolean flag;
Thread t1;
SampleCanvas() throws IOException {
img=Image.createImage("/sprite.png");
sprite=new Sprite(img);
w = getWidth();
h = getHeight();
}
protected void keyPressed(int key) {
keyCode = key;
event = "Pressed";
if(t1==null)
Check();
}
protected void Check()
{
flag=true;
t1=new Thread(this);
t1.start();
}
void handleActions(int keyCode) {
int action = getGameAction(keyCode);
switch (action) {
case LEFT:
x -= 1;
break;
case RIGHT:
x += 1;
break;
case UP:
y -= 1;
break;
case DOWN:
y += 1;
break;
}
}
protected void paint(Graphics g) {
g.setColor(255,255, 255);
g.fillRect(0, 0, w, h);
sprite.setRefPixelPosition(0,0) ;
sprite.setPosition(x, y);
sprite.paint(g) ;
}
public void run() {
while(flag)
{
handleActions(keyCode);
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
bisa di modif sesuka hati asal tau cara modifnya..

nah untuk membuatnya bisa pakek J2ME SDK MOBILE,
Untuk cara decompilenya gunakan aplikasi xplore 377, MJDecompiler, dan aplikasi yang bisa meng-decompile file class menjadi file java.
Diubah oleh qwe2113 27-12-2013 00:34
0
1.3K
6


Komentar yang asik ya
Urutan
Terbaru
Terlama


Komentar yang asik ya
Komunitas Pilihan