Author Topic: ※ Danmakufu Q&A/Problem thread 3 ※  (Read 490790 times)

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #870 on: October 29, 2017, 07:57:11 PM »
It's me Again!
So I'm trying to load the next scene in a Boss Scene object, but my attempts have come up futile. I have no Idea on how to do it. Can you help me?
Code: [Select]

Thanks.

I don't know what exactly you are trying to accomplish here, but here's what I recommend:

Please refer to http://sparen.github.io/ph3tutorials/ph3u2l12.html
You are misusing a number of functions as well. https://dmf.shrinemaiden.org/wiki/Functions_(ph3)#Boss_Scene_Object_Functions

ObjEnemyBossScene_StartSpell is meant to be used in the Single scripts. There is no need to use any fancy notify events since GetEnemyBossSceneObjectID() can be used in a Single script to retrieve the Boss Scene object ID.

If there are issues with my guide (i.e. it's not clear on what to do or there is something missing), please let me know.

IIRawsomeII

  • Treat me as you will
    • Rawcode Studios
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #871 on: October 30, 2017, 12:32:59 AM »
I don't know what exactly you are trying to accomplish here, but here's what I recommend:

Please refer to http://sparen.github.io/ph3tutorials/ph3u2l12.html
You are misusing a number of functions as well. https://dmf.shrinemaiden.org/wiki/Functions_(ph3)#Boss_Scene_Object_Functions

ObjEnemyBossScene_StartSpell is meant to be used in the Single scripts. There is no need to use any fancy notify events since GetEnemyBossSceneObjectID() can be used in a Single script to retrieve the Boss Scene object ID.

If there are issues with my guide (i.e. it's not clear on what to do or there is something missing), please let me know.
Sorry, I thought I clarified more. So I want to load the next stage after the boss's health bar reaches 0. All it did was well... nothing.
I did look at your guide and the functions, but it didn't give me what I need.
Let's start again

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #872 on: October 30, 2017, 03:23:29 PM »
Hello, does anyone know how to make homing player shots, just like Reimu's amulets? I almost did it myself, but i cant find the right way to target the closest enemy, the shots always target the one that spawned first

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #873 on: October 30, 2017, 05:19:48 PM »
I can't say for sure what's going wrong without seeing at least some of your code, unfortunately. Note that, for Reimu's homing amulets, you probably want a task for each individual bullet where it homes in on the enemy closest to it when it spawned. IIRC, there was a nice example of such a task near the very start of this thread.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #874 on: October 30, 2017, 06:23:28 PM »
I can't say for sure what's going wrong without seeing at least some of your code, unfortunately. Note that, for Reimu's homing amulets, you probably want a task for each individual bullet where it homes in on the enemy closest to it when it spawned. IIRC, there was a nice example of such a task near the very start of this thread.
Here's all that i used for shots. https://pastebin.com/i2ZH77sZ

I hope that's not too much code in just 1 post.
And i already read the discussion about homing shots in the beggining of the thread, but that didn't help, the shots already home, the only problem is targeting. Also i tried using GetEnemyIntersectionPosition(GetPlayerX, GetPlayerY, 1);, but i can't do anything with the array that it returns
« Last Edit: November 01, 2017, 09:19:12 PM by Helepolis »

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #875 on: October 30, 2017, 07:13:39 PM »
Sorry, I thought I clarified more. So I want to load the next stage after the boss's health bar reaches 0. All it did was well... nothing.
I did look at your guide and the functions, but it didn't give me what I need.

Danmakufu loads new singles automatically if you've added them to the Boss Scene before registering it. Just make sure that your Singles CloseScript(GetOwnScriptID()); after the boss's HP has reached 0 and the boss has deleted itself.

Hello, does anyone know how to make homing player shots, just like Reimu's amulets? I almost did it myself, but i cant find the right way to target the closest enemy, the shots always target the one that spawned first

For each shot, calculate the distance between the shot and the enemies using the Distance Formula, then lock onto the closest one.

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #876 on: October 31, 2017, 10:46:48 AM »
For each shot, calculate the distance between the shot and the enemies using the Distance Formula, then lock onto the closest one.


That was a bit tricky to do, but it helped. Thanks


Mod notice:  Please use pastebin.com for posting large pieces of code :)  this avoids unnecessary scrolling. -Hele
« Last Edit: November 01, 2017, 09:20:17 PM by Helepolis »

IIRawsomeII

  • Treat me as you will
    • Rawcode Studios
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #877 on: November 04, 2017, 12:02:28 AM »
Okay, this problem has been driving me crazy. I keep getting this error: 敵ライフを適切に返していません。(d:/Users/Rawcode/Desktop/Home/Programs/DanmanfukuPh3/script/CTCStage6Remake/Scripts/test.txt)
I've translated the Japanese and it something vaguely like Cannot Return Fairy Life or something like that.

I have tried even commenting everything in lib_FairyF but I still get the error:
Code: [Select]
let fairyTex = "././Sprites/spr_Fairy01.png";
let red = 0;

function MakeFairy(life, x, y, colour)
{
let obj = ObjEnemy_Create(OBJ_ENEMY); // Make Fairy
ObjEnemy_Regist(obj); // Start Fairy
ObjEnemy_SetLife(obj, life); // Set Life
ObjEnemy_SetIntersectionCircleToShot(obj, 0, 0, 20); // Set Shot Collision
ObjEnemy_SetIntersectionCircleToPlayer(obj, 0, 0, 20); // Set Player Collision
//FairyLoop(obj, colour); // Start loop
ObjMove_SetPosition(obj,x,y); // Set Fairy Position
return obj;
}

task FairyLoop(fairy, colour)
{
let frame = 0;
let rate = 30;
ObjPrim_SetTexture(fairy,fairyTex); // Set Texture
ObjSprite2D_SetDestRect(fairy,0,0,32,32); // Set Center
ObjSprite2D_SetDestCenter(fairy); // Set Center
while(!Obj_IsDeleted(fairy)) // While Fairy is not Deleted.
{
frame++; // Increment Frame
if(frame < rate) // Frame 1
{
ObjSprite2D_SetSourceRect(fairy, 0, colour, 32, 32 + colour);
}
else if(frame > rate && frame < rate * 2) // Frame 2
{
ObjSprite2D_SetSourceRect(fairy, 32, colour, 64, 32 + colour);
}
else if(frame > rate && frame < rate * 2) // Frame 3
{
ObjSprite2D_SetSourceRect(fairy, 64, colour, 96, 32 + colour);
}
if(frame > rate * 4){frame = 0;} // Loop Frame if...
yield;
}
}

I also have a code snippet from the test.txt script: 
Code: [Select]
#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["testinging"]
#Text["testing"]

#include "./Library/lib_FairyF.dnh"
#include "./Library/lib_Misc.dnh"
#include "script/default_system/Default_ShotConst.txt"

// Default Functions
@Initialize // Called At Start
{
MakeFairy(0,GetCenterX,GetCenterY,0);
mainTask; // Call Main Task
}
Let's start again

Chronojet ⚙ Dragon

  • The Oddity
  • 今コソ輝ケ、我ガ未来、ソノ可能性!!
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #878 on: November 04, 2017, 02:16:01 AM »
Okay, this problem has been driving me crazy. I keep getting this error: 敵ライフを適切に返していません。

(snip)

Why don't you try turning your Single script into a Stage script instead? I'm not sure what goes on in mainTask;, so I can't really say anything else about test.txt for certain, but I'm guessing you may have removed the information from @Event that takes care of the boss's life. With a Stage script, you can handle fairies without necessarily having to handle a boss.

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #879 on: November 04, 2017, 02:18:16 AM »
Okay, this problem has been driving me crazy. I keep getting this error: 敵ライフを適切に返していません。
...
I have tried even commenting everything in lib_FairyF but I still get the error:

Firstly, you're setting the enemy's life to 0, and its hitbox only appears for one frame at the top left corner of the screen.

Secondly, the issue is that you're unable to GET the fairy life. Which line does the error appear at in which script, and how are you trying to access the enemy's life at that location? The fact that you can comment out the entire library and still get the error leads me to believe that the cause of the error is outside the library.

IIRawsomeII

  • Treat me as you will
    • Rawcode Studios
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #880 on: November 04, 2017, 04:37:38 AM »
Why don't you try turning your Single script into a Stage script instead? I'm not sure what goes on in mainTask;, so I can't really say anything else about test.txt for certain, but I'm guessing you may have removed the information from @Event that takes care of the boss's life. With a Stage script, you can handle fairies without necessarily having to handle a boss.
Firstly, you're setting the enemy's life to 0, and its hitbox only appears for one frame at the top left corner of the screen.

Secondly, the issue is that you're unable to GET the fairy life. Which line does the error appear at in which script, and how are you trying to access the enemy's life at that location? The fact that you can comment out the entire library and still get the error leads me to believe that the cause of the error is outside the library.

So Thanks, Chronojet. It's apparently the fact I need the script to be a stage script. That fixed the problem. mainTask doesn't have anything in it so don't worry. Also, I guess I need boss information if I'm doing a single script without a boss.

Also thanks, Sparen. I forgot to change the life variable. Also thanks for the reminder for the hitbox placement. For your second response, Some of it was answered by Chrono. I didn't try getting the enemy life at all unless Obj_IsDeleted(); counts.

So my fairy graphic doesn't appear but I'll chock that up to the file address. Thank you two for your help.
Let's start again

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #881 on: December 02, 2017, 06:11:49 PM »
Is there any english tutorials on how to make item scripts?

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #882 on: December 03, 2017, 04:06:18 AM »
Not really, but I found a rough explanation for the basic implementation and usage of item scripts I made a while ago: https://www.shrinemaiden.org/forum/index.php/topic,16584.msg1108259.html#msg1108259

Here is an example of a simple item script I'm using:

Code: [Select]
let ITEM_PENDULUM = 1;

@Initialize{
SetDefaultBonusItemEnable(false);
let dir = GetCurrentScriptDirectory();
LoadItemData(dir~"item_data.dnh");
}

@MainLoop{}

@Event{
alternative(GetEventType())
case(EV_USER+72){
let pos = GetEventArgument(0);
if(length(pos) == 2){
TItem(ITEM_PENDULUM, pos[0], pos[1]);
}
}
case(EV_GET_ITEM){
let type = GetEventArgument(0);
let item = GetEventArgument(1);
alternative(type)
case(ITEM_PENDULUM){
SetPlayerSpell(GetPlayerSpell() + 1);
}
}
case(EV_DELETE_SHOT_TO_ITEM){
let shot = GetEventArgument(0);
let pos = GetEventArgument(1);
TItem(ITEM_PENDULUM, pos[0], pos[1]);
}
}

task TItem(type, x, y){
let obj = CreateItemU1(type, x, y, 0);
Obj_SetRenderPriorityI(obj, 60);
}

Which honestly isn't much different than what's posted in the above link, but is filled with actual data. This is also an item script for player-specific items and not connected to a full game with many items, so you should look for other examples (it shouldn't be much different than just having many item cases and extra behaviour).
« Last Edit: December 03, 2017, 04:25:49 AM by Drake »

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

PyuDi

  • daily touhou~
  • danmakufu!
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #883 on: December 03, 2017, 06:30:11 AM »
Hi. I am trying to play this script, but ph3 always freezes... Anybody know what's the problem? ( I assume that it is related to infinite loop )

https://pastebin.com/DLyLwi8Z




Welcome to our forum. Please put large code like this in pastebin links. I helped you out this time  ;)  -Helepolis
« Last Edit: December 03, 2017, 07:18:36 AM by Helepolis »

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #884 on: December 03, 2017, 07:19:39 AM »
Hi. I am trying to play this script, but ph3 always freezes... Anybody know what's the problem? ( I assume that it is related to infinite loop )

https://pastebin.com/DLyLwi8Z
You didn't yield your while loop which starts at line 64

PyuDi

  • daily touhou~
  • danmakufu!
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #885 on: December 03, 2017, 07:29:42 AM »
You didn't yield your while loop which starts at line 64

Thanks :)

