Yes hi
I am currently taking a AP programming class and my group of friends and i are trying to make a Tank wars game. We are having a problem with making it so two players can move thier tank at the same time. Here is our code so you can see what we have.
/*
Trivial applet that displays a string
*/
import java.awt.;
import java.applet.Applet;
import javax.swing.;
import java.awt.event.;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.;
import java.awt.event.;
import javax.swing.;
public class TrivialApplet extends Applet
{
Image image;
Image image2;
Image image3;
Image image4;
Image image5;
Image display;
int x_pos = 10;
int y_pos = 10;
private Image dbImage;
private Graphics dbg;
public void init()
{
image = getImage(getDocumentBase(), "Tank1.2LEFT.GIF");
image2 = getImage(getDocumentBase(), "Tank1.2UP.GIF");
image3 = getImage(getDocumentBase(), "Tank1.2DOWN.GIF");
image4 = getImage(getDocumentBase(), "Tank1.2RIGHT.GIF");
image5 = getImage(getDocumentBase(), "MAP-1 copy.jpg");
}
public void update (Graphics g)
{
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics();
}
dbg.setColor (getBackground());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
dbg.setColor (getForeground());
paint (dbg);
g.drawImage (dbImage, 0, 0, this);
}
public boolean keyDown(Event e, int key) {
if (key == Event.LEFT){
x_pos = x_pos -3;
display = image;
}
else if (key == Event.RIGHT){
x_pos = x_pos +3;
display = image4;
}
else if (key == Event.UP){
y_pos = y_pos -3;
display = image2;
}
else if (key == Event.DOWN){
y_pos = y_pos +3;
display = image3;
}
repaint();
return true;
}
public void paint(Graphics g)
{
g.drawImage(image5, 0, 0, this);
repaint();
return true;
g.drawImage(display, x_pos, y_pos, this);
}
}
Now what we want to acomplish is to make it so player one with the keys Up, down, left, and right can be pushing thier keys at the same time as player two who has the keys w, s, a, and d without overiding the other players commands. We have an idea that we are going to have to multi thread but don’t know how to.
Also we want to have music playing in the background and sounds can you tell us how to do those as well.
on another note we are working on making it so the tanks can fire but when the tanks fires a “Bullet” it will just pass over the other tank. how do we make it reconize that it touched the other “Tank”.
If you could help us that would be very helpfull.
Please send your hints or answers to smeeging@hotmail.com as well as post them.
again this would be very helpfull.
Smeghead out!
