roninblade
[H]ard|Gawd
- Joined
- Sep 22, 2004
- Messages
- 2,031
THis is really pissing me off im trying to make a spacefighter applet and the damn ships wont move up and done, i have no idea wat im missing, anyway heres the program, i really need help if anyone could find the problem that would be great
//Matt Ross
//Spaceship Program
//4/10/2006
import java.awt.event.*;
import java.applet.Applet;
import java.awt.*;
public class SpaceShip extends Applet implements KeyListener, MouseListener, Runnable
{
int ypos1=200,ypos2=200;
int rhit=0,lhit=0;
int [] laserarray = new int[50];
boolean showRules=true;
//TextArea RulesTA = new TextArea();
Image pic,pic2,laser,buffer;
SpaceClass mp;
Thread main;
Graphics bufferG;
public void init()
{
this.resize(1024,768);
this.setLayout(null);
this.addMouseListener(this);
this.addKeyListener(this);
//RulesTA.setBounds(200,200,270,700);
//RulesTA.setBackground(Color.blue);
//this.add(RulesTA);
//RulesTA.setEnabled(false);
//RulesTA.setVisible(showRules);
buffer = createImage(this.getWidth(),this.getHeight());
bufferG = buffer.getGraphics();
pic=this.getImage(this.getCodeBase(),"pic1.jpg");
pic2=this.getImage(this.getCodeBase(),"pic2.jpg");
laser=this.getImage(this.getCodeBase(),"laser.jpg");
mp = new SpaceClass(laser,1100,1100,10,10,30);
for(int ct=0; ct<=49; ct++)
{
laserarray[ct]=new SpaceClass(laser,2000,2000,0,0,25);
}
//mp.start();
//main.start();
}
public void Rules()
{
//RulesTA.setText("Welcome to Spaceship Fighters To win the game your ship must hit the other player three times. Player 1 is on the left \nPlayer2 is on the right. You can only move up and down Player 1 uses 'W' and 'S' to move up and down and 'D' to shoot Player 2 uses 'I' and 'K' to move up and down and 'J' to shoot \n Click the screen to start the game");
}
public void keyReleased(KeyEvent e)
{
char move;
move=e.getKeyChar();
if(move== 'w')
ypos1=ypos1-10;
if(move== 's' && ypos1<750)
ypos1=ypos1+10;
if(move== 'i' && ypos2>0)
ypos2=ypos2-10;
if(move== 'k' && ypos2<750)
ypos2=ypos2+10;
if(move== 'j')
{
}
if(move== 'd')
{
}
}
public void paint(Graphics g)
{
bufferG.setColor(Color.white);
bufferG.fillRect(0,0,1100,800);
for(int ct=0; ct<=45; ct++)
{
laserarray.getImage();
g.drawImage(laser,120,220,40,20,this);
}
if(showRules==true)
Rules();
if(showRules==false)
{
bufferG.setColor(Color.black);
bufferG.drawImage(pic,0,ypos1,this);
bufferG.drawImage(pic2,900,ypos2,this);
bufferG.drawImage(mp.getImage(),mp.getX(),mp.getY(),this);
bufferG.drawString("Player 1 Hits" +lhit,100,50);
bufferG.drawString("Player 2 Hits" +rhit,700,50);
bufferG.drawString(""+ypos1,100,70);
bufferG.drawString(""+ypos2,100,70);
}
g.drawImage(buffer,0,0,this);
}
public void update(Graphics g)
{
paint(g);
}
public void run()
{
while(true)
{
repaint();
try
{
main.sleep(mp.getSpeed());
}
catch(Exception e){}
}
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseClicked(MouseEvent e)
{
showRules=false;
//RulesTA.setVisible(showRules);
repaint();
}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e){}
}