Author Topic: Danmakufu Q&A/Problem thread number 4  (Read 204710 times)

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Re: Danmakufu Q&A/Problem thread number 4
« Reply #990 on: April 24, 2011, 09:54:41 AM »
Greetings, I'm now trying to make a caterpillar effect where a bunch of familiars chase after an enemy, like in this picture:


(The red bullets are placeholders for the familiars)

It's all going well and stuff, but only when I use 1 enemy.
That's because I'm using common data, and don't know how to expand common data arrays.

Normally expanding arrays would go like:
Code: [Select]
bullet=bullet~[shot];
But since this is common data I'm working with, that trick won't work:
Code: [Select]
GetCommonDataDefault("EnemyX",0)=GetCommonDataDefault("EnemyX",0)~[GetX];== error

Does anyone know what the right way is to add more values to a common data array?

You're supposed to use SetCommonData in order to change stuff in common data remember? As such, it would be like this:
Code: [Select]
SetCommonData("EnemyX", GetCommonDataDefault("EnemyX", 0)~[GetX]);
To make more sense of this, here's an expanded version with a variable for clarity:
Code: [Select]
let arrayX = GetCommonDataDefault("EnemyX", 0);
arrayX = arrayX ~ [GetX];
SetCommonData("EnemyX", arrayX);
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

puremrz

  • Can't stop playing Minecraft!
Re: Danmakufu Q&A/Problem thread number 4
« Reply #991 on: April 24, 2011, 09:58:29 AM »
You're supposed to use SetCommonData in order to change stuff in common data remember? As such, it would be like this:
Code: [Select]
SetCommonData("EnemyX", GetCommonDataDefault("EnemyX", 0)~[GetX]);
To make more sense of this, here's an expanded version with a variable for clarity:
Code: [Select]
let arrayX = GetCommonDataDefault("EnemyX", 0);
arrayX = arrayX ~ [GetX];
SetCommonData("EnemyX", arrayX);

Thanks, I'll try it out. ^_^
I already found a way around using common data by making the familiars into objects, but I'm sure I'll still need to know this for later.
Full Danmakufu game "Juuni Jumon - Summer Interlude" is done!
By the same person who made Koishi Hell 1,2 (except this game is serious)
Topic: http://www.shrinemaiden.org/forum/index.php/topic,9647.0.html

Re: Danmakufu Q&A/Problem thread number 4
« Reply #992 on: April 25, 2011, 11:07:14 AM »
I'm trying to create a spellcard where lasers comes from two sides and then alternates between having collision and not colision (delayed). But no matter what I try it always ends up in an infinite loop somewhere. Any idea of how to spawn the lasers where the old laser was deleted that doesn't freeze danmakufu?

EDIT: Nevermind, fixed it.
« Last Edit: April 25, 2011, 12:31:01 PM by JmLyan »

Thaws

  • _m廿廿m_
Re: Danmakufu Q&A/Problem thread number 4
« Reply #993 on: April 25, 2011, 11:37:52 AM »
I'm trying to create a spellcard where lasers comes from two sides and then alternates between having collision and not colision (delayed). But no matter what I try it always ends up in an infinite loop somewhere. Any idea of how to spawn the lasers where the old laser was deleted that doesn't freeze danmakufu?

Here's the code: http://pastebin.com/5bjC7Jnt
The reason why it's freezing is probably because you're trying to get the coordinates of a deleted object. To solve this, store the coordinates of the old laser first before deleting.
Like
Code: [Select]

                        if(deathTime==0){
                                let tempx = Obj_GetX(obj);
                                Obj_Delete(obj);
                                break;
                        }

Using the Call*horizontal/vertical* functions are not necessary, you can simply call the task inside itself.

Have you considered using Obj_SetCollisionToPlayer?

Hope this helps.

TheTeff007

  • Best Touhou 2015!
  • So much cuteness...!
    • Youtube Channel
Re: Danmakufu Q&A/Problem thread number 4
« Reply #994 on: April 25, 2011, 10:46:30 PM »
How can I make a Bullet to Chase The player?  Currently, I'm trying to use CreateShotA and GetAngleToPlayer function, but it doesn't work and the bullet doesn't chase the player
Small Teaser of my upcoming project~

No need to call me Teff007. Teff will do just as well~

Drake

  • *
Re: Danmakufu Q&A/Problem thread number 4
« Reply #995 on: April 25, 2011, 11:08:53 PM »
Gotta learn how to object bullets, dude. Intermediate tutorial goes over object bullets nicely and it should be easy to get something to follow the player once you get how it works.
« Last Edit: April 25, 2011, 11:11:01 PM by Drake »

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

Stuffman

  • *
  • We're having a ball!
Re: Danmakufu Q&A/Problem thread number 4
« Reply #996 on: April 26, 2011, 09:17:36 AM »
[attach=1]

Code: [Select]
task ArcBullet(targetx,targety,arcdist,speed){
  math???
  CreateShotA(0,GetX,GetY,0);
  SetShotDataA(0,0,speed,???,???,0,0,WHITE05);
  FireShot(0);
}

math is what

Re: Danmakufu Q&A/Problem thread number 4
« Reply #997 on: April 26, 2011, 11:10:49 AM »
The reason why it's freezing is probably because you're trying to get the coordinates of a deleted object. To solve this, store the coordinates of the old laser first before deleting.
Like
Code: [Select]

                        if(deathTime==0){
                                let tempx = Obj_GetX(obj);
                                Obj_Delete(obj);
                                break;
                        }

Using the Call*horizontal/vertical* functions are not necessary, you can simply call the task inside itself.

Have you considered using Obj_SetCollisionToPlayer?

Hope this helps.

Actually, I fixed it by making the VerticalCall and HorizontalCall into tasks instead and putting a yield at the top of the task.

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Re: Danmakufu Q&A/Problem thread number 4
« Reply #998 on: April 26, 2011, 04:08:04 PM »
[attach=1]

Code: [Select]
task ArcBullet(targetx,targety,arcdist,speed){
  math???
  CreateShotA(0,GetX,GetY,0);
  SetShotDataA(0,0,speed,???,???,0,0,WHITE05);
  FireShot(0);
}

math is what

First find cx and cy, where (cx, cy) is the center point of the circle. Unfortunately, I don't know off the top of my head what the math for this is but it is possible with the given information.

The initial angle of the bullet would be atan2(GetY-cy, GetX-cx)+90.

For the angular velocity, you will first need to find the radius of the circle. Radius is easily determined with distance formula from the center to either point: let radius = ((GetX-cx) + (GetY-cy))^0.5. After you have the radius, you can find the circumference of the circle with let circumference = radius * 2 * 3.141592. Now that we have the circumference, we can easily determine how long it would take for the bullet to travel the whole circumference of a circle at the given speed. let time = circumference/speed. With that time, we now know how long it should take for the bullet to turn 360 degrees as well, so angular velocity can be found with let angVelocity = 360/time.

So to fill in some of the missing info for your code:
Code: [Select]
task ArcBullet(targetx,targety,arcdist,speed){
  let initialAngle = atan2(GetY-cy, GetX-cx)+90;
  let cx = ???;
  let cy = ???;
  let radius = ((GetX-cx) + (GetY-cy))^0.5;
  let circumference = radius * 2 * 3.141592;
  let time = circumference/speed;
  let angularVelocity = 360/time;

  CreateShotA(0,GetX,GetY,0);
  SetShotDataA(0,0,speed,initialAngle,angularVelocity,0,0,WHITE05);
  FireShot(0);
}

So now, all you're missing is how to get cx and cy. Maybe someone else knows the math for that, but I can't think of anything right now. As a side note, whoever decides to figure out how to get the center of the circle, make sure that what you write works with a negative arcdist as well because it is perfectly possible for arcdist to go to the other side of the line between (GetX, GetY) and (targetx, targety). Also, if you want the bullet to go counterclockwise instead of clockwise around that circle, you just need to flip the sign of angularVelocity and initialAngle would be atan2(GetY-cy, GetX-cx)-90 instead.

EDIT: Few fixes.
EDIT2: Got bored and googled some info. I think this works with negative arcdist as well, but it's untested in Danmakufu. Setting arcdist to 0 will give you a divide by 0 error, but any other value should work. I also added a parameter to choose whether the bullet should travel clockwise ("cw") or counterclockwise ("ccw"). Here's the full code:

Code: [Select]
task ArcBullet(targetx,targety,arcdist,speed,direction){
  let chordDist = ((GetX-targetx)^2 + (GetY-targety)^2)^0.5; //Finding distance between enemy and target
  let chordAngle = atan2(targety-GetY, targetx-GetX); //Finding angle from enemy to target
  let radius = (arcdist^2 + (chordDist/2)^2)/arcdist/2; //Finding length of radius
  let mx = GetX+cos(chordAngle)*chordDist/2 //Finding x-coord of midpoint of the chord
  let my = GetY+sin(chordAngle)*chordDist/2 // Finding y-coord of midpoint of the chord
  let cx = mx+cos(chordAngle+90)*(radius-arcdist); //Finding x-coord of center of circle
  let cy = my+sin(chordAngle+90)*(radius-arcdist); //Finding y-coord of center of circle
  let circumference = absolute(radius * 2 * 3.141592); //Finding the circumference of the circle
  let time = circumference/speed; //Finding the time it takes to travel the length of the circumference with given speed
  let angularVelocity = 360/time; //Finding the angular velocity to turn 360 degrees in that time
  let initialAngle = atan2(GetY-cy, GetX-cx)+90; //Finding the initial angle to fire bullet

  alternative(direction)
  case("cw"){
    //Do nothing, lol bad code.
  }
  case("ccw"){
    angularVelocity *= -1; //reverse the angular velocity
    initialAngle -=180; //turn the initial angle around 180 degrees
  }
  others {
    RaiseError("ArcBullet expected "cw" or "ccw" for direction parameter but got " + ToString(direction));
  }

  CreateShotA(0,GetX,GetY,0);
  SetShotDataA(0,0,speed,initialAngle,angularVelocity,0,0,WHITE05);
  FireShot(0);
}
« Last Edit: April 26, 2011, 06:46:23 PM by Blargel »
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

Stuffman

  • *
  • We're having a ball!
Re: Danmakufu Q&A/Problem thread number 4
« Reply #999 on: April 26, 2011, 10:46:03 PM »
Whoops, I had forgotten that I would need to specify clockwise or counterclockwise movement.

Looks like it works, thanks Blargs! Time to make some gimmicky streaming attacks :V

Drake

  • *
Re: Danmakufu Q&A/Problem thread number 4
« Reply #1000 on: April 26, 2011, 11:22:54 PM »
lololololol 1000 get lolololollooloooololol new thread

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