0
\$\begingroup\$

I am looking to create a powerup such that when the "playership" object collides with it will affect the playership's speed for a few seconds, let's say 30-60 seconds. I cannot seem to figure this out on my own nor do I know what to look up, so I am asking on here for some help.

I have this for my playership:

y += sign(mouse_y - y) * global.Speedy;
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

A simple implementation can be done on the playership object. You need to track the power-up additional speed (let's call it powerup_speed) and the overall bonus duration time (powerup_countdown). On playership:

Create Event:

powerup_speed = 0;
powerup_countdown = 0;

The power-up effects occur only when the timer is a positive value. This is a countdown timer: As long as it is greater than 0, we set the bonus speed to an arbitrary value and reduce the timer by 1. Otherwise, the bonus is inactive and we reset the bonus speed:

Step Event:

if (powerup_countdown > 0)
{
    powerup_speed = 10;  // Change as needed
    powerup_countdown = powerup_countdown - 1;
}
else
{
    powerup_speed = 0;  // Reset bonus speed
}

Please note, the timer is defined as game steps, not seconds: n seconds = n * room_speed steps.

Then, you change the code snippet controlling the y position as follows:

y += sign(mouse_y - y) * (global.Speedy + powerup_speed);

This way, your power-up logic should be up and working. Applying the power-up to the playership object is just a value assignment when the collision occurs:

Collision Event:

playership.powerup_countdown = 30 * room_speed;  // Power-up lasts for 30 secs
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .