Bullet
(extends Object)
Overview
Bullets are the most important part of any attack, and as such, they can be complicated to set up. This section will first explain creating generic bullets without making new files for them, then detail how to extend them.
Note
By default, all bullets have a scale of 2, and an origin of 0.5, 0.5. This means
its collider, sprite, and any other children will be relative to the topleft
of the bullet’s width and height, which are automatically set to the dimensions
of its sprite if the bullet is initiated with a path specified (in other words,
making all children relative to the topleft of the bullet’s sprite). When making
any bullet’s collider, remember that it will be scaled 2x because of this.
Class Members
(see Object for inherited members)
Useful Functions
Overridable Functions
Internal / Class Overrides
Bullet:update()(fromObject:update())Bullet:draw()(fromObject:draw())
Variables
Class Reference
- class Bullet(x, y, texture)
Creates a new instance of the Bullet class.
- Parameters
x,y (numbers) – The position of the bullet.
texture (string) – The path to the bullet’s texture.
- setSprite(texture[, speed, loop, on_finished])
Sets the
spriteof the bullet to the specified path, and changes the bullet’swidthandheightvariables to the dimensions of the sprite.speed,loop, andon_finishedwill be passed into the sprite’splay()function.- Parameters
texture (string) – The path to the bullet’s texture.
speed (number) – The animation delay between frames.
loop (boolean) – Whether the animation should loop.
on_finished (function) – A function to call when the animation finishes.
- isBullet(id)
Returns whether the bullet is the bullet with the specified ID, or extends it.
- Parameters
id (string) – The id of the bullet.
- Returns
result (boolean)
- getTarget()
Returns the target of the
attacker(if any), orANY.- Returns
target (string or
PartyBattler)
- getDamage()
Returns the
damageof the bullet. Ifdamageisnil, will calculate damage based on the enemy’s attack.- Returns
damage (number)
- test()
This is a test function.
- Parameters
arg1 (string) – The first argument.
arg2 (number) – The second argument.
- Returns
result (number)
result2 (string)
- onDamage(soul)
Called when the player collides with the bullet without invincibility frames. By default, damages the player and sets their invincibility frames.
- Parameters
soul (Soul) – The
Soulthat the bullet collided with.
- onCollide(soul)
Called when the player collides with the bullet, regardless of invincibility frames. By default, calls
Bullet:onDamage(soul)if the player does not have active invincibility frames, and removes the bullet ifdestroy_on_hitis true.- Parameters
soul (Soul) – The
Soulthat the bullet collided with.
- onWaveSpawn(wave)
Called when the bullet is spawned by a wave, via
Wave:spawnBullet(). By default, does nothing.- Parameters
wave (Wave) – The
Wavethat spawned the bullet.
- sprite
The
Spriteof the bullet, set byBullet:setSprite.
- wave
A reference to the current
Wavethat is active. Gets defined afterinit(), but only if spawned throughWave:spawnBullet(); otherwise, it is never defined.
- attacker
A reference to the
EnemyBattlerassociated with the bullet. Gets defined afterinit(), but only if spawned throughWave:spawnBullet(); otherwise, it is never defined.
- damage
Amount of damage the bullet does. If not provided, the game will calculate damage based on the enemy’s attack.
- destroy_on_hit
Whether the bullet will be removed when it collides with the player.
trueby default.
- remove_offscreen
Whether the bullet will be removed when it goes offscreen.
trueby default.
- tp
The amount of TP (in percentage) the player gains from grazing the bullet. Defaults to 1.6 (1/10th of a defend).
- time_bonus
The number of frames, based on 30fps, that the wave’s length will be reduced by when grazing the bullet. Apparently this is a mechanic in Deltarune.
- grazed
(Internal) Whether the bullet has already been grazed. (reduces graze rewards)