lander example
play

LANDER EXAMPLE Fundamentals of Computer Science I Outline - PowerPoint PPT Presentation

OBJECT ORIENTED DESIGN: MARS LANDER EXAMPLE Fundamentals of Computer Science I Outline Approach Find: Objects Instance variables Methods Refine: Instance variables Methods Implementation (Code) 2 What are the


  1. OBJECT ORIENTED DESIGN: MARS LANDER EXAMPLE Fundamentals of Computer Science I

  2. Outline • Approach – Find: • Objects • Instance variables • Methods – Refine: • Instance variables • Methods – Implementation (Code) 2

  3. What are the Nouns? You are an astronaut on the first ever manned mission to Mars. Your auto-pilot computer (running Windows 2037 Hyper Mega Ultimate) has just given you the blue screen of death. Rebooting is going to take awhile, so it's up to you to pilot your ship to a soft landing in the only safe spot around. You have a limited amount of fuel and once that runs out, you are at the mercy of gravity! Spaceship controls: w - bottom thrusters (slows the ship's descent) d - left thrusters (makes the ship go more to the right) a - right thrusters (makes the ship go more to the left) You should start by downloading the file lander.zip. This file contains some example control files and the associated images/sounds. These files will need to be in the same directory where you run your program. Gravity and thrusting. Your program will need to track the current horizontal and vertical position of the ship (let's call the positions posX and posY). You also need to store a velocity composed of an horizontal component velX and a vertical component velY. Both velocities start at 0. At every time step of the game, the gravity term from the control file is added to velY. If the user uses activates the bottom thrusters, the thrust amount from the control file is added to velY. Similarly, the left and right thrusters should change velX. Whenever thrust is applied, the thruster sound should be played and the ship picture updated to the appropriate version. Using any thruster causes the amount of fuel to be reduced by one. The current fuel remaining should be display in the upper-left corner. After updating the velocities, the current position of the ship must be changed. This is achieved by simply adding velX to posX and adding velY to posY. Note that it is possible for the ship to go off the top or sides of the screen. The ship can still be hopefully piloted back toward the landing pad. But of course an off screen ship can still hit the ground! Landing and crashing. Your ship has landed or crashed when the bottom landing pads reaches (or goes below) the y-coordinate of 0. If your landing pads have reached the bottom and either velX or velY is greater than the maximum survivable velocity. Your ship has also crashed if its bottom thrusters are not completely inside the x-coordinates of the landing pad. If you land successfully, you should display the ship landed picture and play the good landing sound. If you crash and burn, you should display the ship crashed picture and play the bad landing sound. After landing or crashing, the game is over and no further updates are performed. The location of the landing pad is read in from the file with a center and a "radius". The height of the pad should be 10 pixels. 3

  4. Objects • Spaceship • Planet • Obstacle • Landing Pad • Game

  5. Instance Variables? Your program MarsLander.java should read in a game control file from a text file as described in lecture 11. Here is an example game control file with comments at the end describing the order and meaning of the values: 1000 500 mars_sky.jpg ship.png ship_bottom.png ship_left.png ship_right.png ship_landed.png ship_crashed.png 20 50 500.0 400.0 100 thrust.wav yay.wav explosion.wav -0.1 2.0 0.5 500 50 # An easy game setup, you start directly above a large pad and have plenty of fuel. # Background image is from one of the NASA Mars rovers. # # Description of values: # <width in pixels> <height in pixels> # <background image> # <normal ship image> <bottom thrusters> <left thrusters> <right thrusters> <ship landed> <ship crashed> # <horizontal distance, ship center to edge of thrusters> <vertical distance, ship center to bottom edge of thrusters> # <ship starting x> <ship starting y> # <starting fuel> # <thruster sound> <good landing sound> <bad landing sound> # <gravity term> # <maximum survivable velocity> # <thrust amount> # <landing pad x center> <distance from center of landing pad to edge>

  6. Instance Variables • Spaceship • rate of fuel expenditure • velocity x • velocity y • fuel • dimension - horizontal • dimension - vertical • position x • position y • maximum survivable velocity • crashed? • sounds • images • thrust

  7. Instance Variables • Planet • gravity • Obstacle • dimensions • LandingPad • image • windFactor/weather (?)

  8. Instance Variables • Obstacle • location • dimensions • image? • Landing Pad (extends Obstacle) • Game • gameOver

  9. Methods • Spaceship • controls (move) • draw • collisionDetection • useFuel • constructor • getters • setters • toString • equals

  10. Methods • Planet • constructor • getters • setters • toString • equals • draw • LandingPad • draw • the 5 general methods

  11. Methods • Obstacle • constructor • getters • setters • toString • equals • draw • Game • readFile

  12. Starting Implementation: Spaceship Constructor public void Spaceship(String file) { // read in all instance variable information from file }

  13. Summary • Approach • Find: • Objects • Instance variables • Methods • Refine: • Instance variables • Methods • Implementation (Code)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend