Programming games Classes and objects (used for Jigsaw, Bouncing stuff, other projects) Homework: Complete cannonball. Video or Audio. Your own project.

Slides:



Advertisements
Similar presentations
1What is the Stage. 2How do you open a panel in Flash
Advertisements

1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
CS 106 Introduction to Computer Science I 03 / 19 / 2008 Instructor: Michael Eckmann.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Programming games Flash drawing trick(s). Rock paper scissors. Classwork: Complete rock paper scissors.
Writing Classes (Chapter 4)
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
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.
Programming games Flash drawing trick(s). Past due: Your completion of rock-paper-scissors) Classwork: Bouncing ball: read tutorial. Start coding.
Programming games Reflection Bouncing things, Memory Server-side: Survey. ActionScript 2 examples. Homework: Finish Video or Audio. Post proposal for your.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Programming Games Preview Video & Audio. Work on cannonball. Homework: finish cannonball!
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Building the Events Components– Lesson 111 Building the Events Components Lesson 11.
Programming games Problems. Schedule Various examples. Homework: rps, bo (don't go back to do this), cannonball, Video or Audio should be complete. Now.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
XP Tutorial 7 Creating a Flash Web Site. XP New Perspectives on Macromedia Flash 82 Objectives Plan and create a Flash Web site Create a Flash template.
Programming games Cannonball due. Drawing & printing example. Acquiring video or sound Homework: Catch up: complete projects (rps, Bo, cb). Start video.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
Computer Science I Variables. Methods. Classwork/Homework: Re-do or do new drawing using variables & function(s). Zip folder and upload to Moodle dropbox.
Programming Games Reprise: radio buttons. Creating instances at runtime. Buttons. Present your sound or video. Final project assignment. Homework: [Catch.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
Chapter 1 Object Orientation: Objects and Classes.
Lecture 5:Interfaces and Abstract Classes
Creating a Flash Web Site
Learning to Program D is for Digital.
Classwork: Examine and enhance falling drop(s) or make your own.
Computer Science I Variables. Methods.
More About Objects and Methods
Introduction to Classes
Chapter 4: Writing Classes
Namespaces, Scopes, Access privileges
Microsoft Windows 2000 Professional
Chapter 13 Abstract Classes and Interfaces
Programming Games Computer science big ideas and Computer Science jargon: review of things we have used in examples. Show virtual dog Homework: [Catch.
Object Based Programming
Introduction to Classes
Chapter 6 Methods: A Deeper Look
MSIS 655 Advanced Business Applications Programming
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Chapter 12 Abstract Classes and Interfaces
Advanced Java Programming
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Tonga Institute of Higher Education
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Object Oriented Programming in java
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Programming games Demonstrate cannonball
Classes CS 21a: Introduction to Computing I
Programming games Share your plans for your virtual something.
Review of Previous Lesson
University of Warith AL-Anbiya’a
Review of Previous Lesson
Chapter 9 Introduction To Classes
Chapter 8 Objects and Classes Part 2
Web Programming and Design
Classes and Objects Object Creation
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
SPL – PS3 C++ Classes.
Presentation transcript:

Programming games Classes and objects (used for Jigsaw, Bouncing stuff, other projects) Homework: Complete cannonball. Video or Audio. Your own project.

General motivation Writing code is hard! It is nice if there is a systematic way to re-use code that works! Languages have various features to do this. For a single application: One way is to write a function that can be called (invoked) from multiple places. the function's parameters can be used for information For one or more applications, other ways involve setting up multiple files.

Objects: Built-in The MovieClip symbols that you create in the Library and move instances of to the Stage are objects. Button component is an object recall the label attribute/property Strings of characters are objects. Timers are objects. These objects have attributes (aka properties, data) and have methods (code) target.gotoAndPlay(2);

Programmer defined objects You/programmers can define your own objects. You do this by coding a Class definition. This is done in a separate file, file extension .as for ActionScript. Class definitions define the data (properties=data=attributes) and the behavior (code=methods=functions) for the objects.

Examples Several examples on my page, including bouncing things jigsaw shooter state capitals quiz

Bouncing things Looking at the program, there must be opportunity for common (shared) code in the stars, rectangles, circles But there are differences. Flash ActionScript (and many other languages) have feature of building class definitions based on other class definitions to do this.

NOTE In the past, students were assigned the Jigsaw application. This used programmer defined classes, using external .as files. A package called jigsaw containing one class definition for Piece. Folder named jigsaw, file in the folder called Piece.as This gives you preview/preparation for larger ActionScript projects You may do [a] jigsaw for your final project. You may do bouncing stuff ?

document class You can put code in an [external] .as file without a package name. This is called the Document class. You make a pointer to this in the .fla file. AND/OR You put code in one or more .as files and put them all in a folder. The name of a folder is the package name. Suppose it is jigsaw. In the .fla file, you put in a statement import jigsaw.*;

Package, class, object A Class definition defines objects of the class Data (attributes, properties) Code (methods) A Class file [for example, Piece] is contained in a package [for example, jigsaw] NOTE: the jigsaw package only has one class (one file) Note: the convention is to make the name of a class start with a capital letter.

constants The modifier const indicates that something will not be changed once it is initialized internal static const ROTUNIT=15; The internal means it is only used by code in the package. The static means just one copy exists, not one for each Piece I regret this use of the word STATIC since it does not mean that it cannot change which is the meaning in STATIC text fields as well as the English meaning of term. I'll repeat this in later slide. The const means it will not be changed It is convention (considered a good practice) to give constants a name in capital letters.

Declarations The var and const terms are used to define variables and constants Associate names with values The term after the : indicates the datatype. internal var offsetx:Number = 0; internal var mclip:MovieClip;

Class data & methods (repeat) A Class definition also can include variables for the whole class and methods for the whole class The term static is used to indicate a class variable or method. THESE CAN CHANGE. The static means there is just one of them. YES, THIS ISN'T A GOOD TERM. Example: Math has the constant PI and Math has the methods: random and floor Example: Piece has variables pieces, dragging, and methods: buildit, mixup, and checkit.

Constructor method The constructor method is the one with name the same name as the Class. It is called when the term new is used. It builds (constructs) the object.

The pieces array Jigsaw keeps an array of all the Piece objects created. In the Piece method (this is the thing being constructed), there is a statement Piece.pieces.push(this); The push adds the piece being built (indicated by the built-in term this) to the single pieces array. One array 'holds' references to all the jigsaw pieces.

The import statement The .fla file has an import statement to bring in the jigsaw package. import jigsaw.*; Again, there is just one class in jigsaw. The Piece.as file has import statements to bring in the necessary parts of ActionScript. import flash.display.*; import flash.events.*; import flash.ui.Keyboard;

About import The import statement means you can use a shorter form of name for these built-in elements. If you forget to include it, the error statements are pretty suggestive that you left something out. Go to help and see what package is required.

Modifiers In ActionScript, you can specify what code can access variables and methods. The modifier public means … any code can. The modifier internal means … only code in the package. The modifier private means … only code in the class.

Why not… Make everything public so no restriction? [You can do this…] Putting in the other modifiers provides an extra level of checking assuming you are thinking things out. The default is internal. If you want a variable or method defined in the class definition in the .as file to be accessed by frame code in the .fla file, then you need to make it public

Reminder The real need and power of object-oriented programming in ActionScript, Java, etc., is for Large projects Many programmers HOWEVER, it also serves us for Jigsaw because all the code in the .as file will work for any jigsaw. Your work to make each jigsaw puzzle (getting an image, slicing it up, calculating the offsets) is in the .fla! Put this another way: write one Piece.as file, and use it for any or all jigsaw puzzles! Note: this is all part of ActionScript 3.0

Piece.as package jigsaw { import statements public class Piece { static var statements var statements public function Piece( ) { } internal function startdragging(ev) { } … public static function buildit() { } }

Folder location The Piece.as file is located in a folder called jigsaw in a folder called as3 (the last name is mine—you can change it). You must use Publish Settings to set the Classpath. It appears that as3 must be the first folder on a drive AND the drive must also contain the .fla file (though it can be anywhere on that drive). See extra tutorial on this topic.

Strong recommendation if you want to do Jigsaw (or bouncing stuff) Print out the whole tutorial and read away from the computer. Do not [just] copy and paste code Much of the code is repeated and shown out of order Review the coding in outline form and then study the details. Write the code in outline form and then fill in the details.

Classwork/homework Work session Finish cannonball and start video/audio project Confer with me on what you are doing Last project is totally your choice. You can build on sample projects.