https://www.jb51.net/files/media/dirtanke.swf
这几天也写了一些类了,是驴子还是骡子,拿出来遛一遛就知道了,先看这个上面这个flash动画!
一个类似坦克游戏的demo程序
使用Direction类来进行方向控制
使用Dot类来计算距离
用上Direction类和Dot类之后,这个demo程序变得异常简单额。。
也没什么好说,主要透过这个例子,让大家类熟悉Direction类和Dot类的使用方法
不懂的可以在后面跟帖提问,高手如果看到什么有错误的地方,请指正出来,多谢指教
下面是fla的源代码:
CODE:
import index.base.game.Direction;
import index.base.events.DirectionEvent;
import index.base.geom.Dot;
//舞台属性设置
stage.showDefaultContextMenu = false;
stage.align = "TL";
stage.scaleMode = "noScale";
//创建坦克
var tank:Tank = new Tank;
tank.x = tank.y = 250;
addChild(tank);
//创建绑定坦克的点
var dot:Dot = new Dot;
dot.bind(tank);
//坦克移动
var dirTank:Direction = new Direction(stage);
//炮台转动
var dirTower:Direction = new Direction(stage,true,87,83,65,68);
//坦克炮台事件
dirTank.addEventListener(DirectionEvent.DO,doTankFun);
dirTower.addEventListener(DirectionEvent.DO,doTowerFun);
//坦克移动
function doTankFun(e:DirectionEvent):void{
if(e.up){
dot.go(2,true);
}
if(e.down){
dot.go(-2,true);
}
if(e.left){
tank.rotation -= 2;
}
if(e.right){
tank.rotation = 2;
}
if(tank.x < 0) tank.x = 0;
if(tank.y < 0) tank.y = 0;
if(tank.x > stage.stageWidth) tank.x = stage.stageWidth;
if(tank.y > stage.stageHeight) tank.y = stage.stageHeight;
}
//是否可以发射炮台,子弹
var isBullet:Boolean = true;
var isShell:Boolean = true;
//炮台发射转动
function doTowerFun(e:DirectionEvent):void{
if(e.up && isBullet){
var bullet:Bullet = new Bullet;
bullet.x = tank.x;
bullet.y = tank.y;
bullet.rotation = tank.rotation tank.tower.rotation;
bullet.addEventListener(Event.ENTER_FRAME,bulletFun);
addChild(bullet);
isBullet = false;
setTimeout(function(){isBullet = true},200);










