Games II Scripting AGAIN - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Games II Scripting AGAIN

Description:

Games Scripting II. 9/3/09. Computing Engineering and Technology David.M.de-Leuw_at_staffs.ac.uk ... attachMovie('gun', 'gun1', 5); attachMovie('sight', 'sight1', 9) ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 23
Provided by: dav133
Category:
Tags: again | games | gun | scripting

less

Transcript and Presenter's Notes

Title: Games II Scripting AGAIN


1
Games II Scripting AGAIN!
1
2
Movie Clips...proximity
  • Movie clips that are placed on-screen in code can
    also be removed in code.
  • var speedNumber 5
  • attachMovie("ball1", "ball1_mc", 0)
  • attachMovie("ball2", "ball2_mc", 1)
  • ball1_mc._x 100
  • ball1_mc._y 200
  • ball2_mc._x 350
  • ball2_mc._y 200

2
3
Proximity collision
  • function onEnterFrame() Void
  • if (ball1_mc._x lt ball2_mc._x - 65)
  • ball1_mc._x speed
  • if (ball1_mc._x gt ball2_mc._x - 65)
  • ball2_mc.removeMovieClip()
  • Proximity1.html

3
4
Linkage
  • Remember that when you wish to use a movie clip
    in script you must initiate Linkage

4
5
Proximity - push
  • Utilising the same technique a slightly different
    effect can be achieved
  • function onEnterFrame() Void
  • if (ball1_mc._x lt ball2_mc._x - 65)
  • ball1_mc._x speed
  • if (ball1_mc._x gt ball2_mc._x - 65)
  • if (ball2_mc._x lt 520)
  • ball2_mc._x 5
  • Proximity2.html

5
6
Proximity - bounce
  • Using Boolean returns
  • var speedNumber 5
  • var stopBoolean false
  • var bounceBoolean false
  • attachMovie("ball1", "ball1_mc", 0)
  • attachMovie("ball2", "ball2_mc", 1)
  • ball1_mc._x 100
  • ball1_mc._y 200
  • ball2_mc._x 350
  • ball2_mc._y 200

6
7
Proximity - push
  • function onEnterFrame() Void
  • if (stop false)
  • if (ball1_mc._x lt ball2_mc._x - 65)
  • ball1_mc._x speed
  • if (ball1_mc._x ball2_mc._x - 65)
  • stop true

7
8
Proximity - push
  • else if (stop true)
  • if (ball2_mc._x lt 520)
  • ball2_mc._x 5
  • if (ball2_mc._x 520)
  • bounce true
  • if (bounce true)
  • if (ball2_mc._x gt 50)
  • ball2_mc._x - 18
  • ball2_mc._y - 8

8
9
Proximity - push
  • This will push the second ball away from the
    first and when it hits the constraint it bounces.
  • Proximity3.html
  • A similar effect can be achieved by calculating
    angles of trajectory using sine and cosine

9
10
Proximity - push
  • The first thing to do would be to figure out the
    angle between the two balls. This could be done
    using the Math.atan2 associated to the x and y
    properties.
  • If dx and dy were set as variables to hold the
    property of the two balls x and y positions
  • var dxNumber ball1._x ball2._x
  • var dynumber ball1._y ball2._y

10
11
Proximity - push
  • You could set up something like this
  • //calculate angle, sine and cosine
  • var angleNumber Math.atan2(dy,dx)
  • var sineNumber Math.sin(angle)
  • var cosineNumber Math.cos(angle)
  • You would of course co ordinate the rotation for
    velocity and position of both balls. It gets a
    little complicated after this

11
12
Mouse movement
  • Changing property of the cursor and tracking the
    mouse.
  • attachMovie("gun", "gun1", 3)
  • attachMovie("sight", "sight1", 2)
  • attachMovie("line", "line1", 1)
  • attachMovie("line", "line2", 0)
  • line1._x 50
  • line1._y 10
  • line2._x 50
  • line2._y 260

12
13
Mouse movement
  • Changing property of the cursor and tracking the
    mouse.
  • function onEnterFrame () Void
  • gun1._x _root._xmouse
  • gun1._y 350
  • if (_root._ymouse gt 10 and _root._ymouse lt 260)
  • sight1._x _root._xmouse
  • sight1._y _root._ymouse
  • Mouse.hide()

13
14
Mouse movement
  • Changing property of the cursor and tracking the
    mouse.
  • else
  • gun1._x 275
  • Mouse.show()
  • MouseLoc1.html

14
15
Mouse movement
  • The next stageshoot
  • Mouse.hide()
  • if (Key.isDown(Key.SPACE))
  • attachMovie("fire", "fire1", 3)
  • fire1._x gun1._x
  • fire1._y gun1._y - 100
  • attachMovie("hole", "hole1", 4)
  • hole1._x sight1._x
  • hole1._y sight1._y
  • MouseLoc2.html

15
16
Mouse movement
  • Back to the target .hitTest
  • var scoreNumber 0
  • attachMovie("gun", "gun1", 5)
  • attachMovie("sight", "sight1", 9)
  • attachMovie("line", "line1", 1)
  • attachMovie("line", "line2", 0)
  • attachMovie("alive", "alive1", 4)
  • alive1._x 300
  • alive1._y 100

16
17
Mouse movement
  • Back to the target .hitTest
  • if (Key.isDown(Key.SPACE))
  • if (sight1.hitTest(alive1))
  • attachMovie("fire", "fire1", 3)
  • fire1._x gun1._x
  • fire1._y gun1._y - 100
  • attachMovie("dead", "dead1", 6)
  • dead1._x alive1._x
  • dead1._y alive1._y
  • alive1.removeMovieClip()
  • score score1
  • text1 score
  • MouseLoc3.htm

17
18
And finally boundingagain
  • We set up the screen
  • attachMovie("ball", "ball", 0)
  • attachMovie("walltop", "walltop1", 1)
  • attachMovie("walltop", "walltop2", 3)
  • attachMovie("wallside", "wallside1", 2)
  • attachMovie("wallside", "wallside2", 4)
  • ball._x 50
  • ball._y 200
  • walltop1._x 300
  • walltop1._y 200
  • walltop2._x 150
  • walltop2._y 260
  • wallside1._x 450
  • wallside1._y 200
  • wallside2._x 300
  • wallside2._y 195

18
19
And finally
  • Set up the collide parameters
  • function onEnterFrame() Void
  • collide _root.ball.hitTest(_root.walltop1)
  • collide2 _root.ball.hitTest(_root.wallside1)
  • collide3 _root.ball.hitTest(_root.wallside2)
  • collide4 _root.ball.hitTest(_root.walltop2)

19
20
And finally
  • Set up the collide parameters
  • if(collide false and collide2 false and
    collide3 false and collide4 false)
  • if(Key.isDown(Key.LEFT))
  • ball._x - 5
  • else if (Key.isDown(Key.RIGHT))
  • ball._x 5
  • else if (Key.isDown(Key.UP))
  • ball._y - 5
  • else if (Key.isDown(Key.DOWN))
  • ball._y 5

20
21
And finally
  • Set up the collide parameters
  • else if(collide true)
  • ball._x 50
  • ball._y 200
  • else if(collide2 true)
  • ball._x 50
  • ball._y 200
  • else if(collide3 true)
  • ball._x 50
  • ball._y 200
  • else if(collide4 true)
  • ball._x 50
  • ball._y 200

22
22
And finally
  • And so we get
  • Bounding1.htm

22
Write a Comment
User Comments (0)
About PowerShow.com