Presentation is loading. Please wait.

Presentation is loading. Please wait.

AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 6 "The games of a people reveal.

Similar presentations


Presentation on theme: "AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 6 "The games of a people reveal."— Presentation transcript:

1 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 6 "The games of a people reveal a great deal about them.“ Marshall McLuhan

2 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule All scripts are in the Actions layer, first frame. This will hide the titleScreen movie clip (intro and title of the game) on the release event and startgame function will be called. titleScreen.onRelease = function() { this._visible = false; startgame(); } this._visible = false;hides titleScreen movie clip

3 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule nmcounter from 0 to 8 nm=“m”+Inm will be m0, m1, m2, m3, …capsule movie clips startgame = function() { for (var i = 0; i < 9; i++) { var nm = "m" + i;

4 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule Functions for each capsule. onPresswhen the user presses mouse button down whacksvariable to calculate number of successful whacks scoreDisplay.whack_txt.text = whacks;displays the new value of whacks in the whack_txt d.text field _root[nm].onPress = function() { if (this._currentframe == 10) { this.play(); whacks++; scoreDisplay.whack_txt.text = whacks; doWhackAt(_xmouse, _ymouse); }

5 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule _root[nm].onPress = function() { if (this._currentframe == 10) { this.play(); whacks++; scoreDisplay.whack_txt.text = whacks; doWhackAt(_xmouse, _ymouse); }

6 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule calls doWhackat function and passes the current position of the mouse cursor doWhackAt(_xmouse, _ymouse);

7 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule Capsule animation function onEnterFramefunction for the capsule will be called every frame of the movie fps = 31, 31 times per second Selects random number from 0 to 100 if the capsule in the 1 frame If capsule on frame 10 (fully extended position) the random value between 0 and 100 will be selected and if this number is less then 10 then capsule.play() will animate capsule down If capsule is down it will rise every 3 seconds If capsule is up if will drop within a second to give the user opportunity to click it

8 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule _root[nm].onEnterFrame = function() { if (this._currentframe == 1) { if ((Math.random() * 100) < 1) { this.play(); } else if (this._currentframe == 10) { if ((Math.random() * 100) < 10) { this.play(); }

9 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule Initialize variable whacks to 0 (the score) And display it in the whacks_txt dynamic text field in the scoreDisplay movie clip whacks = 0; scoreDisplay.whack_txt.text = whacks;

10 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule getTimer() function returns the number of milliseconds elapsed since the game started to execute endTime variablewill take 30 seconds into the future To determine an amount of time remaining in the game endTime = getTimer() + 30000;

11 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule Main timeline function that keeps the time and determines when the game is over etimekeeps track of remaining time between the endTime and now (from getTimer) getTimer() constantly changing causing etime to get smaller as time elapses var etime = endTime - getTimer();

12 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule IF remaining time is lass then 0 then “ TimeUP” message is displayed on the dynamic test field time_txt in the scoreDisplay movie clip _root.onEnterFrame = function() { var etime = endTime - getTimer(); if (etime <= 0) { scoreDisplay.time_txt.text = "Time Up";

13 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule And functions assigned to capsules are deleted onPress, onEnterFrame, stops capsules at current position, and kills timer function in the main timeline for (var i = 0; i < 9; i++) { var nm = "m" + i; delete _root[nm].onPress; delete _root[nm].onEnterFrame; _root[nm].stop(); delete _root.onEnterFrame; }

14 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule If there is still time remaining in the game the time is displayed in the text field time_txt with the wrold “sec” etime/1000 returns number of seconds Math.ceilrounds up floating point value to the nearest integer else { scoreDisplay.time_txt.text = Math.ceil(etime / 1000) + " sec"; }

15 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule doWhackAt function displays a successful graphics “whack!” if the user clicks the capsule at the right moment at the mouse cursor position wcnt variable to store instances of the successful whakcs nmtemporary variable to name instances wc0, wc1, wc2, wc3….. _root.attachMovie("whackSign", nm, wcnt + 99); takes whckSign movie clip from the library and positions it on the stage instance name (wc0, wc1, …) depth level 99, 100, 101, 102,…

16 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule wcnt = 0; doWhackAt = function(x, y) { var nm = "wc" + wcnt; _root.attachMovie("whackSign", nm, wcnt + 99); _root[nm]._x = x; _root[nm]._y = y; _root[nm]._xscale = _root[nm]._yscale = 60;

17 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule Fades away the movie clip from 100% to 0% in 10 frames _root[nm].onEnterFrame = function() { this._alpha -= 10; if (this._alpha <= 10) { delete this.onEnterFrame; this.removeMovieClip(); }

18 AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Whack A Capsule wcnt++; wcnt %= 5; The value of wcnt will be always 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, …. It is unlikely that the user will have more then 5 on screens at once because they fade away quickly


Download ppt "AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 6 "The games of a people reveal."

Similar presentations


Ads by Google