اموزش ساخت یک بازی با فلش....

lordweb

Member
اموزش ساخت یک بازی با فلش....

اول از همه بر روی گذینه file

کلیک کنید و گذینهnew انتخاب کنیدوبعد از اون گذینه Action script file رو انتخاب کنید تا باز بشه بعد توی اون این کد قرار بدید


کد:

MovieClip.prototype.drawCircle = function (x,y,r, alpha) {

if (arguments.length < 4) alpha = 100;

this.lineStyle(0,0,alpha);

var c1=r*(Math.SQRT2-1);

var c2=r*Math.SQRT2/2;

this.moveTo(x+r,y);

this.curveTo(x+r,y+c1,x+c2,y+c2);

this.curveTo(x+c1,y+r,x,y+r);

this.curveTo(x-c1,y+r,x-c2,y+c2);

this.curveTo(x-r,y+c1,x-r,y);

this.curveTo(x-r,y-c1,x-c2,y-c2);

this.curveTo(x-c1,y-r,x,y-r);

this.curveTo(x+c1,y-r,x+c2,y-c2);

this.curveTo(x+r,y-c1,x+r,y);

return this;

}

MovieClip.prototype.drawOuija = function (x,y,w,h) {

this.lineStyle(0,0,100);

w /= 2;

h /= 2;

this.moveTo(-h+y,-w+x);

this.lineTo(h+y,x);

this.lineTo(-h+y,w+x);

this.curveTo(-h/2+y,x,-h+y,-w+x);

return this;

}

MovieClip.prototype.drawRectangle = function (x,y,w,h) {

this.lineStyle(0,0,100);

w /= 2;

h /= 2;

this.moveTo(-w+x,-h+y);

this.lineTo(w+x,-h+y);

this.lineTo(w+x,h+y);

this.lineTo(-w+x,h+y);

this.lineTo(-w+x,-h+y);

return this;

}

MovieClip.prototype.addPropeller = function(x,y){

var prop = this.createEmptyMovieClip("Propeller_mc"+ ++this.depth, this.depth);

prop._x = x;

prop._y = y;

prop.drawCircle(0,0,5);

var spin = function(){

this._x = Math.sin(this.angle+=.5)*20

this._xscale = 100 + Math.abs(Math.sin(this.angle)*250)

}

prop.createEmptyMovieClip("Blade1_mc",1).drawCircle(0,0,5).onEnterFrame = spin;

prop.createEmptyMovieClip("Blade2_mc",2).drawCircle(0,0,5).onEnterFrame = spin;

prop.Blade1_mc.angle = 0;

prop.Blade2_mc.angle = Math.PI;

return this;

}

MovieClip.prototype.addCloud = function(x,y, alpha){

if (arguments.length < 3) alpha = 100;

var cloud = this.createEmptyMovieClip("Cloud_mc"+ this.depth, this.depth++);

cloud._x = x;

cloud._y = y;

cloud.lineStyle(0,0, alpha);

cloud.moveTo(-60,25);

cloud.lineTo(60,25);

cloud.curveTo(40,0, 20,10);

cloud.curveTo(0,-30, -20,0);

cloud.curveTo(-40,-15, -60,25);

cloud.onEnterFrame = function(){

var point = {x: this._x, y:this._y}

this._parent.localToGlobal(point);

this._parent._parent.globalToLocal(point);

if (point.x < -400) this._x += 800;

else if (point.x > 400) this._x -= 800;

if (point.y < -400) this._y += 800;

else if (point.y > 400) this._y -= 800;

}

return this;

}

MovieClip.prototype.addPuff = function(x,y,killer){

var puff = this.createEmptyMovieClip("Puff_mc"+ this.depth, this.depth++).drawCircle(x,y,10).onEnterFrame = function(){

this._xscale = this._yscale += 7;

this._alpha = 200-this._xscale;

if (!killer) killer = this;

if (this._alpha <= 0) killer.removeMovieClip();

}

}

