I have made a shooter game just as a source experiment/action script practice. I made the whole game with AS so just put this code in a frame on the mane time line of a new flash document with 12 fps and 550 x 400 pixels.
[SIZE=“1”]I used createEmptyMovieClip so if you have a version of flash before that it will not work unless you substitute it for an equivalent command like _root.attachMovie(“empty”, name, depth) (if you have an empty MC in library named empty)[/SIZE]
can’t uplode the swf so i’ll just post the code.
var i:Number;
var ro_sp:Number;
var bul_sp:Number;
var u:Number;
var en_sp:Number;
var nx_lvl:Number;
var score:Number;
var level:Number;
var lv_ki:Number;
var life:Number;
var hi:Number = 0;
var my_fmt:TextFormat = new TextFormat();
var alt:Number;
var ag:Number;
var sedAdd:Number;
var si:Number;
var rbul:Number;
var acbul:Number;
var gun:Number;
begin();
function begin() {
removeMovieClip(_root.no);
removeMovieClip(_root.yes);
removeMovieClip(man);
removeMovieClip(_root.scoreBox);
i = 0;
//bulit numbering
ro_sp = 8;
bul_sp = 10;
//bulit speed
u = 0;
//enamy numbering
en_sp = 9;
//enamy speed
nx_lvl = 0;
score = 0;
level = 1;
lv_ki = 5;
life = 3;
alt = 1;
ag = 0;
si = 1;
guns = 1;
//shot gum
sedAdd = 0;
rbul = 3;
//chand for more should gun bulit
acbul = 3;
//definit should gun bulits
drawCircle("bt_m", 0, 0, 100, 0x000000, 1, _root);
bt_m = _root.bt_m;
with (bt_m) {
_x = 140;
_y = 200;
}
drawCircle("bt_k", 0, 0, 100, 0x000000, 2, _root);
bt_k = _root.bt_k;
with (bt_k) {
_x = 410;
_y = 200;
}
_root.createTextField("txt_m", 11, 65, 190, 160, 20);
_root.createTextField("txt_k", 10, 345, 190, 160, 20);
my_fmt.color = 0xFFFFFF;
txt_k.text = "Use Keys for ameing";
txt_m.text = "Use Mouse for ameing";
my_fmt.size = 16;
txt_k.setTextFormat(my_fmt);
txt_m.setTextFormat(my_fmt);
bt_k.onRelease = function() {
game();
mdown = 0;
};
bt_m.onRelease = function() {
game();
mdown = 1;
};
}
function game() {
hart();
_root.createTextField("scoreBox", 700, 40, 10, 100, 100);
my_fmtx.size = 26;
my_fmt.color = 0x000000;
scoreBox.setTextFormat(my_fmt);
sec = 0;
var ena:Number = 1;
removeMovieClip(_root.bt_m);
removeMovieClip(_root.bt_k);
removeMovieClip(_root.txt_m);
removeMovieClip(_root.txt_k);
make_man();
wall = _root.createEmptyMovieClip("all", 30);
with (wall) {
Stage.width;
lineStyle(5, 0x000000);
moveTo(-10, 0);
lineTo(Stage.width, 0);
_y = 320;
}
onMouseDown = function () {
mu = 1;
};
onMouseUp = function () {
mu = 0;
};
t = 0;
onEnterFrame = function () {
if (Key.getAscii()>=49 &&Key.getAscii()<=56){
guns=(Key.getAscii()-48);
}
//gun==0?
t>3 ? (t=0)(sec += .2) : t++;
si>1 ? si-- : si=1;
scoreBox.text = score;
if (nx_lvl>lv_ki) {
levelUp();
}
if (sec>ena) {
ena = sec+(1/level);
enamy();
}
if (mdown) {
way = Math.atan2(_ymouse-man._y, _xmouse-man._x)*180/Math.PI;
man._rotation = way+90;
if (mu) {
fire();
}
} else {
if (Key.isDown(Key.RIGHT)) {
if (man._rotation<80) {
man._rotation += ro_sp;
}
}
if (Key.isDown(Key.LEFT)) {
if (man._rotation>-85) {
man._rotation -= ro_sp;
}
}
if (Key.isDown(Key.SPACE)) {
fire();
}
}
};
}
function enamy() {
drawCircle("enamy"+u, 0, 0, 10, 0x0000FF, 500+u, _root);
na = _root["enamy"+u];
na._x = random(510)+20;
na._y = -10;
bx = random(350)+100;
bx += random(50)*(random(3)-1);
bx += random(50)*(random(3)-1);
by = 320;
na.ang = Math.atan2(380-na._y, bx-na._x);
na.onEnterFrame = function() {
this._x += Math.cos(this.ang)*en_sp;
this._y += Math.sin(this.ang)*en_sp;
if (this._y>300) {
life--;
hart();
removeMovieClip(this);
}
};
u>100 ? u=1 : u++;
}
function fire() {
ag=0
/*
1=right
2=left
3=left/right altinating fire
4=left/right dule fire
5=right shot gun
6=lefe shot gun
7=left/right altinating shot gun
8=left/right dule shot gun
*/
if (guns == 1) {
//right fire
sedAdd = 0;
rl = 125;
shut();
} else if (guns == 2) {
//left fire
sedAdd = 0;
rl = 61;
shut();
} else if (guns == 3) {
//left/right altinating fire
sedAdd = 0;
shut();
alt == 1 ? alt=0 : alt=1;
alt ? rl=61 : rl=125;
} else if (guns == 4) {
//left/right dule fire
sedAdd = 0;
shut();
rl = 61;
shut();
rl = 125;
} else if (guns == 5) {
//right shot gun
if (si == 1) {
ag = -8;
rl = 125;
aho = random(rbul)+acbul;
agi = 16/(aho-2);
for (so=0; so<aho; so++) {
ag += random(agi);
sedAdd = 2+random(2);
//speed added
shut();
ag = aho*(so-1);
}
si += (50/bul_sp)-1;
}
} else if (guns == 6) {
//left shot gun
if (si == 1) {
ag = -8;
rl = 61;
aho = random(rbul)+acbul;
agi = 16/(aho);
for (so=0; so<aho; so++) {
ag += random(agi);
sedAdd = 2+random(2);
//speed added
shut();
ag = aho*(so-1);
}
si += (50/bul_sp)-1;
}
} else if (guns == 7) {
//left/right altinating shot gun
if (si == 1) {
alt == 1 ? alt=0 : alt=1;
alt ? rl=61 : rl=125;
ag = -8;
aho = random(rbul)+acbul;
agi = 16/(aho-2);
for (so=0; so<aho; so++) {
ag += random(agi);
sedAdd = 2+random(2);
//speed added
shut();
ag = aho*(so-1);
}
//time to next shot
si += (50/bul_sp)-1;
}
} else if (guns == 8) {
//left/right dule shot gun
if (si == 1) {
ag = -8;
rl = 61;
aho = random(rbul)+acbul;
agi = 16/(aho-2);
for (so=0; so<aho; so++) {
ag += random(agi);
sedAdd = 2+random(2);
//speed added
shut();
ag = aho*(so-1);
}
rl = 125;
aho = random(rbul)+acbul;
agi = 16/(aho-2);
for (so=0; so<aho; so++) {
ag += random(agi);
sedAdd = 2+random(2);
//speed added
shut();
ag = aho*(so-1);
}
si += (50/bul_sp)+2;
}
}
}
function shut() {
ro = (-rl-man._rotation)/180*Math.PI;
//left gun -125
ro = (-rl-man._rotation)/180*Math.PI;
//right gun -61
//gun's taper in
rl == 125 ? LR=-2.5 : LR=2;
sx = man._x-(Math.cos(ro)*24);
sy = man._y+(Math.sin(ro)*24);
drawCircle("bulit"+i, sx, sy, 3, 0x00FF00, 200+i, _root);
nam = _root["bulit"+i];
nam.ad = sedAdd;
nam.ang = (man._rotation-90+ag+LR)/180*Math.PI;
nam.onEnterFrame = function() {
this._x += Math.cos(this.ang)*(bul_sp+this.ad);
this._y += Math.sin(this.ang)*(bul_sp+this.ad);
if (this._y<-400 || this._y>50) {
removeMovieClip(this);
}
if (this._x<-300 || this._x>300) {
removeMovieClip(this);
}
for (d=0; d<102; d++) {
if (this.hitTest(_root["enamy"+d])) {
nx_lvl++;
score += level*10;
removeMovieClip(_root["enamy"+d]);
removeMovieClip(this);
}
}
};
i>100 ? i=0 : i++;
}
function levelUp() {
life<5 ? life++ : p;
hart();
bul_sp++;
lv_ki += 5;
en_sp++;
nx_lvl = 0;
score += 500*level;
level++;
trace("you have gone up one level to "+level);
if (Math.abs(level%5) == 4) {
trace("shoult gun updrad");
acbul++;
}
}
function hart() {
removeMovieClip(_root["red"+(life+1)]);
life == 0 ? end() : trace("lives: "+life);
for (h=1; h<life+1; h++) {
red = _root.createEmptyMovieClip("red"+h, 710+h);
with (red) {
beginFill(0xFF0000);
lineStyle(1, 0xFF0000);
moveTo(0, 10);
curveTo(0, 0, 10, -2);
curveTo(20, 0, 20, 10);
curveTo(20, 0, 30, -2);
curveTo(40, 0, 40, 10);
curveTo(31, 30, 20, 40);
curveTo(9, 30, 0, 10);
endFill();
_height = 20;
_width = 20;
_x = 400+25*h;
_y = 20;
}
}
}
function end() {
t = 0;
sec = 0;
mu = 0;
for (d=0; d<150; d++) {
removeMovieClip(_root["enamy"+d]);
removeMovieClip(_root["bulit"+d]);
}
my_fmt.size = 16;
my_fmt.color = 0x000000;
_root.createTextField("dead", 1, 150, 135, 350, 25);
score>=hi ? ((hi=score)(dead.text="Your got a high score :) "+score+" the high score was "+hi)) : (dead.text="You missed the high score. you got "+score+" the high scor was "+hi);
dead.setTextFormat(my_fmt);
onEnterFrame = function () {
t>5 ? (t=0)(sec += .5) : t++;
if (sec == 2 && t == 0) {
_root.createTextField("ply", 3, 215, 160, 150, 20);
ply.text = "what to play agane?";
ply.setTextFormat(my_fmt);
drawCircle("bt_b", 0, 0, 40, 0x000000, 2, _root);
bt_b = _root.bt_b;
bt_b._x = 263;
bt_b._y = 250;
_root.createTextField("yes", 5, 220, 240, 200, 24);
my_fmt.color = 0xFFFFFF;
yes.text = "yes play agane?";
yes.setTextFormat(my_fmt);
_root.createTextField("no", 6, 180, 300, 350, 20);
no.text = "if not quit. it' the littel x in the corner";
}
bt_b.onRelease = function() {
removeMovieClip(_root.dead);
removeMovieClip(_root.ply);
removeMovieClip(man);
removeMovieClip(wall);
begin();
};
};
}
function drawCircle(mc, x:Number, y:Number, r:Number, col:Number, depth:Number, path:MovieClip):Void {
mc = path.createEmptyMovieClip(mc, depth);
mc.lineStyle(0, col);
mc.moveTo(x+r, y);
mc.beginFill(col);
gap = 7.2;
for (d=2; d<(50)+1; d += 2) {
ang = (7.2*d)/180*Math.PI;
stes = (7.2*(d-1))/180*Math.PI;
sr = r;
ex = x+Math.cos(ang)*r;
ey = y+Math.sin(ang)*r;
sx = x+Math.cos(stes)*r;
sy = y+Math.sin(stes)*r;
mc.curveTo(sx, sy, ex, ey);
}
endFill();
}
function make_man() {
man = _root.createEmptyMovieClip("man", 100);
gun = man.createEmptyMovieClip("gun", 99);
with (gun) {
lineStyle(0, 0xFF0000);
beginFill(0xFF0000, 100);
moveTo(10, 8);
lineTo(16, 8);
lineTo(16, -18);
lineTo(10, -18);
lineTo(10, 8);
endFill();
}
gunn = man.createEmptyMovieClip("gunn", 98);
with (gunn) {
lineStyle(0, 0xFF0000);
beginFill(0xFF0000, 100);
moveTo(10, 8);
lineTo(16, 8);
lineTo(16, -18);
lineTo(10, -18);
lineTo(10, 8);
endFill();
_x = -25;
_y = 0;
}
body = _root.man.createEmptyMovieClip("body", 111);
drawCircle("body", 0, 0, 10, 0x000000, 101, man);
man._x = 280;
man._y = 360;
}