![]() |
|
||||||||||
|
|||||
|
Регистрация: Jan 2011
Сообщений: 247
|
Делая игру дошел до точки где надо хорошо обдумать а правильно ли я начал делать ...?
вот собственно вопросы по коду: 1)задумался о соприкосновении блоков. 2)также линия сгорания. 3)центральный куб, который будет осью при rotation,можно конечно через if else, ну это куча лишнего кода... package elements { import flash.display.*; import flash.events.*; import flash.text.*; import flash.utils.* public class Blocks extends Sprite { //////////////////////////////////////////////////////////////////// // Public properties //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Private properties //////////////////////////////////////////////////////////////////// private var tetrisblock1: Sprite; private var tetrisblock2: Sprite; private var tetrisblock3: Sprite; private var tetrisblock4: Sprite; private var n1:int; private var move:Number = 20; private var tf:TextField; private var key_left:Boolean = false; private var key_right:Boolean = false; private var key_Up:Boolean = false; private var blockButton: Sprite; private var delay:uint = 400; private var repeat:uint ; private var myTimer:Timer = new Timer(delay, repeat); private var statusTextField:TextField = new TextField(); private var inputTextField:TextField = new TextField(); //////////////////////////////////////////////////////////////////// // Public methods //////////////////////////////////////////////////////////////////// public function Blocks() { this.tetrisblock1 = this.makeSquare(); this.tetrisblock2 = this.makeSquare(); this.tetrisblock3 = this.makeSquare(); this.tetrisblock4 = this.makeSquare(); this.blockButton = new Sprite(); var field: TextField = new TextField(); field.defaultTextFormat = new TextFormat('calibri', 12); field.text = 'ReBlock'; field.selectable = false; this.blockButton.addChild(field); var trigger: Sprite = new Sprite(); trigger.graphics.beginFill(0xff00ff, 0.3); trigger.graphics.drawRect( -3, -3, field.textWidth + 8, field.textHeight + 8); trigger.graphics.endFill(); this.blockButton.addChild(trigger); this.blockButton.buttonMode = true; this.blockButton.x = 245; this.blockButton.y = 150; this.addChild(this.blockButton); myTimer.start(); myTimer.addEventListener(TimerEvent.TIMER, blockDown); myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler); this.blockButton.addEventListener(MouseEvent.CLICK, this.this_onAddedToBlock); addEventListener(Event.ADDED_TO_STAGE, this_onAddedToBlock); addEventListener(Event.ENTER_FRAME, moveBlocks); } public function rect():void { this.tetrisblock1.x = 0 this.tetrisblock1.y = 0 this.tetrisblock2.x = 20 this.tetrisblock2.y = 0 this.tetrisblock3.x = 0 this.tetrisblock3.y = 20 this.tetrisblock4.x = 20 this.tetrisblock4.y = 20 } public function line():void { this.tetrisblock1.x = 0 this.tetrisblock1.y = 0 this.tetrisblock2.x = 20 this.tetrisblock2.y = 0 this.tetrisblock3.x = 40 this.tetrisblock3.y = 0 this.tetrisblock4.x = 60 this.tetrisblock4.y = 0 } public function snake():void { this.tetrisblock1.x = 0 this.tetrisblock1.y = 0 this.tetrisblock2.x = 20 this.tetrisblock2.y = 0 this.tetrisblock3.x = 20 this.tetrisblock3.y = 20 this.tetrisblock4.x = 40 this.tetrisblock4.y = 20 } public function plus():void { this.tetrisblock1.x = 0 this.tetrisblock1.y = 0 this.tetrisblock2.x = 20 this.tetrisblock2.y = 0 this.tetrisblock3.x = 40 this.tetrisblock3.y = 0 this.tetrisblock4.x = 20 this.tetrisblock4.y = 20 } public function horse():void { this.tetrisblock1.x = 0 this.tetrisblock1.y = 0 this.tetrisblock2.x = 20 this.tetrisblock2.y = 0 this.tetrisblock3.x = 40 this.tetrisblock3.y = 0 this.tetrisblock4.x = 40 this.tetrisblock4.y = 20 } //////////////////////////////////////////////////////////////////// // Private methods //////////////////////////////////////////////////////////////////// private function makeSquare() : Sprite { var spr: Sprite = new Sprite(); spr.graphics.beginFill(0xff00ff, 0.3); spr.graphics.drawRect(0, 0, 20, 20); spr.graphics.endFill(); this.addChild(spr); return spr; } private function blockDown(e:TimerEvent):void { repeat--; trace('таймера осталось : ' +repeat); if (tetrisblock1.y < 380 && tetrisblock2.y < 380 && tetrisblock3.y < 380 && tetrisblock4.y < 380 ) { tetrisblock1.y += move; tetrisblock2.y += move; tetrisblock3.y += move; tetrisblock4.y += move; trace('двигаюсь');} if ( tetrisblock4.y >= 380 && tetrisblock4.y <=400) { myTimer.removeEventListener(TimerEvent.TIMER, blockDown); trace('застыл');} } private function completeHandler(e:TimerEvent):void { trace('конец!'); } //////////////////////////////////////////////////////////////////// // Listeners //////////////////////////////////////////////////////////////////// private function this_text():void { var tf: TextField = new TextField(); this.addChild(tf); var format: TextFormat = new TextFormat('Calibri', 18, 0xcccccc, true); tf.defaultTextFormat = format; tf.width = 200; tf.height = 40; tf.text = 'fail'; tf.selectable = false; tf.x = 240; tf.y = 120 tf.width = tf.textWidth + 4; tf.height = tf.textHeight + 4; } private function this_onAddedToBlock(e:Event) : void { removeEventListener(Event.ADDED_TO_STAGE, this_onAddedToBlock); myTimer.addEventListener(TimerEvent.TIMER, blockDown); this.n1 = int(Math.round(Math.random() * 100)); if (n1 >= 0 && n1 < 20) { rect(); } if (n1 >= 20 && n1 < 40) { line(); } if (n1 >= 40 && n1 < 60) { snake(); } if (n1 >= 60 && n1 < 80) { plus(); } if (n1 >= 80 && n1 <= 100) { horse(); } } private function key_down(e:KeyboardEvent):void { trace('нажал'+e.keyCode); if (e.keyCode == 37) { key_left = true; } if (e.keyCode == 39) { key_right = true; } if (e.keyCode == 38) { key_Up = true; } } private function key_up(e:KeyboardEvent):void { trace('отпустил'+e.keyCode); if (e.keyCode == 37) { key_left = false;; } if (e.keyCode == 39) { key_right = false; } if (e.keyCode == 38) { key_Up = false; } } private function moveBlocks(e:Event):void { moveBlock(); stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down); stage.addEventListener(KeyboardEvent.KEY_UP, key_up); } private function moveBlock():void { if (tetrisblock1.x >=20 && tetrisblock2.x > 10 && tetrisblock3.x > 10 && tetrisblock4.x > 10 ) { if (key_left) { tetrisblock1.x -= move; tetrisblock2.x -= move; tetrisblock3.x -= move; tetrisblock4.x -= move; trace('left'); }} if (tetrisblock1.x < 220&& tetrisblock2.x < 220&& tetrisblock3.x < 220&& tetrisblock4.x < 220){ if (key_right){ tetrisblock1.x += move; tetrisblock2.x += move; tetrisblock3.x += move; tetrisblock4.x += move; trace('right'); }} if ( line || snake || plus || horse ) { if (key_Up) { tetrisblock1.rotation += 90; tetrisblock2.rotation += 90; tetrisblock3.rotation += 90; tetrisblock4.rotation += 90; } } } } } Сори что все в одном классе как все доделаю сразу все распределю... P.S.код начеркал за денек,двигаюсь в правильном направлении ? Последний раз редактировалось GrafMine; 05.01.2011 в 18:56. |
![]() |
Часовой пояс GMT +4, время: 21:43. |
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | |
| Опции просмотра | |
|
|