-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|208|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Article Home -> Advanced Techniques


 
Jayenkai
Created : 11 February 2022
 

Swirly Swoopy Baddy Waves



Warning : Hastily written "tutorial" ahead.

I made a nice enemy swirly method yesterday, for a bog-standard Shoot-em-up, and figured others might like to use it.

First off, we'll start with an array.
  --v

The main loop draws the 20 baddies, whilst the Spawn loop goes through and resets them all to 100x100

We'll give them a target to aim for, inside the Spawn loop, along with a Pause.
No movement of the baddy will happen until after the Pause has passed, so they'll all start from A, go to B, but do it one after the other.

  --v

We'll set up speed x and y variables, alongside a top speed and a turn speed.

  --v

Next, we need to make use of those.

If the baddy is to the left of the target, add turnspeed to it's X speed.
if Baddy(b,$CurrentX)<Baddy(b,$TargetX) then Baddy(b,$SpeedX)=Baddy(b,$SpeedX)+Baddy(b,$TurnSpeed)

We then do the same for Right, as well as up and down.
Once done, add a limit to the speed.
Baddy(b,$SpeedX)=Limit(Baddy(b,$SpeedX),0-Baddy(b,$TopSpeed),Baddy(b,$TopSpeed))

Before finally adding the speed to the position.

  --v

If you run it at this point, they'll swirl and swoop around the given co-odinate.
Great, we're halfway there!

You can play around with those TurnSpeed and TopSpeed values, to try out different swirly swoop effects.
Neat!

Next, we'll spawn the enemies from a random position outside of the screen. (A radius of the screen's width, at a random angle, from the middle of the screen.)



And give them a random target, too, somewhere inside the screen.


  --v

On top of that, give them a second target inside the screen, and then an end target outside the screen.

  --v

We'll need to trigger which of these we're targeting as we reach "near" to each of them.

Add a Target variable to keep track of which target we're aiming for, and initially set it to target 1.
Baddy(b,$Target)=1

When we're close enough to the target, move the target up and copy that value to the targetx,targety values.


That way, as our enemy get close enough to the target, they'll change direction and head to the next point.

  --v

We can add a simple respawn check, when the last baddy has reached the end point.
if Baddy(20,$Target)>3 then Gosub Spawn

We'll give it some random values for curve, speed and a gap, and ..
We're pretty much done.

  --v

For a more complete space shooter, make a few sets of enemies of different lengths, and see how it turns out!

 

Comments