mikaela Postad 28 Februari , 2010 Rapport Postad 28 Februari , 2010 I programmet kommer det ett antal fiender (2 st för tillfället). När jag skjuter på dem, är det bara den första fienden(instansen) som kan träffas. Någon som kan hjälpa mig? Koden: var poang=0; text_txt.text=poang; var enemies:Enemies_mc; /////////////////// // Skapa fiender // /////////////////// createEnemies(2); function getNewEnemies():Enemies_mc { enemies=new Enemies_mc(); enemies.alpha=Math.random()+0.5; //alpha=genomskinlighetsgrad enemies.scaleX=enemies.scaleY=(Math.random()*1)+0.5; // Randomstorlekar på gubbarna enemies.hastighet=(Math.random()*2)+0.8; //randomfart return enemies; } function getNewPosition(enemies:Enemies_mc):void { enemies.x=(Math.random()*400)+80; enemies.y=(Math.random()*40)-80; } function moveEnemies(e:Event):void { enemies=Enemies_mc(e.currentTarget); enemies.y+=enemies.hastighet; if (enemies.y>=430) { getNewPosition(enemies); poang--; text_txt.text=poang; } } function createEnemies(antal:Number):void { for (var i:uint=0; i<antal; i++) { enemies=getNewEnemies(); getNewPosition(enemies); addChild(enemies); enemies.addEventListener(Event.ENTER_FRAME,moveEnemies); } } ///////////////////////// // Monsterförflyttning // ///////////////////////// stage.addEventListener(KeyboardEvent.KEY_DOWN, flyttaMonster); stage.addEventListener(KeyboardEvent.KEY_UP, stillaMonster); function stillaMonster(keyEvent:KeyboardEvent):void { monster_mc.gotoAndStop("stilla"); } function flyttaMonster(keyEvent:KeyboardEvent):void { if (keyEvent.keyCode==Keyboard.UP) { monster_mc.gotoAndPlay("up"); createWeapon(1); } if (keyEvent.keyCode==Keyboard.DOWN) { monster_mc.gotoAndPlay("down"); } if(keyEvent.keyCode==Keyboard.RIGHT) { if (monster_mc.hitTestObject(wallRight_mc)) { monster_mc.x-=5; monster_mc.gotoAndPlay("hit"); } else { monster_mc.gotoAndPlay("right"); monster_mc.x+=10; } } if(keyEvent.keyCode==Keyboard.LEFT) { if (monster_mc.hitTestObject(wallLeft_mc)) { monster_mc.x+=5; monster_mc.gotoAndPlay("hit"); } else { monster_mc.gotoAndPlay("left"); monster_mc.x-=10; } } } ///////////////////// // Piluppskjutning // ///////////////////// function getNewWeapon():Weapon_mc { var weapon:Weapon_mc=new Weapon_mc(); weapon.hastighet=3; return weapon; } function getNewWeaponPosition(weapon:Weapon_mc):void { weapon.x=monster_mc.x+14; weapon.y=295; } function moveWeapon(e:Event):void { var weapon:Weapon_mc=Weapon_mc(e.currentTarget); weapon.y-=weapon.hastighet; if(weapon.y<-30) { poang--; text_txt.text=poang; weapon.removeEventListener(Event.ENTER_FRAME,moveWeapon); removeChild(weapon); } if(weapon.hitTestObject(enemies)) { poang++; text_txt.text=poang; weapon.removeEventListener(Event.ENTER_FRAME,moveWeapon); removeChild(weapon); getNewPosition(enemies); } } function createWeapon(antal:Number):void { var weapon:Weapon_mc; weapon=getNewWeapon(); getNewWeaponPosition(weapon); addChild(weapon); weapon.addEventListener(Event.ENTER_FRAME,moveWeapon); } Citera
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.