|
-
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|