PDA

View Full Version : particle engine 2 - starShip



NiñoScript
January 19th, 2006, 07:27 PM
and another entry by NiñoScript, Hooray! (-:

CONTROLS:

_root._ymouse = affects the speed of the spaceShip;

Key.SPACE = creates a hi gravity point in the middle of the universe (aka blackhole), atracting the stars to it, but in this fake world, stars can scape that atraction after some fighting.[/size]


i hope you like it :love:



edit:
it looks weird when i see it in my browser, maybe becouse of the "noScale", dunno... if u want it to look like it should, just make a new document in flash and paste my code :)

another edit:
ok, i removed the "noScale" to add it to the forum, now it works ok :snug:

NiñoScript
January 19th, 2006, 07:29 PM
Stage.scaleMode = "noScale";
//1
//{speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50}
starArray = [{speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50}];
//2
function drawStar(p) {
_root.change({func:"moveTo", value:[p.p.x-p.old.x*2, p.p.y-p.old.y*2]}).change({func:"lineTo", value:[p.p.x, p.p.y]});
//3
}
Object.prototype.change = function(what:Object, who) {
/*
.change({property:"", value:})
or
.change({func:"", value:[]})
*/
what.func == undefined ? this[what.property]=what.value : this[what.func](what.value[0], what.value[1]);
//4
return !who ? this : who;
//5
};
function moveStar(p, i) {
p.speed.change({property:"x", value:p.speed.x+Math.cos(Math.atan2(p.y-Stage.height/2, p.x-Stage.width/2))*speed/100}).change({property:"y", value:p.speed.y+Math.sin(Math.atan2(p.y-Stage.height/2, p.x-Stage.width/2))*speed/100}, p).change({property:"oldx", value:p.x}).change({property:"oldy", value:p.y}).change({property:"x", value:p.x>Stage.width+20 or p.x<-20 ? starArray[i]={speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50} : p.x+p.speed.x}).change({property:"y", value:p.y>Stage.height+20 or p.y<-20 ? starArray[i]={speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50} : p.y+p.speed.y});
//6
return {old:{x:p.x-p.oldx, y:p.y-p.oldy}, p:p};
//7
}
onEnterFrame = function () {
speed = Key.isDown(Key.SPACE) ? -150 : _ymouse;
//8
starArray.length<30 ? starArray.push({speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50}) : null;
//9
_root.change({func:"clear", value:null}).change({func:"lineStyle", value:[0]});
for (var i = 0; i<starArray.length; i++) {
//10
drawStar(moveStar(starArray[i], i));
//11
}
};

hybrid101
January 19th, 2006, 10:39 PM
i'm definitely liking this! nice one, ninoscript!

Seb Hughes
January 20th, 2006, 02:50 PM
nifty

NiñoScript
January 20th, 2006, 03:07 PM
now it reacts to the FPS, and the number of lines hasn't changed :hugegrin:

that means that in each computer, the number of stars will adapt so the FramesPerSecond dont go down from 36 app :azn:



var fps = {variable:0, fps:100, constant:36, starArray:[{speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50}]};
//1
function drawStar(p) {
_root.change({func:"moveTo", value:[p.p.x-p.old.x*2, p.p.y-p.old.y*2]}).change({func:"lineTo", value:[p.p.x, p.p.y]});
//2
}
Object.prototype.change = function(what:Object, who) {
/*
.change({property:"", value:})
or
.change({func:"", value:[]})
*/
what.func == undefined ? this[what.property]=what.value : this[what.func](what.value[0], what.value[1]);
//3
return !who ? this : who;
//4
};
function moveStar(p, i) {
p.speed.change({property:"x", value:p.speed.x+Math.cos(Math.atan2(p.y-Stage.height/2, p.x-Stage.width/2))*speed/100}).change({property:"y", value:p.speed.y+Math.sin(Math.atan2(p.y-Stage.height/2, p.x-Stage.width/2))*speed/100}, p).change({property:"oldx", value:p.x}).change({property:"oldy", value:p.y}).change({property:"x", value:p.x>Stage.width+20 or p.x<-20 ? (fps.fps<fps.constant*2/3 ? (fps.starArray.splice(i, 1), fps.fps += 2) : (fps.starArray[i]={speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50})) : p.x+p.speed.x}).change({property:"y", value:p.y>Stage.height+20 or p.y<-20 ? (fps.fps<fps.constant*2/3 ? (fps.starArray.splice(i, 1), fps.fps += 2) : (fps.starArray[i]={speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50})) : p.y+p.speed.y});
//5
return {old:{x:p.x-p.oldx, y:p.y-p.oldy}, p:p};
//6
}
onEnterFrame = function () {
fps.fps>fps.constant ? fps.starArray.push({speed:{x:0, y:0}, x:Stage.width/2-random(100)+50, y:Stage.height/2-random(100)+50}) : null;
//7
fps.change({property:"variable", value:fps.variable+1}, _root).change({property:"speed", value:Key.isDown(Key.SPACE) ? -150 : _ymouse}).change({func:"clear", value:null}).change({func:"lineStyle", value:[0]});
//8
for (var i = 0; i<fps.starArray.length; i++) {
//9
drawStar(moveStar(fps.starArray[i], i));
//10
}
};
setInterval(function () {
fps.change({property:"fps", value:fps.variable}).change({property:"variable", value:0});
//11
}, 1000);
//12?

(-:

Sinister Shadow
January 20th, 2006, 05:29 PM
Nice! :thumb2:

Deril
January 20th, 2006, 09:19 PM
Mines looks better..

http://www.kirupa.com/forum/showthread.php?t=205315

;)

we used similar concept..

:sigh:

NiñoScript
January 20th, 2006, 10:53 PM
im a copycat, :lol:

but, only mine makes you feel like if you were goin' fast :)

edit: only mine has a black hole in the middle of the universe too :P

Deril
January 21st, 2006, 07:32 PM
bah..

its all for fun for me anywhay.. :)

do your best and good luck..!

gvozden
January 22nd, 2006, 12:11 AM
this two have nothing in common
one is profesional
but why do you have so many vertical and horizontal lines on upper and right edge of SWF file?

NiñoScript
January 22nd, 2006, 07:58 AM
why do you have so many vertical and horizontal lines on upper and right edge of SWF file?

i don't know... that's a bug :P

this two have nothing in common
one is profesional
which one? :h:

033126B
January 23rd, 2006, 01:43 PM
wow... nice one.. i dont even know how to use prototype! can some one teach me!!!???

NiñoScript
January 23rd, 2006, 09:46 PM
of course, i can :)
just pm me

NiñoScript
December 31st, 2007, 01:03 AM
this two have nothing in common
one is profesional
but why do you have so many vertical and horizontal lines on upper and right edge of SWF file?

btw... almost 2 years later, i still would like to know which one is the proffesional one :sigh: