programming games another sound example general review homework: [finish project], look over study...

36
Programming games Another sound example General review Homework: [finish project], look over study guide

Upload: evangeline-copeland

Post on 29-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Programming games Another sound example General review Homework: [finish project], look over study guide

Programming games

Another sound example General review

Homework: [finish project], look over study guide

Page 2: Programming games Another sound example General review Homework: [finish project], look over study guide

Files

• Giving your user a way to download a file

• I did this by adding on to the playing sound file example. IT CAN BE ANY FILE!

• Need to test this on the server, but you can look at the source code (the .fla file)

• I did NOT put in code to monitor the process and report back errors!!!

Page 3: Programming games Another sound example General review Homework: [finish project], look over study guide

from the codevar downloadURL:URLRequest;

var fileName:String = lastplayed;

var file:FileReference;

downloadURL = new URLRequest();

downloadURL.url = lastplayed;

file = new FileReference();

file.download(downloadURL, fileName);

Page 4: Programming games Another sound example General review Homework: [finish project], look over study guide

Jargon

• There IS jargon in computing. It pays to learn it.

• The jargon is [mostly] English words with somewhat more specific meaning.

• Examples:– Event & event handling– Function– Variable– Instance

Page 5: Programming games Another sound example General review Homework: [finish project], look over study guide

Comment

• Much of jargon is common to other computer languages

• You have seen similarities in syntax between JavaScript and ActionScript

• Note: ActionScript 3.0 actually is MORE like Java than JavaScript– Strong-typing– import

Page 6: Programming games Another sound example General review Homework: [finish project], look over study guide

Building an application

• Planning• Design• Choosing technologies

– This is NOT part of most college courses, but may be something you will need to do

– Most projects are part of / relate to other projects

• Implementation• Testing• Refinement• Distribute / deliver / install

This is called the waterfall model. Real process may not be so neat.Constant iteration.

Page 7: Programming games Another sound example General review Homework: [finish project], look over study guide

More…• Most projects are team projects• But…don't specialize / limit what you want to

learn & practice• Most of my other courses feature team work.

– Last Fall, maybe Fall 2011: Creating Databases for Web Applications

– Now: Robotics: Spring 2010– Creating User Interfaces: Spring 2011

Note: Computability: Fall 2010

Page 8: Programming games Another sound example General review Homework: [finish project], look over study guide

Creating games: general

• Prepare 'board'– static material– dynamic material

• things that move• things that change

• Define (internal) information– variables

• strings, numbers, booleans. • arrays• objects (properties and methods)

• Implement player moves & other action– identify/define events and program event handlers

• include random (stochastic) elements– implement logic of game

Page 9: Programming games Another sound example General review Homework: [finish project], look over study guide

Creating games: Flash

Prepare board• Prepare symbols

– graphics– instances– buttons

• Prepare stage– move instances of symbols & components to stage

• this may be 'off-stage', to be re-positioned by code– draw directly on stage (including moving graphic

symbols to stage)– text fields on stage

• static, dynamic, input

Page 10: Programming games Another sound example General review Homework: [finish project], look over study guide

Creating games: Flash

Define (internal) information• variables

– global variables: defined outside of functions, in main movie and

– local variables: variables defined in functions– variables in instances

• programmer defined. See next.

– Datatypes: strings, numbers, booleans– Composite types: arrays, objects

Page 11: Programming games Another sound example General review Homework: [finish project], look over study guide

Creating Games: Flash

• Determine built-in classes (coding) to be used– For example: playback of video

• Determine what classes YOU have written previously can be re-used– Piece.as can be used for any jigsaw!

• Determine what new classes are to be defined– External .as file(s)

Page 12: Programming games Another sound example General review Homework: [finish project], look over study guide

Instances

Built-in attributes aka built-in properties• ball.x,• ball.y• target.rotation• globe.alpha• block.width• block.height• others

ActionScript 3.0. drops the underscore _ you will see in old Flash examples.

Page 13: Programming games Another sound example General review Homework: [finish project], look over study guide

Creating games: Flash

Implement player moves and other actions• ActionScript in frames• ActionScript for instances

