FLASH教程:as3实现的俄罗斯方块
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-07
|
俄罗斯方块swf:
源文件: Tetris.rar
详细代码:
- package
- {
- import Flash.display.Sprite;
- import flash.events.Event;
- import flash.events.KeyboardEvent;
- import flash.events.MouseEvent;
- import flash.events.TimerEvent;
- import flash.geom.Point;
- import flash.text.TextField;
- import flash.ui.Keyboard;
- import flash.utils.Timer;
- import flash.net.*;
- /**
- * ...
- * @author sliz
- * @qq:405628079
- */
- [SWF(width="400", height="500", backgroundColor="0x000000", frameRate="60")]
- public class Main extends Sprite
- {
- private var deadBoxs:Array = new Array();
- private var liveBoxs:Array = new Array();
- private var xNum:int = 20;
- private var yNum:int = 40;
- private var w:Number = 10;
- private var world:Sprite = new Sprite();
- private var liveWrapper:Sprite = new Sprite();
-
- private var keyRight :Boolean = false;
- private var keyLeft :Boolean = false;
- private var keyUp:Boolean = false;
- private var keyRollLeft:Boolean = false;
- private var keyRollRight:Boolean = false;
-
- private var lives:Array = new Array();
- private var livesLength:int = 5;
-
- public function Main():void
- {
- init();
- }
-
- private function init():void
- {
- ////////////////////////////
- var lable1:TextField = new TextField();
- addChild(lable1);
- lable1.textColor = 0xffffff;
- lable1.text = "上,下,左,右,空格";
- var lable2:TextField = new TextField();
- addChild(lable2);
- lable2.textColor = 0xffffff;
- lable2.text = "sliz";
- lable2.width = 50;
- lable2.height=20
- lable2.addEventListener(MouseEvent.CLICK, clickHandler);
- lable2.x = stage.stageWidth - lable2.width;
- lable2.y = stage.stageHeight - lable2.height;
- ///////////////////////////
- var timer:Timer = new Timer(1000);
- var timer2:Timer = new Timer(100);
- addChild(world);
- world.x = stage.stageWidth / 2 - xNum * w / 2;
- world.y = stage.stageHeight / 2 - yNum * w / 2
- addChild(liveWrapper);
- for (var i:int = 0; i < yNum;i++ ) {
- deadBoxs = new Array();
- for (var j:int = 0; j < xNum;j++ ) {
- deadBoxs[j] = 0;
- }
- }
- lives[0] = 1;
- for (i = 0; i < livesLength; i++) {
- initLive();
- }
- update();
- stage.addEventListener(MouseEvent.CLICK, clickHandler);
- stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
- stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
- stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
- timer.addEventListener(TimerEvent.TIMER, timeHandler);
- timer2.addEventListener(TimerEvent.TIMER, timeHandler2);
- timer2.start();
- timer.start();
- }
- private function init
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn
为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
|