Pages

Manual Book Game Base Defender

Aplikasi ini berjudul “Game Base Defender”. Didalam aplikasi ini pemain utama harus menghancurkan pesawat-pesawat yaang terbang yang mana pesawat tersebut bertujuan menjatuhkan pemain utama.
Berikut adalah listing dari game ini :



import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
totalobjects = 0;
curlevel = 1;
passedplanes = 0;
gameon = 1;
var enemyarray:Array = new Array();
function removeEnemy(enemyname) {
for (enemysearch=0; enemysearch
}
}
removeMovieClip(enemyname);
}
function removeAllEnemies() {
for (enemyloop=0; enemyloophighscore.score) {
highscore.score = score.score;
}
explosion(eval(enemyarray[enemysearch])._x, eval(enemyarray[enemysearch])._y);
removeEnemy(eval(enemyarray[enemysearch]));
removeMovieClip(eval(collider));
break;
}
}
}
var grasspng:BitmapData = BitmapData.loadBitmap('grass');
var grass:BitmapData = new BitmapData(grasspng.width, grasspng.height, true, 0x00000000);
this.createEmptyMovieClip('grasscontainer', this.getNextHighestDepth());
function resetGrass() {
grass.copyPixels(grasspng, new Rectangle(0, 0, grasspng.width, grasspng.height), new Point(0, 0), grasspng, new Point(0, 0), true);
grasscontainer.attachBitmap(grass, grasscontainer.getNextHighestDepth());
grasscontainer._y = 275;
}
resetGrass();
this.attachMovie('soldier', 'soldier', this.getNextHighestDepth());
soldier._x = Stage.width/2;
soldier._y = 50;
soldier.xvel = 0;
soldier.yvel = 0;
soldier.airborne = 1;
soldier.onEnterFrame = function() {
for (enemysearch=0; enemysearchStage.height+20) {
loseGame();
this._x = Stage.width/2;
this._y = 30;
}
}
this._x = Math.max(5, Math.min(Stage.width-5, Math.round(this._x+this.xvel)));
this._y = Math.round(this._y+this.yvel);
if (grass.getPixel32((this._x-grasscontainer._x), (this._y-grasscontainer._y+1)) != 0) {
for (moveup=1; moveup<=this.yvel; moveup++) { //check if the soldier has dropped below the top of the ground if (grass.getPixel32((this._x-grasscontainer._x), (this._y-grasscontainer._y-moveup)) == 0) { //there is a collision, so move the y position up this._y -= (moveup); //exit the for loop break; } } //the soldier has hit the ground, so reset the y velocity this.yvel = 0; //the soldier is no longer airborne this.airborne = 0; } else { //else the soldier has not hit the ground, so it is still airborne this.airborne = 1; } //jump if the W key or up arrow are pressed and the soldier is not airborne if ((Key.isDown(Key.UP) || Key.isDown(87)) && !this.airborne) { //soldier is now airborne this.airborne = 1; //soldier jumps, so boost the y velocity this.yvel = -10; } //Left or A key is pressed, so move the soldier left if (Key.isDown(Key.LEFT) || Key.isDown(65)) { this.xvel = -5; //Else if the right or D key are pressed, move the soldier right } else if (Key.isDown(Key.RIGHT) || Key.isDown(68)) { this.xvel = 5; //Else if neither left or right are pressed, stop the soldier horizontally } else if (!this.airborne) { this.xvel = 0; } if (this.xvel != 0 && !this.airborne) { for (buffup=1; buffup<6; buffup++) { if (grass.getPixel32((this._x-grasscontainer._x), (this._y-grasscontainer._y-buffup)) == 0) { this._y -= buffup; break; } } if(buffup==6){ this._y -= 1; } } }; function explosion(xpos, ypos) { this.attachMovie('explosion', 'explosion'+totalobjects, this.getNextHighestDepth()); eval('explosion'+totalobjects)._x = xpos; eval('explosion'+totalobjects)._y = ypos; totalobjects++; } function circleErase(bitmap, xpos, ypos, circlesize) { r2 = circlesize*circlesize; for (circx=-circlesize; circx<=circlesize; circx++) { circy = Math.round(Math.sqrt(r2-circx*circx)+0.5); bitmap.fillRect(new Rectangle(xpos+circx, ypos-circy, 1, circy*2), 0x0); } } function loseGame() { for (xpos=10; xposStage.width || this._y<0 || this._y>Stage.height) {
removeMovieClip(this);
}
};
totalobjects++;
};
this.onEnterFrame = function() {
if (gameon && (Math.random()*100)/curlevel<1) { enemyarray.push('plane'+totalobjects); attachMovie('plane', 'plane'+totalobjects, this.getNextHighestDepth()); eval('plane'+totalobjects).movedir = Math.floor(Math.random()*2)-1; eval('plane'+totalobjects)._y = Math.random()*50+15; eval('plane'+totalobjects)._x = Stage.width*(-eval('plane'+totalobjects).movedir); eval('plane'+totalobjects)._xscale = 100*(1+2*eval('plane'+totalobjects).movedir); eval('plane'+totalobjects).onEnterFrame = function() { this._x += 1+this.movedir*2; if ((Stage.widthStage.height) {
loseGame();
removeEnemy(this._name);
}
};
totalobjects++;
}
};
totalobjects++;
passedplanes++;
if (passedplanes>40) {
passedplanes = 0;
curlevel++;
}
}
};

function visitswfspot() {
getURL("http://www.swfspot.com", "_blank");
}
var myMenu = new ContextMenu();
var menubezz = new ContextMenuItem("Visit swfspot.com for more games and code", visitswfspot);
myMenu.customItems.push(menubezz);
_root.menu = myMenu;



Output Game :

0 komentar:

Posting Komentar