Create Simple Bullet

From LuaSTG Wiki
Jump to navigation Jump to search

A create simple bullet node creates a simple bullet in the gameplay area. This nodes will call the New() function to initialize a simple bullet.


Simple Bullet[edit | edit source]

A simple bullet is a basic object class (see Game Object) in LuaSTG. This means that it has attributes that a common LuaSTG object has , like .x .y .vx .vy .rot .img .colli .hide etc. This also means it can be created via a call to the New() function.

The path a simple bullet will travel in is relatively simple. After a bullet is shot, it can go on a straight line, or on a parabola if the acceleration is set to non-zero. It also has a optional max velocity parameter that limits its speed below a point when an acceleration is present.


Parameters[edit | edit source]

A list of parameters of simple bullets that can be set is shown below:

Parameters Function
Style (LuaSTG object class) The type of the bullet
Color (number) The color of the bullet E.g. COLOR_BLUE which are numerical constants. Some types of bullets like ball_huge do not have full color range
Position (number, number) The initial position of the bullet. In other words, this is the location where the bullet will be at when it is just spawned. This sets the .x .y attributes of a bullet
Velocity (number) The initial speed of the bullet. This is the speed the bullet will travel at when it is just spawned. The unit of this is LuaSTG distance unit per frame. This and the angle parameter below together set the .vx .vy attributes of a bullet
Angle (number) The initial angle of the bullet. This is the angle the bullet will travel at when it is just spawned. The unit of this is degrees. Angle starts rightwards and go counter-clockwise. The rotation of the bullet image will be set with this parameter as well
Aim to player (boolean) whether or not an offset Angle(self, player) will be added to initial angle. Setting this to true is a way to implement aimed bullets
Rotation velocity (number) the speed in which the bullet image rotates counter-clockwise. This sets the corresponding .omiga attribute of the bullet. The unit for this parameter is degrees per frame
Stay on Create (boolean) If true, the bullet will not move during the mist phase. More precisely, the tasks under the bullet will not get executed until the bullet mist phase is over. See Stay on Create section below for more details
Destroyable (boolean) If true, the bullet will not get canceled by player bomb/miss bullet clear. This sets the .group attribute of the bullet to GROUP_INDES instead of GROUP_ENEMY_BULLET. However, the bullet can still be deleted at the end of spell card, or by clear bullet node if Clear indestructible is set to true
Time (number)
Rebound (boolean)
Acceleration (number) Magnitude of acceleration. Acceleration will be added to the velocity of a bullet each frame. The unit for this is LuaSTG distance unit per frame squared
Accel Angle (number) Angle of the acceleration direction
Max Velocity (number) The maximum speed of the bullet. If the speed of bullet goes above this limit, its speed will get cut to this number with movement angle unchanged. The limit is infinite if this is set to 0
Shuttle (boolean)


Default Parameters[edit | edit source]

By default, the bullet will be spawned at (self.x, self.y). This is a position associated with the object represented by self. In spell cards, this will be the position of the boss; in enemy definition, this will be the position of the enemy; in custom bullets, this will be position of the bullet.

Stay on Create[edit | edit source]

It is essential to know how bullets stay or do not stay on create in Touhou series in order to understand this parameter in LuaSTG. The parameter stay on create is connected to a special effect of spawning bullets introduced in the Touhou series by Zun, which is a mist-like effect displayed before the bullets are spawned, creating a natural visual fade-in effect for bullets, comparing to older arcade games in the same category.


Bullet Mist in Touhou[edit | edit source]

This may easily go unnoticed by a player, but bullet mist in Touhou series comes in with many variants.

Depending on the pattern, bullets may be moving or staying at its spawning position during the bullet mist phase. An example of the first case is the Border of Waves and Particles in th11: Subterranean Animism. In that spell, the bullets do not have collision boxes in their entire mist phase, but has already started their movement at the time, allowing the player to survive in a circular-shaped safespot around the boss where the bullets are still in mist phase.

The size of bullet mist is changed sometimes, one of the most noticeable cases being Eternal Meek from th06: Embodiment of Scarlet Devil. You can try to generate some random bullets in LuaSTG and compare the differences between the pattern in EoSD and in LuaSTG.

In some places the bullet mist is not used, like in Sakuya's nons & spells in stage 5 of EoSD.

Finally, sometimes the bullet mist of bullets lasts a longer or shorter period of time than it normally would. See gravity danmaku fairies in the second half of EoSD stage 3 for example.


Bullet Mist in LuaSTG[edit | edit source]

In LuaSTG, if Stay on create is true, the bullet will not move during the mist phase. The parameter Stay on create does not turn on/off the bullet mist, but it controls whether or not the tasks under a bullet will be executed during the mist phase, including the movement of the bullet. If this parameter is set to true, the bullet will not actually do anything until the mist phase is over.

By default, every bullet in LuaSTG will have a bullet mist phase of around 12 frames when it is spawned. Unfortunately, there is no way to turn off this effect, or changing the size and duration of the effect in a satisfactory way. It is possible to set the value of .timer attribute of a bullet to 10 to shorten the mist phase (as the game checks .timer to decide how far is the bullet into the mist phase), but what that does is to only play the second half of the mist animation, cutting the animation in half instead of playing it faster.


Pitfall[edit | edit source]

Extra caution should be taken when dealing with attributes of a bullet with stay on create parameter set to true. At the final frame of bullet mist phase, many attributes of the bullets will be automatically set, whether you want it or not. For examples, .colli will be set to true (which cannot be turned off until tasks start executing in the next frame), .layer and the image of the bullet will be set as well.


Side Effect[edit | edit source]

Create bullet node will be translated to something like "last = New(_straight, ...)" when the script is run. As you may see, the code assigns the new bullet created to a global variable last. In case you want to keep a reference to the bullet just created, you can save the value of last in another variable for later use.

With this side effect, it is possible to add a task to a newly created simple bullet by writing "task.New(last, function() ... end)". Though you would need to be careful about the use of global variable self inside the task.


Deletion[edit | edit source]

When a bullet is deleted, a bullet deletion effect will be left where the bullet was deleted, by default. In some versions of LuaSTG, the deletion animation will keep moving in the same velocity as the velocity of the deleted bullet in the last frame.