home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / bobsleddin.swf / scripts / __Packages / GameInterface.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  4.2 KB  |  163 lines

  1. class GameInterface extends MovieClip
  2. {
  3.    var specialDisplay;
  4.    var tfLives;
  5.    var tfScore;
  6.    var tfTrackTime;
  7.    var message;
  8.    var bestTimes;
  9.    var watchObject;
  10.    var avatar;
  11.    var score;
  12.    var lives;
  13.    var timeRemaining;
  14.    var maxDamage;
  15.    var letters;
  16.    var damage;
  17.    var specialItem;
  18.    var raceTime;
  19.    var raceTimeDisplay;
  20.    var damageBar;
  21.    var menuDisplay;
  22.    var onMenuOpen;
  23.    var onMenuClose;
  24.    function GameInterface()
  25.    {
  26.       super();
  27.       this.specialDisplay._visible = false;
  28.       this.setMenuEnabled(true);
  29.    }
  30.    function setOpenTextFieldColor(hexValue)
  31.    {
  32.       this.tfLives.textColor = this.tfScore.textColor = this.tfTrackTime.textColor = hexValue;
  33.    }
  34.    function showScreen(id, time)
  35.    {
  36.       this.message.play();
  37.       _root.messageName = id;
  38.    }
  39.    function showRecordTime(record)
  40.    {
  41.       this.bestTimes.gotoAndPlay("intro");
  42.       this.bestTimes.character.gotoAndStop(record.name);
  43.       this.bestTimes.value = _global.formatTime(record.time);
  44.    }
  45.    function hideRecordTime()
  46.    {
  47.       this.bestTimes.gotoAndPlay("outro");
  48.    }
  49.    function showLetters()
  50.    {
  51.    }
  52.    function hideLetters()
  53.    {
  54.    }
  55.    function watch(obj, characterName)
  56.    {
  57.       this.watchObject = obj;
  58.       this.avatar.gotoAndStop(characterName);
  59.       this.score = this.watchObject.score;
  60.       this.lives = "X" + this.watchObject.lives;
  61.       this.timeRemaining = this.watchObject.timeRemaining;
  62.       this.setRaceTime(this.watchObject.raceTime);
  63.       this.maxDamage = this.watchObject.maxDamage;
  64.       this.setDamage(this.watchObject.damage);
  65.       this.letters = 0;
  66.    }
  67.    function update(elapsed)
  68.    {
  69.       if(this.score != this.watchObject.score)
  70.       {
  71.          this.score = this.watchObject.score;
  72.       }
  73.       if(this.damage != this.watchObject.damage)
  74.       {
  75.          this.setDamage(this.watchObject.damage);
  76.       }
  77.       if(this.letters != this.watchObject.letters)
  78.       {
  79.          this.setLetters(this.watchObject.letters);
  80.       }
  81.       if(this.specialItem != this.watchObject.specialItem)
  82.       {
  83.          this.setNewSpecialItem(this.watchObject.specialItem);
  84.       }
  85.       else if(this.specialItem)
  86.       {
  87.          this.setSpecialValue(this.specialItem.power);
  88.       }
  89.       this.setRaceTime(this.watchObject.raceTime);
  90.       this.setTimeRemaining(this.watchObject.timeRemaining);
  91.    }
  92.    function setTimeRemaining(value)
  93.    {
  94.       if(this.timeRemaining == Math.ceil(value))
  95.       {
  96.          return undefined;
  97.       }
  98.       this.timeRemaining = Math.ceil(value);
  99.    }
  100.    function setRaceTime(value)
  101.    {
  102.       if(this.raceTime == (this.raceTime = Math.floor(value * 10) * 0.1))
  103.       {
  104.          return undefined;
  105.       }
  106.       this.raceTimeDisplay = _global.formatTime(value);
  107.    }
  108.    function setDamage(damage)
  109.    {
  110.       this.damage = damage;
  111.       this.damageBar.setValue(1 - damage / this.maxDamage);
  112.    }
  113.    function setSpecialValue(value)
  114.    {
  115.       this.specialDisplay.value.setValue(value);
  116.    }
  117.    function setNewSpecialItem(newSpecialItem)
  118.    {
  119.       this.specialItem = newSpecialItem;
  120.       if(this.specialItem)
  121.       {
  122.          this.specialDisplay._visible = true;
  123.          this.specialDisplay.value.maxValue = this.specialItem.power;
  124.          this.setSpecialValue(this.specialItem.power);
  125.          switch(this.specialItem.collisionGroup)
  126.          {
  127.             case BB.MAGNETS:
  128.                this.specialDisplay.gotoAndStop(1);
  129.                break;
  130.             case BB.BLADES:
  131.                this.specialDisplay.gotoAndStop(2);
  132.                break;
  133.             case BB.LASERS:
  134.                this.specialDisplay.gotoAndStop(3);
  135.          }
  136.       }
  137.       else
  138.       {
  139.          this.specialDisplay._visible = false;
  140.       }
  141.    }
  142.    function setLetters(letters)
  143.    {
  144.       this.letters = letters;
  145.    }
  146.    function setMenuEnabled(enabled)
  147.    {
  148.       this.menu.enabled = enabled;
  149.    }
  150.    function showMenu()
  151.    {
  152.       this.menuDisplay.gotoAndPlay("Intro");
  153.       this.onMenuOpen();
  154.       this.setMenuEnabled(false);
  155.    }
  156.    function hideMenu()
  157.    {
  158.       this.setMenuEnabled(true);
  159.       this.menuDisplay.gotoAndStop(1);
  160.       this.onMenuClose();
  161.    }
  162. }
  163.