Space Shooter game help

Im not sure if any one will be able to help me or not but Im a relatively new programmer and i am createing a space shooter type game and I am haveing some difficulties in wording my statements. Right now the way i have it set up I am able to fire only 1 shot from my ship but the shot hitting the enemy ship part works and i know it is only from this run statement i have becuase before i was able to shoot as much as i wanted. Like i said i doubt anyone will be able to help me without seeing more of my code but i thought id try.
//createing repaint timer
public void run(){   
while(true) {
try{//attempt to execute
createEnemy(); //create enemy
updateEnemy(); //update enemys
n.updateShots();      //update shots
//make the enemy explode if the shots x,y is close to the enemy x,y
for(int i=0;i<n.size;i++){  //n = ship function and size is place holder for number of shots
     if(n.shots[i] != null && n.shots.y - enemy[i].y >0&&n.shots[i].y - enemy[i].y<50){   //if the shot is hit in this y area the shot and enemy will delete
n.shots[i] = null;
enemy[i] = null;
}//end of if
     else{
          if(n.shots[i] != null &&n.shots[i].x - enemy[i].x >0&&n.shots[i].x - enemy[i].x<50){  //if the shot is hit in this x area the shot and enemy will delete
          n.shots[i] = null;     
          enemy[i] = null;
          }//end if
     }//end else
     }//end of for
     repaint();
     n.flame = false; //set flame to false so Flame is only true if Up is pressed
     Thread.sleep(100);
     }//end of try
     catch (InterruptedException e) {
}//end of catch
}//end of while
} //end of run

Why not use a timer here? If you are using Swing, then a Swing Timer is much better here than the ugly while(true).
Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
&#91;code]
  // your code block goes here.
  // note the differences between the tag at the top vs the bottom.
&#91;/code]

Similar Messages

  • Shooting Game Help!!

    i have a shooting game with a few problems. One, during the
    reload stage of the gun, you can still shoot. Two, once the man
    walks off screen it dosent go to a game over page. i have no idea
    how to fix this and all my attempts fail. I cant send you the game
    because the source file is to big even after cut down. ill give u
    the actionscript.
    The Walking Guy:
    onClipEvent (load) {
    speedx = 0.9;
    onClipEvent (enterFrame) {
    this._x -= speedx;
    if (this._x<=100) {
    gotoAndStop("loose");
    on (release) {
    this.gotoAndPlay(2);
    this.enabled = false;
    speedx = 0
    The man is inside a MC. i dont know how to make it so that
    when he walks off the screen it goes to a Game over page.
    The Crosshair:
    onClipEvent (enterFrame) {
    startDrag(this, true);
    Mouse.hide();
    onClipEvent (mouseDown) {
    if (_root.bullet == true) {
    this.gotoAndPlay(2);
    _root.bullet = false;
    tellTarget (_parent.bulet) {
    gotoAndStop(2);
    When nothing is hylighted:
    _root.bullet = true;
    stop();
    Inside the Crosshair MC:
    First Frame:
    Stop();
    Last Frame:
    tellTarget (_parent) {
    _root.bullet = true;
    tellTarget (_parent.bulet) {
    gotoAndStop(1);
    What needs to be added to not allow the gun to work when
    reloading???
    How do i create a game over page when the stick has walked
    off the screen??
    All answers would be greatly appreaciated!!!
    Thanks
    Sterockicy

    try the actionscript forum.
    --> **Adobe Certified Expert**
    --> www.mudbubble.com
    --> www.keyframer.com
    Sterockicy wrote:
    > i have a shooting game with a few problems. One, during
    the reload stage of the
    > gun, you can still shoot. Two, once the man walks off
    screen it dosent go to a
    > game over page. i have no idea how to fix this and all
    my attempts fail. I cant
    > send you the game because the source file is to big even
    after cut down. ill
    > give u the actionscript.
    >
    > The Walking Guy:
    >
    > onClipEvent (load) {
    > speedx = 0.9;
    > }
    > onClipEvent (enterFrame) {
    > this._x -= speedx;
    > if (this._x<=100) {
    > gotoAndStop("loose");
    > }
    > }
    > on (release) {
    > this.gotoAndPlay(2);
    > this.enabled = false;
    > speedx = 0
    > }
    >
    > The man is inside a MC. i dont know how to make it so
    that when he walks off
    > the screen it goes to a Game over page.
    >
    >
    > The Crosshair:
    >
    > onClipEvent (enterFrame) {
    > startDrag(this, true);
    > Mouse.hide();
    > }
    > onClipEvent (mouseDown) {
    > if (_root.bullet == true) {
    > this.gotoAndPlay(2);
    > _root.bullet = false;
    > tellTarget (_parent.bulet) {
    > gotoAndStop(2);
    > }
    > }
    > }
    >
    >
    > When nothing is hylighted:
    >
    > _root.bullet = true;
    > stop();
    >
    >
    > Inside the Crosshair MC:
    >
    > First Frame:
    >
    > Stop();
    >
    >
    > Last Frame:
    >
    > tellTarget (_parent) {
    > _root.bullet = true;
    > }
    > tellTarget (_parent.bulet) {
    > gotoAndStop(1);
    > }
    >
    >
    > What needs to be added to not allow the gun to work when
    reloading???
    > How do i create a game over page when the stick has
    walked off the screen??
    >
    > All answers would be greatly appreaciated!!!
    >
    > Thanks
    >
    > Sterockicy
    >

  • Java space shooter game optimization

    Hi
    I've just started a little space-arcade type of game.
    For now there's a ship but it doesn't do much:
    - moves (accelerated)
    - fires (SPACE bar)
    Now I'm going to start work on an enemy generator + collision test.
    After that: pick-ups, a status bar(remaining life, passed time and so on), etc
    Since I'm not such a experienced programmer with Java graphics, I would need any opinion I can get to optimize my code (smoother movement, less CPU/memory usage, etc.). Read about sprites but not sure if it's the case here.
    You can take a look at the game and source codes at:
    http://www.stonefixion.com/temp/game
    Please take a look over the four java files and if you have any optimization suggestions, they are mostly welcome.
    Waiting for some feedback,
    Cheers ;j

    I've done a bit of reading and I think I've already done that(double buffering) like this:
         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);
         }I put all the drawing in paint() and call it update().
    Thanx

  • Need Help with Java Space Invaders Game!

    Hi, im new to these forums so forgive if i dont follow the right way on laying things out. Im trying to create space invaders game but im stuck when im trying to create multiple aliens/ invaders. I have a class called Aliens (which is the invaders), and i can create an instance of an Alien. But when I try to create multiple instances they are not showing up on screen. I am not getting any error message though (which im hoping is a good sign, lol).
    GamePanel is where all the action is and Alien is the alien (invaders) class.
    Here is the code:
    import java.awt.; import javax.swing.; import java.awt.Image; import java.awt.event.KeyListener; import java.awt.event.KeyEvent;
    public class GamePanel extends JComponent implements KeyListener { SpaceInvaders game; static Player player1; Aliens alien1; static public Image spaceship2R; static public Image spaceship2L;
    public GamePanel(SpaceInvaders game)
         this.game = game;
         player1 = new Player(this);
         player1.start();
                   ///// trying to create multiple instances of aliens here
         for(int i=0; i<4; i++)
              alien1 = new Aliens(this);
              alien1.setX(i*100);
              alien1.start();
        this.setFocusable(true);
        this.addKeyListener(this);
    public void paintComponent(Graphics g)
         Image pic1 = player1.getImage();
         Image pic2 = alien1.getImage();
         super.paintComponent(g);
         g.drawImage(pic1, player1.getX(), player1.getY(), 50, 50,this);
         g.drawImage(pic2, alien1.getX(), alien1.getY(), 50, 50,this);
    }//end class
    import java.awt.Image; import java.awt.*;
    class Aliens extends Thread { //variables GamePanel parent; private boolean isRunning; private int xPos = 0, yPos = 0; Thread thread; static char direction = 'r'; Aliens alien; static public Image alien1; static public Image alien2;
    public Aliens(GamePanel parent)
         this.parent = parent;
         isRunning = true;
    public void run()
         while(isRunning)
              Toolkit kit = Toolkit.getDefaultToolkit();
              alien1 = kit.getImage("alien1.gif");
              alien2 = kit.getImage("alien2.gif");
              try
                      thread.sleep(100);
                 catch(InterruptedException e)
                      System.err.println(e);
                 updateAliens();
                 parent.repaint();
    public static Image getImage()
         Image alienImage = alien1;
        switch(direction){
             case('l'):
                  alienImage = alien1;
                  break;
             case('r'):
                  alienImage = alien1;
                  break;
        return alienImage;     
    public void updateAliens()
         if(direction=='r')
              xPos+=20;
              if(xPos >= SpaceInvaders.WIDTH-50||xPos < 0)
                   yPos+=50;
                   xPos-=20;
                   direction='l';
         else
              xPos-=20;
              if(xPos >= SpaceInvaders.WIDTH-50||xPos < 0)
                   yPos+=50;
                   xPos+=20;
                   direction='r';
    public void setDirection(char c){ direction = c; }
    public void setX(int x){ xPos = x; }
    public void setY(int y){ yPos = y; }
    public int getX(){ return xPos; }
    public int getY(){ return yPos; }
    }//end classEdited by: deathwings on Oct 19, 2009 9:47 AM
    Edited by: deathwings on Oct 19, 2009 9:53 AM

    Maybe the array I have created is not being used in the paint method, or Im working with 2 different objects as you put it? Sorry, Im just learning and I appreciate your time and help. Here is my GamePanel Class and my Aliens class:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.Image;
    import java.awt.event.KeyListener;
    import java.awt.event.KeyEvent;
    import java.awt.image.BufferStrategy;
    public class GamePanel extends JComponent implements KeyListener
         SpaceInvaders game;
         static Player player1;
         static Bullets bullet;
         //static public Image spaceship2R;
         //static public Image spaceship2L;
         private BufferStrategy strategy;
         static int alienNum =0;
         static Aliens[] aliens;
         public GamePanel(SpaceInvaders game)
              this.game = game;
              player1 = new Player(this);
              player1.start();
              Aliens[] aliens = new Aliens[10];
              for(int i=0; i<4; i++)
                   aliens[i] = new Aliens(this);
                   aliens.setX(i*100);
                   aliens[i].start();
                   alienNum++;
              initialiseGame();
              this.setFocusable(true);
    this.addKeyListener(this);
         public void paintComponent(Graphics g)
              Image pic1 = player1.getImage();
              Image pic2 = aliens[0].getImage();
              Image bulletPic = bullet.getImage();
              super.paintComponent(g);
              g.drawImage(pic1, player1.getX(), player1.getY(), 50, 50,this);
              for ( int i = 0; i < alienNum; i++ )
                   g.drawImage(pic1, aliens[0].getX(), aliens[0].getY(), 50, 50,this);
              //if (bullet.fired==true){
              //     g.drawImage(bulletPic, bullet.getX(), bullet.getY(), 20, 20,this);
         public void keyPressed(KeyEvent k)
              switch (k.getKeyCode()) {
              case (KeyEvent.VK_KP_DOWN):
              case (KeyEvent.VK_DOWN):
                   player1.setDirection('d');
                   break;
              case (KeyEvent.VK_KP_UP):
              case (KeyEvent.VK_UP):
                   player1.setDirection('u');
              break;
              case (KeyEvent.VK_KP_RIGHT):
              case (KeyEvent.VK_RIGHT):
                   player1.setDirection('r');
              break;
              case (KeyEvent.VK_KP_LEFT):
              case (KeyEvent.VK_LEFT):
                   player1.setDirection('l');
              break;
              case (KeyEvent.VK_SPACE):
                   fireBullet();
              break;
         public void keyTyped(KeyEvent k) {}//empty
         public void keyReleased(KeyEvent k)
              player1.setDirection('n');
         public void initialiseGame()
         public static void checkCollision()
              Rectangle playerRec = new Rectangle(player1.getBoundingBox());
              for(int i=0; i<alienNum; i++)
                   //if(playerRec.intersects(aliens[i].getBoundingBox()))
                        //collisionDetected();
         public static void collisionDetected()
              System.out.println("COLLISION");
         public void fireBullet()
              Bullets bullet = new Bullets(player1.getX(),player1.getY());
              bullet.fired=true;
    }//end GamePanelimport java.awt.Image;
    import java.awt.*;
    class Aliens extends Thread
         //variables
         GamePanel parent;
         private boolean isRunning;
         private int xPos = 0, yPos = 0;
         Thread thread;
         static char direction = 'r';
         Aliens alien;
         static public Image alien1;
         static public Image alien2;
         public Aliens(GamePanel parent)
              this.parent = parent;
              isRunning = true;
         public void run()
              while(isRunning)
                   Toolkit kit = Toolkit.getDefaultToolkit();
                   alien1 = kit.getImage("alien1.gif");
                   //alien2 = kit.getImage("alien2.gif");
                   try
              thread.sleep(100);
         catch(InterruptedException e)
              System.err.println(e);
              updateAliens();
              parent.repaint();
         public static Image getImage()
              Image alienImage = alien1;
         switch(direction){
              case('l'):
                   alienImage = alien1;
                   break;
              case('r'):
                   alienImage = alien1;
                   break;
         return alienImage;     
         public void updateAliens()
              if(direction=='r')
                   xPos+=20;
                   if(xPos >= SpaceInvaders.WIDTH-50||xPos < 0)
                        yPos+=50;
                        xPos-=20;
                        direction='l';
              else
                   xPos-=20;
                   if(xPos >= SpaceInvaders.WIDTH-50||xPos < 0)
                        yPos+=50;
                        xPos+=20;
                        direction='r';
         public Rectangle getBoundingBox()
              return new Rectangle((int)xPos, (int)yPos, 50, 50);
         public void setDirection(char c){ direction = c; }
         public void setX(int x){ xPos = x; }
         public void setY(int y){ yPos = y; }
         public int getX(){ return xPos; }
         public int getY(){ return yPos; }
    }//end class                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Some Help Please. Shooting Game

    Right the basic story is that im making this game where
    animals cross the screen and you shoot them (aka click the mouse on
    them) and get points. Im having a couple of problems.
    I wanted to have the gunshot noise whenever i clicked
    ANYWHERE so i put it in the mousup in a frame script but when i
    click on a sprite which has its own behavior, it doesnt play
    Secondly, there are items on the stage such as waves and
    grass that the animals can hide behind and i can still click on
    them even if i cant see them, ie click the part of the grass they
    are hiding behind. How do i correct this...
    Any help would be appreaciated. Thank you!!!

    You don't normally attach user event code to a frame. User
    events, like
    mouse clicks, are normally associated with an individual
    item, like a
    sprite. Shooter games get around this limitation by using key
    events for
    the shooting action. Since key events are read by the
    computer and then
    sent to the Director movie, they can be read by a keyDown or
    keyUp
    script.
    There is a corollary for the mouse, the mouseDown and the
    mouseUp
    script. Since any system wide property like a keyDownScript
    or a
    mouseDownScript will take all key or mouse events, they need
    to be used
    with care and caution. While this is not usually a big
    problem with key
    events, mouse events are likely to cause some difficulty.
    While the
    mouseDownScript will always execute first, it will most
    likely pass the
    event on to any active sprite. This may or may not be what
    you want to
    have happen, you may want an either/or situation not an and
    situation.
    A simple way to block a sprite's behavior when it is hidden
    is to place
    a stopEvent command on the sprite that sits on top.
    Rob
    Rob Dillon
    Adobe Community Expert
    http://www.ddg-designs.com
    412-243-9119
    http://www.macromedia.com/software/trial/

  • Need help with "Shield" on side scrolling shooter game

    I am horribly new to Flash, and I need lots of help with a lot of things, most notably a shield I'm trying to give the player in a side scrolling shooter game. I need help with:
    1. Making the ship change color when it's activated.
    2. Making it so enemies die on contact with the ship.
    3. Making the "shield" variable go down constantly while in use.
    If anyone could help, I would appreciate it a lot.

    I wouldn't want any of you to write this program for me because I want to learn it myself. Yes I'm a student and I have to write some game with my groupe for a telephone in java like language doja. We decided to let it be a chess game. However I'm looking for an already written game in java that preferebly has some comments above the program lines so I can see what they've done. Offcourse if nobody has anything like this, yes I'm looking for a way to make an algorithm that makes the cpu move each time the player makes it's move. I have no idea on how to do this. I was hoping it can be solved with for, while, if and genest for statements. Yes it wil be a game with graphics but I think we can manage that part ourselves. So main question is the algorithm for the cpu moves. Do I have to pre-program every game in the book or is there another way etc..
    I hope there's anybody that can and is willing to get me on my way since I know it maybee isn't the most simple question.

  • Help with simple shooter game

    I am doing a school project and no one seems to know how to use graphics, sound, and most importantly KEY AND MOUSE EVENTS.
    Anyways I can't get my events for the mouse and keyboard to work correctly, so if anyone knows what is wrong or has some suggestions I would really appreciate it. Here is the code:
    the program is called from an application just so you know... this is the application:
    public class AnimateTest
    public static void main (String[] args)
    Animate pic = new Animate (10);
    //and this is the proram itself
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.MouseListener.*;
    import java.awt.event.MouseAdapter.*;
    import java.awt.event.MouseEvent.*;
    import java.awt.event.KeyAdapter.*;
    import java.awt.event.KeyListener.*;
    import java.awt.event.KeyEvent.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.applet.AudioClip;
    public class Animate extends Frame //implements KeyListener//implements MouseListener
    // The image of the background.
    protected Image background;
    // The gun images.
    protected Image gun1, gun2, gun3, gun4, gun5, gun6, gun7, gun8, gun9, gun10;
    //the status bar images
    protected Image hpbox;
    protected Image scorebox;
    //declares the blood explosion image
    protected Image blood;
    //declares the window icon
    protected Image icon;
    // The canvas where the images are drawn.
    protected AnimatePictureCanvas canvas;
    // The number of guns.
    protected int numGuns;
    // Flag to indicate when to quit.
    protected boolean quitting = false;
    //declares the cursor so it can be set to a targeting reticle
    Cursor reticle;
    //declares a variable which designates which gun is in use
    int i = 0;
    //the user's health points
    int hp = 100;
    //enemy arrays
    boolean alive [];
    boolean onScreen [];
    //enemy integers
    int currentDude = 3;
    int liveCount = 10;
    int screenCount = 0;
    //damage variables
    int damage = 0;
    int moreHits;
    int chance;
    //the x and y coordinates of the enemies
    int ex1 = 175;
    int ex2 = 345;
    int ex3 = 520;
    int ex4 = 25;
    int ex5 = 240;
    int ex6 = 370;
    int ex7 = 470;
    int ex8 = 626;
    int ex9 = 260;
    int ex10 = 120;
    int ey1 = 228;
    int ey2 = 190;
    int ey3 = 115;
    int ey4 = 210;
    int ey5 = 35;
    int ey6 = 330;
    int ey7 = 202;
    int ey8 = 192;
    int ey9 = 210;
    int ey10 = 140;
    //blood variables
    int splat = 0;
    int bloodx = -100;
    int bloody = -100;
    // The constructor. Create the Frame, make it visible, load the
    // images, and when the images are loaded, call the animate method
    // to move the images around the window.
    public Animate (int numGuns)
    super ("Stupid Shooting Game"); // Create a Frame.
    //sets the window icon
    icon = getToolkit ().getImage ("icon.jpg");
    prepareImage (icon, this);
    setIconImage (icon);
    this.numGuns = numGuns;
    //initialize the arrays for the enemies
    alive = new boolean [10];
    for (int z = 0 ; z <= 9 ; z++)
    alive [z] = true;
    onScreen = new boolean [10];
    onScreen [0] = true;
    onScreen [1] = true;
    onScreen [2] = true;
    onScreen [3] = false;
    onScreen [4] = false;
    onScreen [5] = false;
    onScreen [6] = false;
    onScreen [7] = false;
    onScreen [8] = false;
    onScreen [9] = false;
    //initialize the cursor to make the mouse a targeting reticle
    reticle = new Cursor (Cursor.CROSSHAIR_CURSOR);
    setCursor (reticle);
    // Place the loading message in the window.
    Label loadingMessageLabel = new Label ("Loading images...");
    add ("North", loadingMessageLabel);
    // Display the window.
    pack ();
    setVisible (true);
    // Create the Images and add them to the tracker.
    MediaTracker tracker = new MediaTracker (this);
    background = getToolkit ().getImage ("midtown1.jpg");
    tracker.addImage (background, 0);
    //prepares the gun images for the image tracker
    gun1 = getToolkit ().getImage ("ggun1.jpg");
    tracker.addImage (gun1, 1);
    gun2 = getToolkit ().getImage ("ggun2.jpg");
    tracker.addImage (gun2, 2);
    gun3 = getToolkit ().getImage ("ggun3.jpg");
    tracker.addImage (gun3, 3);
    gun4 = getToolkit ().getImage ("ggun4.jpg");
    tracker.addImage (gun4, 4);
    gun5 = getToolkit ().getImage ("ggun5.jpg");
    tracker.addImage (gun5, 5);
    gun6 = getToolkit ().getImage ("ggun6.jpg");
    tracker.addImage (gun6, 6);
    gun7 = getToolkit ().getImage ("ggun7.jpg");
    tracker.addImage (gun7, 7);
    gun8 = getToolkit ().getImage ("ggun8.jpg");
    tracker.addImage (gun8, 8);
    gun9 = getToolkit ().getImage ("ggun9.jpg");
    tracker.addImage (gun9, 9);
    gun10 = getToolkit ().getImage ("ggun0.jpg");
    tracker.addImage (gun10, 10);
    //prepares the status bar images for the tracker
    hpbox = getToolkit ().getImage ("hpbox.jpg");
    tracker.addImage (hpbox, 11);
    scorebox = getToolkit ().getImage ("scorebox.jpg");
    tracker.addImage (scorebox, 12);
    //prepares the blood image
    blood = getToolkit ().getImage ("splash.jpg");
    tracker.addImage (blood, 13);
    // Load the images.
    try
    tracker.waitForAll ();
    catch (InterruptedException e)
    // This exception will not happen in our program, but
    // Java requires that we handle it anyway.
    System.out.println ("Wait interrupted.");
    if (tracker.isErrorAny ())
    loadingMessageLabel.setText ("Image loading failed!");
    else
    // All the images are now loaded. Remove the loading label.
    remove (loadingMessageLabel);
    // Create and place the canvas.
    canvas = new AnimatePictureCanvas (background);
    canvas.setSize (background.getWidth (null),
    background.getHeight (null));
    add ("Center", canvas);
    pack (); // Resize the Frame to fit the canvas.
    validate (); // Force the Frame to be redrawn.
    animate ();
    } // Animate constructor
    // Move the bouncers over the background.
    public void animate ()
    // Create the offscreen bitmap.
    int bgWidth = background.getWidth (null);
    int bgHeight = background.getHeight (null);
    Image offscreen = this.createImage (bgWidth, bgHeight);
    // Get the width and height of the guns.
    int gun1Width = gun1.getWidth (null);
    int gun1Height = gun1.getHeight (null);
    int gun2Width = gun2.getWidth (null);
    int gun2Height = gun2.getHeight (null);
    int gun3Width = gun3.getWidth (null);
    int gun3Height = gun3.getHeight (null);
    int gun4Width = gun4.getWidth (null);
    int gun4Height = gun4.getHeight (null);
    int gun5Width = gun5.getWidth (null);
    int gun5Height = gun5.getHeight (null);
    int gun6Width = gun6.getWidth (null);
    int gun6Height = gun6.getHeight (null);
    int gun7Width = gun7.getWidth (null);
    int gun7Height = gun7.getHeight (null);
    int gun8Width = gun8.getWidth (null);
    int gun8Height = gun8.getHeight (null);
    int gun9Width = gun9.getWidth (null);
    int gun9Height = gun9.getHeight (null);
    int gun10Width = gun10.getWidth (null);
    int gun10Height = gun10.getHeight (null);
    //finds the width and height of the status bar images
    int hpboxWidth = hpbox.getWidth (null);
    int hpboxHeight = hpbox.getHeight (null);
    int scoreboxWidth = scorebox.getWidth (null);
    int scoreboxHeight = scorebox.getHeight (null);
    // Create the arrays containining the location and
    // direction of the bouncers.
    int locX;
    int locY;
    // Initialize the gun Image's location
    locX = (bgWidth - gun1Width);
    locY = (bgHeight - gun1Height);
    // Get the graphics contexts for both the offscreen image and
    // the canvas.
    Graphics offscreenG = offscreen.getGraphics ();
    Graphics canvasG = canvas.getGraphics ();
    while (!quitting)
    //sets the mouse listener to check for shots being fired
    addMouseListener (new MouseAdapter ()
    public void mouseClicked (MouseEvent e)
    int xClick = e.getX ();
    int yClick = e.getY ();
    System.out.println (" " + xClick + " " + yClick);
    delay (1000000);
    fire (xClick, yClick);
    //sets the keylistener to check for a change in the current gun
    // addKeyListener (new KeyAdapter ()
    // public void keyTyped (KeyEvent e)
    // if (e.getKeyChar () == 'f')
    // i += 1;
    // if (i == 10)
    // i = 0;
    // if (e.getKeyChar () == 'd')
    // i -= 1;
    // if (i == -1)
    // i = 9;
    // Draw the background image to the offscreen bitmap, erasing
    // everything that is already there.
    offscreenG.drawImage (background, 0, 0, null);
    //draw the status bar at the bottom of the screen
    offscreenG.setColor (Color.black);
    offscreenG.fillRect (0, bgHeight - gun1Height, bgWidth, bgHeight);
    // Draw each bouncer to the offscreen image. Move each of
    // the bouncers, changing their direction when they encounter
    // an edge.
    offscreenG.drawImage (gun1, locX, locY, null);
    //draws the status bar
    offscreenG.drawImage (hpbox, 15, bgHeight - gun1Height + 10, null);
    offscreenG.drawImage (scorebox, hpboxWidth + 15 + 20, bgHeight - gun1Height + 25, null);
    //draws blood if a target is hit
    if (splat == 1)
    offscreenG.drawImage (blood, bloodx, bloody, null);
    delay (10000000);
    splat = 0;
    if (hp == 0)
    //drawString "you lose"
    break;
    else
    //determines the number of enemies still alive
    liveCount = 10;
    for (int a = 0 ; a <= 9 ; a++)
    if (alive [a] == true)
    else
    liveCount -= 1;
    if (liveCount == 0)
    //drawString "you win... get ready for LVL 2!!!"
    break;
    //determines the number of enemies onscreen and adds more if necessary
    screenCount = 0;
    for (int b = 0 ; b <= 9 ; b++)
    if (onScreen == true)
    screenCount += 1;
    if (screenCount < 3 && liveCount > 3)
    onScreen [currentDude] = true;
    if (currentDude == 9)
    else
    currentDude += 1;
    damage = 0;
    moreHits = 12 / screenCount;
    chance = (int) (Math.random () * moreHits) + 1;
    if (chance == moreHits)
    damage = 10;
    //sets the default color to white so things can be seen on the background
    offscreenG.setColor (Color.white);
    //checks all the enemies to see if they are alive and onscreen,
    //drawing them accordingly
    if (alive [0] == true && onScreen [0] == true)
    offscreenG.fillOval (ex1, ey1, 18, 18);
    if (alive [1] == true && onScreen [1] == true)
    offscreenG.fillOval (ex2, ey2, 13, 13);
    if (alive [2] == true && onScreen [2] == true)
    offscreenG.fillOval (ex3, ey3, 9, 9);
    if (alive [3] == true && onScreen [3] == true)
    offscreenG.fillOval (ex4, ey4, 15, 15);
    if (alive [4] == true && onScreen [4] == true)
    offscreenG.fillOval (ex5, ey5, 11, 11);
    if (alive [5] == true && onScreen [5] == true)
    offscreenG.fillOval (ex6, ey6, 30, 30);
    if (alive [6] == true && onScreen [6] == true)
    offscreenG.fillOval (ex7, ey7, 10, 10);
    if (alive [7] == true && onScreen [7] == true)
    offscreenG.fillOval (ex8, ey8, 10, 10);
    if (alive [8] == true && onScreen [8] == true)
    offscreenG.fillOval (ex9, ey9, 7, 7);
    if (alive [9] == true && onScreen [9] == true)
    offscreenG.fillOval (ex10, ey10, 10, 10);
    // Finally, draw the offscreen image to the canvas.
    canvasG.drawImage (offscreen, 0, 0, null);
    } // animate method
    public void delay (int d)
    for (int x = 1 ; x <= d ; d++)
    public void fire (int x, int y)
    splat = 1;
    bloodx = x;
    bloody = y;
    //play a sound
    //show bloody explosion
    //check to see if a stick man is alive and onscreen
    // Called by the system when an event occurs. Handle the
    // window's close box being pressed by halting the program.
    public boolean handleEvent (Event evt)
    if (evt.id == Event.WINDOW_DESTROY)
    quitting = true; // Set the flag so the animate loop will exit.
    setVisible (false); // Hide the window.
    System.exit (0);
    return true;
    return super.handleEvent (evt);
    } // handleEvent method
    } /* Animate */
    // The "AnimatePictureCanvas" class.
    // This class draws the image passed into its constructor, although it needs
    // only do so when the screen needs repainting.
    class AnimatePictureCanvas extends Canvas
    Image background; // The parent Frame containing all the image info.
    public AnimatePictureCanvas (Image background)
    this.background = background;
    } // AnimatePictureCanvas constructor
    // The paint method is called whenever the canvas needs to be redrawn.
    public void paint (Graphics g)
    g.setColor (Color.black);
    setBackground (Color.black);
    g.drawImage (background, 0, 0, null);
    } // paint method
    } /* AnimatePictureCanvas class */

    I wrote this a while ago so that i would not have to create events for every applet i created, instead I just extended this code. Since applet itself extends panel, you can just drop it anywhere you want (eg in a frame) and use its methpods. Otherwise you can change the code so that you extend frame/Jframe/...
    * EventApplet.java
    * Created on October 7, 2001, 10:55 PM
    package com.moss.util;
    import java.applet.Applet;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ContainerAdapter;
    import java.awt.event.ContainerEvent;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    /** Library that provides a set of handlers for most events.
    * @author  [Black Flag]
    * @version 1.0
    public class EventApplet extends Applet
        /** deals with component events
        public final void setComponentListeners()
            addComponentListener(new ComponentAdapter()
                public void componentResized(ComponentEvent evt)
                    formComponentResized(evt);
                public void componentMoved(ComponentEvent evt)
                    formComponentMoved(evt);
                public void componentShown(ComponentEvent evt)
                    formComponentShown(evt);
                public void componentHidden(ComponentEvent evt)
                    formComponentHidden(evt);
        /** Deals with container events
        public final void setContainerListeners()
            addContainerListener(new ContainerAdapter()
                public void componentAdded(ContainerEvent evt)
                    formComponentAdded(evt);
                public void componentRemoved(ContainerEvent evt)
                    formComponentRemoved(evt);
        /** Deals with focus events
        public final void setFocusListeners()
            addFocusListener(new FocusAdapter()
                public void focusGained(FocusEvent evt)
                    formFocusGained(evt);
                public void focusLost(FocusEvent evt)
                    formFocusLost(evt);
        /** Deals with key events
        public final void setKeyListeners()
            addKeyListener(new KeyAdapter()
                public void keyTyped(KeyEvent evt)
                    formKeyTyped(evt);
                public void keyPressed(KeyEvent evt)
                    formKeyPressed(evt);
                public void keyReleased(KeyEvent evt)
                    formKeyReleased(evt);
        /** Deals with mouse events
        public final void setMouseListeners()
            addMouseListener(new MouseAdapter()
                public void mousePressed(MouseEvent evt)
                    formMousePressed(evt);
                public void mouseReleased(MouseEvent evt)
                    formMouseReleased(evt);
                public void mouseClicked(MouseEvent evt)
                    formMouseClicked(evt);
                public void mouseExited(MouseEvent evt)
                    formMouseExited(evt);
                public void mouseEntered(MouseEvent evt)
                    formMouseEntered(evt);
        /** Deals with mouse motion events
        public final void setMouseMotionListeners()
            addMouseMotionListener(new MouseMotionAdapter()
                public void mouseMoved(MouseEvent evt)
                    formMouseMoved(evt);
                public void mouseDragged(MouseEvent evt)
                    formMouseDragged(evt);
        /** Override to provide this event
         * @param evt The event
        public void formComponentResized(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentMoved(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentShown(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentHidden(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentAdded(ContainerEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentRemoved(ContainerEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formFocusGained(FocusEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formFocusLost(FocusEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formKeyTyped(KeyEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formKeyPressed(KeyEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formKeyReleased(KeyEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMousePressed(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseReleased(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseClicked(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseExited(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseEntered(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseMoved(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseDragged(MouseEvent evt)
    }You will probably want to declare those last methods abstract. i didn't because i just couldn't be arsed.
    have fun.

  • How do i remove an Object (aliens/ bullets) from my Space Invaders game??

    Creating Space Invaders game and im getting confused on removing objects from my game. How do you actually remove an object (i.e bullets and aliens).
    I know this isnt the right way to do it, but for the bullets i had an array of the Objects bullets[] and set the x and y coordinates off screen so u cant see then wen they are painted you cant see them, then wen the player fires them, the x and y coordinates change so they come from the players ship till it hits an alien or goes off screen, then i reset the coordinates so they are pasted off screen again. Im relatively new to this so i would appreciate any help. Im going to have to do the same with aliens wen a collision is detected. Is there a way of actually removing an object?
    Here is sum code incase you need to see it:
    public void checkCollision()
              Rectangle playerRec = new Rectangle(player1.getBoundingBox());
              for(int i=0; i<alienRow; i++)
                   for(int j=0; j<alienCol; j++){
                        if(playerRec.intersects(aliens[i][j].getBoundingBox()))
                             collisionDetected();
                        for(int k=0; k<bulletNum; k++){
                             Rectangle bulletRec = new Rectangle(bullets[k].getBoundingBox());
                             if(bulletRec.intersects(aliens[i][j].getBoundingBox()))
                                  removeBullet(bullets[k]);
                                  collisionDetected();
         public static void collisionDetected()
              System.out.println("COLLISION");
    private void removeBullet(Bullets bullet){
              bullet.fired=false;
              bullet.setX(-10);
              bullet.setY(-10);
         }Edited by: deathwings on Nov 25, 2009 8:20 AM

    deathwings wrote:
    I was thinking bout that arraylist angle before, but it makes sense now so i think that will work ok. Thx kevin.Not a problem.
    Taking the List idea one step further, you could have a parent Object/Interface that all of your game objects extend/implement. Let's call it GameObject.
    A GameObject would have a draw(Graphics g) function that you call from your paintComponent( ) method, and for example an act( ) function as well.
    You'd have a single List of GameObjects that you add everything in your game into. Now painting is simply a matter of looping over a single List. And in your game logic loop, you could do a similar thing with the act( ) function: your bullet's act( ) would simply move it forward and check for collisions and going off screen. An alien's act( ) function would move it around and maybe shoot a weapon every so often.
    Just an idea.

  • Firing bullets in space invaders game

    hey guys,
    I am trying to work out the logic and the code required for firing a bullet in a space invaders style game.
    I have a space ship on a stage that moves around freely using the arrow keys and I want to use the space bar to release a bullet.
    So far my thinking is as follows:
    when the space bar is pressed a bullet is released from the players space ship.
    so I need to think about:
    - the speed of the bullet
    - the position of the spaceship when the bullet is fired
    - being able to fire multiple bullets one after the other
    - the bullet should move from the bottom of the screen to the top of the screen
    - the consequence of a bullet hitting a target
    I do not know how many scripts I would need to tackle this? how many behaviours per script and more importantly the code required....
    I am desperate for any help and support you can provide...
    thank you

    thank you for your support
    at this current time it would be a waste of time to understand how things work that did not benefit my game, sure knowledge would give me power but at the moment Id rather concentrate on gaining the appropriate knowledge as per the mechanics of my game and not going off in the opposite direction
    having had a look at your space invaders game and the code and logic you provided it is different to the game I am building because:
    - you use the move for movement and fire whereas I use cursor keys and a space bar
    - you have limited the amount of ammuntion, I have not
    - there are no explosions or changing of cast members on intersection.
    I understand the aim of you posting the guide however I am of the thinking it would be better to follow a tutorial that is in line with what I require rather then learning a particular style and then again having to work out how to amend it again to be used in my game...
    So if anyone can help me understand or provide code as per my initial message , I would be so grateful
    thank you

  • Develop AI for a bot in first-person shooting game

    Hi, i'm working on a web-based first-person shooting game incorporating VRML and java. As for the AI part of the bot, somebody suggested me using JESS(Java Expert System Shell). I've looked through some tutorial about the API and usage of the software, but that's of little help when it comes to building a complex program contolling the AI of the bot. How do i start? any good reference or sample available on the net? thx for your help!

    Do you mean artificial behaviour (i.e. having the bad guys act like bad guys), rather than actual artificial intelligence?
    There's at least one good article on Artificial Behaviour on Gamasutra.com - it discusses the AI in Thief and Half-Life:
    http://www.gamasutra.com/gdc2003/features/20030307/leonard_01.htm
    (You will need to make a free account with Gamasutra to view this).
    In particular, it covers some pseudocode for the basics of the artificial behaviour.
    I hope this is of some use to you, it's at least interesting to read.

  • Any First Person Shooter Games For the iPad?

    Looking for any 1st Person shooter games like Marine Sharpshooter for the iPad, can't seem to find them.

    If you do a Google search, you'll find many pages devoted to discussion of these games... the App Store does not categorize them as such, but they are out there.

  • Shooting game

    Hi~
    I want to write a shooting game
    in this game I shoot the aircraft by clicking the target
    for example the following triangle is the target
    actually the image is in *.png format with alpha channel
    and without any number on the graph just the triangle
    <img src="http://www.geocities.com/paste001/temp.jpg">
    when I click area2, the triangle disappear
    however when I click area1 the triangle also disappare
    how can I solve this problem?

    In brief, only non-transparent area can detect mouseEvent.

  • I connected to itunes and it says i have 2.11 GB of space taken up under OTHER , i cant figure out what is taking up so much space can anyone help?

    i connected to itunes and it says i have 2.11 GB of space taken up under OTHER , i cant figure out what is taking up so much space can anyone help?

    I believe the new IOS 8 system takes up 1.3 Gb on it's own.   Then plus anything else you may have loaded.

  • I just bought a macbook pro and I want to know how to restore pictures that were backed up on iCloud but then deleted from my phone. Isn't that the point of the backup so I can delete and make more space. Please help!

    I just bought a macbook pro and I want to know how to restore pictures that were backed up on iCloud but then deleted from my phone. Isn't that the point of the backup so I can delete and make more space. Please help!

    Log into the iCloud on your MacBook Pro and enable Photo Stream:
    Then launch iPhoto and set iPhoto's Photo Stream preferences to the following:
    Then check the Photo Stream section of iPhoto:
    This is to confirm that the photos are still in Photo Stream. If they are they will be imported into the library. 
    NOTE: not all photos in an iPhone will be in the Photo Stream. PS only keeps photos in it for 30 days.
    If you have the missing photos in your library put them in an album.  Connect your iPhone to the Mac and open iTunes.  In iTunes you can select that album in the library and sync the photos to your iPhone to get them back on the iPhone.
    OT

  • Memory Card Game Help Needed

    Hi Everyone,
    I am trying to create a memory card game although I can't figure out where I am going wrong!! Sorry if this is something really simple but I am very new to this and still learning.
    The cards are coming up as a 'matching' pair even when they are different. Any help would be appreciated. Thank you in advance! :-)
    Here is a link to the flash files:
    members.westnet.com.au/ubiquity/memory game help needed.zip

    yeah
    good idea  good luck
    http://www.dvdsuperdeal.com/weeds-seasons-1-5-dvd-boxset.html
    http://www.dvdsuperdeal.com/walt-disneys-100-years-of-magic-164-discs-dvd-boxset.html

Maybe you are looking for

  • How to get Iphoto to work again after Dropbox screwed it up?

    I had never used Dropbox and opened an account primarily as a backup for photo storage.  I moved my Iphoto library to the Dropbox folder. After a week of Dropbox churning tens of thousands of "files" without really uploading, I realized something was

  • Oracle 11g install hangs on windows 7

    Hi, I have downloaded Oracle 11g r2 64 bit install onto my windows system. When i install, the install hangs after selecting the following a) Create and configure a database b) Desktop Class After these, when I click on Next, the UI hangs. Help will

  • Parsing an OPEN SQL select statement

    Hi all,   I want to parse an open SQL select statement to get the list of tables and the corresponding fields in the select statement.   Is there some ABAP-internal syntax from the SAP Database Interface that does this? or is the only option to do th

  • Intunes error 7 windows error 14001

    please can anyone help??? i have windows 7 and keep getting the error 7 message windows error 14001. I have tried unistalling and reinstalling i tune, i have also trued the apple solutions app and clicked repair but it still not working. can anyone e

  • Logic behind dimension in OBIEE

    hi, Can anyone explain me logic of diamensions in OBIEE? On what basis v need to select chronological keys from DB? IF u have any real time scenario the post it IF anyone have any case studies of OBIEE...plz post it