PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Code optimization and potential errors
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Code optimization and potential errors

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    Code optimization and potential errors

    Flash 8, AS2.

    This code I am using is rather sluggish I think. Is their a way to optimize it? Also I am having a problem with the npc. sometimes the hit test lets him continue through. Not to mention that if the character touches to proxies at a time (if in a corner) then the npc becomes stuck. Also, sometimes the player draws but the fucntion for the player wont run. but this doesn't always happen.

    Any contributing ideas? I know this code is probably really jacked and but together quite noobish. So maybe there are some ways I can improve it without rewriting it?

    Thanks,

    Actionscript Code:
    /*1*\ <  Start Line Number  End Line Number  > /*14*\
    /*15*\  Variables        /*34*\
    /*35*\  Gui         /*76*\
    /*81*\  Timer           /*145*\
    /*146*\     Player      /*288*\
    /*289*\     NPC01       /*602*\
    /*603*\ Depth           /*632*\
    /*633*\ Visibility      /*662*\
    /*663*\ Transition area /*690*\
    /*691*\ Run Functions   /*709*\
    /*418*\ Entities        /*440*\
    /*442*\     Exit            /*471*\

    //||||||||||Please NOT THAT THE PROXIES ARE ON THE STAGE!
    _level0.objectMaxfd = 12; //Maximum Proxies that push -y
    _level0.objectMaxfu = 11; //Maximum Proxies that push +y
    _level0.objectMaxfr = 29; //Maximum Proxies that push -x
    _level0.objectMaxfl = 23; //Maximum Proxies that push +x
    _level0.npc2up = true; //if false npc cant move up
    _level0.npc2ri = true; //if false npc cant move right
    _level0.npc2do = true; //if false npc cant move down
    _level0.npc2le = true; //if false npc cant move left
    _level0.msg01 = ""; //Character speech default.
    level0.pausemove = false; //Pause players move
    _level0.currentcityinfo.cityname = "Nolta: 1A";
    _level0.currentcityinfo.citycode = 1.11;
    _level0.currentcityinfo.defx = 80; //Positions the player infront of his house
    _level0.currentcityinfo.defy = 240; //positions the player infront of his house
    _level0.npc001._lastfaced = 3; //Keeps track of npcs last faced position and applys it when still.
    _level0.container_mc.playerri = false; //if true npc cant move right
    _level0.container_mc.playerup = false; //if true npc cant move up
    _level0.container_mc.playerle = false;//if true npc cant move left
    _level0.container_mc.playerdo = false;//if true npc cant move down

    /*T*\ Title: Enitiates creating ojects of the scenes (player, np, fence, ground)
    /*1*\ Function Intialized
    /*2*\ Run Once
    /*3*\ Determine to return once when returning from menu or another area.
    /*4*\ Creates Objects
    /*5*\ Run Above Comands::
    /* */

    /*1*/  function intfunc() {
    /*2*/   if (_level0.firstrun == true) {
            trace("inside fr");
            attachMovie("noltaground", "nolta_ground", 1, {_x:0, _y:0});
            attachMovie("woodhome_(lowhalf)", "woodhomelh", 2, {_x:81, _y:234});
            attachMovie("fence 01e", "hh_fence_e", 3, {_x:3.250000E+001, _y:3.686000E+002});
    /*3*/   if (_level0.ingamemenu == true) {
                trace("attach player1");
                attachMovie(_level0.playerstatus.gfx, "player", 100, {_x:2, _y:2});
                _level0.this_lastfaced = _level0.savplayerlf;
                _level0.pausemove = false;
            } else {
                trace("attach player2");
                attachMovie(_level0.playerstatus.gfx, "player", 100, {_x:_level0.currentcityinfo.defx, _y:_level0.currentcityinfo.defy});
            }
            // end else if
    /*4*/   attachMovie("fence 01d", "hh_fence_d", 101, {_x:184, _y:219});
            attachMovie("fence 01dd", "hh_fence_dd", 102, {_x:220, _y:265});
            attachMovie("playerhome_fence_a", "hh_fence_a", 103, {_x:134, _y:367});
            attachMovie("woodhome_(highhalf)", "woodhomehh", 2001, {_x:82, _y:118});
            attachMovie("woodhome_(midhalf)", "woodhomemh", 2002, {_x:81, _y:172});
            attachMovie("clock", "clock", 3003, {_x:0, _y:0});
            attachMovie("bottomborder", "bottom_border", 3004, {_x:0, _y:520});
            attachMovie("tab_menu", "tab_menu", 3005, {_x:0, _y:520});
            attachMovie("Nolta_fence_bridge", "Nolta_fence_bridge", 104, {_x:501, _y:3.277000E+002});
            attachMovie("nolta_tree001", "nolta_tree001", 105, {_x:300, _y:500});
            attachMovie("nolta_tree001", "nolta_tree002", 106, {_x:200, _y:150});
            attachMovie("chest002", "nolta_chest001", 107, {_x:32, _y:502});
            attachMovie("npc001n", "npc001", 109, {_x:100, _y:480});
            _level0.firstrun = false;
        }
    }
    /*5*/intstart = setInterval(function () {
        intfunc();
    }, 50);



    /*T*\ Title: Calculates the clock.
    /*1*\ Function Initialized
    /*2*\ Initialize Variable of day , hour and minute; Increased second
    /*3*\ Update day name
    /*4*\ Update day,hour,minute and second
    /*5*\ Changed Am to Pm and Pm to Am
    /* */


    /*1*/ function timer() {
    /*2*/_level0.game_time_full = _level0.game_time_dayname+", "+_level0.game_time_hour+":"+_level0.game_time_min;
        _level0.game_time_sec += 1;
    /*3*/switch (_level0.game_time_day) {
        case 1 :
            _level0.game_time_dayname = "Monday";
            break;
        case 2 :
            _level0.game_time_dayname = "Tuesday";
            break;
        case 3 :
            _level0.game_time_dayname = "Wednesday";
            break;
        case 4 :
            _level0.game_time_dayname = "Thursday";
            break;
        case 5 :
            _level0.game_time_dayname = "Friday";
            break;
        case 6 :
            _level0.game_time_dayname = "Saturday";
            break;
        case 7 :
            _level0.game_time_dayname = "Sunday";
            break;
        default :
            _level0.game_time_dayname = "Error";
            break;
        }
    /*4*/   if (_level0.game_time_sec>=60) {
            _level0.game_time_sec = 0;
            _level0.game_time_min += 1;
            if (_level0.game_time_min>=60) {
                _level0.game_time_min = 00;
                _level0.game_time_hour += 1;
    /*5*/           if (_level0.game_time_hour>=12) {
                    if (_level0.game_time_tod == "a") {
                        changetod = true;
                    }
                    if (_level0.game_time_tod == "p") {
                        _level0.game_time_tod = "a";
                    }
                    if (changetod == true) {
                        _level0.game_time_tod = "p";
                        changetod = false;
                    }
                    if (_level0.game_time_hour>=13) {
                        _level0.game_time_hour = 1;
                    }
                    _level0.game_time_day += 1;
                    if (_level0.game_time_day>=7) {
                        _level0.game_time_day = 1;
                    }
                }
            }
        }
    }

    /*T*\ Title: Function to control player
    /*1*\ Function Initialized
    /*2*\ Control Treasure Chest
    /*3*\ Determine if game is paused
    /*4*\ Handles this object depth sorting
    /*5*\ Moves player up; also determines pause
    /*6*\ Moves player right; also determines pause
    /*7*\ Moves player left; alos determines pause
    /*8*\ Moves player down; also determines pause
    /*9*\ Determine last faced.
    /*10*\Determines if player walks into npc01 (Applys a proxy)
    /*11*\
    /* */

    /*1*/player.onEnterFrame = function() {
    /*2*/   if (_level0.container_mc.entities.hitTest(_level0.container_mc.player.testhit)) {
                trace("player toching npc")
            if (Key.isDown(Key.ENTER) && _level0.pausemove != true) {
                trace("enter")
                _level0.container_mc.nolta_chest001.gotoAndStop(2);
                _level0.pausemove = true;
                attachMovie("sys_speech", "sys_speech01", 3006, {_x:125, _y:472});
               
                if (_level0.nolta_chest001f == true) {
                    _level0.msg01 = "This chest apears to be empty!";
                } else {
                    _level0.nolta_chest001f = true;
                    _level0.msg01 = "This document could contain important information.";
                }
                //level0.msg._visible = true; doesn't exist yet
                //_level0.msgvar = "You have opened a chest, and pear inside...";
            }
       
    };
    /*3*/   if (_level0.pausemove != true) {
    /*4*/   this.swapDepths(this._y);
    /*5*/   if (Key.isDown(38)) {
                this.gotoAndStop(5);
                if (_level0.container_mc.playerup != true) {
                    this._y = this._y-_level0.speed;
                    _level0.this_lastfaced = 1;
                }
    /*6*/   } else if (Key.isDown(40)) {
                this.gotoAndStop(7);
                if (_level0.container_mc.playerdo != true) {
                    this._y = this._y+_level0.speed;
                    _level0.this_lastfaced = 3;
                }
    /*7*/   } else if (Key.isDown(37)) {
                this.gotoAndStop(8);
                if (_level0.container_mc.playerle != true) {
                    this._x = this._x-_level0.speed;
                    _level0.this_lastfaced = 4;
                }
    /*8*/   } else if (Key.isDown(39)) {
                this.gotoAndStop(6);
                if (_level0.container_mc.playerri != true) {
                    this._x = this._x+_level0.speed;
                    _level0.this_lastfaced = 2;
                }
            }
            // end else if          
    /*9*/   if (!Key.isDown(37)){
                if (!Key.isDown(38)){
                    if (!Key.isDown(39)){
                        if (!Key.isDown(40)){
                this.gotoAndStop(_level0.this_lastfaced);
            }
                    }
                }
            }
            // end if          
        } else {
            this.gotoAndStop(_level0.this_lastfaced);
        }
            _level0.container_mc.playerri = false;
            _level0.container_mc.playerup = false;
            _level0.container_mc.playerle = false;
            _level0.container_mc.playerdo = false;
    /*10*/  if (this.testhit.hitTest(_level0.container_mc.npc001.hit3)) {
            _level0.dontrun = false;
            //_level0.container_mc.npc001.gotoAndStop(3);
            //_level0.container_mc.npc001._y -= 0;
            _level0.npc2do = false;
            _level0.container_mc.player._y += _level0.speed;
            _level0.container_mc.playerup = true;
           
        }
        if (this.testhit.hitTest(_level0.container_mc.npc001.hit4)) {
            _level0.dontrun = false;
            //_level0.container_mc.npc001.gotoAndStop(4);
            //_level0.container_mc.npc001._x += 0;
            _level0.npc2le = false;
            _level0.container_mc.player._x -= _level0.speed;
            _level0.container_mc.playerri = true;
           
        }
        if (this.testhit.hitTest(_level0.container_mc.npc001.hit1)) {
            _level0.dontrun = false;
            //_level0.container_mc.npc001.gotoAndStop(1);
            //_level0.container_mc.npc001._y += 0;
            _level0.npc2up = false;
            _level0.container_mc.player._y -= _level0.speed;
            _level0.container_mc.playerdo = true;
           
        }
        if (this.testhit.hitTest(_level0.container_mc.npc001.hit2)) {
            _level0.dontrun = false;
            //_level0.container_mc.npc001.gotoAndStop(2);
            //_level0.container_mc.npc001._x -= 0;
            _level0.container_mc.player._x += _level0.speed;
            _level0.npc2ri = false;
            _level0.container_mc.playerle = true;
        }
    /*11*/  if (_level0.container_mc.npc001.testhit3.hitTest(_level0.container_mc.player.testhit)) {
            if (Key.isDown(Key.ENTER) && _level0.pausemove != true) {
                _level0.pausemove = true;
                _level0.pausemovenpc001 = true;
                if (_level0.this_lastfaced == 1){
                    _level0.container_mc.npc001.gotoAndStop (3);
                }
                if (_level0.this_lastfaced == 2){
                    _level0.container_mc.npc001.gotoAndStop (4);
                }
                if (_level0.this_lastfaced == 3){
                    _level0.container_mc.npc001.gotoAndStop (1);
                }
                if (_level0.this_lastfaced == 4){
                    _level0.container_mc.npc001.gotoAndStop (2);
                }
                    attachMovie("sys_speech", "sys_speech01", 3006, {_x:(_level0.container_mc.npc001._x+100), _y:(_level0.container_mc.npc001._y-25)});
                if (_level0.nolta_npc001spch == true) {
                    _level0.msg01 = "Go AWAY!!!";
                } else {
                    _level0.nolta_npc001spch = true;
                    _level0.msg01 = "Get out of my way!";
                }
                //level0.msg._visible = true; doesn't exist yet
                //_level0.msgvar = "You have opened a chest, and pear inside...";
            }
       
        }
    };
    Last edited by brickhouse420; 02-28-2010 at 02:45 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    p2

    Actionscript Code:
    //288
    /*T*\ Title: NPC001 determain walking and proxys.
    /*1*\ Function Intialized
    /*2*\ Initalizes Variables
    /*3*\ Pause Npc Movement
    /*4*\ Checks for hit test with proxys
    /*5*\ Checks For Collision With Player Also Restricts
    /   \ the Npc From Walking Into The Player
    /*6*\ Determan Movement
    /*7*\ Change Direction Pause
    /*8*\ Determains pause after movement  
    /* */


    /*1*/function ranmove() {
    /*2*/if (runoncenpc01 !=true){
         h = 0;
         g = 0;
         j =0;
         h2 = 0;
        g2 = 0;
         j2 =0;
         h3 = 0;
         g3 = 0;
        j3 =0;
         h4 = 0;
         g4 = 0;
         j4 =0;
        i = 0;
    e = 0;
     ran6 = 0;
    ran3 = Math.floor(Math.random()*1);
        runoncenpc01 = true;
    }
    /*3*/if (_level0.pausemovenpc001 != true){
    /*4*/trace("h1 = "+2+"\nMax Proxiesdown = "+_level0.objectMaxfd);
            h++;
            if (_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxydown"+h)) {
                trace("||||||||||||||||||||||||||||||||||||||||111111111111111111111111111111");
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(3);
                _level0.container_mc.npc001._y -= 1;
                _level0.npc2do = false;
                _level0.npc2dof = _level0.npc2do;
            }
            if (h>_level0.objectMaxfd) {
                h = 0;
            }
       
       
        g2++;
            if (!_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxydo"+g)) {
                j++;
            }
            if (!_level0.container_mc.player.hit01.hitTest(_level0.container_mc.npc001.testhit && j == _level0.objectMaxfd)) {
                _level0.npc2up = true;
            }
            if (g>_level0.objectMaxfd) {
                g = 0;
                j = 0;
            }
       
       
        trace("h2 = "+h2+"\nMax Proxiesup = "+_level0.objectMaxfu);
            h2++;
            if (_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxyup"+h2)) {
                trace("||||||||||||||||||||||||||||||||||||||||22222222222222222");
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(1);
                _level0.container_mc.npc001._y += 1;
                _level0.npc2up = false;
                _level0.npc2upf = _level0.npc2up;
            }
            if (h2>_level0.objectMaxfu) {
                h2 = 0;
            }
       
       
        g2++;
            if (!_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxyup"+g2)) {
                j2++;
            }
            if (!_level0.container_mc.player.hit01.hitTest(_level0.container_mc.npc001.testhit && j2 == _level0.objectMaxfu)) {
                _level0.npc2up = true;
            }
            if (g2>_level0.objectMaxfu) {
                g2 = 0;
                j2 = 0;
            }
       
       
       
       
           
            trace("h3 = "+h3+"\nMax Proxiesle = "+_level0.objectMaxfl);
            h3++;
            if (_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxyleft"+h3)) {
                trace("|||||||||||||||||||||||||||||||||||||||333333333333333333333");
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(4);
                _level0.container_mc.npc001._x += 1;
                _level0.npc2le = false;
                _level0.npc2lef = _level0.npc2le;
            }
           
            if (h3>_level0.objectMaxfl) {
                trace("13? h3 = "+h3+"\nMax Proxies3 = "+_level0.objectMaxfl);
            h3++;
                h3 = 0;
           
        }
       
        g3++;
            if (!_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxyleft"+g3)) {
                j3++;
            }
            if (!_level0.container_mc.player.hit04.hitTest(_level0.container_mc.npc001.testhit) && j3 == _level0.objectMaxfl) {
                _level0.npc2le = true;
            }
            if (g3>_level0.objectMaxfl) {
                g3 = 0;
                j3 = 0;
           
        }
                trace("h4 = "+h4+"\nMax Proxiesri = "+_level0.objectMaxfr);
                h4++;
            if (_level0.container_mc.npc001.testhit.hitTest("_level0.container_mc.proxyright"+h4)) {
                trace("||||||||||||||||||||||||||||||||||||||||44444444444444444444444444444");
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(2);
                _level0.container_mc.npc001._x -= 1;
                _level0.npc2ri = false;
                _level0.npc2rif = _level0.npc2ri;
            }
            if (h4>_level0.objectMaxfr) {
                h4 = 0;
            }
       
        g4++;
            if (!_level0.container_mc.npc001.hitTest("_level0.container_mc.proxyright"+g4)) {
                j4++;
            }
            if (!_level0.container_mc.player.hit02.hitTest(_level0.container_mc.npc001.testhit) && j4 == _level0.objectMaxfr) {
                _level0.npc2ri = true;
            }
            if (g4>_level0.objectMaxfr) {
                g4 = 0;
                j4 = 0;
        }
       
        trace("up f"+_level0.npc2upf);
        trace("ri f"+_level0.npc2rif);
        trace("do f"+_level0.npc2dof);
        trace("le f"+_level0.npc2lef);
        trace("up "+_level0.npc2up);
        trace("ri "+_level0.npc2ri);
        trace("do "+_level0.npc2do);
        trace("le "+_level0.npc2le);
    /*4*/if (ires != 1) {
            if (_level0.container_mc.player.hit04.hitTest(_level0.container_mc.npc001.hit4)) {
                ires = 1;
                _level0.npc2le = false;
            } else {
                _level0.npc2le = _level0.npc2lef;
                ires = 0;
            }
        }
        if (ires2 != 1) {
            if (_level0.container_mc.player.hit02.hitTest(_level0.container_mc.npc001.hit2)) {
                ires2 = 1;
                _level0.npc2ri = false;
            } else {
                _level0.npc2ri = _level0.npc2rif;
                ires2 = 0;
            }
        }
        if (ires3 != 1) {
            if (_level0.container_mc.player.hit01.hitTest(_level0.container_mc.npc001.hit1)) {
                ires3 = 1;
                _level0.npc2up = false;
            } else {
                _level0.npc2up = _level0.npc2upf;
                ires3 = 3;
            }
        }
        if (ires4 != 1) {
            if (_level0.container_mc.player.hit03.hitTest(_level0.container_mc.npc001.hit3)) {
                trace("Can not move down");
                ires4 = 1;
                _level0.npc2do = false;
            } else {
                _level0.npc2do = _level0.npc2dof;
                ires4 = 3;
            }
        }
    /*5*/if (_level0.dontrunrandisrdir != true) {
            ran1 = Math.floor(Math.random()*4);
            ran2 = Math.floor(Math.random()*100);
            ran5 = Math.floor(Math.random()*24);
            ran2 += 15;
            ran5 += 6;
            ran0 = Math.floor(Math.random()*25);
            x2 = _level0.container_mc.npc001._x-ran2;
            y2 = _level0.container_mc.npc001._y-ran2;
            x3 = _level0.container_mc.npc001._x+ran2;
            y3 = _level0.container_mc.npc001._y+ran2;
            _level0.dontrun = true;
            _level0.dontrunrandisrdir = true;
            e = 0;
        }
    /*6*/trace("Making Decision");
        trace (ran1);
        if (ran1 == 0) {
            ran6 = 0;
            if (_level0.container_mc.npc001._y<=y2) {
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(1);
            } else {
                if (_level0.npc2up != false) {
                    _level0.container_mc.npc001.gotoAndStop(5);
                    _level0.container_mc.npc001._y -= 1;
                } else if (_level0.npc2up == false) {
                    y2 = _level0.container_mc.npc001._y;
                }
            }
        }
        if (ran1 == 1) {
            ran6 = 1;
            if (_level0.container_mc.npc001._x>=x3) {
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(2);
            } else {
                if (_level0.npc2ri != false) {
                    _level0.container_mc.npc001.gotoAndStop(6);
                    _level0.container_mc.npc001._x += 1;
                } else if (_level0.npc2ri == false) {
                    x3 = _level0.container_mc.npc001._x;
                }
            }
        }
        if (ran1 == 2) {
            ran6 = 2;
            if (_level0.container_mc.npc001._y>=y3) {
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(3);
            } else {
                if (_level0.npc2do != false) {
                    _level0.container_mc.npc001.gotoAndStop(7);
                    _level0.container_mc.npc001._y += 1;
                } else if (_level0.npc2do == false) {
                    y3 = _level0.container_mc.npc001._y;
                }
            }
        }
        if (ran1 == 3) {
            ran6 = 3;
            if (_level0.container_mc.npc001._x<=x2) {
                _level0.dontrun = false;
                _level0.container_mc.npc001.gotoAndStop(4);
            } else {
                if (_level0.npc2le != false) {
                    _level0.container_mc.npc001.gotoAndStop(8);
                    _level0.container_mc.npc001._x -= 1;
                } else if (_level0.npc2le == false) {
                    x2 = _level0.container_mc.npc001._x;
                }
            }
        }
    /*7*//*
        if (ran1 == 4 || ran1 == 5) {
            if (i>=ran0+8) {
                i = 0;
                ran2 = 0;
                _level0.dontrun = false;
                _level0.dontrunrandisrdir = false;
                ran3 = Math.floor(Math.random()*1);
            } else {
                i++;
                if (ran3 == 0 && ran6 == 0) {
                    _level0.container_mc.npc001.gotoAndStop(2);
                }
                if (ran3 == 1 && ran6 == 0) {
                    _level0.container_mc.npc001.gotoAndStop(4);
                }
                if (ran3 == 0 && ran6 == 1) {
                    _level0.container_mc.npc001.gotoAndStop(1);
                }
                if (ran3 == 1 && ran6 == 1) {
                    _level0.container_mc.npc001.gotoAndStop(3);
                }
                if (ran3 == 0 && ran6 == 2) {
                    _level0.container_mc.npc001.gotoAndStop(3);
                }
                if (ran3 == 1 && ran6 == 2) {
                    _level0.container_mc.npc001.gotoAndStop(4);
                }
                if (ran3 == 0 && ran6 == 3) {
                    _level0.container_mc.npc001.gotoAndStop(1);
                }
                if (ran3 == 1 && ran6 == 3) {
                    _level0.container_mc.npc001.gotoAndStop(3);
                }
            }
        }*/

    /*8*/ if (ran1<4) {
            if (_level0.dontrun == false) {
                ran1 = -1;
                if (e == ran5) {
                    _level0.dontrunrandisrdir = false;
                }
                e++;
            }
        }
    }
    }

    /*T*\ Depth Sorting
    /*1*\ Function Intialized
    /*2*\ Toggles run mode
    /*3*\ Handles object depth sorting
    /*4*\ Run Above Comands::
    /**/

    /*1*/
    function misc() {
        /*2*/
        if (Key.isDown(Key.SHIFT)) {
            _level0.speed = 6;
        } else {
            _level0.speed = 3;
        }
        /*3*/
        if (_level0.currentcityinfo.citycode == 1.11) {
            //Set movieclips depths by y position.
            hh_fence_a.swapDepths(hh_fence_a._y);
            hh_fence_d.swapDepths(hh_fence_d._y);
            hh_fence_dd.swapDepths(hh_fence_dd._y);
            woodhomena02hh.swapDepths(woodhomena02hh._y);
            woodhomena02lh.swapDepths(woodhomena02lh._y);
            nolta_tree001.swapDepths(nolta_tree001._y-3);
            nolta_tree002.swapDepths(nolta_tree002._y-3);
            Nolta_fence_bridge.swapDepths(Nolta_fence_bridge._y-3);
            nolta_chest001.swapDepths(nolta_chest001._y);
            _level0.container_mc.npc001.swapDepths(_level0.container_mc.npc001._y);
        }
    }

    /*T*\
    /*1*\ Function Intialized:
      CHECKS IF A PLAYER IS UNDER AN OBJECT AND IS UNABLE
      TO BE SEEN. IF SO, THE OBJECT BECOMES TRANSPARENT!
    /*2*\ Run Above Comands::
    /* */

    /*1*/
    function visibility() {
        if (_parent.woodhomehh.alphahh.hitTest(_parent.player.testhit)) {
            _parent.woodhomehh.alphahh._alpha = 75;
        } else {
            _parent.woodhomehh.alphahh._alpha = 100;
        }
        if (_parent.woodhomena02hh.alphahh.hitTest(_parent.player.testhit)) {
            _parent.woodhomena02hh.alphahh._alpha = 75;
        } else {
            _parent.woodhomena02hh.alphahh._alpha = 100;
        }
        if (_parent.nolta_tree001.alpha01.hitTest(_parent.player.testhit) || _parent.nolta_tree001.alpha02.hitTest(_parent.player.testhit)) {
            _parent.nolta_tree001.alpha._alpha = 60;
        } else {
            _parent.nolta_tree001.alpha._alpha = 100;
        }
        if (_parent.nolta_tree002.alpha01.hitTest(_parent.player.testhit) || _parent.nolta_tree002.alpha02.hitTest(_parent.player.testhit)) {
            _parent.nolta_tree002.alpha._alpha = 60;
        } else {
            _parent.nolta_tree002.alpha._alpha = 100;
        }
    }

    /*T*\ Transitioning
    /*1*\ Function Intialized:
      Removes Objects from last area and creats objects
      for the next area. Also sets playors position.
    /*2*\ Run Above Comands::
    /* */

    /*1*/function removemc() {
        if (_parent.enterplayerhome.hitTest(_parent.player.testhit)) {
            removeMovieClip(_parent.nolta_ground);
            removeMovieClip(_parent.woodhomelh);
            removeMovieClip(_parent.hh_fence_e);
            removeMovieClip(_parent.hh_fence_d);
            removeMovieClip(_parent.hh_fence_dd);
            removeMovieClip(_parent.hh_fence_a);
            removeMovieClip(_parent.woodhomehh);
            removeMovieClip(_parent.woodhomemh);
            removeMovieClip(_parent.woodhomena02hh);
            removeMovieClip(_parent.woodhomena02lh);
            removeMovieClip(_parent.bottom_border);
            _parent.attachMovie("inside_nolta1a_playerhome", "inside_nolta1a_playerhome1", 1, {_x:325, _y:535});
            _parent.player._x = 326;
            _parent.player._y = 364;
            _parent.player.gotoAndStop(1);
            _level0.this_lastfaced = 1;
            _parent.gotoAndStop(2);
        }
    }

    /*T*\ Run Functions
    /* */

    game_time = setInterval(function () {
        timer();
    }, 50);
    npc01 = setInterval(function () {
        ranmove();
    }, 50);
    newarea = setInterval(function () {
        removemc();
    }, 50);
    game_misc = setInterval(function () {
        misc();
    }, 50);
    visibilitystart = setInterval(function () {
        visibility();
    }, 50);

    stop();
    Last edited by brickhouse420; 02-28-2010 at 02:24 PM.

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    These variables are set right away (when the loader.swf loads.. then loader.swf preloads and attaches external.swf)
    Actionscript Code:
    stage.quality = StageQuality.LOW
    _level0.drive = null;
    _level0.drive2 = null;
    _level0.returningy = null;
    _level0.returningx = null;
    _level0.library = "/Important Files/Fla Projects/Rpg/Action script/";
    _level0.currentcityinfo.defx;
    _level0.currentcityinfo.defx;
    _level0.currentcityinfo = {defx:80, defy:210};
    _level0.playerstatus = {gfx:1};
    _level0.pausemove = false;
    _level0.speed = 3;
    _level0.game_time_day = 1;
    _level0.game_time_hour = 12;
    _level0.game_time_min = 58;
    _level0.game_time_tod = "a";
    //#include "player status decloration.as"
    _level0.returningy = 0;
    _level0.returningx = 0;
    _level0.drive2 = 0;
    _level0.drive = "c";
    _level0.firstrun = true;
    _level0.ingamemenu = false;

  4. #4
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    That's an awful lot to read through, what is happening on the stage? You mention hitTest, and that throws up a red flag in terms of optimization for me, hitTest can really bog things down if you are performing a lot of them per frame, which you may not be.

    If you have a lot of collisions to check in each frame, try doing them mathematically by checking distances between objects (distance=Math.sqrt(deltax*deltax + deltay*deltay). If you really need to check a complex shape as in the hit test of point vs a movieclip with the shapeflag turned on, then a mathematics check to see if they are close to each other FIRST, followed by a hitTest only after you have decided there is a near collision is often the way to go.

    Sorry if this is totally off topic.
    Last edited by Alluvian; 03-03-2010 at 10:17 PM.

  5. #5
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    not off topic but that is a good point. Mainly that code does a lot in my game.

    Variables
    Gui
    Timer
    Player
    NPC01
    Depth
    Visibility
    Transition area
    Run Functions
    Entities
    Exit

    Variables sets the start variables.
    Gui attaches all the movie clips.
    Timer keeps track of game time.
    Player creates a walkable player.
    NPC creates a npc that randomly walks around but I was told I should use a different code, so I am updating that.
    Depth swaps and updates depths for movieclips that need a 3d aspect. (based on y position)
    Visibility makes certain movie clips invisible when needed.
    transition is when going to another area takes place and distruction and creation of movieclips is needed.
    run functions runs the functions.

    I updated the swap depths do its not needed I dont think. I am updating the npc and the timer and gui seems fine. Visibility I can fix without using a hit test (math areas i can use)

    the code for the new npc was here.
    http://board.flashkit.com/board/show...06#post4237506

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center