In response to the call of www.j2medev.com webmaster Mingjava, I also share with you my experience, I hope you will advise. At the same time www.j2medev.com welcome you to master the original article.
A few days ago to see Tony on the Csdn to publish his study work "is a man to insist on 60s", feel creative although simple but very resistant to play, is to learn the introduction of mobile phone game to create a classic, so a temporary rise, clone a bit, the picture is still using Tony's pictures, pure learning. If you are interested in this game, you can contact Tony or visit his blog.
From the development trend that midp2.0 is the trend, the cheapest midp2.0 mobile phone such as ot735i, has been about 1700 yuan, and Siemens a year ago, the high-end machine cx65, now only about 2500, and 2500-3000 of the price of midp2.0 mobile phones have a variety of options, Siemens , SE, n machine all have. I personally like cx65, if the future handset manufacturers will continue to reduce costs, I believe that the 1500-dollar MIDP is not a dream ... Of course also depends on whether the application is rich.
In turn, we will use MIDP 2.0来 to develop our game, code-named Fly. development tool Jbulider. After all the articles have been written, will provide src download.
Iv. join the submunition to realize the collision operation
V. To achieve the effect of explosion and to add prop missiles
Six, not many, you think?
Seven, the source code
I. The framework of the game
Our game needs a common game framework, but also easy to develop later, but the implementation of an engine is complex. As a beginner if you want to consider too many questions, I am afraid that will let you deviate from the main line, here only give canvas code, do not understand you can see this site's another series of articles "use MIDP2.0 development game."
Use Singlon implementations, because each gamecanvas requires a lot of memory space. In addition, for us, just rewrite gameinit (), Gamemain (), and the one-time initialization code is written in the constructor.
public class Mygamecanvas extends Gamecanvas
Implements Runnable, commandlistener{
private static Mygamecanvas instance;
Graphics G;
Boolean running;
Thread T;
Command Startcmd,exitcmd,restartcmd;
int keystate;
Boolean keyevent;
Boolean key_up,key_down,key_left,key_right,key_fire;
Private Boolean allowinput;
public int screenwidth;
public int screenheight;
Boolean Gameover;
Define your variable here
Define your variable end
Put your init once code here
Put your init once code end
}
Synchronized public static Mygamecanvas getinstance () {
if (instance = = null) {
Instance = new Mygamecanvas ();
System.out.println ("New Mygamecanvas");
}
return instance;
}
public void Run () {
System.out.println ("Mygamecanvas run Start");
Long st=0,et=0,diff=0;
int RATE=50;//16-17 frame per second
while (running) {
St=system.currenttimemillis ();
Gameinput ();
Gamemain ();
Et=system.currenttimemillis ();
Diff=et-st;
if (diff<rate) {
System.out.println ("Sleep" + (Rate-diff));
try {
Thread.Sleep (Rate-diff);
}
catch (Interruptedexception ex) {}
}else{
System.out.println ("Rush, and the frame using Time:á" +diff);
}
}
System.out.println ("Mygamecanvas run End");
}
public void Start () {
if (!running) {
Running=true;
T=new Thread (this);
T.start ();
}
}
private void Gameinput () {
if (allowinput) {
Keystate=getkeystates ();
Keyevent=false;
if ((Keystate & up_pressed)!=0) {//up
Key_up=true;keyevent=true;
Deal your unstop job code here
System.out.println ("Up Press");
Deal your Unstop Job code end
}else if ((Keystate & up_pressed) ==0) {//release key
if (key_up==true) {
Key_up=false;
Deal your one Press-one job code here
System.out.println ("Up release");
Deal your one Press-one job code end
}
}
if ((Keystate & down_pressed)!=0) {//down
Key_down=true;keyevent=true;
Deal your unstop job code here
System.out.println ("Down Press");
Deal your Unstop Job code end
}else if ((Keystate & down_pressed) ==0) {//release key
if (key_down==true) {
Key_down=false;
Deal your one Press-one job code here
System.out.println ("Down release");
Deal your one Press-one job code end
}
}
if ((Keystate & left_pressed)!=0) {//left
Key_left=true;keyevent=true;
Deal your unstop job code here
System.out.println ("left Press");
Deal your Unstop Job code end
}else if ((Keystate & left_pressed) ==0) {//release key
if (key_left==true) {
Key_left=false;
Deal your one Press-one job code here
System.out.println ("left release");
Deal your one Press-one job code end
}
}
if ((Keystate & right_pressed)!=0) {//right
Key_right=true;keyevent=true;
Deal your unstop job code here
System.out.println ("right Press");
Deal your Unstop Job code end
}else if ((Keystate & right_pressed) ==0) {//release key
if (key_right==true) {
Key_right=false;
Deal your one Press-one job code here
System.out.println ("right release");
Deal your one Press-one job code end
}
}
if ((Keystate & fire_pressed)!=0) {//fire
Key_fire=true;keyevent=true;
Deal your unstop job code here
System.out.println ("Fire Press");
Deal your Unstop Job code end
}else if ((Keystate & fire_pressed) ==0) {//release key
if (key_fire==true) {
Key_fire=false;
Deal your one Press-one job code here
System.out.println ("Fire release");
Deal your one Press-one job code end
}
}
if (!keyevent) {
No keyevent here
System.out.println ("NO KEY Press");
No KeyEvent end
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.