|
|
|||||
Деление скрипта на классы
Есть несложный скрипт с Недо - движком игры.
Написан в простыню mxml файла во флекс. При моих попытках деления на классы получил цикличную рекурсию. Помогите корректно разделить на классы 1) Класс с управлением и прослушивателями нажатий кнопок 2) Класс с построением уровня. 3) Класс с определением коллизий. 4) Класс с циклом слушающий enterFrame там анимации ГГ и гравитация. Код прилагаю. <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="600" minHeight="600" currentState="Menu" frameRate="60" keyDown="onkey(event)" keyUp="onup(event)" minWidth.Begin="600" minHeight.Begin="400" maxWidth.Begin="600" minHeight.Menu="400" minHeight.Registration="400" > <fx:Style source="game.css"/> <fx:Script> <![CDATA[ import flash.net.*; import flash.utils.*; public var jump:Boolean = false; public var jmpc:Number = 0; public var i:int = 1; public var colri:Boolean = false; public var colle:Boolean = false; public var coldn:Boolean = false; public var colup:Boolean = false; public var verwall:Array = []; import mx.messaging.AbstractConsumer; public var keyri:uint = 39; public var recive:String = ""; public var keyle:uint = 37; public var connect:Socket = new Socket(); public var keypri:Boolean = false; public var keyple:Boolean = false; public function check():void { connect.connect("127.0.0.1", 1112); if (connect.connected == true) { connect.writeUTF(Loginfield.text); connect.writeUTF(passwordfield.text); connect.flush(); connect.readUTF(); connect.flush(); } } public function start(event:Event):void { verwall.push(verwal1, verwal2); collis(); jmpc=spr1.y-40; } public function jumpanim():void { if((jump == true) && (coldn == true)) { (jmpc=(spr1.y-40)); } if((jump == true) && (jmpc>spr1.y) && (coldn == true)) { jump=false; } } public function onup(event:KeyboardEvent):void { if(event.keyCode == keyri) { keypri = false; } if(event.keyCode == keyle) { keyple = false; } } public function onkey(event:KeyboardEvent):void { if((event.keyCode == Keyboard.RIGHT) && (spr1.x <= 594) && (colri == false)) { (spr1.x=(spr1.x+counter.value)); keypri=true; } if((event.keyCode == Keyboard.LEFT) && (spr1.x >= 0) && (colle == false)) { (spr1.x=(spr1.x-counter.value)); keyple=true; } if((event.keyCode == Keyboard.UP) && (jump == false) && (coldn == true) && (colup == false)) { jump=true; jumpanim(); } } public function collis():void { test.text=coldn.toString(); if((dnco.hitTestObject(verwal1) == true) || (dnco.hitTestObject(verwal2) == true) || (dnco.hitTestObject(verwal3) == true)) { coldn = true; } else { coldn = false; } if((rico.hitTestObject(verwal1) == true) || (rico.hitTestObject(verwal2) == true) || (rico.hitTestObject(verwal3) == true)) { colri = true; } else { colri = false; } if((leco.hitTestObject(verwal1) == true) || (leco.hitTestObject(verwal2) == true) || (leco.hitTestObject(verwal3) == true)) { colle = true; } else { colle = false; } if((upco.hitTestObject(verwal1) == true) || (upco.hitTestObject(verwal2) == true) || (upco.hitTestObject(verwal3) == true)) { colup = true; } else { colup = false; } } public function frasher(event:Event):void { collis(); if (connect.connected == true) { connect.writeUTF(("X" + spr1.x + "Y" + spr1.y + "X01" + nick.text)); connect.flush(); } if((spr1.x > 0) && (coldn == false) && (jump == false)) { spr1.y=(spr1.y + 4); } if((keypri == true) && (spr1.x >= 0) && (spr1.x <= 620) && (colri == false)) { (spr1.x=(spr1.x+counter.value)); } if((keyple == true) && (spr1.x >= 0) && (spr1.x <= 620) && (colle == false)) { (spr1.x=(spr1.x-counter.value)); } if((jump == true) && (spr1.y<jmpc)) { jump = false; } else if(jump == true) { (spr1.y=(spr1.y-8)); } if(colle == true) { jump=false; keypri=false; keyple=false; while(colle == false) { spr1.x=(spr1.x+4); } } if(colri == true) { jump=false; keypri=false; keyple=false; while(colri == false) { spr1.x=(spr1.x-4); } } } ]]> </fx:Script> <s:states> <s:State name="Begin"/> <s:State name="Menu"/> <s:State name="Registration"/> </s:states> <fx:Declarations> <!-- Разместить невизуальные элементы (например, службы или объекты значений) --> </fx:Declarations> <s:BorderContainer id="con" includeIn="Begin" x="0" y="0" width="697" height="400"> <s:BorderContainer id="spr1" borderVisible="true" height="50" width="30" x="29" y="293" visible="true" creationComplete="start(event)" enterFrame="frasher(event)"> <s:backgroundFill> <s:SolidColor alpha="0.5" color="#0099ff"/> </s:backgroundFill> <s:Button x="5" y="45" width="20" height="5" id="dnco" visible="false"/> <s:Button x="25" y="5" width="5" height="40" id="rico" visible="false"/> <s:Button x="0" y="5" width="5" height="40" id="leco" visible="false"/> <s:Button x="5" y="0" width="20" height="5" id="upco" visible="false"/> </s:BorderContainer> <s:BorderContainer x="0" y="350" width="695" height="50" visible="true" id="verwal2" borderVisible="false" cornerRadius="10"> <s:backgroundFill> <s:SolidColor alpha="1" color="#222222"/> </s:backgroundFill> </s:BorderContainer> <s:BorderContainer id="verwal1" visible="true" x="493" y="329" width="100" height="20" borderVisible="false" cornerRadius="10"> <s:backgroundFill> <s:SolidColor alpha="1" color="#222222"/> </s:backgroundFill> </s:BorderContainer> <s:BorderContainer id="verwal3" visible="true" x="314" y="289" width="100" height="10" borderVisible="false" cornerRadius="5"> <s:backgroundFill> <s:SolidColor alpha="1" color="#222222"/> </s:backgroundFill> </s:BorderContainer> <s:Button x="11" y="13" label="Начать"/> <s:Label x="536" y="8" text="Увеличить скорость в"/> <s:NumericStepper id="counter" visible="true" x="571" y="22" width="50" height="20" allowValueWrap="true" alpha="1" enabled="true" maxChars="2" maximum="12" minimum="1"/> <s:Label id="nick" color="red" text="{Loginfield.text}" x="{spr1.x+2}" y="{spr1.y-9}"/> <s:Label x="266" y="15" id="test"/> </s:BorderContainer> <s:Panel includeIn="Menu" x="50" y="30" width="300" height="150"> <s:Button includeIn="Menu" x="200" y="90" label="Отправить" click="currentState='Begin'; check();" /> <s:Label x="16" y="-22" text="Login menu"/> <s:TextInput id="Loginfield" x="6" y="5" enabled="true" text="Логин"/> <s:TextInput id="passwordfield" x="6" y="56" enabled="true" text="Пароль"/> <mx:LinkButton id="registrationlink" x="5" y="90" label="Зарегистрироваться" color="#0096FF" click="currentState='Registration'" enabled="true" fontFamily="Arial" fontSize="12"/> </s:Panel> <s:Panel includeIn="Registration" x="50" y="30" width="300" height="150"> <s:Button x="200" y="90" label="Отправить"/> <s:Label x="16" y="-22" text="Регистрация"/> <s:TextInput id="Loginfield0" x="6" y="5" enabled="true" text="Логин"/> <s:TextInput id="passwordfield0" x="6" y="56" enabled="true" text="Пароль"/> <mx:LinkButton id="registrationlink0" x="5" y="90" label="Войти" color="#0096FF" click="currentState='Menu'" enabled="true" fontFamily="Arial" fontSize="12"/> </s:Panel> </s:Application> |
Часовой пояс GMT +4, время: 22:04. |
|
« Предыдущая тема | Следующая тема » |
|
|