~Hakurei Shrine~ > Rika and Nitori's Garage Experiments
Some noobish questions
(1/6) > >>
Cyclone722:
Hi, I'm new to danmakufu and to the forum. I understand some basics, but I have a few questions.

1.How to make a boss stop and/or switch attacks.(not switching spellcards)
2.How to get the angle to the player when bullet not fired directly from the boss.
3.Correct way to add bgm (just can't seem to figure it out.)

I have looked through the tutorials here, if I just missed something could you point it out for me?
 
I'll probably have more questions later.
Iryan:
I can at least help with your second question.

To aim a regular bullet directly at the player from anywhere, use the command SetShotDirectionType(PLAYER);, then fire it at an angle of 0. It will cause danmakufu to measure the angle differently; 0? is not straight to the right now, but directly towards the player. After you fired the bullet, use the command SetShotDirectionType(ABSOLUTE); to return the measurement of angles to its usual state.
Stuffman:
1) Well I suppose you know that most code for spellcards looks sorta like this:


--- Code: ---@Mainloop
  if frame==100 {
    do the attack
  }
  frame++;
  if frame>100 {
    frame=0
  }
}
--- End code ---

If you want to alternate attacks it would be more like...


--- Code: ---@Mainloop
  if frame==100 {
    do the attack
  }
  if frame==200 {
    do a different attack
  }
  frame++;
  if frame>200 {
    frame=0
  }
}
--- End code ---

Or maybe you want to have it change depending on certain circumstances, in which case it would look more like


--- Code: ---@MainLoop
  if frame==100 && attacktype==1
    do the attack
  }
  if frame==100 && attacktype==2
    do a different attack
  }
  if life<100 or whatever your condition is
    attacktype=2
  }
  frame++
  if frame>100{
    frame=0
  }
}
--- End code ---

3) Put BGM in the same folder as your script.

--- Code: ---let music=GetCurrentScriptDirectory~"insert filename here";
--- End code ---
at the top with the rest of your variables, then

--- Code: ---PlayMusic(music);
--- End code ---
in @Initialize or something.
Cyclone722:
Ah, Thanks!
Closing everything in the bracket things gets confusing sometimes.



Nuclear Cheese:

--- Quote from: Iryan on April 28, 2009, 08:59:43 PM ---I can at least help with your second question.

To aim a regular bullet directly at the player from anywhere, use the command SetShotDirectionType(PLAYER);, then fire it at an angle of 0. It will cause danmakufu to measure the angle differently; 0? is not straight to the right now, but directly towards the player. After you fired the bullet, use the command SetShotDirectionType(ABSOLUTE); to return the measurement of angles to its usual state.

--- End quote ---

Unfortunately, this only works when fired directly from the boss's position (at least in my experience).  SetShotDirectionType(PLAYER) bases the shot angle off of the angle from the boss to the player, regardless of where you're firing the shot from.

In order to get the correct angle from another position, you need to use a quick bit of trigonometry.

Here's a simple example:

--- Code: ---let dy = GetPlayerY() - bullet_y;
let dx = GetPlayerX() - bullet_x;
let a = atan2(dy, dx);
// fire shot from (bullet_x, bullet_y) at angle a
CreateShot01(bullet_x, bullet_y, 1.0, a, RED01, 0);
--- End code ---

Basically, I first store the difference between the player's coordinates and the bullet's coordinates in dx and dy.  Next, I use the function atan2() to get the angle.
atan2() is a special form of the arctangent function (see wikipedia for generic info) which takes the X and Y differences, and produces the angle.


--- Quote from: Cyclone722 on April 28, 2009, 08:53:17 PM ---Hi, I'm new to danmakufu and to the forum. I understand some basics, but I have a few questions.

3.Correct way to add bgm (just can't seem to figure it out.)

--- End quote ---

Use PlayMusic() to start it playing.  The song will loop back to the beginning when it reaches the end.

To use these, you need to pass it the name of the music file.  For instance, if you have a music file awesome_sound.mp3 in the same directory as your script, you can do something like this:


--- Code: ---// Store the file's name so it is easier to reference later
let music_file = GetCurrentScriptDirectory() ~ "awesome_sound.mp3";

@Initialize
{
   // stuff
   PlayMusic(music_file);
   // stuff
}
--- End code ---

You can use DeleteMusic to stop the music playing.
Navigation
Message Index
Next page

Go to full version