1 / 71

Asteroids

Asteroids. Games and Simulations O-O Programming in Java The Walker School. The Walker School – Games and Simulations - 2010. Asteroids. Take some time to play with Asteroids. What can the program do and what can’t it do?. The Walker School – Games and Simulations - 2010.

nemo
Télécharger la présentation

Asteroids

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations - 2010

  2. Asteroids Take some time to play with Asteroids. What can the program do and what can’t it do? The Walker School – Games and Simulations - 2010

  3. Discovering Keyboard Controls Which keyboard key is used to fire a bullet? The Walker School – Games and Simulations - 2010

  4. Explosions Place an explosion into a running scenario. Does it work? What does it do? The Walker School – Games and Simulations - 2010

  5. Painting Stars The Walker School – Games and Simulations - 2010

  6. Create a New Scenario • Directions • Create a new scenario. • Save it as “asteriods-lastname”. The Walker School – Games and Simulations - 2010

  7. Create the World • Directions • Create a new subClass called “Space”. • Leave the background empty. The Walker School – Games and Simulations - 2010

  8. Enlarge the Background • Directions: • Change the size of the world (600, 400, 1). • Change the comment. The Walker School – Games and Simulations - 2010

  9. Painting Backgrounds Part IV - http://www.youtube.com/watch?v=rvZ0ErpfHKM&feature=related The Walker School – Games and Simulations - 2010

  10. Import the Java Color Library The Walker School – Games and Simulations - 2010

  11. Use Java to Paint Black Background The Walker School – Games and Simulations - 2010

  12. Create a method createStars() Comment it out until we create the method. The Walker School – Games and Simulations - 2010

  13. Create a Method Body Takes a parameter of type integer, as we stated we wanted 300 stars. The Walker School – Games and Simulations - 2010

  14. Create The Stars Step through this loop and explain what is happening. The Walker School – Games and Simulations - 2010

  15. For Loops for (initialization; loop-condition; increment) { loop-body; } • The initialization part declares and initializes a loop variable. This variable is often called i, and often initialized to 0. • The loop condition checks whether our loop variable is still less than a given limit. If it is, the loop will continue. • The increment section simply increments the loop variable. The Walker School – Games and Simulations - 2010

  16. Vary Star Brightness The Walker School – Games and Simulations - 2010

  17. Rocket Firing The Walker School – Games and Simulations - 2010

  18. Turning The Walker School – Games and Simulations - 2010

  19. Flying Forward The Walker School – Games and Simulations - 2010

  20. Flying Forward Calls the move() method from SmoothMover class. What happens? The Walker School – Games and Simulations - 2010

  21. What Do We Need To Do? So where are we going to do this? • Add initial movement to the rocket. • To add movement, we need to add force to the rocket. • And we need to change its vector. • So we’ll need to call this vector from the Vector abstract class. • The vector needs 2 variables: direction (dy) and length (dx). The Walker School – Games and Simulations - 2010

  22. Adding Drift What happens when you change the variables in the vector? The Walker School – Games and Simulations - 2010

  23. What Do We Need To Do? • Create variables to handle each rocket image. • Add a method called ignite to checkKeys(), so that we when hit the “up” button, the rocket image is changed. • Define a method called ignite. It will need a boolean parameter and a void return type. The Walker School – Games and Simulations - 2010

  24. Create a Method Stub to Ignite Rocket Remember to create an instance variable called boosterOn. The Walker School – Games and Simulations - 2010

  25. Igniting the Rocket Boosters The Walker School – Games and Simulations - 2010

  26. Colliding with Asteroids The Walker School – Games and Simulations - 2010

  27. What Do We Need to Do? • If we collide with an asteroid, • Remove the rocket from the world; • Place an explosion into the world; • Show final score (game over); The Walker School – Games and Simulations - 2010

  28. Methods for Collision Detectionfile:///C:/Greenfoot/doc/API/index.html Both methods accept a parameter of type Class, which means we can check for intersections with a specific class of objects if we want to. Which of these 2 methods do we want to use and why? The Walker School – Games and Simulations - 2010

  29. Colliding with Asteroids Remember to call the method in the rocket act() method. The Walker School – Games and Simulations - 2010

  30. Creating Better Explosions • Part I - http://www.youtube.com/watch?v=rgZ-_vQ2aIc • Part II - http://www.youtube.com/watch?v=bdv4ZgTcYyY&feature=related • Part III - http://www.youtube.com/watch?v=OFuDEt0xifM&feature=related • Part IV - http://www.youtube.com/watch?v=XMJi4_bzuLw&feature=related • Part V - http://www.youtube.com/watch?v=TKYwL8p_11A&feature=related The Walker School – Games and Simulations - 2010

  31. What Do We Need To Do? • Add abstract classes SmoothMover and Vector from Greenfoot. • Create a constructor for Debris • Update the move() method

  32. Casting The Walker School – Games and Simulations - 2010

  33. Create the Score Board The Walker School – Games and Simulations - 2010

  34. Import Java Libraries The Walker School – Games and Simulations - 2010

  35. Create the Assignment Variables The Walker School – Games and Simulations - 2010

  36. Create the Constructors Why are their 2 constructors? How is this an example of overloading? The Walker School – Games and Simulations - 2010

  37. Make Scoreboard Image So, what else needs to be done? The Walker School – Games and Simulations - 2010

  38. Activity – Change Attributes • Modify the ScoreBoard class: • Change the text shown on it. • Change the color of the text. • Change the background and frame colors. • Change the font size so that your text fits well. • Change the width of the scoreboard to suit your text. The Walker School – Games and Simulations - 2010

  39. Homework – Scoreboard • Search the Greenfoot library for other games that have scoreboards. Study how they were built. What attributes do they have that this board does not? What could you add to your scoreboard? The Walker School – Games and Simulations - 2010

  40. Add a Variable for the Counter The Walker School – Games and Simulations - 2010

  41. Assign the Counter to the Constructor The Walker School – Games and Simulations - 2010

  42. Call the Counter When Game Over How can you make sure that the counter is in the middle of the board without hard coding the numbers? The Walker School – Games and Simulations - 2010

  43. Ensure the Scoreboard is in the Middle of the Background Where do we call the gameOver() method? The Walker School – Games and Simulations - 2010

  44. Call the Game Over Method Example of Casting The Walker School – Games and Simulations - 2010

  45. Casting • Casting is the technique of telling the compiler a more precise type for our object then it can work out for itself. We do this by writing the class name (Space) in parentheses before the method call. Once we have done this we can call methods defined in Space • space.gameOver(); Casting does not change the type of the object returned. The Walker School – Games and Simulations - 2010

  46. Add a Proton Wave What does it do? What doesn’t it do? The Walker School – Games and Simulations - 2010

  47. Import the Library We are going to need the Java List class because we are going to create a list of images to create a proton wave that increases in size. The Walker School – Games and Simulations - 2010

  48. Assign Variables How do we make the wave grow? The Walker School – Games and Simulations - 2010

  49. Add A List (Array) to Store Image Set How many images will this list store? The Walker School – Games and Simulations - 2010

  50. Create a Constructer for the Wave The Walker School – Games and Simulations - 2010

More Related