/************************************************** * * * MarsLanderApplication class: Creates the main * * simulator application. * * * * Created by S.Cartwright ©2000 * * * **************************************************/ package source; //Import the Sun classes we need import java.awt.image.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.borland.jbcl.layout.*; import javax.swing.event.*; import java.applet.*; import javax.swing.border.*; import javax.swing.UIManager; //**********************************************************************************************// //The main applications class definition public class MarsLanderApplication extends JFrame implements ActionListener{ //**********************************************************************************************// //Main panel objects XYLayout xYLayout1 = new XYLayout(); JPanel jPanel1 = new JPanel(); JSlider jSlider1 = new JSlider(); JProgressBar jProgressBar1 = new JProgressBar(); JButton jButton1 = new JButton(); JLabel jLabel1 = new JLabel(); TitledBorder titledBorder1; JLabel jLabel2 = new JLabel(); JCheckBox radar = new JCheckBox(); JLabel jLabel3 = new JLabel(); //**********************************************************************************************// //Declare and create some of the game objects private MonitorEffect mE=new MonitorEffect(1,6); private Lander lander=new Lander(); private Zoom intro=new Zoom(1,5,20),countdown=new Zoom(1,5,20), ending=new Zoom(1,2,100); private BufferedImage buffImage=new BufferedImage(360,370,BufferedImage.TYPE_INT_RGB); private Graphics bufferedImageHandle,jPanel1ImageHandle; private Flash flash=new Flash(true,10,5),panelFlash[]=new Flash[6],verbalWarning=new Flash(false,1,20); private Scroller scroller=new Scroller("", " MARS LANDER By S. Cartwright! "+ " Use the slider control to alter your Mars Lander's engine thrust, "+ "so you touch down gently! Falling too fast will mean you crash. "+ "See how much fuel you can land with to get todays high score!" ,"",40,3); private Audio sound=new Audio(); private MissionTimer missionTimer=new MissionTimer(); private AsteroidDisplay asteroids=new AsteroidDisplay(); private Lightning lightning=new Lightning(); private HighScores scoreTable; private Timer gameTimer; private Image dbackground,nbackground,dforeground,window,dparalax,slider,fuelgage,fuelback,beacon,dlandingPad, nforeground,nparalax,nlandingPad,rforeground,rparalax,rlandingPad,dust; private AudioClip lowThrust,mediumThrust,highThrust,maxThrust,say3,say2,say1,sayGo, pullUp,lowFuel,prepareToLand,finalApproach,lookingGood,asteroid; private Image monitorScreenBlock,digitsBlock,introPicBlock,countDownBlock,lightBulbBlock,reportBlock; private Sprite monitorScreen,introPic,countDown,lightBulb,report; private GraphicalDigits digits; //**********************************************************************************************// //Declare Toolbar objects JMenuBar bar; JMenu fileMenu,effectsMenu,diffMenu,soundMenu; JCheckBoxMenuItem effectsItems[]; JRadioButtonMenuItem diffItems[],soundItems[],effectsRadioItems[]; ButtonGroup diffGroup,effectsGroup,soundGroup; //**********************************************************************************************// //Define local variables boolean _CLOSING=false,highScores=true,oldMenuBusy=false; float thrust; int landerPhase,lastWarning=0,eta=0,highScoreYPos=0,menuOn=0,oldMenuOn=0,dustXPos=0; int warningOverideTimer=0, asteroidStrikeTimer=10;//(int)(Math.random()%1000)+100; boolean saidPrepareToLand=false,saidFinalApproach=false,saidLookingGood=false; boolean isDay=true,dustCloudOn=false,radiationOn=true,asteroidOn=false; //**********************************************************************************************// //Run the application... //The application container class is also the main game object class as we //don't have to have multiple instances. public static void main(String[] args) { //Try to change the look and feel of the window components try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) {} //Instantiate this class new MarsLanderApplication(); } //**********************************************************************************************// //Construct the object public MarsLanderApplication() { for(int j=0;j<50;j++) System.err.println(); System.err.println("ENGINE LOGGER V 1.0"); System.err.print("--------------------------------------------------------------------------------"); //Add on the system menu createAndAddSystemMenu(); //Allow this object to trap window events enableEvents(AWTEvent.WINDOW_EVENT_MASK); //Print a stack trace for any exceptions during initialisation try{jbInit();} catch(Exception e){e.printStackTrace();} //Setup global variables initialiseApplicationEnvironment(); //Create the application window, and grab graphics handles createWindow(); //Automate this objects execution, before we finish the constructor start(); } //**********************************************************************************************// //Define all the system menu items, and add them to the main application window private void createAndAddSystemMenu() { //Create and attach the system menu bar System.err.println("Hooking application with JMenu."); bar=new JMenuBar(); setJMenuBar(bar); //Define all four menus fileMenu=new JMenu("File"); fileMenu.setMnemonic('F'); effectsMenu=new JMenu("Effects"); effectsMenu.setMnemonic('E'); diffMenu=new JMenu("Difficulty"); diffMenu.setMnemonic('D'); soundMenu=new JMenu("Sound"); soundMenu.setMnemonic('S'); //Define the details for the File menu //Define the About option JMenuItem aboutItem=new JMenuItem("About..."); aboutItem.setMnemonic('A'); //Add an anonymous actionPerformed method to the menu item to display a message aboutItem.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { System.err.print("--------------------------------------------------------------------------------"); System.err.println("Displaying About information box."); JOptionPane.showMessageDialog(MarsLanderApplication.this," Mars Lander Simulation Game"+ "\nWritten and designed by S.Cartwright."+ "\n For a second year Java assignment." ,"About Mars Lander V 1.00",JOptionPane.PLAIN_MESSAGE); } } ); //Add the About option to the file menu fileMenu.add(aboutItem); //Define the Exit option JMenuItem exitItem=new JMenuItem("Exit!"); exitItem.setMnemonic('x'); exitItem.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { System.err.print("--------------------------------------------------------------------------------"); System.err.println("Closing application"); stylisedCloseWindow(); scoreTable.save(); System.exit(0); } } ); //Add the Exit option to the file menu fileMenu.add(exitItem); //Define the Effects options final String sn[]={"Sunspot Radiation","Dust Clouds","Asteroids"}; String st[]={"Day","Night"}; effectsRadioItems=new JRadioButtonMenuItem[st.length]; effectsGroup=new ButtonGroup(); for(int i=0;i-5)) { if(!Warned) { if(lastWarning!=3) { jLabel2.setForeground(Color.green); jLabel2.setText("Looking Good!"); } if(!saidLookingGood) { if(soundItems[0].isSelected()&&soundItems[0].isSelected()) lookingGood.play(); saidLookingGood=true; } lastWarning=3; Warned=true; } } else saidLookingGood=false; if(lander.getAltitude()<500) { if(!Warned) { if(lastWarning!=4) { jLabel2.setForeground(Color.orange); jLabel2.setText("Final Approach!"); } if(!saidFinalApproach) { if(soundItems[0].isSelected()) finalApproach.play(); saidFinalApproach=true; } lastWarning=4; Warned=true; } } else saidFinalApproach=false; if(lander.getAltitude()<1500) { if(!Warned) { if(lastWarning!=5) { jLabel2.setForeground(Color.orange); jLabel2.setText("Prepare to land!"); } if(!saidPrepareToLand) { if(soundItems[0].isSelected()) prepareToLand.play(); saidPrepareToLand=true; } lastWarning=5; Warned=true; } } else saidPrepareToLand=false; if((lastWarning!=0)&&!Warned) { if(lastWarning!=0) { jLabel2.setForeground(Color.green); jLabel2.setText("Mission OK!"); } lastWarning=0; } } //**********************************************************************************************// //Process the game request, this is called directly from the actionPerformed method public void processGame() { if((lander.getFuel()<1.0)&&(jProgressBar1.getValue()>0)) { jProgressBar1.setValue(jProgressBar1.getValue()-1); jProgressBar1.setForeground(new Color(255,0,0)); sound.stopAll(); } else { if(lander.getFuel()!=0) { if(thrust==0) sound.stopAll(); if(thrust>0&&thrust<33&&soundItems[0].isSelected()) sound.requestLoop(lowThrust); if(thrust>32&&thrust<66&&soundItems[0].isSelected()) sound.requestLoop(mediumThrust); if(thrust>65&&thrust<100&&soundItems[0].isSelected()) sound.requestLoop(highThrust); if(thrust==100) { if(soundItems[0].isSelected()) sound.requestLoop(maxThrust); lander.setFuel( (int) (lander.getFuel()-1) ); } } } if(lander.getStatus()!=Lander.FLYING) { if(!radar.isSelected()&&dustCloudOn) lander.setStatus(Lander.CRASHED); if(lander.getStatus()==Lander.CRASHED&&soundItems[0].isSelected()) asteroid.play(); else lookingGood.play(); nextLanderPhase(); } if(asteroidOn&&!_CLOSING) { if(--asteroidStrikeTimer==0) { asteroidStrikeTimer=(int)(Math.random()%300)+200; warningOverideTimer=40; lastWarning=-1; lander.setVelocity((int)(lander.getVelocity()-(10-(int)(Math.random()*20)))); jLabel2.setForeground(Color.red); jLabel2.setText("Asteroid Strike!"); if(soundItems[0].isSelected()) asteroid.play(); } } updateWarnings(); updateInGameDisplay(lander.getAltitude()); } //**********************************************************************************************// //Process the game over request, which is dependent on the games outcome public void processEnd() { if(lander.getStatus()==Lander.CRASHED) doLanderCrashed(); if(lander.getStatus()==Lander.LANDED) doLanderLanded(); } //**********************************************************************************************// //Crash animator... public void doLanderCrashed() { float fvalue=300,scale; if(radar.isSelected()) { bufferedImageHandle.clearRect(25,19,266,262); bufferedImageHandle.drawImage(rforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(rparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(rlandingPad,0,(int)(5330-(fvalue*18)),this); } else { if(isDay) { bufferedImageHandle.drawImage(dbackground,0,(int)-(fvalue*1.5),this); bufferedImageHandle.drawImage(dforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(dparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(dlandingPad,0,(int)(5330-(fvalue*18)),this); } else { bufferedImageHandle.drawImage(nbackground,0,(int)-(fvalue*1.5),this); bufferedImageHandle.drawImage(nforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(nparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(nlandingPad,0,(int)(5330-(fvalue*18)),this); } } updateAnimation(); ending.updateZoom(); if(ending.getImageNumber()==1) { ending.resetZoom(); nextLanderPhase(); return; } scale=ending.getScaling(); bufferedImageHandle.drawImage(fuelback,16,307,this); bufferedImageHandle.drawImage(fuelgage,-28-(int)((500-lander.getFuel())/1.8),308,this); report.drawSprite(165-(int)(115*scale),140,scale,scale,1); bufferedImageHandle.drawImage(window,0,0,this); bufferedImageHandle.drawImage(slider,322,20+(int)(fvalue*0.85),this); updateAnimation(); jPanel1ImageHandle.drawImage(buffImage,0,0,this); } //**********************************************************************************************// //Landed animator... public void doLanderLanded() { float fvalue=300,scale; if(radar.isSelected()) { bufferedImageHandle.clearRect(25,19,266,262); bufferedImageHandle.drawImage(rforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(rparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(rlandingPad,0,(int)(5330-(fvalue*18)),this); } else { if(isDay) { bufferedImageHandle.drawImage(dbackground,0,(int)-(fvalue*1.5),this); bufferedImageHandle.drawImage(dforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(dparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(dlandingPad,0,(int)(5330-(fvalue*18)),this); } else { bufferedImageHandle.drawImage(nbackground,0,(int)-(fvalue*1.5),this); bufferedImageHandle.drawImage(nforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(nparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(nlandingPad,0,(int)(5330-(fvalue*18)),this); } } updateAnimation(); ending.updateZoom(); if(ending.getImageNumber()==1) { ending.resetZoom(); nextLanderPhase(); return; } scale=ending.getScaling(); bufferedImageHandle.drawImage(fuelback,16,307,this); bufferedImageHandle.drawImage(fuelgage,-28-(int)((500-lander.getFuel())/1.8),308,this); report.drawSprite(165-(int)(115*scale),140,scale,scale,0); bufferedImageHandle.drawImage(window,0,0,this); bufferedImageHandle.drawImage(slider,322,20+(int)(fvalue*0.85),this); updateAnimation(); jPanel1ImageHandle.drawImage(buffImage,0,0,this); } //**********************************************************************************************// //Draw the gradient background for the 'loading graphics' screen private void drawGradient() { for(int c=0;c100) progress=100; if((progress==0)||(total==0)) return; this.getGraphics().fillRect(122,192,(int)(((float)progress/(float)total)*200.0)-3,17); } //**********************************************************************************************// //Load all the graphics and sound here... private void loadResources() { String relativeSound=".\\audio\\",relativeGfx=".\\graphics\\"; MediaTracker tracker=new MediaTracker(this); Toolkit toolkit=getToolkit().getDefaultToolkit(); drawGradient(); drawProgressBar(0,0); System.err.print("--------------------------------------------------------------------------------"); System.err.print("Attempting to load resources."); lowThrust =sound.getAudio(relativeSound+"low.wav"); mediumThrust =sound.getAudio(relativeSound+"med.wav"); highThrust =sound.getAudio(relativeSound+"high.wav"); maxThrust =sound.getAudio(relativeSound+"max.wav"); say3 =sound.getAudio(relativeSound+"3.wav"); say2 =sound.getAudio(relativeSound+"2.wav"); say1 =sound.getAudio(relativeSound+"1.wav"); sayGo =sound.getAudio(relativeSound+"go.wav"); pullUp =sound.getAudio(relativeSound+"pullup.wav"); lowFuel =sound.getAudio(relativeSound+"lowfuel.wav"); prepareToLand =sound.getAudio(relativeSound+"prepland.wav"); finalApproach =sound.getAudio(relativeSound+"finapp.wav"); lookingGood =sound.getAudio(relativeSound+"good.wav"); asteroid =sound.getAudio(relativeSound+"asteroid.wav"); //Load daytime things dbackground =toolkit.getImage(relativeGfx+"dbackground.gif"); dforeground =toolkit.getImage(relativeGfx+"dforeground.gif"); dparalax =toolkit.getImage(relativeGfx+"dparalax.gif"); dlandingPad =toolkit.getImage(relativeGfx+"dlandingpad.gif"); //Load nightime things nbackground =toolkit.getImage(relativeGfx+"nbackground.gif"); nforeground =toolkit.getImage(relativeGfx+"nforeground.gif"); nparalax =toolkit.getImage(relativeGfx+"nparalax.gif"); nlandingPad =toolkit.getImage(relativeGfx+"nlandingpad.gif"); //LoadRadar things rforeground =toolkit.getImage(relativeGfx+"rforeground.gif"); rparalax =toolkit.getImage(relativeGfx+"rparalax.gif"); rlandingPad =toolkit.getImage(relativeGfx+"rlandingpad.gif"); //Load the rest window =toolkit.getImage(relativeGfx+"window.gif"); slider =toolkit.getImage(relativeGfx+"slider.gif"); fuelgage =toolkit.getImage(relativeGfx+"fuelgage.gif"); fuelback =toolkit.getImage(relativeGfx+"fuelback.gif"); beacon =toolkit.getImage(relativeGfx+"beacon.gif"); dust =toolkit.getImage(relativeGfx+"dust.gif"); //Load the sprite animation blocks monitorScreenBlock=toolkit.getImage(relativeGfx+"monitorBlock.gif"); introPicBlock =toolkit.getImage(relativeGfx+"introBlock.gif"); digitsBlock =toolkit.getImage(relativeGfx+"digits.gif"); countDownBlock =toolkit.getImage(relativeGfx+"countDownBlock.gif"); lightBulbBlock =toolkit.getImage(relativeGfx+"lightBulbBlock.gif"); reportBlock =toolkit.getImage(relativeGfx+"reportBlock.gif"); tracker.addImage(dbackground,0); tracker.addImage(nbackground,1); tracker.addImage(dforeground,2); tracker.addImage(nforeground,3); tracker.addImage(rforeground,4); tracker.addImage(window,5); tracker.addImage(dparalax,6); tracker.addImage(nparalax,7); tracker.addImage(rparalax,8); tracker.addImage(fuelback,9); tracker.addImage(slider,10); tracker.addImage(fuelgage,11); tracker.addImage(fuelback,12); tracker.addImage(monitorScreenBlock,13); tracker.addImage(introPicBlock,14); tracker.addImage(digitsBlock,15); tracker.addImage(beacon,16); tracker.addImage(dust,17); tracker.addImage(countDownBlock,18); tracker.addImage(lightBulbBlock,19); tracker.addImage(dlandingPad,20); tracker.addImage(nlandingPad,21); tracker.addImage(rlandingPad,22); int numberLoaded=0; try { do{ numberLoaded=0; for(int ctr=0;ctr<14;numberLoaded+=tracker.checkID(ctr++)?1:0) drawProgressBar(numberLoaded,23); if(tracker.isErrorAny()) reportFatalError("Some resources could not be loaded.\nReinstall Mars Lander and try again!"); }while(!tracker.waitForAll(10)); }catch(Exception e){reportFatalError("Low level resource error:\n"+e.getMessage());}; tracker=null;System.gc(); drawProgressBar(1,1); declareSprites(); this.getContentPane().setBackground(new java.awt.Color(204, 204, 204)); this.setForeground(Color.lightGray); System.err.println("\nSuccess! Resources are loaded."); System.err.print("--------------------------------------------------------------------------------"); nextLanderPhase(); } //**********************************************************************************************// //If there is an error we can't fix, report it to the user and end private void reportFatalError(String error) { this.setBackground(Color.red); this.setSize(0,0); JOptionPane.showMessageDialog(null,error+"\nClick OK to end the program!","Mars Lander Fatal Error!", JOptionPane.ERROR_MESSAGE); System.exit(1); } //**********************************************************************************************// //Using the Images we've loaded, convert some of them into sprites... private void declareSprites() { monitorScreen=new Sprite(monitorScreenBlock,57,51,111,69,8,buffImage,this); introPic=new Sprite(introPicBlock,223,117,4,buffImage,this); countDown=new Sprite(countDownBlock,223,117,4,buffImage,this); lightBulb=new Sprite(lightBulbBlock,20,20,2,buffImage,this); report=new Sprite(reportBlock,224,117,2,buffImage,this); int[] kerning={11,7,12,11,13,11,12,12,14,12,15}; digits=new GraphicalDigits(digitsBlock,20,20,kerning,buffImage,this); digits.setNoKerningSpace(12); } //**********************************************************************************************// //Component initialization... private void jbInit() throws Exception { titledBorder1 = new TitledBorder(""); xYLayout1.setHeight(519); xYLayout1.setWidth(467); this.getContentPane().setLayout(xYLayout1); this.getContentPane().setBackground(new java.awt.Color(204, 204, 204)); this.setForeground(Color.lightGray); this.setTitle(" Mars Lander!"); jSlider1.setValue(0); jSlider1.setDoubleBuffered(true); jSlider1.addChangeListener ( new javax.swing.event.ChangeListener() { public void stateChanged(ChangeEvent e) { jSlider1_stateChanged(e); } } ); jButton1.setText("Start"); jButton1.addActionListener ( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } } ); jProgressBar1.setOrientation(JProgressBar.VERTICAL); jProgressBar1.setBorder(BorderFactory.createLoweredBevelBorder()); jProgressBar1.setDoubleBuffered(true); jProgressBar1.setOpaque(false); jLabel1.setFont(new java.awt.Font("Serif", 1, 20)); jLabel1.setBorder(BorderFactory.createLoweredBevelBorder()); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setHorizontalTextPosition(SwingConstants.CENTER); jLabel2.setBackground(Color.darkGray); jLabel2.setFont(new java.awt.Font("Dialog", 1, 20)); jLabel2.setForeground(Color.green); jLabel2.setBorder(BorderFactory.createEtchedBorder()); jLabel2.setOpaque(true); jLabel2.setHorizontalAlignment(SwingConstants.CENTER); jLabel2.setHorizontalTextPosition(SwingConstants.CENTER); jLabel2.setText("Mission OK!"); radar.setDoubleBuffered(true); radar.setOpaque(false); radar.setContentAreaFilled(false); radar.setBorder(null); radar.setHorizontalAlignment(SwingConstants.CENTER); radar.setFont(new java.awt.Font("Dialog", 1, 12)); jLabel3.setFont(new java.awt.Font("Dialog", 1, 12)); jLabel3.setText("RADAR"); this.getContentPane().add(jPanel1, new XYConstraints(61, 17, 360, 370)); this.getContentPane().add(jProgressBar1, new XYConstraints(35, 58, 24, 233)); this.getContentPane().add(jSlider1, new XYConstraints(90, 421, 265, -1)); this.getContentPane().add(jButton1, new XYConstraints(184, 418, 71, 29)); this.getContentPane().add(jLabel1, new XYConstraints(21, 451, 402, 32)); this.getContentPane().add(jLabel2, new XYConstraints(93, 390, 257, 23)); this.getContentPane().add(radar, new XYConstraints(355, 410, 21, 16)); this.getContentPane().add(jLabel3, new XYConstraints(374, 403, 55, 31)); } //**********************************************************************************************// //If the user wishes to quit, this method handles the dialog display and informs the //rest of the program. private boolean userIsQuiting() { int tempSlider=jSlider1.getValue(),option; System.err.print("--------------------------------------------------------------------------------"); System.err.println("Player wishes to quit,confirmation dialog box opening."); jSlider1.setValue(0); lander.pause(); missionTimer.pause(); _CLOSING=true; option=JOptionPane.showConfirmDialog(null,"Do you wish to end the program?","Closing Mars Lander!",JOptionPane.CANCEL_OPTION); System.err.print("--------------------------------------------------------------------------------"); System.err.println("Player dissmissed dialog box, so closing dialog box."); _CLOSING=false; jSlider1.setValue(tempSlider); missionTimer.resume(); lander.resume(); if(option==0) return(true); else return(false); } //**********************************************************************************************// //Overiden so we can exit on System Close protected void processWindowEvent(WindowEvent e) { if(e.getID()==WindowEvent.WINDOW_CLOSING) { if(userIsQuiting()) { System.err.print("--------------------------------------------------------------------------------"); System.err.println("Player has quit."); stylisedCloseWindow(); super.processWindowEvent(e); scoreTable.save(); System.exit(0); } } if(e.getID()==WindowEvent.WINDOW_ICONIFIED) { System.err.print("--------------------------------------------------------------------------------"); System.err.println("Game has been minimised, pausing."); sound.pause(); lander.pause(); missionTimer.pause(); stop(); this.setTitle(" PAUSED!"); } if(e.getID()==WindowEvent.WINDOW_DEICONIFIED) { System.err.print("--------------------------------------------------------------------------------"); System.err.println("Game has been restored, resuming."); start(); missionTimer.resume(); lander.resume(); sound.resume(); this.setTitle(" Mars Lander!"); } } //**********************************************************************************************// //Close window private void stylisedCloseWindow() { this.setForeground(new Color(0,0,0)); for(int c=0;c3000) fvalue=3000; fvalue=300-fvalue/10; if(radar.isSelected()) { bufferedImageHandle.clearRect(25,19,266,262); if(isDay) lightning.drawLightning(Lightning.RADAR,(int)-(fvalue*1.5)); bufferedImageHandle.drawImage(rforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(rparalax,200,(int)(1800-(fvalue*7)),this); if(asteroidOn) asteroids.drawAsteroids(AsteroidDisplay.RADAR); if(fvalue>220) bufferedImageHandle.drawImage(rlandingPad,0,(int)(5330-(fvalue*18)),this); } else { if(dustCloudOn) { if(isDay) { bufferedImageHandle.drawImage(dbackground,0,(int)-(fvalue*1.5),this); lightning.drawLightning(Lightning.NORMAL,(int)-(fvalue*1.5)); bufferedImageHandle.drawImage(dforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(dparalax,200,(int)(1800-(fvalue*7)),this); } else { bufferedImageHandle.drawImage(nbackground,0,(int)-(fvalue*1.5),this); bufferedImageHandle.drawImage(nforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(nparalax,200,(int)(1800-(fvalue*7)),this); } if(flash.getFlashIsOn()) bufferedImageHandle.drawImage(beacon,205,(int)(1882-(fvalue*7)),this); int fogLevel=(int)(1880-(fvalue*7)); if(fogLevel<-150) fogLevel=-150; if(asteroidOn) asteroids.drawAsteroids(AsteroidDisplay.NORMAL); bufferedImageHandle.drawImage(dust,-dustXPos,fogLevel,this); if((dustXPos+=5)==300) dustXPos=0; } else //Dust cloud is off... { if(isDay) { bufferedImageHandle.drawImage(dbackground,0,(int)-(fvalue*1.5),this); lightning.drawLightning(Lightning.NORMAL,(int)-(fvalue*1.5)); bufferedImageHandle.drawImage(dforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(dparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(dlandingPad,0,(int)(5330-(fvalue*18)),this); if(flash.getFlashIsOn()) bufferedImageHandle.drawImage(beacon,205,(int)(1882-(fvalue*7)),this); } else { bufferedImageHandle.drawImage(nbackground,0,(int)-(fvalue*1.5),this); bufferedImageHandle.drawImage(nforeground,10,(int)(820-(fvalue*2.8)),this); if(fvalue>220) bufferedImageHandle.drawImage(nparalax,200,(int)(1800-(fvalue*7)),this); if(fvalue>220) bufferedImageHandle.drawImage(nlandingPad,0,(int)(5330-(fvalue*18)),this); if(flash.getFlashIsOn()) bufferedImageHandle.drawImage(beacon,205,(int)(1882-(fvalue*7)),this); } if(asteroidOn) asteroids.drawAsteroids(AsteroidDisplay.NORMAL); } } bufferedImageHandle.drawImage(fuelback,16,307,this); bufferedImageHandle.drawImage(fuelgage,-28-(int)((500-lander.getFuel())/1.8),308,this); bufferedImageHandle.drawImage(window,0,0,this); bufferedImageHandle.drawImage(slider,322,20+(int)(fvalue*0.85),this); updateAnimation(); jPanel1ImageHandle.drawImage(buffImage,0,0,this); } //**********************************************************************************************// //This method updates the intro display, either the High Score table, or the credits public void updateIntroDisplay() { if(highScores) updateHighScoreDisplay(); else updateIntroScaledDisplay(); } //**********************************************************************************************// //This method updates the High Score display public void updateHighScoreDisplay() { if((highScoreYPos+=2)>=520) { highScoreYPos=0; highScores=false; return; } bufferedImageHandle.drawImage(dbackground,0,0,this); bufferedImageHandle.drawImage(dforeground,10,0,this); bufferedImageHandle.drawImage(dparalax,200,0,this); if(flash.getFlashIsOn()) bufferedImageHandle.drawImage(beacon,205,82,this); if(highScoreYPos<100) { bufferedImageHandle.setColor(new Color(0,0,0,(int)(highScoreYPos*2.55))); } else { bufferedImageHandle.setColor(new Color(0,0,0,255)); } if(highScoreYPos>420) { bufferedImageHandle.setColor(new Color(0,0,0,(int)((100-(highScoreYPos-420))*2.55))); } bufferedImageHandle.fillRect(25,19,266,262); double alp=highScoreYPos+480; alp=Math.sin((alp/1.4)/180.0*Math.PI); alp=Math.abs(alp*255); int alpa=(int)(alp%256); bufferedImageHandle.setColor(new Color(0,alpa,0)); bufferedImageHandle.drawString("HIGH SCORES!",75,300-highScoreYPos); for(int y=0;y<10;y++) { alp=highScoreYPos+(20-y)*20+60; alp=Math.sin((alp/1.4)/180.0*Math.PI); alp=Math.abs(alp*255); alpa=(int)(alp%256); bufferedImageHandle.setColor(new Color(0,alpa,0)); bufferedImageHandle.drawString( scoreTable.getScore(y), //The string to draw, eg "AAA---123" 160-scoreTable.getScorePixelLength(y)/2, //The X pos, in this case centered in window (325-highScoreYPos)+y*20); //The Y pos,using the scores place in the // table and the overall table offset } bufferedImageHandle.drawImage(fuelback,16,307,this); bufferedImageHandle.drawImage(window,0,0,this); bufferedImageHandle.drawImage(slider,322,20,this); updateAnimation(); jPanel1ImageHandle.drawImage(buffImage,0,0,this); } //**********************************************************************************************// //This method updates the Credits display public void updateIntroScaledDisplay() { double scale,alph; bufferedImageHandle.drawImage(dbackground,0,0,this); bufferedImageHandle.drawImage(dforeground,10,0,this); bufferedImageHandle.drawImage(dparalax,200,0,this); bufferedImageHandle.drawImage(fuelback,16,307,this); if(flash.getFlashIsOn()) bufferedImageHandle.drawImage(beacon,205,82,this); intro.updateZoom(); if(intro.getImageNumber()==4) { intro.resetZoom(); highScores=true; return; } scale=intro.getScaling(); if(intro.getDirection()==Zoom.OUT) { alph=1+(double)(1.2-(1.2*scale)); for(double a=alph;a>=1.0;a-=.05) introPic.drawSprite(165-(int)(115*(scale/a)),140,scale/a, scale/a,intro.getImageNumber()); } introPic.drawSprite(165-(int)(115*scale),140,scale, scale,intro.getImageNumber()); bufferedImageHandle.drawImage(window,0,0,this); bufferedImageHandle.drawImage(slider,322,20,this); updateAnimation(); jPanel1ImageHandle.drawImage(buffImage,0,0,this); } //**********************************************************************************************// //This method updates the Countdown display public void updateCountdownDisplay() { double scale,alph; if(isDay) bufferedImageHandle.drawImage(dbackground,0,0,this); else bufferedImageHandle.drawImage(nbackground,0,0,this); if(isDay) lightning.drawLightning(Lightning.NORMAL,0); bufferedImageHandle.drawImage(fuelback,16,307,this); for(int acc=0;acc<3;acc++) { if(!_CLOSING) countdown.updateZoom(); if(countdown.isStartedPausing()&&soundItems[0].isSelected()) { switch(countdown.getImageNumber()) { case 0: say3.play();break; case 1: say3.stop();say2.play();break; case 2: say2.stop();say1.play();break; case 3: say1.stop();sayGo.play();break; } } } if(countdown.getImageNumber()==4) {sayGo.stop();nextLanderPhase();lightning.reset();return;} scale=countdown.getScaling(); if(countdown.getDirection()==Zoom.OUT) { alph=1+(double)(2-(2*scale)); for(double a=alph;a>=1.0;a-=.1) countDown.drawSprite(165-(int)((115*(scale/a))+((a-1)*40)),140,scale/a, scale/a,countdown.getImageNumber()); countDown.drawSprite(165-(int)(115*scale),140,scale, scale,countdown.getImageNumber()); } else { countDown.drawSprite(85-(int)((115*scale)+((scale-2)*80)),140,scale, scale,countdown.getImageNumber()); } bufferedImageHandle.drawImage(window,0,0,this); bufferedImageHandle.drawImage(slider,322,20,this); updateAnimation(); jPanel1ImageHandle.drawImage(buffImage,0,0,this); } //**********************************************************************************************// //The following are the user triggered events recognised by the game. //Menu and System control events are handled elsewhere. //**********************************************************************************************// //**********************************************************************************************// //This method is called when the Dynamic Thrust Control (Slider) is moved void jSlider1_stateChanged(ChangeEvent e) { int value=jSlider1.getValue(),red,green,blue; thrust=value; lander.setThrust(thrust); if(lander.getFuel()<1.0) return; jProgressBar1.setValue(value); red=(int)(value*2.55); green=(int)((100-value)*2.55); blue=0; jProgressBar1.setForeground(new Color(red,green,blue)); } //**********************************************************************************************// //This method is called when the Start/Play Button is pressed. void jButton1_actionPerformed(ActionEvent e) { //lander phases -1, 1 and 2 are automatically terminated, and can't be overiden by the user if((landerPhase==0)||(landerPhase==3)) nextLanderPhase(); } }//End of class scope