R. P. Genocraft

  • Craftsman of absolute unpredictability
  • Boundary of productive and lazy
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #886 on: December 03, 2017, 09:38:13 AM »
I don't know if I'll be able to explain this right, please bear with me :V
I want to fire a curvy laser at a constant speed and angular velocity(probably 3 and 1 but I might change it) but I want it to go through the player's current position no matter where on the screen. To do that I'd need a way to calculate an angle for it to be fired based on its position, speed, angular velocity and the player's position, how can I do that?

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #887 on: December 03, 2017, 09:50:18 AM »
Not really, but I found a rough explanation for the basic implementation and usage of item scripts I made a while ago: https://www.shrinemaiden.org/forum/index.php/topic,16584.msg1108259.html#msg1108259

Here is an example of a simple item script I'm using:

Which honestly isn't much different than what's posted in the above link, but is filled with actual data. This is also an item script for player-specific items and not connected to a full game with many items, so you should look for other examples (it shouldn't be much different than just having many item cases and extra behaviour).

Thanks, it helped a lot.

I don't know if I'll be able to explain this right, please bear with me :V
I want to fire a curvy laser at a constant speed and angular velocity(probably 3 and 1 but I might change it) but I want it to go through the player's current position no matter where on the screen. To do that I'd need a way to calculate an angle for it to be fired based on its position, speed, angular velocity and the player's position, how can I do that?

If you want the laser to fly only in one direction (like a regular shot) you can set its angle using GetAngleToPlayer, ang then just make it look curvy with another task. But if you want it to follow the player, that would require some complicated calculations, which i dont know

R. P. Genocraft

  • Craftsman of absolute unpredictability
  • Boundary of productive and lazy
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #888 on: December 03, 2017, 10:19:20 AM »
If you want the laser to fly only in one direction (like a regular shot) you can set its angle using GetAngleToPlayer, ang then just make it look curvy with another task. But if you want it to follow the player, that would require some complicated calculations, which i dont know
It's pretty crazy, so let me explain again. I want the laser to PASS THROUGH the player's position when it's fired, so that it will hit them directly unless they dodge, no matter where on the screen. The speed and angular velocity will be constant(3 and 1, though I might change them).

CrestedPeak9

  • Fangame Advocate
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #889 on: December 03, 2017, 02:58:53 PM »
It's pretty crazy, so let me explain again. I want the laser to PASS THROUGH the player's position when it's fired, so that it will hit them directly unless they dodge, no matter where on the screen. The speed and angular velocity will be constant(3 and 1, though I might change them).

The simplest way is to check for when the laser's angle is the same as its angle to the player, then set angular velocity to 0, which causes a sort of unfurling effect.
From your description you want to laser to curve constantly, which actually does make it only possible to hit the player's position from certain angles.
When you have a set angular velocity, think of it as the laser travelling in a set circle, which is angled based off its spawn angle.

If you're willing to change the angular velocity or speed, then it's some very scary mathematics things which varies depending on the pattern you want to make.
Lunatic 1cc: EoSD, PCB, IN, MoF, TD, DDC, LoLK, HSiFS, WBaWC

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #890 on: December 03, 2017, 03:24:27 PM »
It's me again since I was not very active in danmakufu after my last post until this week...
I know it sounds stupid but how to let bullet shoot from downwards ?
#Edit : And shoot from left and shoot from right are also needed, thanks  :3
« Last Edit: December 03, 2017, 03:53:15 PM by BananaCupcakey »
Just keep it neutral :3

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #891 on: December 03, 2017, 04:30:18 PM »
I don't know if I'll be able to explain this right, please bear with me :V
I want to fire a curvy laser at a constant speed and angular velocity(probably 3 and 1 but I might change it) but I want it to go through the player's current position no matter where on the screen. To do that I'd need a way to calculate an angle for it to be fired based on its position, speed, angular velocity and the player's position, how can I do that?

I don't know Danmakufu, but the math should look something like this (using degrees as an angle unit):

starting angle = 90? - ( arccos( ( distance / 2 ) / radius  ) )

starting angle is the difference in angle between a straight line shot and the intended arc shot.
distance is the distance between the player and the firing point.
radius is the radius of the arc.

radius = speed / ( angular velocity / 360? ) / 2π

Depending on what units they are in, you might need to multiply speed and/or angular velocity by a constant.

Make sure that radius is greater than half of the maximum possible distance, or the arccos() may blow up on you.
« Last Edit: December 03, 2017, 04:49:21 PM by niektory »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #892 on: December 17, 2017, 03:52:59 AM »
Greetings again! I've been doing kind of well with Danmakufu and I've playing around with several patterns. I have two questions to ask for the experts of Danmakufu

1. Since some danmakufu patterns require trigonometry, can you...
?Teach me how to harness the power of trigonometry myself (Note: I already went to Sparen's Danmakufu Tutorial site to figure it out but it seems very hard to pull off if you want to do it yourself, especially if you don't have a graphing calculator or how to plug it into the script itself)
?Give me just few examples of trigonometry in action in Danmakufu (this is optional)

2. I've noticed that Imperishable Night bosses use a lot of spell circle shaped familiars to shoot for them. ESPECIALLY Marisa in stage 4. Can you possibly teach me how to summon said familiars in Danmakufu so I can incorporate it in my own scripts?

Thank you in advance if you manage to help me out~♫

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #893 on: December 17, 2017, 05:53:50 AM »
1. Since some danmakufu patterns require trigonometry, can you...
?Teach me how to harness the power of trigonometry myself (Note: I already went to Sparen's Danmakufu Tutorial site to figure it out but it seems very hard to pull off if you want to do it yourself, especially if you don't have a graphing calculator or how to plug it into the script itself)
?Give me just few examples of trigonometry in action in Danmakufu (this is optional)
I'm just going to post a bunch of links for this one
?Khan Academy (learning trig in case you are unfamiliar with the basics)
https://www.khanacademy.org/math/trigonometry
?Parametric Equations and various curves (Example equations, etc)
https://sites.math.washington.edu/~aloveles/Math124Fall2017/m124ParametricEquationsIntro.pdf
http://www-history.mcs.st-and.ac.uk/Curves/Curves.html

2. I've noticed that Imperishable Night bosses use a lot of spell circle shaped familiars to shoot for them. ESPECIALLY Marisa in stage 4. Can you possibly teach me how to summon said familiars in Danmakufu so I can incorporate it in my own scripts?

You can either create additional enemies or you can use render objects. If they need a hitbox, I recommend using additional enemies. Essentially, create enemies the same was as with a boss, but set the health, etc. manually. Refer to https://dmf.shrinemaiden.org/wiki/Enemy_Object_Functions
« Last Edit: December 17, 2017, 05:55:32 AM by Sparen »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #894 on: December 17, 2017, 05:56:23 AM »
1.

The trigonometry I use most often boils down to the following:
-Using atan2 to get angles from arbitrary points is the big one
-You can do some cool things with the oscillatory properties of sin and cos. Its worth noting that you can apply them to things other then angle or position, so you could have a bullet pattern where the velocity or density went back and forth.
-Spawning bullets in a circle. It essentially works like this:
CreateShotA1(X+radius*cos(angle),Y+radius*sin(angle),otherparametersthatareirrelevanthere)
Where X and Y are the X and Y coordinates of the center of the circle and angle is the angle from the center of the circle to the bullet.

I'm sure there are other clever uses for trigonometry, like drawing stars Sanae style or making interesting curves with parametric equations, but the above are the vast majority of what I do with trigonometry.
2.

Basically, familiars work by creating and registering an enemy object. Then you can have them move around just like a boss or a bullet would and use stuff like CreateShotOA1 to spawn bullets at their position. You could use a render object if you don't need them to take damage, but then you can't use the helpful Move Object functions on them. By default, they'll be invulnerable, but you can give them a hitbox[Again, in much the same way as you would give a boss at hitbox] if you want them to be destroyable. If you want them to be destroyable only if the player is focussed, like in Imperishable Night, then you'll have to have a way to detect whether the player is focussed or not. I don't believe Sparen's tutorials yet extend to how virtual keys work, but Helepolis' player tutorial has a relevant section on detecting player focus state at around 7:45. As for the spell circle itself, you should just be able to set their graphic to be that of a spell circle, just like when rendering a boss.  This site has some useful assets in general, including nice looking spell circles in a variety of colours[You want the link that leads to th3_7008].
« Last Edit: December 17, 2017, 07:36:53 PM by Arcvasti »

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #895 on: December 17, 2017, 08:44:32 PM »
I'm just going to post a bunch of links for this one
?Khan Academy (learning trig in case you are unfamiliar with the basics)
https://www.khanacademy.org/math/trigonometry
?Parametric Equations and various curves (Example equations, etc)
https://sites.math.washington.edu/~aloveles/Math124Fall2017/m124ParametricEquationsIntro.pdf
http://www-history.mcs.st-and.ac.uk/Curves/Curves.html

Well you answered my second question quite nicely, but I was wondering how to actually PLUG IN the equations in a Danmakufu script. Say I would want to implement the Devil's Curve pattern for my shots (http://www-history.mcs.st-and.ac.uk/Curves/Devils.html) how would I go about that?

Sparen

  • Danmakufu Artist
  • Git ready, git set, PUUSH!
    • AFCDTech
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #896 on: December 18, 2017, 01:09:12 AM »
Well you answered my second question quite nicely, but I was wondering how to actually PLUG IN the equations in a Danmakufu script. Say I would want to implement the Devil's Curve pattern for my shots (http://www-history.mcs.st-and.ac.uk/Curves/Devils.html) how would I go about that?

For parametric equations such as the Lissajous curve, you simply parameterize with the target coordinate as origin:
e.g.
Code: [Select]
CreateShotA1(GetEnemyX(objBoss)+120*cos(angleT*3), GetEnemyY(objBoss)+90*sin(angleT*5), 1, angleT*3, graph, 0);
The Devil's Curve has the following parametric representation, according to Wolfram Mathworld:
x = cos(t)*sqrt((a^2*sin(t)^2 - b^2*cos(t)^2)/(sin(t)^2 - cos(t)^2)
y = sin(t)*sqrt((a^2*sin(t)^2 - b^2*cos(t)^2)/(sin(t)^2 - cos(t)^2)

Therefore, you could do the following in Danmakufu:
Code: [Select]
task DevilCurve{
        let t = 0;
        // Control the curve parameters
        let a2 = 1;
        let b2 = 2;
        // Control the scaling parameters
        let scalex = 64;
        let scaley = 64;
        while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
            let s_num = a2*sin(t)*sin(t) - b2*cos(t)*cos(t);
            let s_denom = sin(t)*sin(t) - cos(t)*cos(t);
            let s_all = (s_num/s_denom)^0.5;
            CreateShotA2(ObjMove_GetX(objBoss) + scalex*cos(t)*s_all, ObjMove_GetY(objBoss) + scaley*sin(t)*s_all, 0, t*2, 0.01, 3, DS_BALL_BS_SKY, 10);
            t++;
            yield;
        }
    }
Above, I've used three variables (s_num, s_denom, and s_all) for sanity purposes, as the mess under the square root is hard to check for errors

I've attached a working example. Note that I've added a loop and some other stuff to showcase the drawing of the curve itself.
« Last Edit: December 18, 2017, 01:11:12 AM by Sparen »

JDude :3

  • tururu
  • boy with code
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #897 on: December 20, 2017, 11:11:16 AM »
My objective is to create a shape and move that shape like is was a bullet (without deforming), but I don't know an easier way (or an obvious way) to do that.  ???

PS: My level of knowledge is pretty basic, please be patient with me.
"dnh is hard" - said no one
"dnh is bullshit" - everyone making a creative pattern

Drake

  • *
Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #898 on: December 20, 2017, 10:38:43 PM »
It depends on what the shape is. This is not an easy problem and involves some thinking and math, but we do have some existing implementations lying around.

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Re: ※ Danmakufu Q&A/Problem thread 3 ※
« Reply #899 on: December 20, 2017, 11:14:46 PM »
Generally, the best way to do that is to have a bunch of bullets defined around a central point in such a way that they form a shape and then fire the bullets at an angle calculated from that central point. If you wanted to do more then just fire the shape, like having it rotate after firing or something, then its probably best to have a task that maintain's the shape's formation relative to the central bullet of the shape.

The actually hard part is forming a shape. Circles are definitely easiest. Triangles and squares aren't that bad either, although I've had a bit of a hard time making the corners look nice. Sanae-style stars are more difficult.

Code: [Select]
function BulletCircle(X, Y, angle, radius, numBullets) {
    let increment = 360/numBullets;
    ascent(i in 0..numBullets){
if(Obj_IsDeleted(bossObj)){return;} //Prevents bullets from spawning after the script finishes
        let obj = CreateShotA1(X+radius*cos(i*increment),Y+radius*sin(i*increment),3,angle,DS_RICE_S_YELLOW,30);
    }
}

Here's an example of how firing a circle as a single bullet would work. The important part is firing all the bullets in the same direction, but from different starting locations.