Alert.show(array[i]);
}
}
4.循环控制for…in语句foreach…in语句while语句do…while语句
5.条件语句if…else语句if..elseif语句switch语句
6.Math对象math类及其常用方法
Alert.show(Math.abs(8).toString());
Alert.show(Math.random().toString());//随机数范围0-1
Alert.show(Math.round(58.4).toString());//四舍五入
Alert.show(Math.ceil(3.5).toString());//向上取整
7.数据类型装换asis
转换为FLEX组件
作业:
1.让键盘控制坦克(尝试)
2.制作素材坦克
总结
用户名:
blue_wait@
密码:
dd111111
1月12日
画子弹,爆炸效果以及敌人
面向对象分析(属性,行为)
坦克
-外观
-速度
-方向
-死亡状态
-大小
-攻击力
-开火()
-移动()
-重生()
-升级()
子弹
-长相
-大小
-速度
-方向
-射程
-死亡状态
-攻击力
-攻击()
-移动()
-去死()
事件监听以及相应函数方法的写法
TankObj.as
packagecom.wepull.tank
{
importflash.events.KeyboardEvent;
importflash.utils.setInterval;
importmx.core.FlexGlobals;
importmx.events.FlexEvent;
importponents.Application;
publicclassTankObjextendsTank
{
publicfunctionTankObj()
{
super();
/*加载完成后进行初始化*/
this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
}
/**速度*/
publicvarsp:
Number=5;
/**
*U:
上
*UR:
上右
*R:
右
*RD:
右下
*D:
下
*DL:
下左
*L:
左
*LU:
左上
*"":
停止
*方向*/
publicvarasp:
String="";
/**炮筒方向*/
publicvarptAsp:
String="U";
/**死亡状态
*使用继承而来的可视属性表示
**/
/**大小
*使用继承而来的高度宽度
**/
/**初始化
*定高宽
*循环移动
*添加键盘控制坦克的行动*/
publicfunctioninit(e:
FlexEvent):
void{
this.height=100;
this.width=70;
setInterval(domove,40);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,onkey);
this.stage.addEventListener(KeyboardEvent.KEY_UP,onkeyend);
}
/**开火
*1.产生一个子弹
*2.坐标同步
*3.方向同步*/
publicfunctionfire():
void{
/**获得application,无法获得application的值,有错*/
varapplication:
Application=Application(FlexGlobals.topLevelApplication);
varbul:
BulletObj=newBulletObj();
application.addElement(bul);
bul.x=this.x;
bul.y=this.y;
bul.asp=this.ptAsp;//子弹方向与炮筒方法同步
}
/**移动
*根据速度和方向*/
publicfunctiondomove():
void{
//--控制炮口方向
if(asp!
=""){
this.ptAsp=this.asp;
}
if(asp=="U"){//--上
this.y-=sp;
this.rotationZ=0;
}elseif(asp=="UR"||asp=="RU"){//--上右
this.x+=sp;
this.y-=sp;
this.rotationZ=45;
}
elseif(asp=="R"){//--右
this.x+=sp;
this.rotationZ=90;
}
elseif(asp=="RD"||asp=="DR"){//--右下
this.x+=sp;
this.y+=sp;
this.rotationZ=135;
}
elseif(asp=="D"){//--下
this.y+=sp;
this.rotationZ=180;
}
elseif(asp=="DL"||asp=="LD"){//--下左
this.x-=sp;
this.y+=sp;
this.rotationZ=225;
}
elseif(asp=="L"){//--左
this.x-=sp;
this.rotationZ=270;
}
elseif(asp=="LU"||asp=="UL"){//--左上
this.x-=sp;
this.y-=sp;
this.rotationZ=315;
}
}
/**去死*/
publicfunctiondead():
void{
}
/**重生*/
publicfunctionrelive():
void{
}
/**当键盘压下,改变坦克的方向*/
publicfunctiononkey(e:
KeyboardEvent):
void{
varkey:
int=e.keyCode;
/**用上下左右控制*/
/*if(key==38){
this.asp="U";
}elseif(key==39){
this.asp="R";
}elseif(key==40){
this.asp="D";
}elseif(key==37){
this.asp="L";
}*/
/**用WASD控制*/
if(key==87&&asp.length<2&&asp.indexOf("U")==-1){
this.asp+="U";
}elseif(key==68&&asp.length<2&&asp.indexOf("R")==-1){
this.asp+="R";
}elseif(key==83&&asp.length<2&&asp.indexOf("D")==-1){
this.asp+="D";
}elseif(key==65&&asp.length<2&&asp.indexOf("L")==-1){
this.asp+="L";
}elseif(key==74){//--按j键开火
fire();
}
}
/**只要有键盘弹起方向为无
*就将对应的方向的字符从asp中清除*/
publicfunctiononkeyend(e:
KeyboardEvent):
void{
varkey:
int=e.keyCode;
if(key==87){
asp=asp.replace("U","");
}elseif(key==68){
asp=asp.replace("R","");
}elseif(key==83){
asp=asp.replace("D","");
}elseif(key==65){
asp=asp.replace("L","");
}
}
}
}
BulletObj.as
packagecom.wepull.tank
{
importflash.utils.setInterval;
importmx.events.FlexEvent;
publicclassBulletObjextendsBullet
{
publicfunctionBulletObj()
{
super();
this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
}
/**速度*/
publicvarsp:
Number=10;
/**方向*/
publicvarasp:
String="";
/**死亡状态用可视元素替代*/
/**初始化
*大小初始化
*移动
**/
publicfunctioninit(e:
FlexEvent):
void{
this.height=60;
this.width=20;
setInterval(domove,40);
}
/**移动AI*/
publicfunctiondomove():
void{
if(asp=="U"){//--上
this.y-=sp;
this.rotationZ=0;
}elseif(asp=="UR"||asp=="RU"){//--上右
this.x+=sp;
this.y-=sp;
this.rotationZ=45;
}
elseif(asp=="R"){//--右
this.x+=sp;
this.rotationZ=90;
}
elseif(asp=="RD"||asp=="DR"){//--右下
this.x+=sp;
this.y+=sp;
this.rotationZ=135;
}
elseif(asp=="D"){//--下
this.y+=sp;
this.rotationZ=180;
}
elseif(asp=="DL"||asp=="LD"){//--下左
this.x-=sp;
this.y+=sp;
this.rotationZ=225;
}
elseif(asp=="L"){//--左
this.x-=sp;
this.rotationZ=270;
}
elseif(asp=="LU"||asp=="UL"){//--左上
this.x-=sp;
this.y-=sp;
this.rotationZ=315;
}
}
/**去死*/
publicfunctiondead():
void{
}
}
}
Wepull_tank_01.mxml
xmlversion="1.0"encoding="utf-8"?
>
ApplicationapplicationComplete="init(event)"xmlns:
fx="
xmlns:
s="library:
//
xmlns:
mx="library:
//minWidth="955"minHeight="600">
Script>
[CDATA[
importcom.wepull.tank.BulletObj;
importcom.wepull.tank.TankObj;
importmx.events.FlexEvent;
[Bindable]
publicvartank:
TankObj=newTankObj();
publicvarbul:
BulletObj=newBulletObj();
protectedfunctioninit(event:
FlexEvent):
void{
this.addElement(tank);
}
]]>
Script>
Declarations>
--Placenon-visualelements(e.g.,services,valueobjects)here-->
Declarations>
Application>
作业:
如何优化性能,回收子弹,写想法
1月13日
-越界子弹处理回收
-在坦克内部加入弹夹
-初始化时先制造所有子弹运行中只管使用
找到可用的子弹~~~运用visible函数
坦克左右一起按,再按开火。
子弹不动,如何解决
开火时音效
作业:
子弹依然停留问题
让子弹DU,UD,LR,RL的方向不存在即可
在domove中加入
if(asp!
=""&&asp!
="DU"&&asp!
="UD"&&asp!
="LR"&&asp!
="RL"){
this.ptAsp=this.asp;
}
坦克越界停止
获得坦克当前越界时的方向,除了该方向,其他方向都可以移动
爆炸效果加入到每一个对象中去
还要考虑哪些碰撞情况
游戏性
去公司参观
关山饭店~~~