Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Beginner. Need Help finishing a simple Shoot em up game ASAP!!!!

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Beginner. Need Help finishing a simple Shoot em up game ASAP!!!!

    I am trying to create a simple shoot em up on java and it is due by tomorrow 5/2.

    I need help making the gun I have created, shoot up to 10 bullets using the space bar. Also, I need some kind of either bullet countdown bar or something to show the shooter the number of bullets that he has left to shoot out of 10.

    So far I have created the Ufo's that bounce around the screen randomly and the gun that moves along the bottom using the arrow keys. When a Ufo huts the gun the game ends and goes to a blank screen.

    Here is what I have so far:


    //Shoot.java 
    import acm.graphics.*;
    import acm.program.*; 
    import java.awt.event.*;
    import java.awt.*;
    import acm.util.*;
     
    public class Shoot extends GraphicsProgram
    {
      public static final int APPLICATION_WIDTH = 800; 
      public static final int APPLICATION_HEIGHT = 500;
     
      final int AW=APPLICATION_WIDTH;
      final int AH=APPLICATION_HEIGHT;
      final int WAIT=5;
      final int MV_AMT=5;
      final int JUMP_AMT=100;
      final int U_SIZE=30;
      int xMove,yMove;
     
      UFO u1,u2,u3;
     
     
      public void init()
      {
       u1=new UFO();
       u2=new UFO();
       u3=new UFO();
     
       RandomGenerator rg= new RandomGenerator();
       int rand1= rg.nextInt(0,AW-50);
       int rand2= rg.nextInt(0,AW-75);
       int rand3= rg.nextInt(0,AW-100);
     
       add(u1,rand1,0);
       add(u2,rand2,0);
       add(u3,rand3,0);
     
       xMove=yMove=0;
       addKeyListeners();
      }//init
     
      public void keyPressed(KeyEvent e) 
      { 
        int key = e.getKeyCode( ); 
     
        if (key == KeyEvent.VK_RIGHT) 
        { xMove = MV_AMT ; } 
     
        else if (key == KeyEvent.VK_LEFT) 
        { xMove = -MV_AMT ; } 
      } //keyPressed
     
      public void run()
      { 
        RandomGenerator rg =new RandomGenerator();
        GRectangle u1Box, u2Box, u3Box, g1Box;
     
        int xMove1=1,xMove2=1,xMove3=1;
        int yMove1=1,yMove2=0,yMove3=1/4;
     
        boolean u1Done=false, u2Done=false, u3Done=false;
     
     
        GUN g1=new GUN();
        add(g1,300,480);
        xMove=yMove=0;
        addKeyListeners();
     
        waitForClick();
     
     
     
     
        while(true)
        {
     
          u1.move(xMove1,yMove1);
          u2.move(xMove2,yMove2);
          u3.move(xMove3,yMove3);
     
          u1Box=u1.getBounds();
          u2Box=u2.getBounds();
          u3Box=u3.getBounds();
          g1Box=g1.getBounds();
     
     
          pause(WAIT);
          g1.move(xMove,yMove);
          xMove=yMove=0;
     
          //intersections
          if(u1Box.intersects(g1Box)==true)
          {g1.setVisible(false);
          u1.setVisible(false);
          u2.setVisible(false);
          u3.setVisible(false);
          break;
          }
          if(u2Box.intersects(g1Box)==true)
          {g1.setVisible(false);
           u1.setVisible(false);
           u2.setVisible(false);
           u3.setVisible(false);
           break;
          }
          if(u3Box.intersects(g1Box)==true)
          {g1.setVisible(false);
           u1.setVisible(false);
           u2.setVisible(false);
           u3.setVisible(false);
           break;
          }
     
          //at top of window 
          if (u1.getY( ) == 0) 
          { yMove1 = -yMove1 ; } 
          if (u2.getY( ) == 0) 
          { yMove2 = -yMove2 ; } 
          if (u3.getY( ) == 0) 
          { yMove3 = -yMove3 ; } 
     
         //at left or right side 
          if ((u1.getX( ) <= 0) || (u1.getX( ) + U_SIZE >= AW)) 
          { xMove1 = -xMove1 ; } 
          if ((u2.getX( ) <= 0) || (u2.getX( ) + U_SIZE >= AW)) 
          { xMove2 = -xMove2 ; } 
          if ((u3.getX( ) <= 0) || (u3.getX( ) + U_SIZE >= AW)) 
          { xMove3 = -xMove3 ; }
     
         //at bottom of window
          if (u1.getY( ) == 450) 
          { yMove1 = -yMove1 ; } 
          if (u2.getY( ) == 450) 
          { yMove2 = -yMove2 ; } 
          if (u3.getY( ) == 450) 
          { yMove3 = -yMove3 ; } 
     
     
     
     
     
        }
     
      }
    }


    Thank you so much

    Courtney


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Beginner. Need Help finishing a simple Shoot em up game ASAP!!!!

    It sounds pretty much like you need to finish most of the assignment. And a word to the wise, mentioning your deadlines actually decreases your chances of getting help because it makes you seem impatient. There are hundreds of posts here, each with an urgent user behind it, so is your time more valuable than theirs simply because you mismanaged a deadline?

    Anyway, if you want help, you'll have to be more specific- what have you tried? Where are you stuck? I don't see any code for the stuff you mentioned. Did you even attempt to start it?

    PS- Why are you adding your KeyListeners twice? And I can't even compile this, because what you've posted is incomplete. You'll have to provide us with an SSCCE if you want help.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] Simple question from a beginner
    By jimmylee7706 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 6th, 2011, 09:57 PM
  2. beginner and need simple help. please!
    By alal12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 19th, 2010, 05:38 PM
  3. error with a java game..(beginner)
    By Skat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 1st, 2010, 02:04 PM
  4. Need simple JAVA program fixing ASAP
    By theviper in forum Paid Java Projects
    Replies: 1
    Last Post: April 14th, 2010, 10:59 AM
  5. Beginner needs help with simple java assignment.
    By joachim89 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 07:53 PM