Greenfoot Asteroids Mrs. C. Furman August 16, 2010.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Chapter 3 – Fundamental Statements
Getting to know Greenfoot
Games and Simulations O-O Programming in Java The Walker School
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Chapter 2 - The First Program: Little Crab
Program: Little Crab Mr Gano.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Wombats Creating Games with Greenfoot The Walker School – Games and Simulations
Chapter 1 - Getting to know Greenfoot Bruce Chittenden.
Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
1 Programming Week 2 James King 12 August Creating Instances of Objects Basic Java Language Section.
Chapter 12 Java Code Examples Showing Problem Domain Classes.
Start by reading the first three Typing Tips.
Using the Unity 98 Cordless Response System Directions : Courtesy of IHC public relations.
Games and Simulations O-O Programming in Java The Walker School
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Created by NW 2012 – please note all copyright on images used is property of copyright holder. Note: some of the more complicated descriptions are taken.
05/09/ Introducing Visual Basic Sequence Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Game Maker Day 2 Making a Maze Game.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Chapter 1 - Getting to know Greenfoot
Chapter 02 (Part III) Introduction to C++ Programming.
Chapter 6 – Interacting Objects: Newton’s Lab. topics: objects interacting with each other, using helper classes, using classes from the Java library.
CMPS 1371 Introduction to Computing for Engineers MatLab.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Greenfoot Game Programming Club.
Game Maker – Getting Started What is Game Maker?.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Constructors & Garbage Collection Ch. 9 – Head First Java.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Advanced Stuff Learning by example: Responding to the mouse.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Introduction To Greenfoot
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
Basic Syntax อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 2.
JAVA CLASSES, METHODS AND VARIABLES.  Defined Noun: A set or category of things having some property or attribute in common and differentiated from others.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Newton’s Lab Games and Simulations O-O Programming in Java.
Chapter 4 - Finishing the Crab Game
Chapter 4 - Finishing the Crab Game
A variable is a name for a value stored in memory.
Class Inheritance Part I
Game Maker Intro to Programming Game Maker Pop Quiz (Both Groups)
Java Unit 11: Inheritance I
Can perform actions and provide communication
The Little Crab Scenario
Can perform actions and provide communication
Unit-1 Introduction to Java
Games and Simulations O-O Programming in Java The Walker School
Can perform actions and provide communication
Classes and Objects Still Chapter 1.
Introduction to Object-Oriented Programming in Alice
Game Maker Intro to Programming Game Maker Pop Quiz (Both Groups)
Greenfoot November 8, 2009.
Running a Java Program using Blue Jay.
1.7 A Second Example.
Presentation transcript:

Greenfoot Asteroids Mrs. C. Furman August 16, 2010

Open Asteroids Open Greenfoot. Open Scenario, “asteroids1” in the chapter01 folder in book scenarios.

Class Diagram In Greenfoot, you always have a World class. Space is a specific class made for this scenario World Classes

Inheritance In greenfoot you always a more specific class under World. The arrow between the class represents an is-a relationship. Space is-a World. Space is a subclass of World.

More on World When we open a scenario, greenfoot automatically creates an object of the World subclass, in this case Space. That is why the black screen automatically pops up.

Actor Classes Under the World classes is the set of Actor classes. How many subclasses of Mover are there? What are the subclasses of Actor?

Subclass Bullet, Rocket, and Asteroid are subclasses of Mover Explosion and Mover are subclasses of Actor While Bullet, Rocket and Asteroid are all subclasses of Mover as well as Actor, but are NOT subclasses of Explosion

Subclass and Superclass Superclasses – these classes are less specific Subclasses – these classes inherit the traits of the superclass, and then expands on them. Subclasses are BIGGER than Superclasses.

Other Classes Vector – helper class We can not place objects of it into the World.

Playing with Asteroids We can only create objects of classes that do not have subclasses. Which classes can we create objects for? Place objects into the World, then click run. Use the arrow keys to move your spaceship and space bar to fire shots.

Exercise 1 After you’ve played the game for a little bit. Lets tweak it! Invoke the setGunReloadTime method and set the reload time to 5. Then play again.

Exercise 2 Stop the execution by pressing pause. Find out how many shots you have fired. Invoke a Rocket method.

Exercise 3 You will notice that the rocket moves a bit as soon as you place it into the World. What is its initial speed?

Exercise 4 Asteroids have an inherent stability. Each time they get hit by a bullet, their stability decreases. When it reaches zero, they break up. What is their initial stability value after you create them?

Exercise 4B By how much does the stability decrease from a single hit by a bullet? Just shoot an asteroid once, and then check the stability again.

Constructors Asteroids have 2 constructor methods Constructors are used to set up the object. new Asteroid() – called a default constructor. Sets it to a default size new Asteroid(int size) – allows us to set the size of the Asteroid by passing an integer.

Exercise 5 Make a very big asteroid. Make a very small asteroid.

Variables In Java, we often want to store values. We see this in our gun speed. We used setGunReloadTime and passed a value in order to be saved by the variable speed. These values are stored in variables.

Variable names… Identifiers When we name a variable we need to use a “proper identifier”. Here are the rules for proper identifiers: Must start with a letter. As a convention, it starts with a lowercase letter Must contain only numbers, letter or underscores Must not be a keyword. Like new.

Java is Case Sensitive Java is what we call case sensitive. Which means that it distinguishes between upper and lower case letters differently.

Assignment Statements We can assign values to our variables with assignment statements. Variable has to be on the left, value you are giving to the variable is on the right. variable = 8; Variable Name Value that is being given to the variable Assignment Operator

Source Code Behavior of each Object is defined by its class. Source code – the code that specifies all the details about a class and its objects. Select Open editor for the Rocket class, or double click on the Rocket class to open the source code.

Rocket Source Code We can change the reload speed on all Rockets in the source code. Change getReloadTime to 5. Recompile.