sirlink99 56 Practically a Master Poster

My bullet animation does not work. Can anyone help. Thanks

// The "SpaceShoot" class.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class SpaceShoot extends Applet implements KeyListener
{
    int x = 10, dx, y = 10, dy, a = 0, by = 47, bx = 95;
    char m;
    private Image dbImage;
    private Graphics dbg;
    Thread thread;
    Image img, tile, background, bullet, blank, mon1, mon2, mon3, mon4, mon5, mon6, mon7;
    Graphics backg;
    boolean triMove = false;
    // Place instance variables here

    public void init ()
    {
	img = getImage (getDocumentBase (), "Shoot.jpg");
	bullet = getImage (getDocumentBase (), "bullet.jpg");
	blank = getImage (getDocumentBase (), "Blank.jpg");
	mon1 = getImage (getDocumentBase (), "mon1.jpg");
	mon2 = getImage (getDocumentBase (), "mon2.jpg");
	mon3 = getImage (getDocumentBase (), "mon3.jpg");
	mon4 = getImage (getDocumentBase (), "mon4.jpg");
	mon5 = getImage (getDocumentBase (), "mon5.jpg");
	mon6 = getImage (getDocumentBase (), "mon6.jpg");
	mon7 = getImage (getDocumentBase (), "mon7.jpg");
	addKeyListener (this);

	/*tile = createImage (1280, 690);
	backg = tile.getGraphics ();
	backg.setColor (Color.blue);
	*/

	// Place the body of the initialization method here
    } // init method


    public void paint (Graphics g)
    {


	//backg.drawImage(background, 0, 0, this);
	g.drawImage (img, x, y, 100, 100, this);

	if (triMove == true)
	{
	    for (int i = -50 ; i < 350 ; i++)
	    {

		bx += 1;

		for (int q = 0 ; q < 1000000 ; q++)
		{
		}
		g.drawImage (blank, bx , y + 37, 20, 10, this);
		g.drawImage (bullet, bx, y + 37, 20, 10, this);

	    }

	    triMove = false;


	}

	if (bx >= 250 + 95)
	{
	    bx = 95;
	}
	//backg.drawImage(background,0,0,this);

	//Placethebodyofthedrawingmethodhere
    } //paintmethod




    public void keyPressed (KeyEvent e)
    {
	int key = e.getKeyCode ();
	/*if(key==KeyEvent.VK_RIGHT)
	{
	//backg.drawImage(background,0,0,1280, 960, this);
	dx=2;
	dy=0;
	x=x+dx;
	repaint();
	}
	elseif(key==KeyEvent.VK_LEFT)
	{
	//backg.drawImage(img,0,0,1280, 960, this);
	dx=-2;
	dy=0;
	x=x+dx;
	repaint();
	}*/
	if (key == KeyEvent.VK_UP)
	{

	    //backg.drawImage (img, 0, 0, 1280, 960, this);
	    dy = -10;
	    dx = 0;
	    y = y + dy;
	    repaint ();
	}
	else if (key == KeyEvent.VK_DOWN)
	{
	    //backg.drawImage (img, 0, 0, 1280, 960, this);
	    dy = 10;
	    dx = 0;
	    y = y + dy;
	    repaint ();
	}
	else if (key == KeyEvent.VK_SPACE)
	{
	    triMove = true;

	    repaint ();
	}
    }


    public void keyReleased (KeyEvent e)
    {

    }


    public void keyTyped (KeyEvent e)
    {

    }


    public void update (Graphics g)
    {
	// initialize doublebuffers

	dbImage = createImage (this.getSize ().width, this.getSize ().height);
	dbg = dbImage.getGraphics ();


	// save background
	dbg.setColor (getBackground ());
	dbg.fillRect (0, 0, this.getSize ().width, this.getSize ().height);

	// draw foreground on background
	dbg.setColor (getForeground ());
	paint (dbg);

	// Now indicate ready drawn picture Offscreen on the right screen
	g.drawImage (dbImage, 0, 0, this);
    }
} // SpaceShoot class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.