MovieClip.prototype.addExplosion = function(x,y){

var explode = this.createEmptyMovieClip("Explosion_mc"+ this.depth, this.depth++);

explode.onEnterFrame = function(){

if (++this.frame == 2) this.addPuff(random(21)-10, random(21)-10, false);

if (this.frame == 8) this.addPuff(random(21)-10, random(21)-10, false);

if (this.frame == 11) this.addPuff(random(21)-10, random(21)-10, false);

if (this.frame == 15) this.addPuff(random(21)-10, random(21)-10, this);

return this;

}

explode._x = x;

explode._y = y;

return this;

}

MovieClip.prototype.asProjectile = function(x,y,v){

this._x = x;

this._y = y;

this.v = v;

this.path = [];

var par = this._parent;

this.Path_mc = par.createEmptyMovieClip("Path_mc" + par.depth, par.depth++);

this.onEnterFrame = function(){

var lastPos = [this._x,this._y];

this._x += this.v[0];

this._y += this.v[1] += 1;

var xdiff = this._x - lastPos[0];

var ydiff = this._y - lastPos[1];

this._rotation = Math.atan2(ydiff,xdiff)*180/Math.PI;

if (!(this.frame++ % 2)){

this.path[this.path.length] = [this._x,this._y];

var vis, len = this.path.length;

this.Path_mc.clear();

this.Path_mc.moveTo(this.path[len-1][0], this.path[len-1][1]);

while(len-- > 0){

if ((vis = 20-this.path.length+len) >= 0){

this.Path_mc.lineStyle(vis/2, 0, vis);

this.Path_mc.lineTo(this.path[len][0], this.path[len][1]);

}

}

}

if (this._y > Player_mc._y+500 || this._x < Player_mc._x-500 || this._x > Player_mc._x+500){

this.Path_mc.onEnterFrame = function(){ if ((this._alpha -= 10) <= 0) this.removeMovieClip(); }

this.removeMovieClip();

}else{

var mc;

for (mc in this._parent){

if (this._parent[mc].isTarget){

xdiff = Math.abs(this._x - this._parent[mc]._x);

ydiff = Math.abs(this._y - this._parent[mc]._y);

if (xdiff < 20 && ydiff < 20){

this._parent[mc].removeMovieClip();

this.Path_mc.onEnterFrame = function(){ if ((this._alpha -= 10) <= 0) this.removeMovieClip(); }

this._parent.addExplosion(this._x, this._y);

this._parent.spears--;

this.removeMovieClip();

scope.score.text = number(scope.score.text)+1;

}

}

}

}

}

return this;

}


scope = this;

scope.center = 222;

scope.drawRectangle(scope.center, scope.center, scope.center*2, scope.center*2);

scope.createTextField("score",-10,5,5,40,20);

scope.score.border = true;

scope.score.borderColor = scope.score.text = 0;

theWorld = scope.createEmptyMovieClip("World_mc",1);

theWorld._x = theWorld._y = scope.center;

theWorld.createEmptyMovieClip("Environment_mc", 1).onEnterFrame = function(){

this._x += ((-this._parent._xmouse/1.5 - this.Player_mc._x) - this._x)/20;

this._y += ((-this._parent._ymouse/1.5 - this.Player_mc._y) - this._y)/20;

if (this.spears < 6 && !random(50)){

var spear = this.createEmptyMovieClip("Spear_mc"+ this.depth, this.depth++).drawCircle(0,0,20, 15).addPropeller(0,28);

spear.isTarget = true;

spear._x = this.Player_mc._x + random(401)-200;

spear._y = this.Player_mc._y + 600;

spear.createEmptyMovieClip("SpearOuija_mc", 1).drawOuija(0,0,10,30)._rotation = -90;

spear.onEnterFrame = function(){

this._y -= 3;

if (this._y < this._parent.Player_mc._y-500 || this._x < Player_mc._x-1000 || this._x > Player_mc._x+1000){

this._parent.spears--;

this.removeMovieClip();

}

}

this.spears++;

}

}

theWorld.Environment_mc.addCloud(-50,-50, 10).addCloud(-70,350, 10).addCloud(260,100, 10).addCloud(300,520, 10);


