纯as3坦克大战源码
MVC框架
备注都写得很清楚,
适合学习
package {
import Controllers.BasicController;
import Controllers.MonsterController;
import flash.display.Sprite;
import flash.display.Stage;
import flash.geom.Point;
import flash.utils.Timer;
import Objects.Base;
import Objects.GameObject;
import Objects.GameSounds;
import Objects.Item;
import Objects.Monster;
import Objects.Player;
import Objects.Stone;
import Sence.Sence;
import Controllers.KeyController;
import Objects.ActionObject;
import flash.events.TimerEvent;
public class Main extends Sprite{
private var mapconfig:Array = [
[0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1],
[0, 1, 0, 0, 0, 1, 4, 0, 0, 0, 1, 0],
[0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0],
[0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
];
public function Main() {
// constructor code
var sence:Sence.MapSence = new Sence.MapSence(stage);
sence.setup(mapconfig);
addChild(sence);
new GameSounds("open.mp3");
var timer:Timer = new Timer(10000);
timer.addEventListener(TimerEvent.TIMER, createItem);
timer.start();
}
private function createItem(e:TimerEvent) {
for each(var obj:GameObject in Global.sence.objectArray) {
if (obj is Item) obj.die(obj);
}
//删除当前的物品
/**
* 新建物品
*/
var p:Point = getRandomPlace();
var item:Item = new Item(new Item_Speed());
item.x = item.width * p.x + Global.INTERVAL;
item.y = item.width * p.y + Global.INTERVAL;
Global.sence.addObject(item);
}
private function getRandomPlace():Point {
var ry:uint = int(Math.random() * mapconfig.length);
var rx:uint = int(Math.random() * mapconfig[0].length);
if (mapconfig[ry][rx] == 0) return new Point(rx, ry);
return getRandomPlace();
}
}
}