1 / 18

Whack A Capsule Game

Play the Whack A Capsule game and test your reflexes by whacking the capsules as they randomly appear on the screen. Keep track of your score and see how fast you can whack!

townsley
Download Presentation

Whack A Capsule Game

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. "The games of a people reveal a great deal about them.“ Marshall McLuhan Intro to Action Script 6

  2. 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 Whack A Capsule

  3. nm counter from 0 to 8 nm=“m”+I nm will be m0, m1, m2, m3, …capsule movie clips startgame = function() { for (var i = 0; i < 9; i++) { var nm = "m" + i; Whack A Capsule

  4. Functions for each capsule. onPress when the user presses mouse button down whacks variable 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); } } Whack A Capsule

  5. _root[nm].onPress = function() { if (this._currentframe == 10) { this.play(); whacks++; scoreDisplay.whack_txt.text = whacks; doWhackAt(_xmouse, _ymouse); } } Whack A Capsule

  6. calls doWhackat function and passes the current position of the mouse cursor doWhackAt(_xmouse, _ymouse); Whack A Capsule

  7. Capsule animation function onEnterFrame function 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 Whack A Capsule

  8. _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(); } } } Whack A Capsule

  9. 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; Whack A Capsule

  10. getTimer() function returns the number of milliseconds elapsed since the game started to execute endTime variable will take 30 seconds into the future To determine an amount of time remaining in the game endTime = getTimer() + 30000; Whack A Capsule

  11. Main timeline function that keeps the time and determines when the game is over etime keeps 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(); Whack A Capsule

  12. 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"; Whack A Capsule

  13. 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; } } Whack A Capsule

  14. 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.ceil rounds up floating point value to the nearest integer else { scoreDisplay.time_txt.text = Math.ceil(etime / 1000) + " sec"; } Whack A Capsule

  15. 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 nm temporary 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,… Whack A Capsule

  16. 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; Whack A Capsule

  17. 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(); } } Whack A Capsule

  18. 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 Whack A Capsule

More Related