Membuat Game Tower Defense Bagian 2 (AS2)
Membuat GameTower Defense
Lanjutkan tutorial sebelumnya, pada frame 1 layer action tambahkan actionscript pada baris 65-102.
Read more
Bagian Bagian Tutorial
Bagian 1 : Persiapan
Bagian 2 : Menambahkan Prajurit
Bagian 3 : Menambahkan Musuh
Bagian 4 : Membuat Prajurit Menembak Musuh
Bagian 5 : Win / Loss Game
Bagian 6 : Membuat Properti Game
Bagian 7 : Sentuhan Akhir
Bagian 2 : Menambahkan Prajurit
Bagian 3 : Menambahkan Musuh
Bagian 4 : Membuat Prajurit Menembak Musuh
Bagian 5 : Win / Loss Game
Bagian 6 : Membuat Properti Game
Bagian 7 : Sentuhan Akhir
Bagian 2 : Menambahkan Prajurit
Pada bagian ini kita akan menambahkan prajurit pada saat kita klik daerah yang kosong.Lanjutkan tutorial sebelumnya, pada frame 1 layer action tambahkan actionscript pada baris 65-102.
stop(); //setting vars to step in for turns and special blocks var S:String = 'START'; var F:String = 'FINISH'; var U:String = 'UP'; var R:String = 'RIGHT'; var D:String = 'DOWN'; var L:String = 'LEFT'; var startDir:String;//the direction the enemies go when they enter var finDir:String;//the direction the enemies go when they exit var startCoord:Number;//the coordinates of the beginning of the road var lvlArray:Array = new Array();//this array will hold the formatting of the roads lvlArray = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,R,1,1,D,0,0,R,1,1,D,0,0,R,1,1,D,0,0, 0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0, 0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0, S,D,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,R,1,F, 0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0, 0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0, 0,R,1,1,U,0,0,R,1,1,U,0,0,R,1,1,U,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ]; //the names of these variables explain what they do var currentLvl:Number = 1; var gameOver:Boolean = false; function startGame():Void{//we'll run this function every time a new level begins //right now we don't have any code } _root.createEmptyMovieClip('roadHolder',_root.getNextHighestDepth());//add a MovieClip to hold the road function makeRoad():Void{ var row:Number = 0;//the current row we're working on var block;//this will act as the block that we're placing down for(i=0;i<lvlArray.length;i++){//creating a loop that'll go through the level array if(lvlArray[i] == 0){//if the current index is set to 0 /////*****EMPTY BLOCK*****///// _root.createEmptyMovieClip('block'+i,_root.getNextHighestDepth());//create a gray empty block _root['block'+i].beginFill(0x333333); _root['block'+i].lineTo(0,0); _root['block'+i].lineTo(0,25); _root['block'+i].lineTo(25,25); _root['block'+i].lineTo(25,0); _root['block'+i].endFill(); //and set the coordinates to be relative to the place in the array _root['block'+i]._x= (i-row*22)*25; _root['block'+i]._y = row*25; //giving the block some rollover and rollout effects _root['block'+i].onRollOver = function(){ //Change the color to green var newColor = new Color(this); newColor.setRGB(0x006600); } _root['block'+i].onRollOut = function(){ //Change this color back to gray var newColor = new Color(this); newColor.setRGB(0x333333); } _root['block'+i].onRelease = function(){ //this function will run when the empty block is clicked on //change this guy's color back var newColor = new Color(this); newColor.setRGB(0x333333); //set all other mouse functions to null in order to keep it from being clicked again this.onRollOver = null; this.onRollOut = null; this.onRelease = null; //create an empty turret movieclip that will be on the top root layer _root.createEmptyMovieClip('t'+this._name,_root.getNextHighestDepth()); //drawing the turret, it will have a gray, circular, base with a white gun _root['t'+this._name].beginFill(0x999999);//coloring the base light gray _root['t'+this._name].moveTo(0, 12.5);//move the entire shape a certain way //create 4 curves so that it'll look like a circle _root['t'+this._name].curveTo(0,25,12.5,25); _root['t'+this._name].curveTo(25,25,25,12.5); _root['t'+this._name].curveTo(25,0,12.5,0); _root['t'+this._name].curveTo(0,0,0,12.5); _root['t'+this._name].endFill();//end the fill so we can make a new one _root['t'+this._name].createEmptyMovieClip('gun',_root['t'+this._name].getNextHighestDepth()); _root['t'+this._name].gun.beginFill(0xFFFFFF); _root['t'+this._name].gun.lineTo(-2,-2); _root['t'+this._name].gun.lineTo(2,-2); _root['t'+this._name].gun.lineTo(2,15); _root['t'+this._name].gun.lineTo(-2,15); _root['t'+this._name].gun.lineTo(-2,-2); _root['t'+this._name].gun.endFill(); _root['t'+this._name].gun._x = 12.5; _root['t'+this._name].gun._y = 12.5; _root['t'+this._name].gun._rotation=90; _root['t'+this._name]._x = this._x; _root['t'+this._name]._y = this._y; } } else if(lvlArray[i] == 1){//if there is supposed to be a row /////*****EMPTY ROAD*****///// //just add a box that will be a darker color and won't have any actions roadHolder.createEmptyMovieClip('block'+i,roadHolder.getNextHighestDepth()); roadHolder['block'+i].beginFill(0x111111); roadHolder['block'+i].lineTo(0,0); roadHolder['block'+i].lineTo(0,25); roadHolder['block'+i].lineTo(25,25); roadHolder['block'+i].lineTo(25,0); roadHolder['block'+i].endFill(); roadHolder['block'+i]._x= (i-row*22)*25; roadHolder['block'+i]._y = row*25; } else if(String(lvlArray[i])){//if it's a string, meaning a special block /////*****SPECIAL DIRECTIONAL ROAD PIECE*****///// roadHolder.createEmptyMovieClip('block'+i,roadHolder.getNextHighestDepth()); roadHolder['block'+i].beginFill(0x111111); roadHolder['block'+i].lineTo(0,0); roadHolder['block'+i].lineTo(0,25); roadHolder['block'+i].lineTo(25,25); roadHolder['block'+i].lineTo(25,0); roadHolder['block'+i].endFill(); roadHolder['block'+i]._x= (i-row*22)*25; roadHolder['block'+i]._y = row*25; } for(var c:Number = 1;c<=16;c++){ if(i == c*22-1){ //if 22 columns have gone by, then we move onto the next row row++; } } } } //run these functions at the start makeRoad(); startGame();
Preview