the code

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

mail

Postby deepak_evil » Sat Sep 01, 2007 4:06 pm

did u get my mail code tiger
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Sun Sep 02, 2007 12:20 pm

yeah, I got it and will post the problem by monday...
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby deepak_evil » Tue Sep 04, 2007 3:54 pm

i am still wating for the reply
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby deepak_evil » Tue Sep 04, 2007 3:56 pm

can the class custom item be also used to raw menus in the game
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Wed Sep 05, 2007 2:48 am

you can better use item list class for menu which you can add icons with each item...
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby deepak_evil » Wed Sep 05, 2007 4:50 pm

how do u people programme menu for your games
can u please give me a hint
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby deepak_evil » Wed Sep 05, 2007 5:04 pm

was the proceedure correct for the menu screen but whats the problem why isnt the next screen loaded and why isnt why is it throwing null pointer exception whats the problem in it do real game developers use the same technique to programme games as i am doing or there is any other technique or proceedure which i am unaware of.
of i have decompiled some .class files of games from companies like gameloft the proceedure looks totally diferent.
am i going some where wrong.
plz reply me some questions which i had in my mind since long...
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Thu Sep 06, 2007 3:04 am

Here is the corrected code...

a.java

Code: Select all
import javax.microedition.lcdui.*;
import java.util.*;
import javax.microedition.midlet.*;

public class a extends MIDlet  {
    Display display;
    Display pauseDisplay;
    boolean isSplash = true;
    b menuScreen;
    public a() {
        display = Display.getDisplay(this);
        b menuScreen = new b(display);
        display.setCurrent(menuScreen);
    }
   
    protected void startApp() throws MIDletStateChangeException {
    }
   
    protected void pauseApp() { }
   
    protected void destroyApp(boolean flag) throws MIDletStateChangeException {}
   
}


b.java

Code: Select all
import javax.microedition.lcdui.*;
public class b extends Canvas implements Runnable {
    static final Font lowFont = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN, Font.SIZE_SMALL);
    static final Font highFont = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD, Font.SIZE_MEDIUM);
    static final int lowColor = 0x000000FF;
    static final int highColor = 0x00FF0000;
    static final int highBGColor = 0x00CCCCCC;
    static int width;
    static int height;
    static int startHeight;
    private c next;
    private Display display;
    static final int spacing = highFont.getHeight()/2;
    static final String[] mainMenu = {"New Game","HighScore","Settings","Help","About"};
    static int menuIdx;
    Thread menuThread;
   
    public b(Display dis) {
        display = dis;
        width = getWidth();
        height = getHeight();
        next=new c();
        startHeight = (highFont.getHeight() * mainMenu.length) + ((mainMenu.length-1) *
                spacing);
        startHeight = (height - startHeight) / 2;
        menuIdx = 0;
        menuThread = new Thread(this);
        menuThread.start();
    }
   
    public void run() {
        while(true) {
            repaint();
        }
    }
   
    public void paint(Graphics g) {
        g.setColor(0x00FFFFFF);
        g.fillRect(0,0,width,height);
        for (int i=0; i<mainMenu.length; i++) {
            if (i==menuIdx) {
                g.setColor(highBGColor);
                g.fillRect(0,startHeight + (i*highFont.getHeight()) +
                        spacing,width,highFont.getHeight());
                g.setFont(highFont);
                g.setColor(highColor);
                g.drawString(mainMenu[i],(width - highFont.stringWidth(mainMenu[i])) / 2,startHeight + (i*highFont.getHeight()) + spacing,20);
            } else {
                g.setFont(lowFont);
                g.setColor(lowColor);
                g.drawString(mainMenu[i],(width - lowFont.stringWidth(mainMenu[i]) ) / 2,startHeight + (i*highFont.getHeight()) + spacing,20);
            }
        }
    }
   
    protected void keyPressed(int code) {
        try {
            if (getGameAction(code) == Canvas.UP && menuIdx - 1 >= 0) {
                menuIdx--;
            } else if (getGameAction(code) == Canvas.DOWN && menuIdx + 1 <
                    mainMenu.length) {
                menuIdx++;
            } else if(getGameAction(code)==Canvas.FIRE) {
                if(menuIdx==0) {
                    next.start();
                    display.setCurrent(next);
                } else if(menuIdx==1) {
                    System.out.println("High Scores selected");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}


This code works and there is no changes required in c.java
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Thu Sep 06, 2007 3:12 am

deepak_evil wrote:was the proceedure correct for the menu screen but whats the problem why isnt the next screen loaded and why isnt why is it throwing null pointer exception whats the problem in it do real game developers use the same technique to programme games as i am doing or there is any other technique or proceedure which i am unaware of.
of i have decompiled some .class files of games from companies like gameloft the proceedure looks totally diferent.
am i going some where wrong.
plz reply me some questions which i had in my mind since long...


I can understand your doubt regarding the proceedure... As you saw the code decomplied from the class files in the games of other companies, you have changed your class names and variables in to a and b...

Actually It is not how we write code, Its the same way as you usually do for other codes like the user preffered name for classes and variables. But before we deliver the games, we obfuscate our code so that if anyone tries to decompile our code he sees only 'a's and 'b's in the code which makes him defficuilt to find what the code exactly does...

This option of obfuscation comes with all IDE's like Netbeans and Eclipse. Progaurd is one of the obfuscator which you need to attach with your compiler...

More over in come companies the images are compiled into a single file and sometimes encrypted... We have tried this idea once for an application. you are not so far from a professional game developer but use your freedom while coding, and the question however raises only before you deliver it...
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Previous

Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 1 guest