~Hakurei Shrine~ > Rika and Nitori's Garage Experiments
I'm really lost @_@
<< < (8/12) > >>
Nuclear Cheese:

--- Quote from: yuritakehashi on May 19, 2009, 11:57:08 PM ---I was wondering how you would do this pattern:

A large number of bullets appear and stay in the air
for a period of time then come at the enemy.

I'm not sure how to get individual bullets that are looped to all come together in a homing fashion.
Is using looped bullets even the right way to go about this?
Pweeze help!

--- End quote ---


--- Quote from: Drake on May 20, 2009, 12:07:54 AM ---Object Bulleeeeeeetttttsss.

It's easy. You would just loop a task that makes object bullets a bajillion times, with random x positions and start a counter. When the counter hits whatever number, they all home in.

--- End quote ---

As Drake mentions, this can be done with object bullets.  Specifically, an array of object bullets.

It can also be achieved using the CreateShotA() ... FireShot() functions.  The trick is to set them up, as you're launching them, so that they'll all change to move towards the player at the same time.  Like this:


--- Code: ---#TouhouDanmakufu
#Title[Target]
#Text[by Nuclear Cheese]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
   let count;
   let count2;

   @Initialize
   {
      count = 80;
      count2 = 360;
      SetLife(700);
      LoadGraphic("script\img\ExRumia.png");
      SetGraphicRect(64, 1, 127, 64);
      SetMovePosition02(GetCenterX(), 120, 60);
      SetScore(150000);
      SetTimer(60);
      SetDamageRate(15, 8);
      SetInvincibility(150);
      CutIn(YOUMU, "Target", 0, 0, 0, 0, 0);

      SetShotDirectionType(ABSOLUTE);
   }

   @MainLoop
   {
      // When count reaches zero, a new shot will spawn.
      // This is supressed if count2 is less than zero, since that is the phase of the attack where the shots start
      // moving.
      count--;
      if (count <= 0 && count2 >= 0)
      {
         // ID for CreateShotA ... entirely arbitrary, can be reused once a shot is fired.
         let id = 1;

         // This while loop chooses a random place to spawn the shot, ensuring that it is at least
         // 50 units away from the player's current position
         let bx;
         let by;
         bx = rand(GetClipMinX(), GetClipMaxX());
         by = rand(GetClipMinY(), GetClipMaxY());
         while ((((GetPlayerX() - bx) ^ 2 + (GetPlayerY() - by) ^ 2) ^ 0.5) < 50)
         {
            bx = rand(GetClipMinX(), GetClipMaxX());
            by = rand(GetClipMinY(), GetClipMaxY());
         };

         // Make sure we're using player-relative directions for the shots
         SetShotDirectionType(PLAYER);

         // Create the shot
         CreateShotA(id, bx, by, 10);

         // Initially, the shot stays still
         SetShotDataA(id, 0, 0, 0, 0, 0, 0, WHITE01);

         // This changes the shot to move to the player.
         // The time is count2 + 30.  Since count2 decrements every frame, this ensures that all bullets start moving
         //   at the same time.
         // Since our shot direction type, set above, is PLAYER, the bullet will re-aim for the player's position
         //   because we give it a new angle of zero.
         SetShotDataA(id, count2 + 30, 0, 0, 0, 0.02, 4, BLUE21);

         // This command actually spawns the shot
         FireShot(id);

         // Delay until the next shot
         count = 5;
      }

      // count2 deals with the timing of entire waves.  When count2 is >= 0, the boss is spawning bullets.  When
      // count2 drops below zero, the boss stops spawning bullets, and the bullets will all start moving when
      // count2 reaches -30 (due to how SetShotDataA is set up previously).  When count2 reaches -60, it is reset and
      // the pattern starts over again.
      count2--;
      if (count2 <= -60)
      {
         count2 = 300;
      }

      SetCollisionA(GetX(), GetY(), 32);
      SetCollisionB(GetX(), GetY(), 24);
   }

   @DrawLoop
   {
      SetTexture("script\img\ExRumia.png");
      DrawGraphic(GetX(), GetY());
   }

   @Finalize
   {
      DeleteGraphic("script\img\ExRumia.png");
      let amnt = 15;
      if (GotSpellCardBonus)
      {
         amnt = 45;
      }
      let i = 0;
      while (i < amnt)
      {
         CreateItem(ITEM_SCORE, GetCenterX() + prand(-100, 100), 100 + prand(-60, 60));
         i++;
      }
   }
}
--- End code ---

