Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #2170

Lunar Lander

Received by 10.224.138.142 with SMTP id a14mr9446627qau.4.1351116709990; Wed, 24 Oct 2012 15:11:49 -0700 (PDT)
Received by 10.52.97.101 with SMTP id dz5mr3316236vdb.2.1351116709940; Wed, 24 Oct 2012 15:11:49 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!x14no7146402qar.0!news-out.google.com!r17ni57592152qap.0!nntp.google.com!x14no7146392qar.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.java.help
Date Wed, 24 Oct 2012 15:11:49 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=35.24.44.2; posting-account=LuqwpQoAAAD9BAbaIy01VkPLwHJCFZnH
NNTP-Posting-Host 35.24.44.2
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <a02ca455-c62d-4397-8673-26489e368630@googlegroups.com> (permalink)
Subject Lunar Lander
From sqwundle@gmail.com
Injection-Date Wed, 24 Oct 2012 22:11:49 +0000
Content-Type text/plain; charset=ISO-8859-1
X-Received-Bytes 2362
Xref csiph.com comp.lang.java.help:2170

Show key headers only | View raw


hello im making a lunar lander program but im having trouble with the accleration and when you click the left and right arrows the ball goes flying can anyone help fix my code 

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()
		{
			addMouseListener(this);
			addKeyListener(this);
		}
		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;
			g.fillOval((int)x,(int)y,30,30);
			for(int i = 0; i < 100000; i ++)
			repaint();
			if(y < 100)
			g.drawString("Crash", 800, 800);
		}
		public void keyReleased(KeyEvent ke){}
		public void keyPressed(KeyEvent ke)
		{
			if(ke.getKeyCode() == KeyEvent.VK_UP)
				vy-=vy+2.0;
			else if(ke.getKeyCode() == KeyEvent.VK_DOWN)
				vy-=vy-4.0;
			else if(ke.getKeyCode() == KeyEvent.VK_LEFT)
				vx+=x-0.01;
			else if(ke.getKeyCode() == KeyEvent.VK_RIGHT)
				vx+=x-0.01;
		}
		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){}
}

Back to comp.lang.java.help | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Lunar Lander sqwundle@gmail.com - 2012-10-24 15:11 -0700
  Re: Lunar Lander Knute Johnson <nospam@knutejohnson.com> - 2012-10-24 17:57 -0700
    Re: Lunar Lander sqwundle@gmail.com - 2012-10-24 18:32 -0700
      Re: Lunar Lander Knute Johnson <nospam@knutejohnson.com> - 2012-10-24 21:11 -0700
      Re: Lunar Lander Lew <lewbloch@gmail.com> - 2012-10-25 01:05 -0700
  Re: Lunar Lander Lew <lewbloch@gmail.com> - 2012-10-24 18:31 -0700
  Re: Lunar Lander Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-24 20:37 -0700

csiph-web