rendered paste body//Main Game Script
//Global variables
var xVelocity=0; // pc's x velocity
var yVelocity=0; // pc's y velocity
var acceleration=2; // pc's acceleration due to arrow key
var depth=1001; // display depth for platforms; starts at 1
var platforms = new Array(); // platform data
//initialisation code
theLevel = new XML();
theLevel.ignoreWhite=true;
theLevel.onLoad=parseLevel;
theLevel.load("level0.xml");
imMask._visible = false;
imScene.setMask(imMask);
function parseLevel() {
trace("Read level description.");
var p=theLevel.childNodes[0];
//set up the background
imScene.attachMovie(p.attributes.backgroundClip,"i"+p.attributes.backgroundClip,0);
//set up the player's character(pc)
imPC._x=Number(p.attributes.xStart);
imPC._y=Number(p.attributes.yStart);
imPC.swapDepths(1000);
trace(imPC._x);
trace(imPC._y);
// set up the platforms
var q=p.childNodes[0];
parsePlatforms(q);
}
//functions
onEnterFrame=function () {
checkInput();
imScene._x -= xVelocity;
imScene._y -= yVelocity;
}
function checkInput() {
if(Key.isDown(Key.RIGHT)) {
xVelocity += acceleration;
}
if (Key.isDown(Key.LEFT)) {
xVelocity -= acceleration;
}
if (Key.isDown(Key.UP)) {
yVelocity -= acceleration;
}
if (Key.isDown(Key.DOWN)) {
yVelocity += acceleration;
}
}
function Platform(x,y,w,h,v,clip,clipName) {
this._x = x;
this._y = y;
this._width = w;
this._height = h;
this._visible = v;
this._clip = clip;
this._clipName = clipName;
this.swapDepths(1000);
trace("Platform func ("+this._x+","+this._y+")");
}
function parsePlatforms(p) {
numPlatforms=p.childNodes.length;
for (var i=0;i<numPlatforms;i++) {
platforms[i] = new Platform(
Number(p.childNodes[i].attributes.x),
Number(p.childNodes[i].attributes.y),
Number(p.childNodes[i].attributes.w),
Number(p.childNodes[i].attributes.h),
Boolean(p.childNodes[i].attributes.v=="true"),
p.childNodes[i].attributes.clip,
"i"+p.childNodes[i].attributes.clip+i);
theClip = imScene.attachMovie(platforms[i]._clip,platforms[i]._name,depth);
depth++;
theClip._x = platforms[i]._x;
theClip._y = platforms[i]._y;
theClip._height = platforms[i]._height;
theClip._width = platforms[i]._width;
theClip._visible = platforms[i]._visible;
}
}