Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Lunar Lander

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Thanked 0 Times in 0 Posts

    Default Lunar Lander

    Hello. im making a lunar lander program but im having trouble with the arrow keys and the accelaration. right now the code is in its first form and i just want to get the ball to function like the lunar lander game. could someone fix the key functions, make the object functional like the lunar lander program or atleast give me some tips. any help would be appreciated

    import java.awt.*;
    import java.awt.event.*;

    public class lunarlander extends java.applet.Applet implements MouseListener, KeyListener
    double x = 100, y = 40;
    double vx = 0.1, vy = 0.1;

    public lunarlander()
    public void paint(Graphics g)
    vy = vy + 0.1;
    vx = vx + 0.001;
    vy = vy * 0.999;
    vx = vx * 0.999;
    if(y > 600 && vy > 0)
    vy = - vy;
    x = x + vx;
    y = y + vy;
    for(int i = 0; i < 100000; i ++)
    if(y < 100)
    g.drawString("Crash", 800, 800);
    public void keyReleased(KeyEvent ke){}
    public void keyPressed(KeyEvent ke)
    if(ke.getKeyCode() == KeyEvent.VK_UP)
    else if(ke.getKeyCode() == KeyEvent.VK_DOWN)
    else if(ke.getKeyCode() == KeyEvent.VK_LEFT)
    else if(ke.getKeyCode() == KeyEvent.VK_RIGHT)
    public void keyTyped(KeyEvent ke){}
    public void mouseExited(MouseEvent me){}
    public void mouseEntered(MouseEvent me){}
    public void mouseClicked(MouseEvent me){}
    public void mouseReleased(MouseEvent me){}
    public void mousePressed(MouseEvent me){}
    Last edited by sqwundle; October 24th, 2012 at 05:38 PM. Reason: file

  2. Default Related threads:

  3. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 632 Times in 540 Posts

    Default Re: Lunar Lander

    That isn't really how this works. We can't just do things for you, especially with the out-of-context code you've posted here (which should be posted using the highlight tags to preserve formatting). You haven't actually told us what's wrong exactly, so it's going to be pretty hard for anybody to fix anything for you. It's better to ask a specific technical question and post an SSCCE that demonstrates exactly what you're talking about.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Tags for this Thread