Sunday, November 8, 2009

Backbone research(action scripts)

Backbone Research
Action Scripts for “Nature vs. Homo sapiens”

Sample 1 :
stop();
var blood = 40;
var maxSpeed = 16;
var minSpeed = 2;
gametime = 30;
var music = new Sound();
music.attachSound("music");
music.start();

for (var i = 0; i var mc = this.attachMovie("blood", "blood"+i, i);
mc._x = random(Stage.width);
mc._y = random(Stage.height);
mc.speed = random(maxSpeed-minSpeed)+minSpeed;
var size = random(2)+1.5*(random(4));
mc._width = size;
mc._height = size;
}

function moveBlood() {
for (var j = 0; j var mc = this["blood"+j];
if (mc._y mc._y += mc.speed;
} else {
mc._y = random(Stage.height)
mc.speed = random(maxSpeed-minSpeed)+minSpeed;
mc._x = random(Stage.width);
}
}
}
function countDown(){
gametime -= 1;
if(gametime <= 0){
clearInterval(t2);
attachMovie("gover","gover",_root.getNextHighestDepth());
gover._x = Stage.width/2;
gover._y = Stage.height/2;

}
}

t2 = setInterval(countDown, 1000);


Sample 2 :
var speed = 5;
var bc = 0; //bc is bulletcounter
var m;
var bulletno = 0; //'0' for default bullet
var bulletname = "herobullet";
var life = 30;
var k = new Object();
var music = new Sound();
music.attachSound("explode");

onEnterFrame = function(){
if(_root.gameover==false){
if(Key.isDown(Key.RIGHT)) {
this._x += speed;
}if(Key.isDown(Key.LEFT)) {
this._x -= speed;
}if(Key.isDown(Key.UP)) {
this._y -= speed;
}if(Key.isDown(Key.DOWN)) {
this._y += speed;
}
if(Key.isDown(50)) {
bulletno = 2;
}else if(Key.isDown(49)){
bulletno = 1;
}
if(Key.isDown(Key.SPACE)){
if(bulletno == 1){
bulletname = "herobullet";
}else if(bulletno == 2){
bulletname = "herobullet2";
}

music.start();
m = _root.attachMovie(bulletname,"hb"+bc,
_root.getNextHighestDepth());
bc ++;
m._x = this._x;
m._y = this._y;

m.onEnterFrame = function(){
this._y -=20;
for (var j=1; j<=10; j++){
if (this.hitTest(_root["c"+j])){
_root["c"+j].damage += this.power;
_root["c"+j].gotoAndPlay(2);
this.removeMovieClip(); //remove bullet
}
}
}
}
}
}

Sample 3 :
stop();
var speed1 = (random(10)+5)/10;
var alreadyhit = false;
var t1 = setInterval(fire, 3000);

onEnterFrame = function () {
if (_root.gameover == false) {
this._y += speed1;
if (this.damage>=10) {
this.damage = 0;
//reset damage to 0
this._y = -50;
//place enemy on top
_root.score += 1;
}
if (this.alreadyhit == false) {
if (this.hitTest(_root.h)) {
//trace("hit!");
_root.score -= 5;
this.alreadyhit = true;
this.gotoAndPlay(2);
_root.h.life -= 5;
_root.lifebar._xscale = _root.h.life;
if (_root.h.life<=0) {
_root.gameover = true;
_root.gotoAndPlay(2);
}
}
}
if (this._y>Stage.height) {
this._y = -10;
var i = this.id;
_root["b"+i]._y = -10+(this._height/2);
_root["b"+i].alreadyhit = false;
}
}
};

function fire() {
if (_root.gameover == false) {
var f = _root.attachMovie("bullet", "b"+_root.bc, _root.getNextHighestDepth());
f._x = _x;
f._y = _y+(_height/2);
_root.bc++;
}
}

No comments:

Post a Comment