Fangames > Programming Questions

Help with a boss attack

(1/3) > >>

LoneTree_tv:
I'm trying to make that attack where the boss shoots a cherry at you that leaves behind more cherries, and at the end all the cherries shoot off in random directions.
But, I'm doing it an excruciatingly painful way where I assign every cherry a different variable and, at the end, make every cherry variable go in a different direction.
Also, when the spawning cherry goes offscreen, it spawns the cherries at x=0, y=0.
How do I make it like it is in all the other games?

lawatson:
Make the cherry that follows the player into an object, make the cherries that stay still when spawned into another object, and then when you want them to shoot off, execute the code:

with fruit{
    direction=random(360);
    speed=8;
}

Change fruit to the name of the stand-still fruit that will move, and change speed to whatever fits your liking.

If some of the cherries spawn at 0,0, that means that the cherry that spawned them got deleted. Make sure that it doesn't get deleted when it goes outside the room.

LoneTree_tv:
Thanks so much!  :atkHappy:
so, just to help me understand in future situations, does "with" make it so it runs the code
for every instance of "fruit"?

lawatson:
Yes. when you use the with statement, it affects every object and runs the code from their perspective. Another neat thing you can do is address the object running the with statement while within the code itself, like so:
with fruit{
    direction=point_direction(x,y,other.x,other.y);
}
and that'll make its direction actually go towards the object that's running the with statement.

LoneTree_tv:
Thanks for all the help. I got the attack working, and I started using "with" a lot more.
There's only one problem, my game freezes before I can even load the game data,
it just freezes on the "Loading Game Data ... " window, so all of my progress is gone.  :atkCry: Oh well.

Navigation

[0] Message Index

[#] Next page

Go to full version