Can anyone fix this.??please help.

i want to learn how to program games in java and i found a good tutorial on 1javast.com on making a space invaders applet. i can get the code to compile but the applet doesnt work properly. does anyone have any ideas? here is the code.
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.*;
public class Game extends Applet implements Runnable, MouseMotionListener, MouseListener
BufferedImage bufferdImg;
Graphics2D bufferdImgSurface;
Thread gameThread;
int width=400, height=400, MAX=50, speed=10;
int currentX[] = new int[MAX];
int currentY[] = new int[MAX];
int step=0, // Number of movements left/right
direction=1, // Current left/right direction (0=left, 1=right)
shipX=width/2-10, // Current player X possition
shipY=height-45, // Current player Y possition
mbx=-10, // The mouse position after mouse down, sets the_
mby=-10, // enemy bullet position to this.
randomShoot=0, // Used to work out which enemy is shooting
health=50, // The players health
BNUM=10, // Number of bullets
playing=0; // Are is the game playing (0=Playing, 1=Paused, 2=Game Over, 3=Win)
int bX[] = new int[BNUM]; // Bullet X pos.
int bY[] = new int[BNUM]; // Bullet Y pos.
int ebX[] = new int[BNUM]; // Enemy Bullet X pos.
int ebY[] = new int[BNUM]; // Enemy Bullet Y pos.
long start=0, // Frame start time
tick_end_time, // End frame time
tick_duration, // Time taken to display the frame
sleep_duration; // How long to sleep for
static final int MIN_SLEEP_TIME = 10, // Min time to sleep for
MAX_FPS = 20, // Max frame rate.
MAX_MS_PER_FRAME = 1000 / MAX_FPS; // MS per frame
float fps=0, // Current frame rate
dist; // Distance between 2 points
public void start()
Thread gameThread = new Thread(this);
gameThread.start();
public void init()
currentX[0]=0;
currentY[0]=0;
int row=10, // Current Y position
col=10, // Current X position
count=0; // How many circles have been drawn
//set the co-ordinates for each circle
for(int i=0;i<50;i++)
count++;
currentX=col;
col+=25;
currentY[i]=row;
if(count==10)
row+=25;
col=10;
count=0;
addMouseMotionListener(this);
addMouseListener(this);
for(int i=0;i<BNUM;i++)
bX[i]=-10;
bY[i]=-10;
ebX[i]=0;
ebY[i]=height+10;
public void run()
while(true){     // Starts the game loop
start = System.currentTimeMillis(); // Sets the current time
// Are we playing or is the game over?
if(playing==0)
step++;
for(int i=0;i<MAX;i++)
if(step>15)
if(direction==1)
direction=0;
else
direction=1;
step=0;
for(int j=0;j<MAX;j++)
currentY[j]+=speed;
if(direction==1)
currentY[i]+=speed;
else
currentX[i]-=speed;
for(int i=0; i<BNUM;i++)
if(bY[i]<=0)
bX[i]=mbx;
bY[i]=mby;
mbx=-10;
mby=-10;
bY[i]-=speed;
for(int i=0;i<MAX;i++)
for(int j=0;j<BNUM;j++)
if(!(bY[j]<=0))
dist=(int)(Math.sqrt(Math.pow((currentX[i]+10)-bX[j],2)+
Math.pow((currentY[i]+10)-bY[j],2)));
if(dist<=20)
bY[j]=-50;
currentY[i]=-500;
for(int k=0;k<MAX;k++)
randomShoot=(int)(Math.random()*MAX);
if(currentY[randomShoot]>=0)
for(int i=0;i<BNUM;i++)
if(ebY[i]>=height)
ebX[i]=currentX[randomShoot];
ebY[i]=currentY[randomShoot];
break;
//shooting the alien bullets
for(int k=0;k<MAX;k++)
randomShoot=(int)(Math.random()*MAX);
if(currentY[randomShoot]>=0)
for(int i=0;i<BNUM;i++)
if(ebY[i]>=height)
ebX[i]=currentX[randomShoot];
ebY[i]=currentY[randomShoot];
break;
for(int j=0; j < BNUM; j++) {
if(!(ebY[j]>=height)){
dist = (int)(Math.sqrt(Math.pow((shipX+10)-ebX[j],2) + Math.pow((shipY+10)-ebY[j],2)));
if(dist <= 20){
ebY[j]=height+10;
health-=10;
for(int i=0; i < BNUM; i++){
if(ebY[i] < height) {
ebY[i]+=speed;
if(health <=0)
playing=2;
int count=0;
for(int j=0; j < MAX; j++){
if(currentY[j]<0)
count++;
if(currentY[j]>=340)
playing=2;
if(count==MAX)
playing=3;
} else { }
repaint(); // Redraw the screen
public void paint(Graphics g)
update(g);
public void update(Graphics g)
Graphics2D g2 = (Graphics2D)g;
// Set the background color.
bufferdImgSurface.setBackground(Color.black);
// Clear the applet.
bufferdImgSurface.clearRect(0, 0, width, height);
bufferdImgSurface.setColor(Color.green);
//(X pos, Y pos, Width, Height)
for(int i=0; i < MAX; i++)
bufferdImgSurface.fillOval(currentX[i], currentY[i], 20,20);
// Draw the read ship (a square)
bufferdImgSurface.setColor(Color.red);
bufferdImgSurface.fillRect(shipX, shipY, 20, 20);
for(int j=0; j < BNUM; j++){
bufferdImgSurface.setColor(Color.yellow);
bufferdImgSurface.fillOval(bX[j], bY[j], 5,5);
bufferdImgSurface.setColor(Color.blue);
bufferdImgSurface.fillOval(ebX[j], ebY[j], 5,10);
// Draw a bottom line to our window
bufferdImgSurface.setColor(Color.red);
bufferdImgSurface.drawString("_________________________________________________________",0,375);
if(playing==1)
bufferdImgSurface.drawString("PAUSED", width/2-10, 390);
else if(playing==2)
bufferdImgSurface.drawString("****Game Over****", width/2-10, 390);
else if(playing==3)
bufferdImgSurface.drawString("****You Win!****", width/2-10, 390);
for(int i=0; i < health; i++)
bufferdImgSurface.drawString(" |", (2*i), 390);
// Draw the buffered image to the screen.
g2.drawImage(bufferdImg, 0, 0, this);
public void mouseMoved(MouseEvent e) { shipX=e.getX()-5; }
public void mouseDragged(MouseEvent e) { shipX=e.getX()-5; }
public void mouseClicked(MouseEvent e) {
mbx=e.getX();
mby=shipY;
public void mousePressed(MouseEvent e) {
mbx=e.getX();
mby=shipY;
public void mouseEntered(MouseEvent e) { playing=0; }
public void mouseExited(MouseEvent e) { playing=1; }
public void mouseReleased(MouseEvent e) { }

this doesn't come close to compiling

Similar Messages

  • In xcode i deleted my default.png file and know my app says 0 target and missing base sdk how can i fix this please

    please help mw fix my app i deleted my default .png file the one that displays an image when u first run the the and after i deleted my app wont run and says at the very top 0 target , missing base sdk. how can i fix this please help.

    hello , i did exactly the same thing , and my app store icon look like this :
    http://i.imgur.com/FIrph.png
    so can you tell me how did your friend send the app store for you? please

  • Apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    Thanks Barney, I tried that but all that comes up in Spotlight are the log files that show the file paths! I don't know how Steam works. Are all the files held by Steam on their server perhaps?

  • A previous and unrelated text always appears when I need to send a new text. This prevents forwarding texts also, which I need to do all the time for my business. How can I fix? Please help!

    A previous and unrelated text always appears when I need to send a new text. This prevens forwarding texts also, which I need to do all the time for my businss. How can I fix? Please help?

    Hi,
    This sounds like it is about Window positions.
    iChat has Default places for Incoming Invites.
    Video is always top Center of your Screen
    Audio and Text chats are Upper right with the Audio slightly lower than Text Chats.
    Secondary invites are sort of Stacked like when you open multiple files from the same App.
    Your outgoing Windows are "Remembered" as to where the last one was when you used it.
    This can be an issue if you use your Mac with a second display and turn Off Mirroring.
    You windows can get "left" on the other screen.
    Go to System Preferences > Displays and turn On Mirroring and the windows should come back to one Screen/display.
    If this does not help go to your Home Folder/Library/Preferences and delete (Drag to Trash) com.apple.ichat.plist and restart iChat.
    Unfortunately you will need to reset any iChat Preferences you have changed from defaults.
    10:42 PM      Tuesday; April 26, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.7)
    , Mac OS X (10.6.7),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Blank screen in itunes store-please help im not very technical and when i click on my itunes app the screen is blank how can i fix this please?

    Blank screen in itunes store-please help im not very technical and when i click on my itunes app the screen is blank how can i fix this please?

    See if any of the following fix it.
    Try logging out of your account on your phone by tapping on your id in Settings > iTunes & App Store and tap 'Sign Out' on the popup and then log back in.
    If that doesn't fix it then try closing the iTunes store app via the phone's multitasking bar and see if it works properly when you open the app : double-click the home button to open the taskbar and then swipe or drag iTunes from there up and off the top of the screen to close it, and the click the home button to close the taskbar.
    A third thing to try is a soft-reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the equivalent of a reboot.

  • Update Unavailable with This Apple ID This update is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled... How can i fix it Please help !!

    Update Unavailable with This Apple ID This update is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled... How can i fix it
    Please help !!

    Hello chiêu trần
    If there is an issue with any app then use the steps in the article below to report the issue to the App Store.
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/HT1933
    Regards,
    -Norm G. 

  • When trying to download a app, I am being told my Apple ID has been diabled.  why is this happening?  how can I fix? Please help!

    When trying to download an app, I am being told my Apple ID has been disabled!  Why is this happening?  How can I fix?  Please Help.

    We are fellow users, we won't know why it's disabled. You might be able to re-enable it via this page : http://appleid.apple.com, then 'reset your password'
    You might then need to log out of your account on your device by tapping on your id in Settings > Store (Settings > iTunes & App Stores on iOS 6) and then log back in so as to 'refresh' the account on it
    If that doesn't fix it then you might need to contact iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • I just recently got my I phone five and none of my soundsh are working as to ringing notifications etc. what can I do to fix this please help me

    I just recently got my I phone five and none of my sounds are
    working as to ringing notifications etc.
    what can I do to fix this please help me

    You are sure the mute switch is not on?
    The mute switch is at the left side above the volume buttons. If it's red/orange then mute is on.

  • TS1372 I have an error code of 1434 on my iPod classic, how can i fix this please ?

    I have an error code of 1434 on my ipod classic, how can i fix this please ?

    See if this helps you: <br />
    http://domino.symetrikdesign.com/2011/03/25/getting-the-delicious-bookmarks-add-on-to-work-with-firefox-4-0/comment-page-1/#comment-5807
    BTW, you would need to use '''5.0.*''' as the maxVersion for Firefox 5.0.

  • Hello! I was on my Mac and then I clicked on iTunes. Then I clicked on iTunes, and accidentally removed my device from my Mac, how can I get it back? Also when I plug my iPod into the computer, it downloads everything, how can I stop this. please help!thx

    Hello! I was on my Mac and then I clicked on iTunes. Then I clicked on Account, and accidentally removed my device from my Mac, how can I get it back? Also when I plug my iPod into the computer, it downloads everything that is on my computer, how can I stop this. please help! please help!!!!!!thank you

    Is the iPod still singed into the account isn Settings>iTunes and App Stores and SettingsZ>iCloudl? If it is then I would not be concerned.
    Also see:
    iTunes Store: Associating a device or computer to your Apple ID
    since you may have started the 90 day window.
    For the other "problem", go to iTunes>Preferences>Devices and check the box that says Prevent iPod....automatically syncing.

  • TS3988 I have an icloud account and I view my mail with Mail V5.2. I recieve my email but the senders get messages saying the delivery failed. Can anyone explain this or help me.

    I have an icloud account and I view my mail with Mail V5.2. I recieve my email but the senders get messages saying the delivery failed. Can anyone explain this or help me.

    Thank you for replying.    Yes I deleted the old email address..   

  • Hello my computer will not load the photoshop program as it has Inefficient disc space how can i fix this please?

    hello my computer will not load the photoshop program as it has Inefficient disc space how can i fix this please?
    Regards
    Geoff

    Hi The Lad,
    If you have "INSUFFICIENT" disk space, then you can try and change the install location while performing the installation of the desired product. I am not sure when the error message would pop up saying that the disk space is "INEFFICIENT". Could you please share a screen shot of the error message along with the system information.
    Cheers,
    Kartikay Sharma

  • The camera and HDR flash option disappear from my iPad 2.  How can I fix this please?

    The HDR and camera flash disappear from my iPad 2.  How can I fix this please?

    The iPad doesn't have a flash or an HDR option on its cameras.

  • I upgraded my 4s to 7.0.4 and now I can't access hotmail through my main mail app. When I open it a pop up says password incorrect even after I put my password in it pops up again. How do I fix this please help

    I upgraded my 4s to 7.0.4 and now I can't acicess hotmail through my main mail app. When I open it a pop up says password incorrect even after I put my password in it pops up again. How do I fix this please help

    After I upgraded to Mavericks I was also having this message when I tried to update. There was a previous post about this problem which offered this simple solution which worked for me:
    b0n0b0
    Re: Recently upgraded to Maverick from SnowLeopard. Unable to get updates from App store.
    Mar 15, 2014 9:05 AM (in response to Terence Devlin)
    Got it! Thanx.  What I did was go to my account, check that they had my new ID and Password which they did, then hit reset button. All fixed.

  • Can anyone fix this vi

    The right button is not working in this vi. Can anyone fix it??
    Attachments:
    Boolean grid.vi ‏21 KB

    He is using LV 2009. If he wouldn't, opening the VI in newer versions would create the *-symbol in the end of the VIs name showing that there are unsaved changes. Looking into the VI settings >> General >> List unsaved Changes would reveal the original version.
    To answer the question:
    The VI has too many unnecessary local variables and lacks in a proper architecture. You do not have a timing in your loop leading to 100% CPU load at a single core. Please look into the State Machine (Video and Exercise here) or the UI Event Handler for further info (event handler only with LV FDS oder PDS).
    Additionally, your algorithm for shifting the active LED is no good. I cannot give you any useful information on a solution since it is not clear how the move should look like (what happens if LED is shifted out of the 3x3 array in any direction? Does it appear on the opposite side in the same column/row or does it shift to another one?)
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • I installed LabVIEW 5.1 on an XP machine and some of the VI's, such as fit to curve, do not have icons. Instead, they have a ? where the icon should be, and they cannot be inserted into my VI's. Can anyone fix this?

    I am using a Dell Inspiron I8100 Laptop with Windows XP Home and am running LabVIEW 5.1 in Windows 95 compatability [I also did so for the install to get rid of the "wrong os" message]. I am able to use nearly all of the functions, but a few of them did not make the transition to my machine. I cannot use some of the VI's contained in the Mathematics sub-palette, I cannot use some of the demos, and it is really setting me back. Instead of an icon for the Mathematics>>Curve Fit sub-palette I get a ? in an icon-sized box that says Curve Fit for it
    s description. Can anyone fix these broken links?
    Attachments:
    LabView.bmp ‏2731 KB
    labview2.bmp ‏2731 KB

    From your discussion I have seen that you try to use LV 5.1.
    It seems that 5.1.1 will work correct. The difference is that 5.1.1 is compatible with Win 2000 and 5.1 is not. This can by a issue.
    Another thing I have seen under Win2000 is the rights a user has. Since you use XP Home there should be no restrictions to the user of the machine. One thing to take into account is do you install and use LV as the same user?
    Waldemar
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

Maybe you are looking for

  • Base Value not changing in MIGO Excise Tab

    Dear Gururs, We are using MIGO to capture & Post Excise Invoice for our Import PO (PO type ZIMP). the problem is, when we change the qty in MIGO Qty tab, corresponding base value is not getting update in Excise tab. Please suggest a solution.

  • Upgraded to Lion, now iMovie opens then crashes. Please help.

    I upgraded to Lion a couple days ago and now each time I open iMovie, it acts like it's going to work and 10 seconds later it crashes.  This is the 'error message' I get. Hopefully this will make sense to someone out there...   Thank you for your hel

  • How to know the run time of a program..?

    Hi Gurus, How to know the exact run time of a program....? Suppose i've a program....I've changed the code to improve the performance. Now i want to compare run time of older and new one...How to do this...? Pls help me .... Thanks and Regards, Nagar

  • Need help with 865MS-LS MB startup problems

    I recently purchased an 865GM2-LS motherboard in order to use with a new computer that I am building. After making sure everything was attached, I tried to boot the system by turning the power on. But, the machine beeped and an error came up, saying

  • BCM , batch ID creation Problem,

    Hi , I have a problem in creating the batch ID for payment run for a particular company code: Scenario is as follows: 1. F110 and payment run- success 2.FBPM1, creating the merge date and merge ID but its not creating the Batch ID. 3.After FBPM1 , ba