Programming games - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Programming games

Description:

Strong-typing. import. Building an application. Planning. Design ... Shipping cost: free for preferred customer, a calculation for regular customer. Random ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 31
Provided by: Jeanin
Category:

less

Transcript and Presenter's Notes

Title: Programming games


1
Programming games
  • Bo, Disease, ?
  • General review
  • Homework finish project, look over study guide

2
New examples
  • Check my site, also blog for new examples.
  • Will be server side (php and MySql) developed
    over the summer
  • Examples generally come about by requests
  • and some from me

3
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

4
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

5
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.
6
More
  • Most projects are team projects
  • Butdon't specialize / limit what you want to
    learn practice
  • Most of my other courses feature team work.
  • Robotics Spring 2010
  • Creating Databases Fall 2009

7
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

8
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

9
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

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

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

14
Creating games logic
  • ActionScript closely resembles other languages
  • statements
  • assignment
  • if (condition)
  • if (condition) else
  • for (initializationcondition increment)
  • switch

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

16
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

17
Functions
  • Functions are ways to package code to be used
    (and re-used)
  • Function definitions specify name and can specify
    parameters
  • Variables defined (var statement) within the
    function cannot be accessed outside the function.

18
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

19
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

20
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

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

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

23
Trigonometry!!!
  • Go from angle to position and position to angle
  • used in ballistics, robotics, driving, etc.

R
Y
Y R sin(a) X R cos(a) a atan(Y/X)
a
X
24
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.

25
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)ltgap)(Math.abs(dr
    agon.y-gold.y))

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

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

28
http//Processing.org
  • Language built on Java for graphics, physical
    computing, other.
  • My initial attemptshttp//newmedia.purchase.edu/
    Jeanine/processing

29
Programming Courses
  • Math/CS
  • CS I programming in Processing!, every semester
  • CS II every Spring
  • Creating Databases for Web Applications Fall 2009
  • Robots Spring 2010
  • New Media
  • New hires (!) will offer new upper-level
    electives

30
Homework
  • Finish project
  • Upload
  • Review study guide
  • Review lecture charts
Write a Comment
User Comments (0)
About PowerShow.com