Game Programming I - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Game Programming I

Description:

Create a flash Movie. In frame 1 create an input text box. Use a button from the common library ... Individual Games. We are going to look at the game samples ... – PowerPoint PPT presentation

Number of Views:57
Avg rating:3.0/5.0
Slides: 26
Provided by: student5
Category:

less

Transcript and Presenter's Notes

Title: Game Programming I


1
Game Programming I
  • MULT 110
  • Week 5
  • All About ActionScript! Again.

2
Review - Question 1
  • You have a Dynamic Text field in Flash named
    feedback_txt
  • How do you set it to display the message
  • Youve Won! Play again?

3
Review - Question 1
  • You have a Dynamic Text field in Flash named
    feedback_txt
  • How do you set it to display the message
  • Youve Won! Play again?

feedback_txt.text Youve Won! Play again?
4
Review - Question 2
  • You have a variable names totalPoints which
    stores how many points a player has earned in
    your game.
  • If theyve earned more then 50 they have won the
    game.
  • How do you code to check whether or not they have
    won?

5
Review - Question 2
  • if (totalPoints 50)
  • //They Win
  • Do Something
  • else
  • //They Lose
  • Do Something

6
if Statement
  • if (condition)
  • Example
  • if (answer "Option 2")
  • gotoAndPlay("CorrectAnswer", 1)
  • else
  • gotoAndPlay("IncorrectAnswer", 1)

7
miniLab1 - 5 Minute Lab
  • Create a flash Movie
  • In frame 1 create an input text box
  • Use a button from the common library
  • When the button is clicked evaluate if the number
    in the text box is greater then 5
  • Use traces to check your work

8
Review Question 3
  • The Switch Statement
  • What is it?
  • Why do we need it?
  • How does it work?

9
Review Question 3
  • switch (condition)
  • case value
  • actions
  • break
  • case value
  • actions
  • break
  • default
  • actions

10
miniLab2 - 5 Minute Lab
  • Duplicate your scene from miniLab1
  • Replace the if statement with a switch statement
    that evaluates if red, blue or green was entered
    the text box.
  • If anything else was entered have the trace
    display you didnt enter the right color

11
Review Question 4
  • What is this?
  • What is it doing?
  • What is i?

12
miniLab3 - 5 Minute Lab
  • Duplicate your scene from miniLab2
  • Create a loop that runs 25 times when the button
    is clicked
  • Every time the loop runs display a random number
    with the trace function
  • Now add text to the trace that says x I am
    random number n2 I am random number 10

13
Review Question 5
  • Objects
  • Methods
  • Properties
  • Event Methods

14
miniLab4 - 5 Minute Lab
  • Create a new scene
  • Create a new movie clip symbol
  • Create an onEnterFrame event that pulls a random
    number

15
Arrays
  • A collection or set of information that has some
    relationship
  • All of these items are named the same and
    arranged in a list
  • Each item, called an element, is accessed by its
    location in the list.
  • The location is a number called the index.

16
Example of an Array
  • Name the array PlayerNames
  • Lets put 4 names into the list
  • Jane PlayerNames0
  • Wayne PlayerNames1
  • Dane PlayerNames2
  • Lane PlayerNames3
  • Visually
  • PlayerNames

17
The Array Object
  • An Object preset with methods and properties
  • To declare an array, generate a new object
  • myArray new Array(4)
  • To populate an array, name or assign the elements
  • myArray Jane, Wayne, Dane, Lane
  • or
  • myArray0 Jane
  • myArray2 Dane
  • myArray3 Lane
  • myArray1 Wayne

Note that the order of assignment matters here,
but not here.
18
Array Object Methods
  • Items may be collected into a single string
  • myArray.join( )
  • Easy way to test your arrays
  • trace(myArray.join( ))
  • Items in the array may be sorted
  • myArray.sort( )
  • Length of the array may be queried
  • numberElements myArray.length

19
Dynamic Arrays
  • Need not declare the number of elements in an
    array
  • dynamicArray new Array( )
  • Add elements with a push
  • dynamicArray.push(new one, another new one )
  • Elements are added on to the end of the array
  • Number of elements is passed back as a value
  • Delete elements with a pop
  • dynamicArray.pop( )
  • Last element is deleted but passed back as a
    value.

20
miniLab5 - 5 Minute Lab
  • Create a new scene
  • Declare an Array called players
  • Populate the array with 4 player names
  • Randomly select a play and display the name using
    a trace
  • Try other Methods see what happens
  • How can you display the each element in the
    array?

21
Matrix A Multidimensional Array
  • You create multidimensional arrays in
    ActionScript by constructing an array, the
    elements of which are also arrays.

myMatrix12 holds Score 2
MyMatrix
22
Matrix A Multidimensional Array
  • A list of lists An array within an array
  • myMatrix new Array( )
  • myPlayers new Array(4)
  • myScores new Array(4)
  • myMatrix myPlayers, myScores
  • myMatrix which arraywhich element

MyMatrix
23
Matrix A Multidimensional Array
  • To access elements of a multidimensional array,
    you can nest the array access operator with
    itself, as in the following
  • // create the array
  • var chessboard new Array()
  • for (var i0 i
  • chessboard.push(new Array(8))
  • // reference the array
  • function getContentsOfSquare(row, column)
  • chessboardrowcolumn

24
Example with Deck of Cards
  • suits new Array(4)
  • values new Array(13)
  • // assign values
  • suit "Clubs", "Diamonds", "Hearts",
    "Spades"
  • value "2","3","4","5","6","7","8","9","10","J"
    ,"Q","K","A"
  • cards new Array()
  • // create matrix for deck of cards, 4 suits of
    13 cards
  • for (i0 i
  • cards.push(new Array(13))

25
Chapter 8 and Individual Games
  • We are going to look at the game samples in
    Chapter 8.
  • Pick your favorite one and modify for your
    individual game
  • Modifications must be done to the actionScript as
    well as Visual.
  • Ideas
  • Scoring
  • Levels
  • Cursors
  • Audio
  • Fix broken games
  • Create New Game Based on engine
Write a Comment
User Comments (0)
About PowerShow.com