-1

Hi guys I'm trying to make a FPS game, I'd like some help to get a 'baddie' movieclip to randomly spawn off stage and move towards the 'Player' movieclip, I'd also like it to allow several instances of that movieclip to be on the stage at the same time and to increase the amount of them over time i.e 1 extra 'Baddie' per 30 seconds.

I can also post my current code if needed?

Thanks in advanced.

Code

I need 10 rep to post more than two links so I've put the links into one. I put my code on to PasteBin to minimise the post.

Links to my code

ziggystar
  • 28,410
  • 9
  • 72
  • 124
cm125192
  • 5
  • 1
  • 1
  • 6
  • What 3D tools are you using for the FPS? – Marty Dec 16 '13 at 21:54
  • Please post some code so we know exactly where you need the help. – Marcela Dec 16 '13 at 22:29
  • @MartyWallace, It's 2D and being made in Adobe CS6 Flash Pro, by FPS I meant First Person Shooter (just defining to save confusion with Frames Per Second). – cm125192 Dec 16 '13 at 22:38
  • @Marcela, I have 5 classes but one of which is used as a library (so I can use it elsewhere in other projects) and imported into my 'Main' class to shorten down the amount of code there. I'll edit my post and include all the classes there. – cm125192 Dec 16 '13 at 22:38
  • @Marcela I've posted the links for my code. – cm125192 Dec 16 '13 at 23:01
  • Your question seems very vague. It appears that you already know how to instantiate objects over time and add them to the display list (as evidenced by your `shootBullet` method being called on `ENTER_FRAME`). Can you please be specific about the help you need. – Marcela Dec 17 '13 at 14:26
  • I followed a tutorial to get to where I am, though it didn't show how to add enemies, which is what I'm trying to do (my biggest problem is that I have very little knowledge of actionscript, but I do of other languages its just that my project has to be done in AS3). But I think you've shed some light for me, as you just mentioned about the bullet class, theres code there that pulls several 'Bullet' moviecips to the stage at any one time (until it reaches the end). I should be able to use some of that code to put multiple 'Enemies' on the stage..... Right? – cm125192 Dec 17 '13 at 16:59
  • Correct, you'll want to create instances of `Baddy` and add them to the stage in much the same way your `Bullet` instances are being created. – Marcela Dec 17 '13 at 17:06
  • Thanks, I shall give it a go. And I've changed the 'Baddy' class to 'Enemy' as is the movieclip also. – cm125192 Dec 17 '13 at 17:16
  • I've successfully done it. Thanks for your help with my question. – cm125192 Dec 19 '13 at 22:32

1 Answers1

0

For movement, add an ENTER_FRAME Event to baddie that moves right if the enemy is on the left, left if right, down if up, up if down, etc:

baddie.addEventListener(Event.ENTER_FRAME, moveTowardsPlayer);
function moveTowardsPlayer(e:Event):void
{
    var speed = 5;
    if(e.currentTarget.x > char.x)
    {
        e.currentTarget.x -= speed;
    }else
    {
       if(e.currentTarget.x < char.x)
       {
           e.currentTarget.x += speed;
       }else
       {
           //...so on...
       }
    }
}

Also, you can make a timer with a delay of how much milliseconds you want to spawn (30,000 for 30 seconds) an enemy, and if you want multiple enemies, you can add the Event to all of them through an Array loop:

for(var i = 0; i < enemyArray.length; i++)
{
var baddie:Baddie = new Baddie; addChild(baddie); 
enemyArray.push(baddie); 
//...so on...
}

Also, Math.random() could be used for a random location of the enemy, like enemy.x = Math.random() * widthMax and enemy.y = Math.random() * heightMax

Cilan
  • 13,101
  • 3
  • 34
  • 51
  • Thanks for your contribution although I have manage to get baddies (now called enemies/enemy as it's better way to name them) to spawn and move towards the player, however not in the way I wanted them to since the all group up in a bunch and look like one after moving around a little so I will amend my code with this to see how it works out. Thanks – cm125192 Dec 20 '13 at 01:43