Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] J2ME "dance" game - help

Started by Dane Apr 26, 2007 at 6:04 AM 1 replies 1.6k views
Original Post
Dane
Dane
Hi, I am currently trying to make a dancemat game for a cellphone. The basics of the game is that I will have numbers, from 0-9, fall down randomly from the top of the screen. And when those numbers hit a certain area of the screen, you are supposed to press the correct number on your keypad. I have made a Number Class like this
public class Number{
    private int yPos;
    private int xPos;
    private int number;
    private TangoCanvas parent;
    
    
    
    /** Creates a new instance of Number */
    public Number(int width) {
       yPos=0;
        Random r = new java.util.Random();
       number =  r.nextInt(9);
       xPos=r.nextInt(width);
       
    }

public void nextYpos(int deltaY){
    yPos = yPos+deltaY;
}

    int getY() {
        return yPos;
    }
    
}
The number class is supposed to make objects and assign numbers to the objects. and also tell it to scroll down, with the nextYpos() method The Second Class is Numbers, which is supposed to put a lot of Number() in a Vector

public class Numbers{
    Vector myNumbers;
    int width;
    int height;
    /** Creates a new instance of Numbers */
    public Numbers() {
        myNumbers = new Vector();
        myNumbers.addElement(new Number(120));
        myNumbers.addElement(new Number(120));
        myNumbers.addElement(new Number(120));
    }
/**
 Uppdaterar spelbrädan, samt kollar om någon siffra har trillat utanför skärmen, och tar bort den.
 */
    
    private void upDateAndTest(){
    for (int i = 0; i < myNumbers.size(); i++) {
        Number n =(Number)myNumbers.elementAt(i);
        n.nextYpos(1);
        if (n.getY()>height) {
            myNumbers.removeElementAt(i);
        } 
    }
}
/**
 
    Kollar om det finns siffror i området man kan trycka på
 
 */
public boolean testIfNumberInArea(){
    return true;
}
And then I also have a Gamecanvas, which is supposed to show the whole thing.. or at least get the objects to scroll down on the screen. My question is how? I know some Java, but I haven't made a game in java before.. So I don't know how to procede from here.. Can anyone lend a hand?
Dane
Dane
Hi again.. I reorganized the game and ended up with something like this:

public class TangoCanvas extends GameCanvas implements Runnable{    Numbers numb = new Numbers();    private Sprite one;    private Sprite two;    private Sprite three;    private Sprite four;    private Sprite five;    private Sprite six;    private Sprite seven;    private Sprite eight;    private Sprite nine;    private Sprite zero;    private int width;    private int height;    private int currentX;    private int currentY;    private int delay;   //alla siffror    private Image inine;    private Image ione;    private Image itwo;    private Image ithree;    private Image ifour;    private Image ifive;    private Image isix;    private Image iseven;    private Image ieight;    private Image izero;    private Image background;    private Vector v;    private Timer repainter;    private int currentYi;    private int number;    /** Creates a new instance of TangoCanvas */            public TangoCanvas(boolean supress,FingerTango ft) {        super(supress);        width = getWidth();        height = getHeight();        currentX = width / 2;        currentY = 0;        delay = 20;        v=new Vector();       // run();        try {            // numb.myNumbers;        //alla bilder        inine  = Image.createImage(getClass().getResourceAsStream("9.png"));        ione  = Image.createImage(getClass().getResourceAsStream("1.png"));        itwo  = Image.createImage(getClass().getResourceAsStream("2.png"));        ithree  = Image.createImage(getClass().getResourceAsStream("3.png"));        ifour  = Image.createImage(getClass().getResourceAsStream("4.png"));        ifive  = Image.createImage(getClass().getResourceAsStream("5.png"));        isix  = Image.createImage(getClass().getResourceAsStream("6.png"));        iseven  = Image.createImage(getClass().getResourceAsStream("7.png"));        ieight  = Image.createImage(getClass().getResourceAsStream("8.png"));        izero  = Image.createImage(getClass().getResourceAsStream("0.png"));        background  = Image.createImage(getClass().getResourceAsStream("proj.png"));        } catch (IOException ex) {            ex.printStackTrace();        }               one =new Sprite(ione);       // one.setPosition(60,0);        two =new Sprite(itwo);       // two.setPosition(80,-134);        three =new Sprite(ithree);       // three.setPosition(100,-50);        four =new Sprite(ifour);        four.setPosition(130,-260);        five =new Sprite(ifive);               six =new Sprite(isix);        seven =new Sprite(iseven);        eight =new Sprite(ieight);        nine =new Sprite(inine);        zero =new Sprite(izero);               v.addElement(one);        v.addElement(two);        v.addElement(three);        v.addElement(four);        v.addElement(five);        v.addElement(six);        v.addElement(seven);        v.addElement(eight);        v.addElement(nine);        v.addElement(zero);        beginRepaintTimer();                    }    private void start(){                }    public void beginRepaintTimer() {        repainter = new Timer();        TimerTask task = new TimerTask() {           public void run() {               repaint();           }         };                        repainter.schedule(task, 100, 50);          }                public void paint(Graphics g) {        g.setColor(0xFFFFFF);        g.fillRect(0, 0, getWidth(), getHeight());       Sprite back =new Sprite(background);       back.setPosition(0,0);       back.paint(g);  //     System.out.println("hej");//        one.setPosition(50,currentY);//        one.paint(g);//        two.setPosition(80,currentYi);//        two.paint(g);        //update();     Random r = new java.util.Random();                              System.out.println(number);        Sprite s = (Sprite) v.elementAt(number);        Sprite s1 = (Sprite) v.elementAt(number);      for (int i = 0; i < v.size(); i++) {           s.setPosition(10,s.getY()+1);           s1.setPosition(30,s1.getY()+1);                         if (s.getY()>getHeight()){                s.setPosition(s.getX(),-20);                                 number =  r.nextInt(9);              }else if(s1.getY()>getHeight()){                 s1.setPosition(s1.getX(),-20);                            }        }        s.paint(g);        s1.paint(g);           }        public void run() {       Graphics g = getGraphics();        while(true){           paint(g);                      System.out.println("dsa");            currentY+=1;        }            }     public void keyPressed (int keyCode) {        if (getGameAction (keyCode) == KEY_NUM3 && three.getY()>10){            System.out.println("JAAA");        }else{                }                }    }


I have some questions:
Right now I have Sprites falling down from the top, like Tetris. But only in one row. What would I do to make three rows? I tried adding another Sprite, called s1. but that just made it weird, It came falling down from the middle, and very irregular.

The other question is, How would I handle the the Keypress action? What I want is that, when Sprite two falls down and goes beneath a certain point, and you press the num 2 on the mobiles keypad, you will get a point. And the same for all the other Sprites and their numbers. and if you hit it before that point, you will get a point deduction.

Thanks in advance, Hope you can help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.