– onclipEvent– on(release)

• ActionScript may also be in frames of movie clip symbols brought into main movie– Target in cannonball had stop()– Other?

"depreciated". Should use procedural/frame code to set up event handling

Page 14: Programming games Another sound example General review Homework: [finish project], look over study guide

There will be another version of ActionScript

• Basic concepts the same!– Functions, naming, logic, variables.– Event handling

• Use Help– May need to be on-line

Page 15: Programming games Another sound example General review Homework: [finish project], look over study guide

Creating games logic

• ActionScript closely resembles other languages

• statements– assignment– if (condition) { }– if (condition) { } else { }– for (initialization;condition; increment) { }– switch

Page 16: Programming games Another sound example General review Homework: [finish project], look over study guide

Logic: object view(If you study OOPL, such as Java)• Logic sometimes is implemented more-or-less

implicitly.• In objects (movie clip instances are objects), the

programmer can define methods each different types (sub classes) so the 'if' is done by which method. Example:– Method to calculate power done one way for super

hero, another way for mortal.– Shipping cost: free for preferred customer, a

calculation for regular customer.

Page 17: Programming games Another sound example General review Homework: [finish project], look over study guide

Random

• aka pseudo-random because the random values are produced by a well-defined procedure. They appear random.

• Math.random() produces a number (fraction) from zero up to but not including 1.

• Math.floor(Math.random()* 6) produces one of 0,1,2,3,4,5

Page 18: Programming games Another sound example General review Homework: [finish project], look over study guide

Functions

• Functions are ways to package code to be used (and re-used)

• Function definitions specify name and parameters.

• Variables defined (var statement) within the function cannot be accessed outside the function.

Page 19: Programming games Another sound example General review Homework: [finish project], look over study guide

DefinitionsRemember: questions about function, variable,

array refer to technical meaning (programming jargon) NOT the English meaning of the term.

• A function in programming is a construct that sets up a sequence of statements, along with definition of parameters. The coding for function definition is

function fn (parameter name(s)) { code}

coding for a call to a function uses its name followed by ( the parameter(s)) and closing )

Page 20: Programming games Another sound example General review Homework: [finish project], look over study guide

Definitions, continued

• A variable in programming is associating a name with a value. The value can change! Using the name will return the current value.

• An array in programming is a particular type of value, namely a set of values. The common form of array is a sequence of values. To get the individual values, you write code with arrayname[indexvalue]

Page 21: Programming games Another sound example General review Homework: [finish project], look over study guide

NotationProgramming uses a variety of symbols

• ( and ) are used to – control order of evaluation: a*(b+c)– hold the parameters in a function definition– hold the parameters in a function call– hold the condition in an if statement– hold the condition in a while statement or

switch statement– hold the set up values for a for loop

Page 22: Programming games Another sound example General review Homework: [finish project], look over study guide

Notation, cont.

• { and } are used– hold the body of the function in a function

definition– hold the if true clause and the else clause– hold the clause in a while or for loop– hold the clause in a for loop

• [ and ] are used – setting up arrays, as in var ma = [];– indexing arrays

Page 23: Programming games Another sound example General review Homework: [finish project], look over study guide

Timing

For internal calculations and for display

• Use playing of frames (standard is 12 fps)

• Use Timer object– See bouncing ball, bouncing stuff, cannonball,

shooter

Page 24: Programming games Another sound example General review Homework: [finish project], look over study guide

Flash issues

• Main movie and movie clip instances each loop from frame to frame in main movie AND each movie clip instances unless there are stop(); or gotoAndPlay() statements

• Functions and variables (outside of functions) are accessible by name of movie instance.– suggestion: put all functions and main movie variables

in first frame, actions layer.

• Material on stage in a frame (and in a layer)– layers are defined to layer graphical material– organize actionscript, graphics, frame labels

Page 25: Programming games Another sound example General review Homework: [finish project], look over study guide

Flash possibilities

• For games, more likely to have fewer frames, more movement by program control– Remember: cel animation vs computed animation

Applications may use both!• Game/application can contain many movie clip

instances– Use frame code or code in external .as files to create

objects• Need to addDisplay

– movie clip symbols may be simple or complex (for example, multi-frame)

– movie clip instances can have actions

Page 26: Programming games Another sound example General review Homework: [finish project], look over study guide

3 D

• Instead of locating objects in/on 2 dimensional Stage, position in 3 dimensions– also may need to orient objects– position and orient camera/eye to do calculation for

what you see

• 3D in Flash is only partial 3-D. The display list and layers overrides the 3D positioning.

• I expect improved 3D is coming….

Page 27: Programming games Another sound example General review Homework: [finish project], look over study guide

Reprise for games

• What's on the board– static– dynamic (changing)

• What is the information• What are the events and what should be the

response (event handler)? What is the logic of the game?– capture and respond to player moves– respond to other events (for example, timed events)

Page 28: Programming games Another sound example General review Homework: [finish project], look over study guide

Flash

• Publish application– Use .fla file and, possibly. .as files– produces .html and .swf files

• One copy of AS.RunActiveContent.js needed

– Need to upload both .html and .swf– If you are using any .flv files or .mpg, need to upload

them and use correct reference.

– Warning: the published application has smaller screen than the development application (.fla file)

Page 29: Programming games Another sound example General review Homework: [finish project], look over study guide

Trigonometry!!!• Go from angle to position and position to

angle

• used in ballistics, robotics, driving, etc.

R

X

Y Y = R * sin(a)

X = R * cos(a)

a = atan(Y/X)

a

Page 30: Programming games Another sound example General review Homework: [finish project], look over study guide

Degrees and radians

• How to measure an angle?• Traditional way: 360 degrees is a full circle

– 90 degrees is a 'right angle'– 180 degrees is a half circle. 'Do a 180' means to turn

around.• Alternative measure: a circle is PI (3.14159…)

worth of radians. This is an intrinsic measure.• Conversion formula:

radians = (PI/180) * degrees

Flash uses both!!!! cannon.rotation takes degrees, the Math trig methods use radians.

Page 31: Programming games Another sound example General review Homework: [finish project], look over study guide

Positions• THE position of an object in Flash and

other languages: x, y [and z] values.

• Is dragon near enough to the gold ? Say within gap both horizontally and vertically

What if it can be to the right or the left and above or below?Use Math.abs() Math.abs(30)=Math.abs(-30)

if ((Math.abs(dragon.x-gold.x)<gap)&&(Math.abs(dragon.y-gold.y))

Page 32: Programming games Another sound example General review Homework: [finish project], look over study guide

Collisions

• Flash provides two methods:dragon.hitTestPoint(gold.x,gold.y,true) checks if

the single point gold.x, gold.y overlaps with any occupied pixel of the dragon

dragon.hitTestObject(gold) checks if the bounding box containing the dragon overlaps with the bounding box containing the gold.

Page 33: Programming games Another sound example General review Homework: [finish project], look over study guide

3D modeling• Build a virtual world

– approximate shapes using polyhedra (facetted objects)• surface textures

– special procedures (e.g., fractals) for objects in nature

• Move objects– articulated (jointed) motions– expression

• Render objects– eye (camera), focal point, lighting

Products to do these things but imagination AND knowledge of mathematics & physics is helpful.

Try Google SketchUP (free version)

Page 34: Programming games Another sound example General review Homework: [finish project], look over study guide

http://Processing.org

• Language built on Java for graphics, physical computing, other….

• My initial attempts:http://faculty.purchase.edu/jeanine.meyer/processing

Page 35: Programming games Another sound example General review Homework: [finish project], look over study guide

Programming Courses

Math/CS (often cross-listed with New Media)• CS I: programming in Processing!, every semester• CS II: every Spring• Creating User Interfaces: Spring 2011• Games for Change: Spring 2011

• Social Software: Fall 2010

• Physical Computing: Fall 2010

• Robotics, Creating Databases for Web application, others probably every other year.

Page 36: Programming games Another sound example General review Homework: [finish project], look over study guide

Homework

• [Finish project– Upload ]

• Review study guide

• Review lecture charts