Basically, for each shot it spawns, it sets up the delay until it starts moving (the second SetShotDataA command) so that they all start moving at the same time.



Looks like another vote for me doing an object bullets tutorial :V

... I'll get to it when I stop feeling lazy.  Working full-time has its downsides. :-\
Halca:
Well, that's almost what I'm looking for, but I don't want the positions to be random.
I wanted the bullets to appear around the enemy in a circle, have a delay, then all attack at once.

I really just want to know how to stop the movement of a bullet after it's been created
and how to make several move at the enemy all together.
I hope that makes sense >_<
JormundElver:

--- Quote from: Nuclear Cheese on May 20, 2009, 02:05:06 AM ---Looks like another vote for me doing an object bullets tutorial :V

--- End quote ---

I can do one if you can't find the time, although my tutorials would probably end up being about as eloquent as my scripting:  Not very.


--- Quote from: yuritakehashi on May 20, 2009, 05:40:33 PM ---Well, that's almost what I'm looking for, but I don't want the positions to be random.
I wanted the bullets to appear around the enemy in a circle, have a delay, then all attack at once.

I really just want to know how to stop the movement of a bullet after it's been created
and how to make several move at the enemy all together.
I hope that makes sense >_<

--- End quote ---


--- Code: ---    task RoundAttack(){

let Length = 75;

let Angular = 0;

let RollerX;
let RollerY;

ascent(a in 0..10){
    RollerX = GetPlayerX + Length * cos(Angular+a*36);
    RollerY = GetPlayerY + Length * sin(Angular+a*36);
       CreateShotA(0, RollerX, RollerY, 30);
       SetShotDataA(0, 0, 0, atan2(GetPlayerY - RollerY, GetPlayerX - RollerX), 0, 0, 0, WHITE01);
       SetShotDataA(0, 60, NULL, NULL, 0, 0.03, 2, WHITE01);
       FireShot(0);
     }

}
--- End code ---

I coded some of this in the post so I hope to god it all works (ok I just tested it, it does), but here's basically whats going on.  This task, when used, will fire a single ring of shots around the player with a delay lasting half a second; then for another half second they should be still.  At that point they'll accelerate towards the center where the player was; slowly, but to a max speed of 2.

How this is done is through dreaded trigonometry, the variables are all set as usual for the task, and ascent 0..10 gives us 10 shots of course.

RollerX = GetPlayerX + Length * cos(Angular+a*36);
RollerY = GetPlayerY + Length * sin(Angular+a*36);

are the variables I used to define the X and Y position of each shot, they get put in place for the X and Y coordinates in the CreateShotA line.  The math is relatively simple, for each of them you take the players coordinates and add the length (defined earlier as 75, this is how far away from the player these will be appearing; the same length should be used for both the X and Y math).  Then multiply by the cos (or sin, depending on whether or not we solve for X or Y) of Angular (initially defined as 0 for simplicity, this can be whatever) plus a*36; because a is increasing by 1 for every shot, multiplying each by 36 ensures a full ring of shots is made (cause 360 etc. blah blah).

RollerX and RollerY are now the coordinates of the shots, but now you gotta aim them at the player.  atan2(GetPlayerY - RollerY, GetPlayerX - RollerX) solves for this.  Since I'm actually bad at trig I can't really do well to explain the inner working of this function, but basically atan2(y - y2, x - x2) will point whatever's position is y2 and x2 at y and x when used for angle.  So now our ring of shots are all aimed at the middle of their own circle.

Second SetShotDataA will fire at the 60th frame these shots are out, make sure angle is NULL and not 0 or else all the bullets will fly to the right (cause 0 -----> is that way); and we just add a little acceleration, a cap on the speed and these shots will go from being still to speeding up towards their target.

Hope this helps.
Halca:
I was wondering, how do you go about
creating and controlling familiars?
Naut:
I dunno, lol.
Navigation
Message Index
Next page
Previous page

Go to full version