programming games problems. schedule various examples. homework: rps, bo (don't go back to do...

Post on 17-Jan-2016

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Programming games

Problems. ScheduleVarious examples.

Homework: rps, bo (don't go back to do this), cannonball, Video or Audio

should be complete. Now propose and plan your own project.

Recent problems: Names• Need to give instance name to instance of movie

clip symbol on the stage– The name of the symbol in the Library is NOT relevant.

ActionScript refers to objects on the Stage using the instance name.

– This also applies to buttons • From Common Library• Components• Programmer-made

– This also applies to text fields• Selectable (dynamic)• Editable (input)

Recent problems: frame to frame

• Remember to put stop(); in the Actions panel for a frame whenever you do want to stop on that frame!

• NOTE: if there are any syntactic errors, you will see the frames being re-displayed.

• Remember to check syntactic errors using the check icon. Also, use the format icon to examine the functions, if clauses, etc.

Know where your file is

Don't

• Edit a .fla file in one place (say the Desktop) and

• Have another copy in another place (say, your Documents) and have a video or audio file in that place.

Schedule• (Completed) rps, bo, cannonball

– Cannonball: just hitting target or ground. Target crumbles.

• Video or Audio: one of examples OR modify rps or bouncing ball or cannonball OR ?

• Propose and then work on your own game– can be variant of 'my' games. Variant must have

enhanced coding as well as graphics• Can be enhanced version of Bo. Do something new with the

coding.

– can be something completely different…

– can ask for help

Event handling

• Need to identify event• Multiple steps

– Declare object using var statement OR– Place instance on Stage, such as Button, and give

name– Define a function that will do something in response to

the event– Use addEventListener(event, functionname) OR

have definition of a function as second parameterRecall: rock paper scissors

Examples• mytimer.addEventListener(TimerEvent.TIMER,moveball)• rockbtn.addEventListener(MouseEvent.CLICK, function (ev)

{ computermove("rock");} );

May need to use HELP to figure out what the event is. For example,

• playback.addEventListener(VideoEvent.COMPLETE,playagain);

Run, Bo, Run

• You can download the source file

• Combination of cel animation (dog moving its legs) and computed animation (positioning bo instance like bouncing ball)

• Built up gradually, but the posted version does rotate the instance in 3D (around Y axis) to allow dog to run from right to left!

• Also a version with Sound– sound imported to frame in the symbol in the Library

where Bo starts to run.

Interface

Look at examples, source code and tutorials: • coffee shop example

– Created all by code:• radio button • pull down menu

– text field (could have created this also by code but chose not to)

• Presidential preference – radio button

SharedObject

• Flash's version of cookies:– small files kept on client's (player's) computer

to be used by restricted set of programs.

– Also used for behavioral marketing!!!

• One way to get persistent data: data that stays around after program finishes.

navigateToURL

See examples, source

• Go to URL (probably an html file) from Flash.– options to make new window or not.

Pre-loader

• Show something while the rest of a large Flash project loads– NOTE: Flash compresses content efficiently

so it really has to be big AND/OR slow communications.

• Tutorial assumes that you have created the project and 'after the fact' decided to do a pre-loader.

Logic

• First frame: create a message

• Frame 5: label it "loading"• Next frame, say frame 6: check if the

whole file is loaded, if no, go back to "loading", else go to "main"

• Frame 10: label it "main", copy in original frames

timeline

Frame 1import jigsaw.*;

import flash.text.*;

var loadMsg:TextField = new TextField();loadMsg.text = "Loading...";loadMsg.autoSize = TextFieldAutoSize.LEFT;loadMsg.border = true;loadMsg.background = true;loadMsg.selectable = false;addChild(loadMsg);

Frame after "loading" frame

if (framesLoaded == totalFrames) {

gotoAndStop("main");

} else {

gotoAndPlay("loading");

}

Frame "main"

• This is the first frame of the original program, with one new line:

removeChild(loadMsg);var p1:Piece = new Piece(41.6,48.1,piece1);var p2:Piece = new Piece(101.5,48.5,piece2);…Piece.buildit();

Suggestions

• You can do additional actions and/or have more graphics in frames 1 through "loading"

• Don't put in so much that that requires a loader

http://kinderspiel.us/

Cannonball

Much of this is taste…

• Create a new layer, above the board, and put the ground instance in it.

• Place the target below the top of the ground.– Target will sink into ground– Ball will sink (slightly) into ground

Positioning

• You can move instances with the mouse

• You can change the x and y values– In Property Panel or in Info Panel

• You can write code to change positions during run time

• Same goes for width and height

Bouncing heads

• The code refers to a movie clip instance named ball.

• When you create the ball symbol in the Library (or when you edit it), you can change this to be…whatever you want– Some people like heads.

• You also can make the ball symbol a movie clip with multiple frames so it changes as it bounces in the ‘box’.

Comment

• Flash provides facilities for setting up symbols, instances of which, operate more or less independently….

Shooter

• demonstration

• shooter.fla file plus .as files defining a class for each of– Aa– Gun– Bar– Ground– Bomb

Note

• There are multiple aa's and bomb's.

• All these are defined as MovieClips in the usual way.

• Use Linkage to associate with an external file.

• The external .as file has coding.

Find places game

• Inspired by Lufthansa virtual pilot AND

• request for a game about NY CD 19

• My game has additional feature of regions as well as points

• Demonstrate– note progression of features

Classwork/homework

• Work session

• Last project is totally your choice. You can build on sample projects.

top related