| Scraps | ©2008-2013 *SophieHoulden |
stage.quality = "low"
var keyLEFT = false
var keyRIGHT = false
var keySPACE = false
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKP)
function onKP(evt:KeyboardEvent){
switch(evt.keyCode){
case 37:
keyLEFT = true
break;
case 39:
keyRIGHT = true
break;
case 32:
keySPACE = true
break;
}
}
stage.addEventListener(KeyboardEvent.KEY_UP,onKR);
function onKR(evt:KeyboardEvent){
switch(evt.keyCode){
case 37:
keyLEFT = false
break;
case 39:
keyRIGHT = false
break;
case 32:
keySPACE = false
break;
}
}
var xMove = 0;
var yMove = 0;
var shipSpeed = 4;
var pArray = new Array();
for (var i=0;i<400;i++){
var parti = new Star()
parti.x=Math.random()*550
parti.y=Math.random()*400
pArray.push([parti,1]);
thing.addChild(pArray[pArray.length-1][0])
pArray[pArray.length-1][1]=Math.random()+1
pArray[pArray.length-1][0].width= 2*pArray[pArray.length-1][1]
pArray[pArray.length-1][0].height = pArray[pArray.length-1][0].width
}
var jetArray = new Array();
var astArray = new Array();
for (i=0;i<100;i++){
var asty = new Aster();
asty.x
Math.random()*10000)-5000
asty.y
Math.random()*10000)-5000
asty.width
Math.random()*70)+150
asty.height = asty.width
asty.rotation = Math.random()*360
astArray.push(asty)
thing.addChild(astArray[astArray.length-1]);
}
stage.addEventListener(Event.ENTER_FRAME,onTick);
function onTick(evt:Event){
if (keySPACE){
shipSpeed = 16
}else{
shipSpeed = 4
}
if (keyLEFT){
spaceship.rotation-=5
}
if (keyRIGHT){
spaceship.rotation+=5
}
xMove = -Math.cos((spaceship.rotation/180)*Math.PI)
yMove = -Math.sin((spaceship.rotation/180)*Math.PI)
jetArray.push([275+(xMove*7),200+(yMove*7)])
thing2.graphics.clear()
thing2.graphics.moveTo(275,200)
var lineWidth = 15
var lineAlpha = 1
for (i=jetArray.length-1;i>jetArray.length-15;i--){
if (i>0){
jetArray[i][0]+=xMove*4*shipSpeed
jetArray[i][1]+=yMove*4*shipSpeed
lineWidth--
lineAlpha-=0.04
thing2.graphics.lineStyle(lineWidth,0xFF00FF,lineAlpha);
thing2.graphics.lineTo(jetArray[i][0],jetArray[i][1])
}
}
for (i=0;i<
Array.length;i++){
pArray[i][0].x+= xMove * pArray[i][1] * shipSpeed
pArray[i][0].y+= yMove * pArray[i][1] * shipSpeed
if (pArray[i][0].x<0){
pArray[i][0].x+=550
}
if (pArray[i][0].x>550){
pArray[i][0].x-=550
}
if (pArray[i][0].y<0){
pArray[i][0].y+=400
}
if (pArray[i][0].y>400){
pArray[i][0].y-=400
}
}
for (i=0;i<astArray.length;i++){
astArray[i].x+= xMove * 3 * shipSpeed
astArray[i].y+= yMove * 3 * shipSpeed
if (astArray[i].x<-5000){
astArray[i].x+=10000
}
if (astArray[i].x>5000){
astArray[i].x-=10000
}
if (astArray[i].y<-5000){
astArray[i].y+=10000
}
if (astArray[i].y>5000){
astArray[i].y-=10000
}
}
}
Or maybe as a screensaver or something
I was wondering, how did you make the fire out of the rocket?
basically its an array of points that move from the ships, and I use the graphics drawing stuff to join the dots
onClipEvent(enterFrame) {
myParent = "dot1";
_x = _root[myParent]._x + Math.cos(((Math.atan2(_y-_root[myParent]._y,_x-_root[myParent]._x)*Math.PI)/180));
_y = _root[myParent]._y + Math.sin(((Math.atan2(_y-_root[myParent]._y,_x-_root[myParent]._x)*Math.PI)/180));
}
or something like that?
for the init:
var lineArray = new Array();then every frame:
//add mouse position to the array
lineArray.push(new Point(mouseX,mouseY));
//clear the last frames graphics
myMovieClip.graphics.clear();
//set up the graphics for a new line
myMovieClip.graphics.lineStyle(1,0x000000);
myMovieClip.graphics.moveTo(lineArray[0].x,lineArray[0].y);
//go through each point in the array and draw between them
for (var i=0;i<lineArray.length;i++){
myMovieClip.graphics.lineTo(lineArray[i].x,lineArray[i].y)
lineArray[i].x++
}
the 'lineArray[i].x++' bit is just to show you can move the points together in the loop, as with my spaceship one, the ship isnt moving, everything else is
also, sorry its in AS3 but its just what I'm used to now, it shouldnt be too hard to convert to AS2 I dont think, its just preperty names that have changed, and I dont think you need the .graphics subobject