Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Programming games Another sound example General review Homework: [finish project], look over study guide."— Presentation transcript:

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

2 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!!!

3 from the code var downloadURL:URLRequest; var fileName:String = lastplayed; var file:FileReference; downloadURL = new URLRequest(); downloadURL.url = lastplayed; file = new FileReference(); file.download(downloadURL, fileName);

4 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

5 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

6 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.

7 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

8 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

9 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

10 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

11 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)

12 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.

13 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

14 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

15 Creating games logic ActionScript closely resembles other languages statements –assignment –if (condition) { } –if (condition) { } else { } –for (initialization;condition; increment) { } –switch

16 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.

17 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

18 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.

19 Definitions Remember: 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 )

20 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]

21 Notation Programming 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

22 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

23 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

24 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

25 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

26 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….

27 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)

28 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)

29 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

30 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.

31 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))

32 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.

33 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)

34 http://Processing.org Language built on Java for graphics, physical computing, other…. My initial attempts: http://faculty.purchase.edu/jeanine.meyer/ processing http://faculty.purchase.edu/jeanine.meyer/ processing

35 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.

36 Homework [Finish project –Upload ] Review study guide Review lecture charts


Download ppt "Programming games Another sound example General review Homework: [finish project], look over study guide."

Similar presentations


Ads by Google