ForumsProgramming ForumPowerups? MC Spawn?

8 2648
mystera
offline
mystera
39 posts
Nomad

A friend and I just started to make a random game. I want to include a power-up that makes the main character move faster for let's say...8 seconds, then it disappears. How do you code that part?

Also... There are coins in the game as separate MCs. How can I make then appear randomly then at fixed places without using arrays?

Thanks.

  • 8 Replies
Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

exactly 8 seconds or approximately?

It depends on how many frames per second (FPS) your game runs, if it's 15 FPS it means your main loop looops 15 times per second, so do the math and find how much you'd have to add to a specific variable to get exactly 8 seconds

About the random coins, if you want to throw a random position for them, and then have this position permanent for them, you'll have to save these values somewhere. You could code inside the coin movie clip if that works better for you

mystera
offline
mystera
39 posts
Nomad

exactly 8 secs.

Also? I am using AS2. Is there a specific code i should use?

30FPS

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

30 FPS means your loop runs 30 times in a second

So you just have to make a "variable += 1;" it would be a value of 30 in 1 second, and 240 in 8 seconds

if(variable >= 240)
{
fasterpowerup = false;
}

mystera
offline
mystera
39 posts
Nomad

Yes. How can i make the main character "man" go faster when it comes in contact with the powerup.

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

What code are you using for the movement?

mystera
offline
mystera
39 posts
Nomad

onKeyPress x+=1

sonam
offline
sonam
840 posts
Nomad

you do realize you two are the only ones in this thread and i dont really get your game. isnt a game supposed to be in the forum games.

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

He's making a Flash game and he needs help with the programming, this is the Programming Help section after all. Although only the two of us are posting, the answer can be ueful to other people, posting here or finding it by Google

Back to the subject, I don't know why you weren't able to make your own code, it could be something like that

Normal code

if (Key.isDown(39))
{
MyCharacter._x += 1;
}


Power-Up code

//Initializing values
speed = 1;
PowerUpTimer = 0;

if (Key.isDown(39))
{
MyCharacter._x += speed;
}

if (MyCharacter.hitTest(MyPowerUp))
{
PowerUpOn = true;
PowerUpTimer = 0;
}

if(PowerUpOn == false)
{
speed = 1;
}

if (PowerUpOn == true and PowerUpTimer < 240)
{
speed = 3;
PowerUpTimer += 1;
}

if(PowerUpOn == true and PowerUpTimer >= 240)
{
PowerUpOn = false;
speed = 1;
}
Showing 1-8 of 8