Feeds:
Posts
Comments

Archive for April, 2013

Became a family man, why not? at least this is my activity a weekend time, gathering with a family have a lot of fun time.

From Monday to Friday we have activity at outside family environment, even on Saturday we still have some activity. Became a business man 🙂 .

ulin1ulin2

Read Full Post »

This is true,  as far as I know everything needs life cycle, especially in doing something.

Yesterday  I discuss with a friend about strategic and management planning (this topic for doing planning), audit and control (this is for reduce risk), and last about management of project (for making perfect excellent project).

Three topic above need life cycle, believe me . The life cycle are planning, analysis, implementing and evaluation. That step of life cycle purpose is  for making better improvement.

Read Full Post »

maniac football fans

maniac football fans

Do you ever became fans of football club? that question appear when there is a championship such as league Champion.

How depth some one became fans, we can see from their attention, my friend make gambling with his college 50 $ when Malaga vs Dortmund  play. Arrghhh how came…

For me myself became fans just for fun only, really. I do really like some sport include football, but not until make gambling 🙂

Read Full Post »

Kali ini saya akan share mengenai bagaimana membuat game collision dengan sprite di java. Kita akan memanfaatkan method collidesWith yang dimiliki oleh class sprite.

Untuk membuat kasus ini paling tidak ada 4 script java yang harus disiapkan yaitu midlet, gamecanvas dan 2 script untuk sprite itu sendiri.

Langsung saja, file-file yang sudah saya buat untuk contoh di atas adalah sebagai berikut:

Midlet


import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;
/**
* @author Yudhistira
*/
public class GambarGerak extends MIDlet {
Display ds;
RotateCanvas rc =new RotateCanvas();

public void startApp() {
ds= Display.getDisplay(this);
ds.setCurrent(rc);
rc.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}

}

Sprite (benda pertama)


import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
/**
*
* @author Yudhistira
*/
public class bonteng extends Sprite{

public bonteng(Image image) {
super(image);
setRefPixelPosition(getWidth()*4/3, getWidth()*4/3);
}

}

Sprite (benda kedua)


import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
*
* @author Yudhistira
*/
public class brokoli extends Sprite {

int koorx, koory;
int awalx, awaly;

public brokoli(Image image) {
super(image);
koorx = getWidth();
koory = getHeight();
setPosition(koorx, koory);
}

public void kiri() {
koorx = koorx - 1;
setPosition(koorx, koory);
simpanPos();
}

public void kanan() {
koorx = koorx + 1;
setPosition(koorx, koory);
simpanPos();
}

public void atas() {
koory = koory - 1;
setPosition(koorx, koory);
simpanPos();
}

public void bawah() {
koory = koory + 1;
setPosition(koorx, koory);
simpanPos();
}

public void simpanPos() {
awalx = koorx;
awaly = koory;
}

public void kembaliPos() {
setPosition(awalx, awaly);
}
}

GameCanvas


import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;

/**
*
* @author Yudhistira
*/
public class RotateCanvas extends GameCanvas implements Runnable {

int koorx, koory;
GambarSprite gs;
bonteng bt;
brokoli bk;
LayerManager lm;
boolean flag = false;

public RotateCanvas() {
super(true);
koorx = getWidth();
koory = getHeight();
try {
bt = new bonteng(Image.createImage("/bonteng.jpg"));
bk = new brokoli(Image.createImage("/brokoli.jpg"));
lm = new LayerManager();
lm.append(bt);
lm.append(bk);

} catch (IOException ex) {
ex.printStackTrace();
}

}

private void drawImage(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
lm.paint(g, 0, 0);
flushGraphics();
}

public void start() {
Thread t = new Thread(this);
flag = true;
t.start();
}

public void run() {
Graphics gp = getGraphics();

while (flag) {
try {
int keyState = getKeyStates();
if ((keyState & LEFT_PRESSED) != 0) {
bk.kiri();
} else if ((keyState & RIGHT_PRESSED) != 0) {
bk.kanan();
} else if ((keyState & UP_PRESSED) != 0) {
bk.atas();
} else if ((keyState & DOWN_PRESSED) != 0) {
bk.bawah();
}
if (tabrakan()) {
bk.kembaliPos();
System.out.println("Collision happen... tabrakan euyyy");
} else {
drawImage(gp);
}
Thread.sleep(20);

} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}

private boolean tabrakan() {
boolean fl = false;
if (bk.collidesWith(bt, true)) {
fl = true;
}
return fl;
}
}

Percobaan di atas sudah proven ditest dengan netbean 7.3 dan dideploy di nokia N700

Tampilan saat dirun

Tampilan saat dirun

 

Read Full Post »