Player_mc = theWorld.Environment_mc.createEmptyMovieClip("Player_mc", theWorld.Environment_mc.depth++).drawCircle(0,0,20).drawCircle(-5,-5,7, 25).addPropeller(0,28);

Player_mc.createEmptyMovieClip("Turret_mc", Player_mc.depth++).drawRectangle(30,0,30,5);

Player_mc.onEnterFrame = function(){

var xdiff = this._parent._xmouse - this._x;

var ydiff = this._parent._ymouse - this._y;

this.angle = Math.atan2(ydiff, xdiff);

this.Turret_mc._rotation = this.angle*180/Math.PI;

this.Turret_mc._xscale = 100-this.power*3;

this.Turret_mc._yscale = 200-this.Turret_mc._xscale;

var dx, dy;

if (dx = (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))/4) this.speedx = Math.min(Math.max(-3, this.speedx+dx) ,3);

else this.speedx *= .9;

if (dy = (Key.isDown(Key.DOWN)-Key.isDown(Key.UP))/4) this.speedy = Math.min(Math.max(-3, this.speedy+dy) ,3);

else this.speedy *= .9;

this._x += this.speedx;

this._y += this.speedy;

if (this.power) if (this.power++ >= 20) this.shoot();

}

Player_mc.shoot = function(){

this.power += 5;

var x = this._x+Math.cos(this.angle)*30;

var y = this._y+Math.sin(this.angle)*30;

var vector = [Math.cos(this.angle)*this.power, Math.sin(this.angle)*this.power];

var par = this._parent;

par.createEmptyMovieClip("Projectile_mc" + par.depth, par.depth++).asProjectile(x,y,vector).drawOuija(0,0,10,30).drawCircle(0,0,20, 15).onEnterFrame();

this.power = 0;

}

Player_mc.onMouseDown = function(){ this.power++; }

Player_mc.onMouseUp = function(){ if (this.power) this.shoot(); }


حالا با نام propellercannongame ذخیره کنید

بعد از اینکه اونو ذخیره کردید از نو گذینه file انتخاب کنید و بعد گذینه new

و بعد گذینهflash document رو انتخاب کنید

بعد گذینه Window بعد گذینه actions انتخاب کنید و در داخل اون این کد بزارید


کد:

#include "propellercannongame.as"


بعد با این نامpropellercannongame ذخیرش کنیدحالابرید یکم باهاش بازیکنید ......
 
آخرین ویرایش توسط مدیر:

mohammad.sub7

کاربر فعال
دوست عزیز به این که نمیگن آموزش!

برای آموزش دادن باید توضیحات کامل رو بدید و مرحله به مرحله برید جلو.

موفق باشی
 

mehranrm7

New Member
گزینه ها به ترتیب بعد از
file
new
و در پنجره جدید
flash document
ندارد و
flash project دارد که اون هم
window و ... ندارد
 

mehranrm7

New Member
منظور دقیق رو دوباره می نویسم ولی پیش از اون یک توضیح اولیه رو لازم می دونم
وقتی این آموزش رو دیدم برای اولین بار وارد نرم افزار فلش شدم یعنی دقیقا اولین بار
Adobe CS5.5 Master Collection
رو قبلا نصب کرده بودم اما حتی وارد فلش نشدم و این ساخت بازی هم به نظرم با دانش من هماهنگ میومد بنابراین امتحانش کردم
در توضیحات شما قسمت پایانی اومده بود که بعد از این که ذخیره انجام شد بروید در فایل و نیو و فلش داکیومنت و ادامه ماجرا
پس من بعد از ذخیره از محیط برنامه فلش خارج نشدم و وارد بخش فایل و نیو در برنامه فلشی که همچنان باز بود شدم در ادامه هم فلش داکیومنت را نیافتم بنابراین مشابهش را که دیدم با نام فلش پروجکت انتخاب کردم که اون هم گزینه ویندو و اکشنی دیگر نداشت.
 

30min

Banned
مهران دیگه تو نسخه های جدید Flash Document نداره و باید Acition script 3 یا 2 رو که اولین و دومین گزینه هست رو انتخاب کنی .
 

جدیدترین ارسال ها

بالا